mDot / Mbed OS mbed-os-Thread_Test

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Thread.h"
00003 #include "Callback.h"
00004 
00005 DigitalOut led1(LED1);
00006 
00007 #define mySignal 0x01
00008 class MyTest 
00009 {
00010     public:
00011     osThreadId _id;
00012     Thread _thread;
00013         
00014     void myWorker(void const* arge)
00015     {
00016         MyTest* t = (MyTest*)arge;
00017         int i;
00018         i++;
00019         osSignalSet(t->_id, mySignal);
00020     }
00021      
00022     MyTest(osThreadId id) :
00023     _id(id),
00024     _thread()
00025     {
00026        osStatus status =  _thread.start(this, &MyTest::myWorker);  
00027   //   osStatus status =  _thread.start(mbed::Callback<void()>((MyTest*)this, &MyTest::myWorker));  
00028     }
00029         
00030 };
00031 
00032 // main() runs in its own thread in the OS
00033 // (note the calls to Thread::wait below for delays)
00034 int main() {
00035     osThreadId id = Thread::gettid();
00036     MyTest* test = new MyTest(id);
00037     while (true) {
00038         led1 = !led1;
00039         Thread::wait(500);
00040     }
00041 }
00042