mbed official
/
rtos_isr
Basic example showing the Queue API with a producer in an ISR and a consumer in a normal thread.
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 00004 Queue<uint32_t, 5> queue; 00005 00006 DigitalOut myled(LED1); 00007 00008 void queue_isr() { 00009 queue.put((uint32_t*)2); 00010 myled = !myled; 00011 } 00012 00013 void queue_thread(void const *args) { 00014 while (true) { 00015 queue.put((uint32_t*)1); 00016 Thread::wait(1000); 00017 } 00018 } 00019 00020 int main (void) { 00021 Thread thread(queue_thread); 00022 00023 Ticker ticker; 00024 ticker.attach(queue_isr, 1.0); 00025 00026 while (true) { 00027 osEvent evt = queue.get(); 00028 if (evt.status != osEventMessage) { 00029 printf("queue->get() returned %02x status\n\r", evt.status); 00030 } else { 00031 printf("queue->get() returned %d\n\r", evt.value.v); 00032 } 00033 } 00034 }
Generated on Tue Jul 12 2022 11:27:42 by 1.7.2