]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - tmk_core/tool/mbed/mbed-sdk/libraries/tests/rtos/mbed/basic/main.cpp
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[qmk_firmware.git] / tmk_core / tool / mbed / mbed-sdk / libraries / tests / rtos / mbed / basic / main.cpp
diff --git a/tmk_core/tool/mbed/mbed-sdk/libraries/tests/rtos/mbed/basic/main.cpp b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/rtos/mbed/basic/main.cpp
new file mode 100644 (file)
index 0000000..5414367
--- /dev/null
@@ -0,0 +1,44 @@
+#include "mbed.h"
+#include "test_env.h"
+#include "rtos.h"
+
+/*
+ * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
+ * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
+ * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
+ */
+#if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
+#define STACK_SIZE DEFAULT_STACK_SIZE/4
+#else
+#define STACK_SIZE DEFAULT_STACK_SIZE
+#endif
+
+void print_char(char c = '*') {
+    printf("%c", c);
+    fflush(stdout);
+}
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+
+void led2_thread(void const *argument) {
+    while (true) {
+        led2 = !led2;
+        Thread::wait(1000);
+        print_char();
+    }
+}
+
+int main() {
+    MBED_HOSTTEST_TIMEOUT(15);
+    MBED_HOSTTEST_SELECT(wait_us_auto);
+    MBED_HOSTTEST_DESCRIPTION(Basic thread);
+    MBED_HOSTTEST_START("RTOS_1");
+
+    Thread thread(led2_thread, NULL, osPriorityNormal, STACK_SIZE);
+
+    while (true) {
+        led1 = !led1;
+        Thread::wait(500);
+    }
+}