summaryrefslogtreecommitdiff
path: root/tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z
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
commita3d96d3aa96318d339a67de1085e0ae495d57c84 (patch)
treedb85c16d03b52399d6c109eda7ea0341a0de0b1d /tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z
parent1d5bac21dc6f1425b8ef4bbe7935330c37c3a93e (diff)
parent1fe4406f374291ab2e86e95a97341fd9c475fcb8 (diff)
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
Diffstat (limited to 'tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z')
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z/lptmr/main.cpp48
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z/pit/main.cpp48
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z/rtc/main.cpp72
3 files changed, 168 insertions, 0 deletions
diff --git a/tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z/lptmr/main.cpp b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z/lptmr/main.cpp
new file mode 100644
index 0000000000..170fc46987
--- /dev/null
+++ b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z/lptmr/main.cpp
@@ -0,0 +1,48 @@
+#include "mbed.h"
+
+volatile unsigned int ticks = 0;
+
+DigitalOut led(LED_BLUE);
+
+extern "C" void lptmr_isr(void) {
+ // write 1 to TCF to clear the LPT timer compare flag
+ LPTMR0->CSR |= LPTMR_CSR_TCF_MASK;
+
+ ticks++;
+}
+
+int main() {
+ /* Clock the timer */
+ SIM->SCGC5 |= SIM_SCGC5_LPTMR_MASK;
+
+ /* Reset */
+ LPTMR0->CSR = 0;
+
+ /* Compare value */
+ LPTMR0->CMR = 1000;
+
+ /* Enable interrupt */
+ LPTMR0->CSR |= LPTMR_CSR_TIE_MASK;
+
+ /* Set interrupt handler */
+ NVIC_SetVector(LPTimer_IRQn, (uint32_t)lptmr_isr);
+ NVIC_EnableIRQ(LPTimer_IRQn);
+
+ /* select LPO for RTC and LPTMR */
+ LPTMR0->PSR = LPTMR_PSR_PCS(3); // ERCLK32K -> 8MHz
+ LPTMR0->PSR |= LPTMR_PSR_PRESCALE(2); // divide by 8
+
+ /* Start the timer */
+ LPTMR0->CSR |= LPTMR_CSR_TEN_MASK;
+
+ led = 0;
+ while (true) {
+ wait(1);
+ led = 1;
+ printf("%d\n", ticks);
+
+ wait(1);
+ led = 0;
+ printf("%d\n", ticks);
+ }
+}
diff --git a/tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z/pit/main.cpp b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z/pit/main.cpp
new file mode 100644
index 0000000000..3b13af2730
--- /dev/null
+++ b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z/pit/main.cpp
@@ -0,0 +1,48 @@
+#include "mbed.h"
+
+extern "C" {
+volatile uint32_t msTicks;
+
+void SysTick_Handler(void) {
+ msTicks++;
+}
+
+void Delay(uint32_t dlyTicks) {
+ uint32_t curTicks;
+
+ curTicks = msTicks;
+ while ((msTicks - curTicks) < dlyTicks);
+}
+}
+
+int main() {
+ SysTick_Config(SystemCoreClock / 1000);
+
+ SIM->SCGC6 |= SIM_SCGC6_PIT_MASK; // Clock PIT
+ PIT->MCR = 0; // Enable PIT
+
+ // Timer 1
+ PIT->CHANNEL[1].LDVAL = 0xFFFFFFFF;
+ PIT->CHANNEL[1].TCTRL = 0x0; // Disable Interrupts
+ PIT->CHANNEL[1].TCTRL |= PIT_TCTRL_CHN_MASK; // Chain to timer 0
+ PIT->CHANNEL[1].TCTRL |= PIT_TCTRL_TEN_MASK; // Start timer 1
+
+ // Timer 2
+ PIT->CHANNEL[0].LDVAL = 0xFFFFFFFF;
+ PIT->CHANNEL[0].TCTRL = PIT_TCTRL_TEN_MASK; // Start timer 0, disable interrupts
+
+ DigitalOut led(LED_BLUE);
+ while (true) {
+ Delay(1000);
+ led = !led;
+
+ uint64_t ticks = (uint64_t)PIT->LTMR64H << 32;
+ ticks |= (uint64_t)PIT->LTMR64L;
+ printf("ticks: 0x%x%x\n", (uint32_t)(ticks>>32), (uint32_t)(ticks & 0xFFFFFFFF));
+
+ ticks = (~ticks) / 24;
+ uint32_t us = (uint32_t)(0xFFFFFFFF & ticks);
+
+ printf("us : 0x%x\n", us);
+ }
+}
diff --git a/tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z/rtc/main.cpp b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z/rtc/main.cpp
new file mode 100644
index 0000000000..31d7e64d26
--- /dev/null
+++ b/tmk_core/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);
+ }
+}