Marco Zecchini
/
Example_RTOS
Rtos API example
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 volatile unsigned int ticks = 0; 00004 00005 DigitalOut led(LED_BLUE); 00006 00007 extern "C" void lptmr_isr(void) { 00008 // write 1 to TCF to clear the LPT timer compare flag 00009 LPTMR0->CSR |= LPTMR_CSR_TCF_MASK; 00010 00011 ticks++; 00012 } 00013 00014 int main() { 00015 /* Clock the timer */ 00016 SIM->SCGC5 |= SIM_SCGC5_LPTMR_MASK; 00017 00018 /* Reset */ 00019 LPTMR0->CSR = 0; 00020 00021 /* Compare value */ 00022 LPTMR0->CMR = 1000; 00023 00024 /* Enable interrupt */ 00025 LPTMR0->CSR |= LPTMR_CSR_TIE_MASK; 00026 00027 /* Set interrupt handler */ 00028 NVIC_SetVector(LPTimer_IRQn, (uint32_t)lptmr_isr); 00029 NVIC_EnableIRQ(LPTimer_IRQn); 00030 00031 /* select LPO for RTC and LPTMR */ 00032 LPTMR0->PSR = LPTMR_PSR_PCS(3); // ERCLK32K -> 8MHz 00033 LPTMR0->PSR |= LPTMR_PSR_PRESCALE(2); // divide by 8 00034 00035 /* Start the timer */ 00036 LPTMR0->CSR |= LPTMR_CSR_TEN_MASK; 00037 00038 led = 0; 00039 while (true) { 00040 wait(1); 00041 led = 1; 00042 printf("%d\n", ticks); 00043 00044 wait(1); 00045 led = 0; 00046 printf("%d\n", ticks); 00047 } 00048 }
Generated on Sun Jul 17 2022 08:25:26 by 1.7.2