Synchronize two tasks by the help of an event signal. Thread2 changes the state of LED1 when an event flag arrives. Thread1 (the main thread) sends event flags at reguar intervals.

Dependencies:   mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /** 10_rtos_signals_ledblink
00002  *
00003  * Synchronize two tasks by the help of an event signal.
00004  * Thread2 changes the state of LED1 when an event flag arrives.
00005  * Thread1 (the main thread) sends event flags at reguar intervals.
00006  */
00007 
00008 #include "mbed.h"
00009 #include "rtos.h"
00010 
00011 DigitalOut led(LED1);
00012 
00013 void led_thread(void const *argument)
00014 {
00015     while (true) {
00016         // Signal flags that are reported as event are automatically cleared.
00017         osEvent evt = Thread::signal_wait(0x1);   //Wait for a signal
00018         led = !led;
00019     }
00020 }
00021 
00022 int main (void)
00023 {
00024     Thread thread2(led_thread);
00025 
00026     while (true) {
00027         Thread::wait(1000);
00028         thread2.signal_set(0x1);
00029     }
00030 }