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.
Revision 0:e2662deac7e9, committed 2016-02-23
- Comitter:
- icserny
- Date:
- Tue Feb 23 13:25:29 2016 +0000
- Commit message:
- First version
Changed in this revision
diff -r 000000000000 -r e2662deac7e9 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Feb 23 13:25:29 2016 +0000 @@ -0,0 +1,30 @@ +/** 10_rtos_signals_ledblink + * + * 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. + */ + +#include "mbed.h" +#include "rtos.h" + +DigitalOut led(LED1); + +void led_thread(void const *argument) +{ + while (true) { + // Signal flags that are reported as event are automatically cleared. + osEvent evt = Thread::signal_wait(0x1); //Wait for a signal + led = !led; + } +} + +int main (void) +{ + Thread thread2(led_thread); + + while (true) { + Thread::wait(1000); + thread2.signal_set(0x1); + } +}
diff -r 000000000000 -r e2662deac7e9 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Tue Feb 23 13:25:29 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#07314541bd12
diff -r 000000000000 -r e2662deac7e9 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Feb 23 13:25:29 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/252557024ec3 \ No newline at end of file