Übungen zu Events im MbedOS https://os.mbed.com/users/fpucher/code/HIM0Board/wiki/Events

Revision:
0:0e8dbc229b3a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Mar 28 17:12:15 2019 +0000
@@ -0,0 +1,29 @@
+#include "mbed.h"
+ 
+DigitalOut led(LED1);
+InterruptIn btn(p15);
+ 
+Semaphore updates(1);
+ 
+void fall_handler() {
+    // release the semaphore
+    updates.release();
+}
+ 
+int main() {
+    btn.fall(&fall_handler);  // The 'fall' handler will execute in IRQ context
+    printf("Starting in context %p\r\n", Thread::gettid());
+    
+    while(1){
+            int32_t v = updates.wait(); // wait for the semaphore to be released from the ISR
+ 
+            if (v == 1) {     // now this runs on the main thread, and is safe
+                led = !led;
+                printf("fall_handler in context %p\r\n",Thread::gettid());
+            }
+        
+        }
+    
+    
+    wait(osWaitForever);
+}