![](/media/cache/profiles/af7fc8485f40dc495bc626d6dbe7faf1.50x50_q85.png)
Basic example showing the CMSIS-RTOS timer API
mbed 2 and mbed OS 5
This is an mbed 2 example. mbed OS 5 has integrated the mbed library with mbed-rtos. For an mbed-os example, please see:
Import programrtos_timer
timer example
main.cpp@2:2ced6669ccc4, 2012-11-23 (annotated)
- Committer:
- emilmont
- Date:
- Fri Nov 23 11:01:45 2012 +0000
- Revision:
- 2:2ced6669ccc4
- Parent:
- 1:50f9df2d7dd6
update libraries
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:50f9df2d7dd6 | 1 | #include "mbed.h" |
emilmont | 1:50f9df2d7dd6 | 2 | #include "cmsis_os.h" |
emilmont | 1:50f9df2d7dd6 | 3 | |
emilmont | 1:50f9df2d7dd6 | 4 | DigitalOut LEDs[4] = { |
emilmont | 1:50f9df2d7dd6 | 5 | DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4) |
emilmont | 1:50f9df2d7dd6 | 6 | }; |
emilmont | 1:50f9df2d7dd6 | 7 | |
emilmont | 1:50f9df2d7dd6 | 8 | void blink(void const *n) { |
emilmont | 1:50f9df2d7dd6 | 9 | LEDs[(int)n] = !LEDs[(int)n]; |
emilmont | 1:50f9df2d7dd6 | 10 | } |
emilmont | 1:50f9df2d7dd6 | 11 | |
emilmont | 1:50f9df2d7dd6 | 12 | osTimerDef(blink_0, blink); |
emilmont | 1:50f9df2d7dd6 | 13 | osTimerDef(blink_1, blink); |
emilmont | 1:50f9df2d7dd6 | 14 | osTimerDef(blink_2, blink); |
emilmont | 1:50f9df2d7dd6 | 15 | osTimerDef(blink_3, blink); |
emilmont | 1:50f9df2d7dd6 | 16 | |
emilmont | 1:50f9df2d7dd6 | 17 | int main(void) { |
emilmont | 1:50f9df2d7dd6 | 18 | osTimerId timer_0 = osTimerCreate(osTimer(blink_0), osTimerPeriodic, (void *)0); |
emilmont | 1:50f9df2d7dd6 | 19 | osTimerId timer_1 = osTimerCreate(osTimer(blink_1), osTimerPeriodic, (void *)1); |
emilmont | 1:50f9df2d7dd6 | 20 | osTimerId timer_2 = osTimerCreate(osTimer(blink_2), osTimerPeriodic, (void *)2); |
emilmont | 1:50f9df2d7dd6 | 21 | osTimerId timer_3 = osTimerCreate(osTimer(blink_3), osTimerPeriodic, (void *)3); |
emilmont | 1:50f9df2d7dd6 | 22 | |
emilmont | 1:50f9df2d7dd6 | 23 | osTimerStart(timer_0, 2000); |
emilmont | 1:50f9df2d7dd6 | 24 | osTimerStart(timer_1, 1000); |
emilmont | 1:50f9df2d7dd6 | 25 | osTimerStart(timer_2, 500); |
emilmont | 1:50f9df2d7dd6 | 26 | osTimerStart(timer_3, 250); |
emilmont | 1:50f9df2d7dd6 | 27 | |
emilmont | 1:50f9df2d7dd6 | 28 | osDelay(osWaitForever); |
emilmont | 1:50f9df2d7dd6 | 29 | } |