Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-os-example-mbed5-blinky by
main.cpp
00001 #include "mbed.h" 00002 00003 InterruptIn _BlueButton(USER_BUTTON); 00004 DigitalOut _led1(LED1); 00005 00006 class myComp { 00007 public: 00008 00009 Thread _ISRthread; 00010 EventQueue _ISRqueue; 00011 int _cnt; 00012 00013 void ThreadBodyFunc () { 00014 printf ("ThreadBodyFunc tid: %x activated\n\r", (unsigned int)_ISRthread.gettid()); 00015 _led1 = !_led1; 00016 _cnt++; 00017 } 00018 void start() { 00019 printf ("starting tid: %x ...\n\r", (unsigned int)_ISRthread.gettid()); 00020 _cnt=0; 00021 _ISRthread.start(callback(&_ISRqueue, &EventQueue::dispatch_forever)); 00022 _ISRthread.set_priority(osPriorityRealtime); // after having called break_dispatch it FAILS with "Thread 00000000 error -4: Parameter error" 00023 _BlueButton.fall(_ISRqueue.event(this, &myComp::ThreadBodyFunc )); 00024 00025 } 00026 void stop() { 00027 printf ("Stopping th...\n\r"); 00028 _cnt=0; 00029 _ISRqueue.break_dispatch(); 00030 _ISRthread.terminate(); 00031 _ISRthread.join(); 00032 printf ("... th joined\n\r"); 00033 } 00034 }; 00035 00036 // main() runs in its own thread in the OS 00037 // pushing the BlueButton 4 times trigger the break_dispatch 00038 00039 int main() { 00040 myComp comp; 00041 printf ("Main started\n\r"); 00042 comp.start(); 00043 00044 while (1) { 00045 Thread::yield(); 00046 if (comp._cnt>3) { 00047 comp.stop(); 00048 Thread::yield(); 00049 comp.start(); 00050 } 00051 } 00052 } 00053
Generated on Tue Jul 12 2022 20:55:25 by
1.7.2
