/** * \brief Interrupt handler for the RTC. Refreshes the display. */ static void sysc_handler(void) { uint32_t dwStatus = RTC->RTC_SR; /* Second increment interrupt */ if ((dwStatus & RTC_SR_SEC) == RTC_SR_SEC) { /* Disable RTC interrupt */ rtc_disable_it(RTC_IDR_SECDIS); _RefreshDisplay(); RTC->RTC_SCCR = RTC_SCCR_SECCLR; rtc_enable_it(RTC_IER_SECEN); } /* Time or date alarm */ else { if ((dwStatus & RTC_SR_ALARM) == RTC_SR_ALARM) { /* Disable RTC interrupt */ rtc_disable_it(RTC_IDR_ALRDIS); alarmTriggered = 1; _RefreshDisplay(); printf("\t Done \r"); /* shown additional menu item for clear notification */ bMenuShown = 0; RTC->RTC_SCCR = RTC_SCCR_ALRCLR; rtc_enable_it(RTC_IER_ALREN); } } }
/** * \brief Interrupt handler for the RTT. * * Displays the current time on the terminal. */ void RTT_Handler(void) { uint32_t status; /* Get RTT status */ status = RTT_GetStatus(RTT); /* Time has changed, refresh display */ if ((status & RTT_SR_RTTINC) == RTT_SR_RTTINC) _RefreshDisplay(); /* Alarm */ if ((status & RTT_SR_ALMS) == RTT_SR_ALMS) { alarmed = 1; _RefreshDisplay(); } }
int main(void) { uint8_t ucKey; /* Disable watchdog */ wdt_disable(); /* Configure console */ board_cfg_console(); /* Output example information */ printf("\r\n\r\n\r\n"); printf("-- RTC Example " SOFTPACK_VERSION " --\r\n"); printf("-- " BOARD_NAME "\r\n"); printf("-- Compiled: " __DATE__ " " __TIME__ " --\n\r"); // put 25 °C as a default temp, if there is no temprature sensor Temperature = 25; printf("Configure TC.\r\n"); configure_tc(); /* Default RTC configuration */ rtc_set_hour_mode(0); /* 24-hour mode */ struct _time empty_time = {0,0,0}; if (rtc_set_time_alarm(&empty_time)) { printf("\r\n Disable time alarm fail!"); } struct _date empty_date = {0,0,0}; if (rtc_set_date_alarm(&empty_date)) { printf("\r\n Disable date alarm fail!"); } /* Configure RTC interrupts */ rtc_enable_it(RTC_IER_SECEN | RTC_IER_ALREN); aic_set_source_vector(ID_SYSC, sysc_handler); aic_enable(ID_SYSC); /* Refresh display once */ _RefreshDisplay(); new_time.hour = 0; new_time.min = 0; new_time.sec = 30; rtc_set_time_alarm(&new_time); bMenuShown = 0; alarmTriggered = 0; rtc_calibration(Temperature); /* Handle keypresses */ while (1) { ucKey = console_get_char(); /* set time */ if (ucKey == 't') { bState = STATE_SET_TIME; aic_disable(ID_TC0); do { printf("\r\n\r\n Set time(hh:mm:ss): "); } while (get_new_time()); /* if valid input, none of variable for time is 0xff */ if (new_time.hour != 0xFF) { if (rtc_set_time (&new_time)) { printf ("\r\n Time not set, invalid input!\n\r"); } } bState = STATE_MENU; bMenuShown = 0; _RefreshDisplay(); CountDownTimer = 0; aic_enable(ID_TC0); } /* clock calibration */ else if (ucKey == 'p') { rtc_calibration(30); bState = STATE_MENU; bMenuShown = 0; _RefreshDisplay(); } /* set date */ else if (ucKey == 'd') { bState = STATE_SET_DATE; aic_disable(ID_TC0); do { printf("\r\n\r\n Set date(mm/dd/yyyy): "); } while (get_new_date()); /* if valid input, none of variable for date is 0xff(ff) */ if (new_date.year != 0xFFFF) { if (rtc_set_date(&new_date)) { printf ("\r\n Date not set, invalid input!\r\n"); } } /* only 'mm/dd' inputed */ if (new_date.month != 0xFF && new_date.year == 0xFFFF) { printf("\r\n Not Set for no year field!\r\n"); } bState = STATE_MENU; bMenuShown = 0; CountDownTimer = 0; aic_enable(ID_TC0); _RefreshDisplay(); } /* set time alarm */ else if (ucKey == 'i') { bState = STATE_SET_TIME_ALARM; aic_disable(ID_TC0); do { printf("\r\n\r\n Set time alarm(hh:mm:ss): "); } while (get_new_time()); if (new_time.hour != 0xFF) { if (rtc_set_time_alarm(&new_time)) { printf ("\r\n Time alarm not set, invalid input!\r\n"); } else { printf ("\r\n Time alarm is set at %02d:%02d:%02d!", new_time.hour, new_time.min, new_time.sec); } } bState = STATE_MENU; bMenuShown = 0; alarmTriggered = 0; CountDownTimer = 0; aic_enable(ID_TC0); _RefreshDisplay(); } /* set date alarm */ else if (ucKey == 'm') { bState = STATE_SET_DATE_ALARM; aic_disable(ID_TC0); do { printf("\r\n\r\n Set date alarm(mm/dd/): "); } while (get_new_date()); if (new_date.year == 0xFFFF && new_date.month != 0xFF) { if (rtc_set_date_alarm(&new_date)) { printf ("\r\n Date alarm not set, invalid input!\r\n"); } else { printf ("\r\n Date alarm is set on %02d/%02d!", new_date.month, new_date.day); } } bState = STATE_MENU; bMenuShown = 0; alarmTriggered = 0; CountDownTimer = 0; aic_enable(ID_TC0); _RefreshDisplay(); } /* clear trigger flag */ else if (ucKey == 'c') { alarmTriggered = 0; bMenuShown = 0; _RefreshDisplay(); } /* quit */ else if (ucKey == 'q') { break; } } return 0; }
/** * \brief Application entry point for RTT example. * * Initializes the RTT, displays the current time and allows the user to * perform several actions: clear the timer, set an alarm, etc. * * \return Unused (ANSI-C compatibility). */ extern int main( void ) { unsigned char c; /* Disable watchdog */ WDT_Disable(WDT); SCB_EnableICache(); SCB_EnableDCache(); /* Output example information */ printf("-- RTT Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME); /* Configure RTT */ _ConfigureRtt(); /* Initialize state machine */ state = STATE_MAINMENU; alarmed = 0; _RefreshDisplay(); /* User input loop */ while (1) { /* Wait for user input */ c = DBG_GetChar(); /* Main menu mode */ if (state == STATE_MAINMENU) { /* Reset timer */ if (c == 'r') { _ConfigureRtt(); _RefreshDisplay(); } /* Set alarm */ else if (c == 's') { state = STATE_SETALARM; newAlarm = 0; _RefreshDisplay(); } /* Clear alarm */ else { if ((c == 'c') && alarmed) { alarmed = 0; _RefreshDisplay(); } } } /* Set alarm mode */ else { if (state == STATE_SETALARM) { /* Number */ if ((c >= '0') && (c <= '9')) { newAlarm = newAlarm * 10 + c - '0'; _RefreshDisplay(); } /* Backspace */ else { if (c == 8) { newAlarm /= 10; _RefreshDisplay(); } /* Enter key */ else { if (c == 13) { /* Avoid newAlarm = 0 case */ if (newAlarm != 0) { RTT_SetAlarm(RTT, newAlarm); } state = STATE_MAINMENU; _RefreshDisplay(); } } } } } } }