Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "cmsis_os.h"
00003 
00004 #if defined(MBED_RTOS_SINGLE_THREAD)
00005   #error [NOT_SUPPORTED] test not supported
00006 #endif
00007 
00008 DigitalOut led(LED1);
00009 
00010 void led_thread(void const *argument) {
00011     while (true) {
00012         // Signal flags that are reported as event are automatically cleared.
00013         osSignalWait(0x1, osWaitForever);
00014         led = !led;
00015     }
00016 }
00017 
00018 osThreadDef(led_thread, osPriorityNormal, DEFAULT_STACK_SIZE);
00019 
00020 int main (void) {
00021     osThreadId tid = osThreadCreate(osThread(led_thread), NULL);
00022 
00023     while (true) {
00024         osDelay(1000);
00025         osSignalSet(tid, 0x1);
00026     }
00027 }