Lab 8 part 5

Dependencies:   mbed mbed-rtos

Files at this revision

API Documentation at this revision

Comitter:
wssingle
Date:
Sun May 03 19:16:47 2020 +0000
Parent:
12:4e3f46e615d9
Commit message:
Lab 8 part 5

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 4e3f46e615d9 -r 8357f333d806 main.cpp
--- a/main.cpp	Mon Mar 30 18:54:14 2020 +0000
+++ b/main.cpp	Sun May 03 19:16:47 2020 +0000
@@ -0,0 +1,34 @@
+#include "mbed.h"
+#include "rtos.h"
+ 
+Queue<uint32_t, 5> queue;
+ 
+DigitalOut myled(LED1);
+ 
+void queue_isr() {
+    queue.put((uint32_t*)2);
+    myled = !myled;
+}
+ 
+void queue_thread(void const *args) {
+    while (true) {
+        queue.put((uint32_t*)1);
+        Thread::wait(1000);
+    }
+}
+ 
+int main (void) {
+    Thread thread(queue_thread);
+    
+    Ticker ticker;
+    ticker.attach(queue_isr, 1.0);
+    
+    while (true) {
+        osEvent evt = queue.get();
+        if (evt.status != osEventMessage) {
+            printf("queue->get() returned %02x status\n\r", evt.status);
+        } else {
+            printf("queue->get() returned %d\n\r", evt.value.v);
+        }
+    }
+}
\ No newline at end of file