Basic example showing the Queue API with a producer in an ISR and a consumer in a normal thread.
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 4:40078e697304, committed 2017-01-13
- Comitter:
- mab5449
- Date:
- Fri Jan 13 19:48:25 2017 +0000
- Parent:
- 3:b3d67501ac55
- Child:
- 5:23a456bf0487
- Commit message:
- Updated to mbed 5
Changed in this revision
--- a/main.cpp Tue Jun 04 16:01:58 2013 +0100 +++ b/main.cpp Fri Jan 13 19:48:25 2017 +0000 @@ -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,19 +10,17 @@ myled = !myled; } -void queue_thread(void const *args) { +void queue_thread() { while (true) { queue.put((uint32_t*)1); - Thread::wait(1000); + wait(1); } } int main (void) { - Thread thread(queue_thread); - - Ticker ticker; + thread.start(callback(queue_thread)); ticker.attach(queue_isr, 1.0); - + while (true) { osEvent evt = queue.get(); if (evt.status != osEventMessage) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Fri Jan 13 19:48:25 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#2885c1b41e63158cb6faf5f107cd821ae06ef26c
--- a/mbed-rtos.lib Tue Jun 04 16:01:58 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/ \ No newline at end of file
--- a/mbed.bld Tue Jun 04 16:01:58 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/ \ No newline at end of file