]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/tests/KL25Z/lptmr/main.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / tests / KL25Z / lptmr / main.cpp
1 #include "mbed.h"
2
3 volatile unsigned int ticks = 0;
4
5 DigitalOut led(LED_BLUE);
6
7 extern "C" void lptmr_isr(void) {
8 // write 1 to TCF to clear the LPT timer compare flag
9 LPTMR0->CSR |= LPTMR_CSR_TCF_MASK;
10
11 ticks++;
12 }
13
14 int main() {
15 /* Clock the timer */
16 SIM->SCGC5 |= SIM_SCGC5_LPTMR_MASK;
17
18 /* Reset */
19 LPTMR0->CSR = 0;
20
21 /* Compare value */
22 LPTMR0->CMR = 1000;
23
24 /* Enable interrupt */
25 LPTMR0->CSR |= LPTMR_CSR_TIE_MASK;
26
27 /* Set interrupt handler */
28 NVIC_SetVector(LPTimer_IRQn, (uint32_t)lptmr_isr);
29 NVIC_EnableIRQ(LPTimer_IRQn);
30
31 /* select LPO for RTC and LPTMR */
32 LPTMR0->PSR = LPTMR_PSR_PCS(3); // ERCLK32K -> 8MHz
33 LPTMR0->PSR |= LPTMR_PSR_PRESCALE(2); // divide by 8
34
35 /* Start the timer */
36 LPTMR0->CSR |= LPTMR_CSR_TEN_MASK;
37
38 led = 0;
39 while (true) {
40 wait(1);
41 led = 1;
42 printf("%d\n", ticks);
43
44 wait(1);
45 led = 0;
46 printf("%d\n", ticks);
47 }
48 }
Imprint / Impressum