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

Files at this revision

API Documentation at this revision

Comitter:
icserny
Date:
Tue Feb 23 13:25:29 2016 +0000
Commit message:
First version

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /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);
+    }
+}
--- /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
--- /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