Basic example showing the Queue API with a producer in an ISR and a consumer in a normal thread.

Dependencies:   mbed-rtos mbed

mbed 2 and mbed OS 5

This is an mbed 2 example. mbed OS 5 has integrated the mbed library with mbed-rtos. For an mbed-os example, please see:

Import programrtos_isr

isr example

Revision:
5:23a456bf0487
Parent:
4:40078e697304
--- a/main.cpp	Fri Jan 13 19:48:25 2017 +0000
+++ b/main.cpp	Wed Feb 15 13:59:58 2017 -0600
@@ -1,8 +1,8 @@
 #include "mbed.h"
+#include "rtos.h"
 
-Thread thread;
-Ticker ticker;
 Queue<uint32_t, 5> queue;
+
 DigitalOut myled(LED1);
 
 void queue_isr() {
@@ -10,17 +10,19 @@
     myled = !myled;
 }
 
-void queue_thread() {
+void queue_thread(void const *args) {
     while (true) {
         queue.put((uint32_t*)1);
-        wait(1);
+        Thread::wait(1000);
     }
 }
 
 int main (void) {
-    thread.start(callback(queue_thread));
+    Thread thread(queue_thread);
+    
+    Ticker ticker;
     ticker.attach(queue_isr, 1.0);
-
+    
     while (true) {
         osEvent evt = queue.get();
         if (evt.status != osEventMessage) {