]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z/rtc/main.cpp
3 DigitalOut
status_led(LED_BLUE
);
4 DigitalOut
error_led(LED_RED
);
6 extern "C" void RTC_IRQHandler(void) {
10 extern "C" void RTC_Seconds_IRQHandler(void) {
14 extern "C" void HardFault_Handler(void) {
18 extern "C" void NMI_Handler_Handler(void) {
23 // enable the clock to SRTC module register space
24 SIM
->SCGC6
|= SIM_SCGC6_RTC_MASK
;
25 SIM
->SOPT1
= (SIM
->SOPT1
& ~SIM_SOPT1_OSC32KSEL_MASK
) | SIM_SOPT1_OSC32KSEL(0);
28 NVIC_DisableIRQ(RTC_Seconds_IRQn
);
29 NVIC_DisableIRQ(RTC_IRQn
);
32 RTC
->CR
= RTC_CR_SWR_MASK
;
33 RTC
->CR
&= ~RTC_CR_SWR_MASK
;
36 RTC
->CR
= RTC_CR_UM_MASK
| RTC_CR_SUP_MASK
;
38 NVIC_EnableIRQ(RTC_Seconds_IRQn
);
39 NVIC_EnableIRQ(RTC_Seconds_IRQn
);
41 printf("LR: 0x%x\n", RTC
->LR
);
42 printf("CR: 0x%x\n", RTC
->CR
);
44 if (RTC
->SR
& RTC_SR_TIF_MASK
){
49 // After setting this bit, wait the oscillator startup time before enabling
50 // the time counter to allow the clock time to stabilize
51 RTC
->CR
|= RTC_CR_OSCE_MASK
;
52 for (volatile int i
=0; i
<0x600000; i
++);
54 //enable seconds interrupts
55 RTC
->IER
|= RTC_IER_TSIE_MASK
;
57 // enable time counter
58 RTC
->SR
|= RTC_SR_TCE_MASK
;
69 status_led
= !status_led
;
70 printf("%u\n", RTC
->TSR
);