void rtc_settime(void) { unsigned long year = 12; unsigned long month = 5; unsigned long date = 1; unsigned long hour = 12; unsigned long min = 0; unsigned long sec = 0; unsigned long weekday= 3; year = (((year/100)<<8) + (((year/10)%10)<<4) + (year%10)); month = ( ((month/10)<<4)+ (month%10) ); date = ( ((date/10)<<4) + (date%10) ); weekday = (weekday%10); hour = ( ((hour/10)<<4) + (hour%10) ); min = ( ((min/10)<<4) + (min%10) ); sec = ( ((sec/10)<<4) + (sec%10) ); rtc_enable(true); BCDSEC = sec; BCDMIN = min; BCDHOUR = hour; BCDDAYWEEK = date; BCDDAY = weekday; BCDMON = month; BCDYEAR = year; rtc_enable(false); printf("reset success\r\n"); }
static int rtc_suspend(struct platform_device *pdev, pm_message_t state) { ticnt_save = readb(rtc_base + S3C2410_TICNT); rtc_enable(pdev, 0); return 0; }
/* * Test command to set RTC Alarm time, and start RTC: rtc alarm <rtc_alarm_time> * * @param[in] argc Number of arguments in the Test Command (including group and name) * @param[in] argv Table of null-terminated buffers containing the arguments * @param[in] ctx The context to pass back to responses */ void rtc_alarm_tcmd(int argc, char *argv[], struct tcmd_handler_ctx *ctx) { struct rtc_config config = { 0 }; struct device *rtc_dev; uint32_t keys = 0; if (argc == RTC_ARG_NO && isdigit(argv[RTC_TIME_IDX][0])) { keys = irq_lock(); tcmd_user_alarm_rtc_val = (uint32_t)strtoul(argv[RTC_TIME_IDX], NULL, 10); test_rtc = 0; config.alarm_val = tcmd_user_alarm_rtc_val; config.alarm_enable = true; config.cb_fn = test_rtc_interrupt_fn; alarm_pending = true; irq_unlock(keys); rtc_dev = device_get_binding(RTC_DRV_NAME); assert(rtc_dev != NULL); rtc_dev->driver_data = (void *)ctx; rtc_enable(rtc_dev); rtc_set_config(rtc_dev, &config); rtc_set_alarm(rtc_dev, config.alarm_val); } else { TCMD_RSP_ERROR(ctx, "Usage: rtc alarm <alarm_time>"); } }
static int rtc_resume(struct platform_device *pdev) { rtc_enable(pdev, 1); writeb(ticnt_save, rtc_base + S3C2410_TICNT); return 0; }
void auto_init(void) { #ifdef MODULE_BOARD_DISPLAY extern void lcd_init(); lcd_init(); DEBUG("DISP OK"); #endif #ifdef MODULE_DISPLAY_PUTCHAR extern void init_display_putchar(); init_display_putchar(); DEBUG("DISP OK"); #endif #ifdef MODULE_HWTIMER DEBUG("Auto init hwtimer module.\n"); hwtimer_init(); #endif #ifdef MODULE_VTIMER DEBUG("Auto init vtimer module.\n"); vtimer_init(); #endif #ifdef MODULE_UART0 DEBUG("Auto init uart0 module.\n"); board_uart0_init(); #endif #ifdef MODULE_RTC DEBUG("Auto init rtc module.\n"); rtc_init(); rtc_enable(); #endif #ifdef MODULE_SHT11 DEBUG("Auto init SHT11 module.\n"); sht11_init(); #endif #ifdef MODULE_GPIOINT DEBUG("Auto init gpioint module.\n"); gpioint_init(); #endif #ifdef MODULE_CC110X DEBUG("Auto init CC1100 module.\n"); cc1100_init(); #endif #ifdef MODULE_LTC4150 DEBUG("Auto init ltc4150 module.\n"); ltc4150_init(); #endif #ifdef MODULE_MCI DEBUG("Auto init mci module.\n"); MCI_initialize(); #endif #ifdef MODULE_PROFILING extern void profiling_init(void); profiling_init(); #endif main(); }
void rtc_realtime_display(void) { int counter = 0; unsigned long usec = 0; rtc_enable(true); rtc_ticktime_enable(true); while( counter < 5) { if(usec != BCDSEC) { usec = BCDSEC; rtc_print(); counter++; } } rtc_ticktime_enable(false); rtc_enable(false); }
static void ui_button_rtc_init(void) { irq_register_handler(button_rtc_irq, BUTTON_RTC_IRQ, BUTTON_RTC_IRQ_PRIORITY); rtc_init(&AVR32_RTC, RTC_OSC_32KHZ, 7); rtc_set_top_value(&AVR32_RTC, 0); rtc_enable_interrupt(&AVR32_RTC); rtc_enable(&AVR32_RTC); }
void main(void) { struct device *rtc_dev; struct rtc_config config; u32_t now; printk("LMT: Quark SE PM Multicore Demo\n"); k_fifo_init(&fifo); build_suspend_device_list(); ipm = device_get_binding("alarm_notification"); if (!ipm) { printk("Error: Failed to get IPM device\n"); return; } rtc_dev = device_get_binding("RTC_0"); if (!rtc_dev) { printk("Error: Failed to get RTC device\n"); return; } rtc_enable(rtc_dev); /* In QMSI, in order to save the alarm callback we must set * 'alarm_enable = 1' during configuration. However, this * automatically triggers the alarm underneath. So, to avoid * the alarm being fired any time soon, we set the 'init_val' * to 1 and the 'alarm_val' to 0. */ config.init_val = 1; config.alarm_val = 0; config.alarm_enable = 1; config.cb_fn = alarm_handler; rtc_set_config(rtc_dev, &config); while (1) { /* Simulate some task handling by busy waiting. */ printk("LMT: busy\n"); k_busy_wait(TASK_TIME_IN_SEC * 1000 * 1000); now = rtc_read(rtc_dev); rtc_set_alarm(rtc_dev, now + (RTC_ALARM_SECOND * IDLE_TIME_IN_SEC)); printk("LMT: idle\n"); k_fifo_get(&fifo, K_FOREVER); } }
static void ui_display_init_rtc(void) { irq_register_handler(display_rtc_irq, DISPLAY_RTC_IRQ, DISPLAY_RTC_IRQ_PRIORITY); rtc_init(&AVR32_RTC, RTC_OSC_32KHZ, RTC_PSEL_32KHZ_1HZ - 1); rtc_enable_wake_up(&AVR32_RTC); rtc_set_top_value(&AVR32_RTC, 0); rtc_enable_interrupt(&AVR32_RTC); rtc_enable(&AVR32_RTC); }
static void setup_rtc(void) { struct rtc_config cfg; /* Configure RTC device. RTC interrupt is used as 'wake event' when we * are in C2LP state. */ cfg.init_val = 0; cfg.alarm_enable = 0; cfg.alarm_val = 0; cfg.cb_fn = NULL; rtc_dev = device_get_binding(CONFIG_RTC_0_NAME); rtc_enable(rtc_dev); rtc_set_config(rtc_dev, &cfg); }
static void setup_rtc(void) { struct rtc_config config; rtc_dev = device_get_binding("RTC_0"); config.init_val = 0; config.alarm_enable = 0; config.alarm_val = ALARM; config.cb_fn = rtc_interrupt_fn; rtc_enable(rtc_dev); rtc_set_config(rtc_dev, &config); }
void main(void) { struct rtc_config config; PRINT("Power Management Demo\n"); config.init_val = 0; config.alarm_enable = 0; config.alarm_val = RTC_ALARM_SECOND; config.cb_fn = NULL; rtc_dev = device_get_binding(CONFIG_RTC_DRV_NAME); rtc_enable(rtc_dev); rtc_set_config(rtc_dev, &config); create_device_list(); while (1) { task_sleep(SLEEPTICKS); } }
void main(void) { struct rtc_config config; struct device *rtc_dev; printk("Test RTC driver\n"); rtc_dev = device_get_binding(CONFIG_RTC_0_NAME); config.init_val = 0; config.alarm_enable = 1; config.alarm_val = ALARM; config.cb_fn = test_rtc_interrupt_fn; rtc_enable(rtc_dev); rtc_set_config(rtc_dev, &config); while (1) { /* do nothing */ } }
void rtc_init_qt( void ) { // Disable all interrupts. */ Disable_global_interrupt(); // Register the RTC interrupt handler to the interrupt controller. INTC_register_interrupt(&rtc_irq, AVR32_RTC_IRQ, AVR32_INTC_INT0); // Initialize the RTC // Frtc = 1024Hz rtc_init(&AVR32_RTC, RTC_OSC_32KHZ, 4); // Set top value to 0 to generate an interrupt every seconds */ rtc_set_top_value(&AVR32_RTC, 1); // Enable the interrupts rtc_enable_interrupt(&AVR32_RTC); // Enable the RTC rtc_enable(&AVR32_RTC); // Enable global interrupts Enable_global_interrupt(); }
void rtc_init_qt( void ) { // Init touch_states controller_clear(); // Disable all interrupts Disable_global_interrupt(); // Register the RTC interrupt handler to the interrupt controller. BSP_INTC_IntReg( &rtc_irq, AVR32_RTC_IRQ, AVR32_INTC_INT1); // Initialize the RTC rtc_init(&AVR32_RTC, RTC_OSC_32KHZ, 4); rtc_set_top_value(&AVR32_RTC, 1); // Enable the interrupts rtc_enable_interrupt(&AVR32_RTC); // Enable the RTC rtc_enable(&AVR32_RTC); // Enable global interrupts Enable_global_interrupt(); }
static int __devinit rtc_probe(struct platform_device *pdev) { int ret; struct rtc_device *rtc; struct resource *res; rtc_alarmno = platform_get_irq(pdev, 0); if (rtc_alarmno < 0) { dev_err(&pdev->dev, "No irq for alarm\n"); return -ENOENT; } rtc_tickno = platform_get_irq(pdev, 1); if (rtc_tickno < 0) { dev_err(&pdev->dev, "No irq for rtc tick\n"); return -ENOENT; } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (res == NULL) { dev_err(&pdev->dev, "Failed to get memory region resource\n"); return -ENOENT; } rtc_mem = request_mem_region(res->start, res->end - res->start + 1, pdev->name); if (rtc_mem == NULL) { dev_err(&pdev->dev, "Failed to reserve memory region\n"); ret = -ENOENT; goto err_no_res; } rtc_base = ioremap(res->start, res->end - res->start + 1); if (rtc_base == NULL) { dev_err(&pdev->dev, "Failed ioremap()\n"); ret = -EINVAL; goto err_nomap; } rtc_enable(pdev, 1); rtc_setfreq(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1); rtc = rtc_device_register("my2440", &pdev->dev, &rtc_fops, THIS_MODULE); if (IS_ERR(rtc)) { dev_err(&pdev->dev, "Cannot attach rtc\n"); ret = PTR_ERR(rtc); goto err_nortc; } rtc->max_user_freq = 128; platform_set_drvdata(pdev, rtc); return 0; err_nortc: rtc_enable(pdev, 0); iounmap(rtc_base); err_nomap: release_resource(rtc_mem); err_no_res: return ret; }
void controller_init(uint32_t fcpu_hz, uint32_t fhsb_hz, uint32_t fpbb_hz, uint32_t fpba_hz) { static const gpio_map_t QT60168_SPI_GPIO_MAP = { { QT60168_SPI_SCK_PIN, QT60168_SPI_SCK_FUNCTION }, // SPI Clock. { QT60168_SPI_MISO_PIN, QT60168_SPI_MISO_FUNCTION }, // MISO. { QT60168_SPI_MOSI_PIN, QT60168_SPI_MOSI_FUNCTION }, // MOSI. { QT60168_SPI_NPCS0_PIN, QT60168_SPI_NPCS0_FUNCTION } // Chip Select NPCS. }; // SPI options. spi_options_t spiOptions = { .reg = QT60168_SPI_NCPS, .baudrate = QT60168_SPI_MASTER_SPEED, // Defined in conf_qt60168.h. .bits = QT60168_SPI_BITS, // Defined in conf_qt60168.h. .spck_delay = 0, .trans_delay = 0, .stay_act = 0, .spi_mode = 3, .modfdis = 1 }; // Assign I/Os to SPI. gpio_enable_module(QT60168_SPI_GPIO_MAP, sizeof(QT60168_SPI_GPIO_MAP) / sizeof(QT60168_SPI_GPIO_MAP[0])); // Set selection mode: variable_ps, pcs_decode, delay. spi_selectionMode(QT60168_SPI, 0, 0, 0); // Enable SPI. spi_enable(QT60168_SPI); // Initialize QT60168 with SPI clock Osc0. spi_setupChipReg(QT60168_SPI, &spiOptions, fpba_hz); // Initialize QT60168 component. qt60168_init(fpba_hz); // Init timer to get key value. rtc_init_qt(); // Invalidate the timeout already cpu_set_timeout(0, &cpu_time_clear_wheel); } void rtc_init_qt( void ) { // Init touch_states controller_clear(); // Disable all interrupts cpu_irq_disable(); // Register the RTC interrupt handler to the interrupt controller. irq_register_handler(rtc_irq, AVR32_RTC_IRQ, 0); // Initialize the RTC rtc_init(&AVR32_RTC, RTC_OSC_32KHZ, 4); rtc_set_top_value(&AVR32_RTC, 1); // Enable the interrupts rtc_enable_interrupt(&AVR32_RTC); // Enable the RTC rtc_enable(&AVR32_RTC); // Enable global interrupts cpu_irq_enable(); }
int main (void) { // Variables -- Misc const twim_options_t twi_option_GYRO = twi_opt_GYRO; const twim_options_t twi_option_ACC = twi_opt_ACC; const twim_options_t twi_option_MAGN = twi_opt_MAGN; // Variables -- Control system float prev_e_z = 0; float prev_e_roll = 0; float prev_e_pitch = 0; float prev_e_yaw = 0; float eint_z = 0; float eint_roll = 0; float eint_pitch = 0; float eint_yaw = 0; float pitch_ederiv = 0; // Error derivative float roll_ederiv = 0; float prev_deriv_e_roll = 0; float yaw_ederiv = 0; float z_ederiv = 0; float e = 0; float dt; // Time between samples unsigned long t1 = 0; unsigned long t2 = 0; float u1, u2, u3, u4 = 0; float m1, m2, m3, m4 = 0; float g_force = 240; int xcount = 0; float gain = 1; int time_to_update_data = 0; int deriv_count=0; const usart_options_t usart_option = usart_opt; const usart_options_t usart_option_2 = usart_opt_2; // Setting up the board pcl_configure_clocks(&pcl_freq_param); board_init(); // Initialize Bluetooth configure_AT(FPBA_HZ, usart_option); irq_initialize_vectors(); cpu_irq_enable(); Disable_global_interrupt(); // Initialize interrupt vectors. INTC_init_interrupts(); INTC_register_interrupt(&usart_int_handler, USART_IRQ, AVR32_INTC_INT0); USART->ier = AVR32_USART_IER_RXRDY_MASK; // Enable all interrupts. Enable_global_interrupt(); // Enable Ultrasonic sensors enable_Ultrasonic(); // Initialize motors initialize_PWM(); tc_start(tc1, PWM_MOTOR1_CHANNEL); tc_start(tc0, PWM_MOTOR2_CHANNEL); tc_start(tc1, PWM_MOTOR3_CHANNEL); tc_start(tc1, PWM_MOTOR4_CHANNEL); // Waits for button press here after battery is connected while (gpio_get_pin_value(GPIO_PUSH_BUTTON_0)); delay_ms(1000); /* while(1){ while (motor2_speed<60) { motor2_speed += 1; update_Motors(); delay_ms(300); } while (motor2_speed>0) { motor2_speed -= 1; update_Motors(); delay_ms(300); } } while (gpio_get_pin_value(GPIO_PUSH_BUTTON_0));*/ //delay_ms(3000); // Initialize RTC //AVR32_RTC->ctrl & AVR32_RTC_CTRL_BUSY_MASK = 0; rtc_init(&AVR32_RTC, RTC_OSC_32KHZ, 1); rtc_enable(&AVR32_RTC); // Initialize IMU parts initialize_IMU(); // TESTING ONLY float test_array[2000]; float test_array_2[2000]; float test_array_3[2000]; for (int k = 0; k < FILTER_LENGTH; k++){ FIFO_deriv_roll[k] = roll; } time_to_update_data = 0; // Control system code begins while(1) { t1 = rtc_get_value(&AVR32_RTC); // Current time in ms dt = ((float)(t1-t2))*0.001*0.125; // dt in seconds if (t1 < t2) // Timer overflowed { dt = ((float)(t1 + rtc_get_top_value(&AVR32_RTC))*0.001*0.125); } t2 = t1; get_Angles(); //pitch = 0; yaw = 0; e = des_z-z; //calculating height error eint_z = eint_z + ((e+prev_e_z)/2)*dt; //calculate error integral term z_ederiv = (e - prev_e_z)/dt; //calculate error derivative term u1 =(KP_Z*e) + (KI_Z*eint_z) + (KD_Z*z_ederiv)+g_force; //calculating control output prev_e_z=e; //ROLL e = des_roll-roll; //calculating roll error eint_roll = eint_roll + ((e+prev_e_roll)/2)*dt; //calculate error integral term prev_e_roll=e; for (int i = 0; i < (FILTER_LENGTH - 1); i++) { FIFO_deriv_roll[i] = FIFO_deriv_roll[i+1]; } FIFO_deriv_roll[FILTER_LENGTH-1] = e; roll_ederiv = (FIFO_deriv_roll[FILTER_LENGTH-1] - FIFO_deriv_roll[0])/(FILTER_LENGTH*dt); u2 =(KP_ROLL*e) + (KI_ROLL*eint_roll) + (KD_ROLL*roll_ederiv); //calculating control output if(xcount < 2000){ test_array[xcount] = roll_ederiv; test_array_2[xcount] = roll; test_array_3[xcount] = g_roll; } xcount++; //PITCH e = des_pitch-pitch; //calculating pitch error eint_pitch = eint_pitch + ((e+prev_e_pitch)/2)*dt; //calculate error integral term pitch_ederiv = (e - prev_e_pitch)/dt; //calculate error derivative term u3 =(KP_PITCH*e) + (KI_PITCH*eint_pitch) + (KD_PITCH*pitch_ederiv); //calculating control output prev_e_pitch=e; //YAW e = des_yaw-yaw; //calculating yaw error eint_yaw = eint_yaw + ((e+prev_e_yaw)/2)*dt; //calculate error integral term yaw_ederiv = (e - prev_e_yaw)/dt; //calculate error derivative term u4 =(KPYAW*e) + (KIYAW*eint_yaw) + (KDYAW*yaw_ederiv); //calculating control output prev_e_yaw=e; //MOTOR SPEEDS m1=(0.25*u1+0.5*u2+0.25*u4)*gain; m2=(0.25*u1+0.5*u3-0.25*u4)*gain; m3=(0.25*u1-0.5*u2+0.25*u4)*gain; m4=(0.25*u1-0.5*u3-0.25*u4)*gain; if (m1 > 95) m1 = 95; else if (m1 < 5) m1 = 5; if (m2 > 95) { m2 = 95; } else if (m2 < 5) { m2 = 5; } if (m3 > 95) { m3 = 95; } else if (m3 < 5) { m3 = 5; } if (m4 > 95) { m4 = 95; } else if (m4 < 5) { m4 = 5; } motor1_speed = m2; //m2 motor2_speed = m1; //m3 motor3_speed = m4; //m4 motor4_speed = m3; //m1..... the imu was turned 90 degrees.... update_Motors(); //Bluetooth Send if (time_to_update_data > 3) { // Get Ultrasonic data update_Ultrasonic(); // Send out update through Bluetooth meas_roll = roll; meas_pitch = pitch; meas_yaw = yaw; transmitted_data(); time_to_update_data = 0; received_data(); } else { delay_ms(7); } time_to_update_data++; } }
void sys_time_init() { #if (SYS_TIMER_SOFT_RTC == 0) rtc_enable(SYS_TIMER_RTC); #endif //SYS_TIMER_SOFT_RTC == 0 }
static int hisik3_pm_enter(suspend_state_t state) { unsigned long flage = 0; switch (state) { case PM_SUSPEND_STANDBY: case PM_SUSPEND_MEM: break; default: return -EINVAL; } if (has_wake_lock(WAKE_LOCK_SUSPEND)) { printk("hisik3_pm_enter has wake lock\n"); return -EAGAIN; } if (unlikely(in_atomic())) { pr_warn("PM: in atomic[%08x] at %d\n", preempt_count(), __LINE__); } local_irq_save(flage); hisik3_pm_save_gic(); if (unlikely(in_atomic())) { pr_warn("PM: in atomic[%08x] at %d\n", preempt_count(), __LINE__); } #ifdef CONFIG_CACHE_L2X0 hisik3_pm_disable_l2x0(); #endif if (unlikely(in_atomic())) { pr_warn("PM: in atomic[%08x] at %d\n", preempt_count(), __LINE__); } /*set pmu to low power*/ pmulowpower(1); if (unlikely(in_atomic())) { pr_warn("PM: in atomic[%08x] at %d\n", preempt_count(), __LINE__); } /* here is an workround way to delay 40ms * make sure LDO0 is poweroff very clean */ mdelay(40); /* protect timer0_0 timer0_1 and disable timer0 clk */ protect_timer0_register(); #ifdef CONFIG_LOWPM_DEBUG /*set io to lowpower mode*/ ioshowstatus(1); setiolowpower(); ioshowstatus(1); /*set pmu to low power mode*/ pmulowpower_show(1); pmulowpowerall(1); pmulowpower_show(1); #endif if (unlikely(in_atomic())) { pr_warn("PM: in atomic[%08x] at %d\n", preempt_count(), __LINE__); } edb_putstr("[PM]Enter hilpm_cpu_godpsleep...\r\n"); #ifdef CONFIG_LOWPM_DEBUG /*time enable*/ timer0_0_enable(); /*rtc*/ rtc_enable(); #endif if (unlikely(in_atomic())) { pr_warn("PM: in atomic[%08x] at %d\n", preempt_count(), __LINE__); } hilpm_cpu_godpsleep(); if (unlikely(in_atomic())) { pr_warn("PM: in atomic[%08x] at %d\n", preempt_count(), __LINE__); } /* *the status has been changed in fastboot, *it causes difference with kernel's status, */ pmctrl_reinit(); pctrl_reinit(); sysctrl_reinit(); /*uart init.*/ edb_reinit(); if (unlikely(in_atomic())) { pr_warn("PM: in atomic[%08x] at %d\n", preempt_count(), __LINE__); } #ifdef CONFIG_LOWPM_DEBUG /*restore debug uart0*/ debuguart_reinit(); /*disable timer0*/ timer0_0_disable(); /*restore pmu config*/ pmulowpowerall(0); #endif if (unlikely(in_atomic())) { pr_warn("PM: in atomic[%08x] at %d\n", preempt_count(), __LINE__); } /*PMU regs restore*/ pmulowpower(0); if (unlikely(in_atomic())) { pr_warn("PM: in atomic[%08x] at %d\n", preempt_count(), __LINE__); } /* restore timer0_0 timer0_1 and enable timer0 clk */ restore_timer0_register(); flush_cache_all(); if (unlikely(in_atomic())) { pr_warn("PM: in atomic[%08x] at %d\n", preempt_count(), __LINE__); } #ifdef CONFIG_CACHE_L2X0 hisik3_pm_enable_l2x0(); #endif if (unlikely(in_atomic())) { pr_warn("PM: in atomic[%08x] at %d\n", preempt_count(), __LINE__); } hisik3_pm_retore_gic(); if (unlikely(in_atomic())) { pr_warn("PM: in atomic[%08x] at %d\n", preempt_count(), __LINE__); } local_irq_restore(flage); pr_notice("[PM]Restore OK.\r\n"); return 0; }
/*! * \brief main function : do init and loop (poll if configured so) */ int main( void ) { char temp[20]; char *ptemp; static const gpio_map_t USART_GPIO_MAP = { {EXAMPLE_USART_RX_PIN, EXAMPLE_USART_RX_FUNCTION}, {EXAMPLE_USART_TX_PIN, EXAMPLE_USART_TX_FUNCTION} }; // USART options static const usart_options_t USART_OPTIONS = { .baudrate = 57600, .charlength = 8, .paritytype = USART_NO_PARITY, .stopbits = USART_1_STOPBIT, .channelmode = 0 }; pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); // Assign GPIO pins to USART0. gpio_enable_module(USART_GPIO_MAP, sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0])); // Initialize USART in RS232 mode at 12MHz. usart_init_rs232(EXAMPLE_USART, &USART_OPTIONS, 12000000); // Welcome sentence usart_write_line(EXAMPLE_USART, "\x1B[2J\x1B[H\r\nATMEL\r\n"); usart_write_line(EXAMPLE_USART, "AVR32 UC3 - RTC example\r\n"); usart_write_line(EXAMPLE_USART, "RTC 32 KHz oscillator program test.\r\n"); // Disable all interrupts. */ Disable_global_interrupt(); // The INTC driver has to be used only for GNU GCC for AVR32. #if __GNUC__ // Initialize interrupt vectors. INTC_init_interrupts(); // Register the RTC interrupt handler to the interrupt controller. INTC_register_interrupt(&rtc_irq, AVR32_RTC_IRQ, AVR32_INTC_INT0); #endif // Initialize the RTC if (!rtc_init(&AVR32_RTC, RTC_OSC_32KHZ, RTC_PSEL_32KHZ_1HZ)) { usart_write_line(&AVR32_USART0, "Error initializing the RTC\r\n"); while(1); } // Set top value to 0 to generate an interrupt every seconds */ rtc_set_top_value(&AVR32_RTC, 0); // Enable the interrupts rtc_enable_interrupt(&AVR32_RTC); // Enable the RTC rtc_enable(&AVR32_RTC); // Enable global interrupts Enable_global_interrupt(); while(1) { if (print_sec) { // Set cursor to the position (1; 5) usart_write_line(EXAMPLE_USART, "\x1B[5;1H"); ptemp = print_i(temp, sec); usart_write_line(EXAMPLE_USART, "Timer: "); usart_write_line(EXAMPLE_USART, ptemp); usart_write_line(EXAMPLE_USART, "s"); print_sec = 0; } } }