]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/tests/rtos/mbed/timer/main.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / tests / rtos / mbed / timer / main.cpp
1 #include "mbed.h"
2 #include "test_env.h"
3 #include "rtos.h"
4
5 DigitalOut LEDs[4] = {
6     DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4)
7 };
8
9 void print_char(char c = '*')
10 {
11     printf("%c", c);
12     fflush(stdout);
13 }
14
15 void blink(void const *n) {
16     static int counter = 0;
17     const int led_id = int(n);
18     LEDs[led_id] = !LEDs[led_id];
19     if (++counter == 75) {
20         print_char();
21         counter = 0;
22     }
23 }
24
25 int main(void) {
26     MBED_HOSTTEST_TIMEOUT(15);
27     MBED_HOSTTEST_SELECT(wait_us_auto);
28     MBED_HOSTTEST_DESCRIPTION(Timer);
29     MBED_HOSTTEST_START("RTOS_7");
30
31     RtosTimer led_1_timer(blink, osTimerPeriodic, (void *)0);
32     RtosTimer led_2_timer(blink, osTimerPeriodic, (void *)1);
33     RtosTimer led_3_timer(blink, osTimerPeriodic, (void *)2);
34     RtosTimer led_4_timer(blink, osTimerPeriodic, (void *)3);
35
36     led_1_timer.start(200);
37     led_2_timer.start(100);
38     led_3_timer.start(50);
39     led_4_timer.start(25);
40
41     Thread::wait(osWaitForever);
42 }