mbed_example
/
rtos_isr
isr example
main.cpp@4:40078e697304, 2017-01-13 (annotated)
- Committer:
- mab5449
- Date:
- Fri Jan 13 19:48:25 2017 +0000
- Revision:
- 4:40078e697304
- Parent:
- 2:3ded4c6c9dff
- Child:
- 7:985db97e8ae0
Updated to mbed 5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:3043ec651794 | 1 | #include "mbed.h" |
mbed_official | 0:4979ad0f5cb9 | 2 | |
mab5449 | 4:40078e697304 | 3 | Thread thread; |
mab5449 | 4:40078e697304 | 4 | Ticker ticker; |
emilmont | 1:3043ec651794 | 5 | Queue<uint32_t, 5> queue; |
emilmont | 1:3043ec651794 | 6 | DigitalOut myled(LED1); |
emilmont | 1:3043ec651794 | 7 | |
emilmont | 1:3043ec651794 | 8 | void queue_isr() { |
emilmont | 1:3043ec651794 | 9 | queue.put((uint32_t*)2); |
emilmont | 1:3043ec651794 | 10 | myled = !myled; |
emilmont | 1:3043ec651794 | 11 | } |
emilmont | 1:3043ec651794 | 12 | |
mab5449 | 4:40078e697304 | 13 | void queue_thread() { |
emilmont | 1:3043ec651794 | 14 | while (true) { |
emilmont | 1:3043ec651794 | 15 | queue.put((uint32_t*)1); |
mab5449 | 4:40078e697304 | 16 | wait(1); |
emilmont | 1:3043ec651794 | 17 | } |
emilmont | 1:3043ec651794 | 18 | } |
emilmont | 1:3043ec651794 | 19 | |
emilmont | 1:3043ec651794 | 20 | int main (void) { |
mab5449 | 4:40078e697304 | 21 | thread.start(callback(queue_thread)); |
emilmont | 1:3043ec651794 | 22 | ticker.attach(queue_isr, 1.0); |
mab5449 | 4:40078e697304 | 23 | |
emilmont | 1:3043ec651794 | 24 | while (true) { |
emilmont | 1:3043ec651794 | 25 | osEvent evt = queue.get(); |
emilmont | 1:3043ec651794 | 26 | if (evt.status != osEventMessage) { |
emilmont | 1:3043ec651794 | 27 | printf("queue->get() returned %02x status\n\r", evt.status); |
emilmont | 1:3043ec651794 | 28 | } else { |
emilmont | 1:3043ec651794 | 29 | printf("queue->get() returned %d\n\r", evt.value.v); |
emilmont | 1:3043ec651794 | 30 | } |
emilmont | 1:3043ec651794 | 31 | } |
emilmont | 1:3043ec651794 | 32 | } |