diff options
author | Jun Wako <wakojun@gmail.com> | 2015-04-24 16:26:14 +0900 |
---|---|---|
committer | Jun Wako <wakojun@gmail.com> | 2015-04-24 16:26:14 +0900 |
commit | a3d96d3aa96318d339a67de1085e0ae495d57c84 (patch) | |
tree | db85c16d03b52399d6c109eda7ea0341a0de0b1d /tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z/lptmr | |
parent | 1d5bac21dc6f1425b8ef4bbe7935330c37c3a93e (diff) | |
parent | 1fe4406f374291ab2e86e95a97341fd9c475fcb8 (diff) |
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
Diffstat (limited to 'tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z/lptmr')
-rw-r--r-- | tmk_core/tool/mbed/mbed-sdk/libraries/tests/KL25Z/lptmr/main.cpp | 48 |
1 files changed, 48 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); + } +} |