int main() { target_init(); HAL_SET_PIN_DIRECTIONS(); wdt_disable(); led_on( LED_ALL ); hal_delay( 500 ); led_off( LED_ALL ); dbo_open(0, 38400); TiRtc * rtc; rtc = rtc_construct( (void *)&g_rtc, sizeof(g_rtc) ); rtc = rtc_open( rtc, NULL, NULL, 0x00 ); rtc_start( rtc ); while(1) {} // if not use listener while (!rtc_expired(rtc)) { //do something; } // rtc_expired now }
void osx_tlsche_execute( TiOsxTimeLineScheduler * sche ) { rtc_setinterval( sche->timer, 0, 2, 0x01); //定时周期为一秒 hal_enable_interrupts(); rtc_start( sche->timer ); while (1) { osx_tlsche_evolve( sche, NULL ); set_sleep_mode(SLEEP_MODE_IDLE); sleep_enable(); sleep_cpu(); sleep_disable(); } // rtc_stop( sche->rtc ); }
int main(void) { RT_TASK *maint; int maxcnt; printf("GIVE THE NUMBER OF INTERRUPTS YOU WANT TO COUNT: "); scanf("%d", &maxcnt); start_rt_timer(0); if (!(maint = rt_task_init(nam2num("MAIN"), 1, 0, 0))) { printf("CANNOT INIT MAIN TASK > MAIN <\n"); exit(1); } if (!(dspsem = rt_sem_init(nam2num("DSPSEM"), 0))) { printf("CANNOT INIT SEMAPHORE > DSPSEM <\n"); exit(1); } tasklet = rt_init_tasklet(); mlockall(MCL_CURRENT | MCL_FUTURE); rt_insert_tasklet(tasklet, 0, timer_handler, 111, nam2num("TSKLET"), 1); rt_request_irq_task(TIMER_IRQ, tasklet, RT_IRQ_TASKLET, 1); rtc_start(TIMER_FRQ); rtc_enable_irq(TIMER_IRQ, TIMER_FRQ); while (intcnt < maxcnt) { rt_sem_wait(dspsem); printf("OVERRUNS %d, INTERRUPT COUNT %d\n", ovr, intcnt); } rtc_stop(); rt_release_irq_task(TIMER_IRQ); printf("TEST ENDS\n"); rt_remove_tasklet(tasklet); rt_delete_tasklet(tasklet); rt_sem_delete(dspsem); rt_task_delete(maint); return 0; }
int main(void) { uint16_t counter; char c; uint8_t stop = TRUE; usart_init(); sonar_init(); rtc_setup(); counter = 0; usart_resume(0); strcpy_P(usart->tx0_buffer, PSTR("\nTsunami Simulator ")); strcat_P(usart->tx0_buffer, PSTR(GITREL)); strcat_P(usart->tx0_buffer, PSTR("\n\nConnected!\n")); usart_printstr(0, NULL); rtc_start(); while (1) { /* Restart the counter */ rtc_clear(); c = usart_getchar(0, FALSE); switch (c) { case '0': stop = TRUE; break; case '1': stop = FALSE; break; default: break; } if (stop) { /* stop the code */ while(usart_getchar(0, FALSE) != '1'); stop = FALSE; rtc_clear(); } /* send the trigger */ sonar_trigger(); /* clear all the data */ sonar_clear(); /* * Wait 40mS maximum and collect all the * data during the period. */ while (rtc_us < 4000) sonar_set(); /* * speed = ((i * SCALEuS)/1000000) * 340 / 2 * where: * i * SCALEuS is the duration in uS of the signal. * (i * SCALEuS)/1000000 is the same in seconds. * 340 is the speed of the sound and * /2 we need only half of the way. * The simplyfied formula in cm. * 340 mm/msec = 34cm/msec = 0.029 msec/cm = 29 uS/cm * dist (cm) = T (uS) / 29 /2. */ usart->tx0_buffer = utoa(counter, usart->tx0_buffer, 10); usart_printstr(0, NULL); usart_printstr(0, " "); counter++; sonar_print(); /* if the counter has already reach 50mS, * then this cycle takes too long. */ if (rtc_us > 5000) usart_printstr(0, "Warning! Time overrun.\n"); /* Wait up to 50mS before restart */ while (rtc_us < 5000); } return(0); }
void set_date(int argc, char **argv) { unsigned char *str_rtc; struct rtc_time tmku; int ret; time_t clk; rtc_reset(); rtc_init(); rtc_start(); str_rtc = pvPortMalloc(512); if (str_rtc == NULL) { printf("ERR: alok failed\r\n"); //free(str_rtc); vPortFree(str_rtc); return; } //printf("dapat free %X\r\n", str_rtc); memset(str_rtc, 0, 512); printf(" set_date tahun bulan tanggal jam menit\r\n"); printf(" misalnya : set_date 2010 3 5 10 22\r\n"); printf(" artinya : set waktu ke tgl 5 Maret 2010, jam 10:22 pagi\r\n"); if (argc < 5) { printf("Argument kurang !\r\n"); vPortFree(str_rtc); return; } //display_args(argc, argv); sprintf(str_rtc, "%s:%s:%s:%s:%s", argv[1], argv[2], argv[3], argv[4], argv[5]); ret = sscanf(str_rtc, "%d:%d:%d:%d:%d", &tmku.tm_year, &tmku.tm_mon, &tmku.tm_mday, &tmku.tm_hour, &tmku.tm_min); if (ret < 5) { printf(" ERR: format salah !\r\n"); vPortFree(str_rtc); return; } printf(" Set : %d-%d-%d %d:%d ", tmku.tm_year, tmku.tm_mon, tmku.tm_mday, tmku.tm_hour, tmku.tm_min); tmku.tm_year = tmku.tm_year - 1900; tmku.tm_mon = tmku.tm_mon - 1; tmku.tm_sec = 0; debug_printf(" OK : %d-%d-%d %d:%d\r\n", tmku.tm_year, tmku.tm_mon, tmku.tm_mday, tmku.tm_hour, tmku.tm_min); /* if (rtc_valid_tm(&tmku)) { printf(" ERR: waktu tidak mungkin !\r\n"); return; }*/ //rtc_set_time_tm( tmku ); rtcWrite( &tmku ); //clk = mktime(&tmku); //ret = rtc_time_to_bfin(clk); //bfin_write_RTC_STAT(ret); vPortFree(str_rtc); printf(" ..OK\r\n"); }
// ************************************************************************************************* // @fn mx_time // @brief Clock set routine. // @param uint8_t line LINE1, LINE2 // @return none // ************************************************************************************************* void mx_time(uint8_t line) { // Clear display clear_display_all(); #ifdef CONFIG_USE_SYNC_TOSET_TIME if (sys.flag.low_battery) return; display_sync(LINE2, DISPLAY_LINE_UPDATE_FULL); start_d7_sync(); #else uint8_t select; int32_t timeformat; int16_t timeformat1; int32_t hours; int32_t minutes; int32_t seconds; uint8_t * str; // Convert global time to local variables // Global time keeps on ticking in background until it is overwritten if (sys.flag.am_pm_time) { timeformat = TIMEFORMAT_12H; } else { timeformat = TIMEFORMAT_24H; } timeformat1 = timeformat; hours = sTime.hour; minutes = sTime.minute; seconds = sTime.second; // Init value index select = 0; // Loop values until all are set or user breaks set while(1) { // Idle timeout: exit without saving if (sys.flag.idle_timeout) { // Roll back time format if (timeformat1 == TIMEFORMAT_12H) sys.flag.am_pm_time = 1; else sys.flag.am_pm_time = 0; display_symbol(LCD_SYMB_AM, SEG_OFF); break; } // Button STAR (short): save, then exit if (button.flag.star) { // Stop clock timer //Timer0_Stop(); rtc_stop(); // Store local variables in global clock time sTime.hour = hours; sTime.minute = minutes; sTime.second = seconds; // Start clock timer //Timer0_Start(); rtc_start(); // Full display update is done when returning from function display_symbol(LCD_SYMB_AM, SEG_OFF); #ifdef CONFIG_SIDEREAL if(sSidereal_time.sync>0) sync_sidereal(); #endif break; } switch (select) { #if (OPTION_TIME_DISPLAY == CLOCK_DISPLAY_SELECT) case 0: // Clear LINE1 and LINE2 and AM icon - required when coming back from set_value(seconds) clear_display(); display_symbol(LCD_SYMB_AM, SEG_OFF); // Set 24H / 12H time format set_value(&timeformat, 1, 0, 0, 1, SETVALUE_ROLLOVER_VALUE + SETVALUE_DISPLAY_SELECTION + SETVALUE_NEXT_VALUE, LCD_SEG_L1_3_1, display_selection_Timeformat1); // Modify global time format variable immediately to update AM/PM icon correctly if (timeformat == TIMEFORMAT_12H) sys.flag.am_pm_time = 1; else sys.flag.am_pm_time = 0; select = 1; break; #else case 0: #endif case 1: // Display HH:MM (LINE1) and .SS (LINE2) str = itoa(hours, 2, 0); display_chars(LCD_SEG_L1_3_2, str, SEG_ON); display_symbol(LCD_SEG_L1_COL, SEG_ON); str = itoa(minutes, 2, 0); display_chars(LCD_SEG_L1_1_0, str, SEG_ON); str = itoa(seconds, 2, 0); display_chars(LCD_SEG_L2_1_0, str, SEG_ON); display_symbol(LCD_SEG_L2_DP, SEG_ON); // Set hours set_value(&hours, 2, 0, 0, 23, SETVALUE_ROLLOVER_VALUE + SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE, LCD_SEG_L1_3_2, display_hours_12_or_24); select = 2; break; case 2: // Set minutes set_value(&minutes, 2, 0, 0, 59, SETVALUE_ROLLOVER_VALUE + SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE, LCD_SEG_L1_1_0, display_value1); select = 3; break; case 3: // Set seconds set_value(&seconds, 2, 0, 0, 59, SETVALUE_ROLLOVER_VALUE + SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE, LCD_SEG_L2_1_0, display_value1); select = 0; break; } } // Clear button flags button.all_flags = 0; #endif }
void rtc_restart( TiRtc * rtc ) { rtc_start( rtc ); }
int main(void) { system_init(); rtc_init_counter_mode(); rtc_start(); //test_fec_encoding(); //test_fec_decoding(); button_enable_interrupts(); phy_init(); phy_set_rx_callback(rx_callback); while(1) { if (INTERRUPT_BUTTON1 & interrupt_flags) { interrupt_flags &= ~INTERRUPT_BUTTON1; // led_toggle(1); start_tx(); button_clear_interrupt_flag(); button_enable_interrupts(); } if (INTERRUPT_BUTTON3 & interrupt_flags) { interrupt_flags &= ~INTERRUPT_BUTTON3; if (rtcEnabled) { rtcEnabled = 0; rtc_disable_interrupt(); } else { rtcEnabled = 1; rtc_enable_interrupt(); } button_clear_interrupt_flag(); button_enable_interrupts(); } if (INTERRUPT_RTC & interrupt_flags) { interrupt_flags &= ~INTERRUPT_RTC; led_toggle(0); start_tx(); } if (!phy_is_rx_in_progress() && !phy_is_tx_in_progress()) { start_rx(); } if (phy_is_rx_in_progress()) { led_on(2); } else { led_off(2); } if (phy_is_tx_in_progress()) { led_on(3); } else { led_off(3); } // system_lowpower_mode(4,1); } return 0; }