summaryrefslogtreecommitdiff
path: root/tool/mbed/mbed-sdk/libraries/tests/KL25Z/pit/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/pit/main.cpp
parenta20ef7052c6e937d2f7672dd59456e55a5c08296 (diff)
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/pit/main.cpp')
-rw-r--r--tool/mbed/mbed-sdk/libraries/tests/KL25Z/pit/main.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/tool/mbed/mbed-sdk/libraries/tests/KL25Z/pit/main.cpp b/tool/mbed/mbed-sdk/libraries/tests/KL25Z/pit/main.cpp
new file mode 100644
index 0000000000..3b13af2730
--- /dev/null
+++ b/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);
+ }
+}