EventQueue break_dispatch test
Fork of mbed-os-example-mbed5-blinky by
Diff: main.cpp
- Revision:
- 67:b82d86fdf0ae
- Parent:
- 29:0b58d21e87d6
- Child:
- 68:3701a2e4ec3d
--- a/main.cpp Thu May 10 05:15:08 2018 +0100
+++ b/main.cpp Wed May 16 12:45:17 2018 +0000
@@ -1,12 +1,50 @@
#include "mbed.h"
-DigitalOut led1(LED1);
+InterruptIn _BlueButton(USER_BUTTON);
+DigitalOut _led1(LED1);
+
+class myComp {
+public:
+
+Thread _ISRthread;
+EventQueue _ISRqueue;
+int _cnt;
+
+void ThreadBodyFunc () {
+ printf ("ThreadBodyFunc tid: %x activated\n\r", (unsigned int)_ISRthread.gettid());
+ _led1 = !_led1;
+ _cnt++;
+}
+void start() {
+ printf ("starting tid: %x ...\n\r", (unsigned int)_ISRthread.gettid());
+ _cnt=0;
+ _ISRthread.start(callback(&_ISRqueue, &EventQueue::dispatch_forever));
+ _ISRthread.set_priority(osPriorityRealtime); // after having called break_dispatch it FAILS with "Thread 00000000 error -4: Parameter error"
+ _BlueButton.fall(_ISRqueue.event(this, &myComp::ThreadBodyFunc ));
+
+}
+void stop() {
+ printf ("Stopping ...\n\r");
+ _cnt=0;
+ _ISRqueue.break_dispatch();
+}
+};
// main() runs in its own thread in the OS
+// pushing the BlueButton 4 times trigger the break_dispatch
+
int main() {
- while (true) {
- led1 = !led1;
- wait(0.5);
- }
+ myComp comp;
+ printf ("Main started\n\r");
+ comp.start();
+
+ while (1) {
+ Thread::yield();
+ if (comp._cnt>3) {
+ comp.stop();
+ Thread::yield();
+ comp.start();
+ }
+ }
}
