University of Plymouth - Stages 1, 2 and 3 / Mbed OS signal-wait-demo_F429

Files at this revision

API Documentation at this revision

Comitter:
noutram
Date:
Thu Apr 26 07:57:38 2018 +0000
Commit message:
Demonstration of signal-wait

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib 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	Thu Apr 26 07:57:38 2018 +0000
@@ -0,0 +1,45 @@
+#include "mbed.h"
+#define WAIT_FOR_ISR    1
+//Function declarations
+void Function1();
+void ISR();
+
+//Thread
+Thread t1;
+
+//I/O
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+InterruptIn  onBoardSwitch(USER_BUTTON);
+
+//Switch ISR
+void ISR() {
+    t1.signal_set(WAIT_FOR_ISR);
+}
+
+//Thread
+void Function1() {
+    while (true) {
+        Thread::signal_wait(WAIT_FOR_ISR);
+        wait(0.2); //Debounce
+        Thread::signal_clr(WAIT_FOR_ISR);
+        led1 = !led1;
+    }
+}
+
+//Main thread
+int main() {
+    //Initial state
+    led1 = 1;
+    led2 = 1;   
+    onBoardSwitch.rise(ISR);
+    
+    //Create and run threads (C function pointers)
+    t1.start(Function1);           
+        
+    //Main thread loop
+    while(1) {
+        led2 = !led2;
+        Thread::wait(100);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Thu Apr 26 07:57:38 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#e62a1b9236b44e70ae3b0902dc538481c04d455b