]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/tests/rtos/mbed/basic/main.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / tests / rtos / mbed / basic / main.cpp
1 #include "mbed.h"
2 #include "test_env.h"
3 #include "rtos.h"
4
5 /*
6  * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
7  * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
8  * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
9  */
10 #if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
11 #define STACK_SIZE DEFAULT_STACK_SIZE/4
12 #else
13 #define STACK_SIZE DEFAULT_STACK_SIZE
14 #endif
15
16 void print_char(char c = '*') {
17     printf("%c", c);
18     fflush(stdout);
19 }
20
21 DigitalOut led1(LED1);
22 DigitalOut led2(LED2);
23
24 void led2_thread(void const *argument) {
25     while (true) {
26         led2 = !led2;
27         Thread::wait(1000);
28         print_char();
29     }
30 }
31
32 int main() {
33     MBED_HOSTTEST_TIMEOUT(15);
34     MBED_HOSTTEST_SELECT(wait_us_auto);
35     MBED_HOSTTEST_DESCRIPTION(Basic thread);
36     MBED_HOSTTEST_START("RTOS_1");
37
38     Thread thread(led2_thread, NULL, osPriorityNormal, STACK_SIZE);
39
40     while (true) {
41         led1 = !led1;
42         Thread::wait(500);
43     }
44 }