aboutsummaryrefslogtreecommitdiffstats
path: root/tool/mbed/mbed-sdk/libraries/tests/KL25Z/rtc/main.cpp
diff options
context:
space:
mode:
authorJun Wako <wakojun@gmail.com>2015-04-24 16:26:14 +0900
committerJun Wako <wakojun@gmail.com>2015-04-24 16:26:14 +0900
commit1fe4406f374291ab2e86e95a97341fd9c475fcb8 (patch)
tree1be0e16b4b07b5a31ea97ec50a9eb13a288c3d27 /tool/mbed/mbed-sdk/libraries/tests/KL25Z/rtc/main.cpp
parenta20ef7052c6e937d2f7672dd59456e55a5c08296 (diff)
downloadfirmware-1fe4406f374291ab2e86e95a97341fd9c475fcb8.tar.gz
firmware-1fe4406f374291ab2e86e95a97341fd9c475fcb8.tar.bz2
firmware-1fe4406f374291ab2e86e95a97341fd9c475fcb8.zip
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
b9e0ea0 Merge commit '7fa9d8bdea3773d1195b04d98fcf27cf48ddd81d' as 'tool/mbed/mbed-sdk' 7fa9d8b Squashed 'tool/mbed/mbed-sdk/' content from commit 7c21ce5 git-subtree-dir: tmk_core git-subtree-split: b9e0ea08cb940de20b3610ecdda18e9d8cd7c552
Diffstat (limited to 'tool/mbed/mbed-sdk/libraries/tests/KL25Z/rtc/main.cpp')
-rw-r--r--tool/mbed/mbed-sdk/libraries/tests/KL25Z/rtc/main.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/tool/mbed/mbed-sdk/libraries/tests/KL25Z/rtc/main.cpp b/tool/mbed/mbed-sdk/libraries/tests/KL25Z/rtc/main.cpp
new file mode 100644
index 000000000..31d7e64d2
--- /dev/null
+++ b/tool/mbed/mbed-sdk/libraries/tests/KL25Z/rtc/main.cpp
@@ -0,0 +1,72 @@
+#include "mbed.h"
+
+DigitalOut status_led(LED_BLUE);
+DigitalOut error_led(LED_RED);
+
+extern "C" void RTC_IRQHandler(void) {
+ error_led = 0;
+}
+
+extern "C" void RTC_Seconds_IRQHandler(void) {
+ error_led = 0;
+}
+
+extern "C" void HardFault_Handler(void) {
+ error_led = 0;
+}
+
+extern "C" void NMI_Handler_Handler(void) {
+ error_led = 0;
+}
+
+void rtc_init(void) {
+ // enable the clock to SRTC module register space
+ SIM->SCGC6 |= SIM_SCGC6_RTC_MASK;
+ SIM->SOPT1 = (SIM->SOPT1 & ~SIM_SOPT1_OSC32KSEL_MASK) | SIM_SOPT1_OSC32KSEL(0);
+
+ // disable interrupts
+ NVIC_DisableIRQ(RTC_Seconds_IRQn);
+ NVIC_DisableIRQ(RTC_IRQn);
+
+ // Reset
+ RTC->CR = RTC_CR_SWR_MASK;
+ RTC->CR &= ~RTC_CR_SWR_MASK;
+
+ // Allow write
+ RTC->CR = RTC_CR_UM_MASK | RTC_CR_SUP_MASK;
+
+ NVIC_EnableIRQ(RTC_Seconds_IRQn);
+ NVIC_EnableIRQ(RTC_Seconds_IRQn);
+
+ printf("LR: 0x%x\n", RTC->LR);
+ printf("CR: 0x%x\n", RTC->CR);
+ wait(1);
+ if (RTC->SR & RTC_SR_TIF_MASK){
+ RTC->TSR = 0;
+ }
+ RTC->TCR = 0;
+
+ // After setting this bit, wait the oscillator startup time before enabling
+ // the time counter to allow the clock time to stabilize
+ RTC->CR |= RTC_CR_OSCE_MASK;
+ for (volatile int i=0; i<0x600000; i++);
+
+ //enable seconds interrupts
+ RTC->IER |= RTC_IER_TSIE_MASK;
+
+ // enable time counter
+ RTC->SR |= RTC_SR_TCE_MASK;
+
+
+}
+
+int main() {
+ error_led = 1;
+ rtc_init();
+
+ while (true) {
+ wait(1);
+ status_led = !status_led;
+ printf("%u\n", RTC->TSR);
+ }
+}