finished

Dependencies:   mbed-rtos mbed

Fork of rtos_mutex by mbed official

Committer:
cathal66
Date:
Fri Feb 13 00:03:22 2015 +0000
Revision:
5:969aeadd077e
Parent:
1:0f886ffbe0c1
Comments put in

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cathal66 5:969aeadd077e 1 #include "mbed.h" //Include the mbed.h file
cathal66 5:969aeadd077e 2 #include "rtos.h" //Include the rtos.h file
emilmont 1:0f886ffbe0c1 3
cathal66 5:969aeadd077e 4 Mutex stdio_mutex; //Setup the mutex
emilmont 1:0f886ffbe0c1 5
cathal66 5:969aeadd077e 6 void notify(const char* name, int state) { //function and passes data NAME and STATE to the function
cathal66 5:969aeadd077e 7 stdio_mutex.lock(); //mutex lock stdio_mutex
cathal66 5:969aeadd077e 8 printf("%s: %d\n\r", name, state); //read name and state and print them on serial
cathal66 5:969aeadd077e 9 stdio_mutex.unlock(); //mutex unlock stdio_mutex
emilmont 1:0f886ffbe0c1 10 }
emilmont 1:0f886ffbe0c1 11
cathal66 5:969aeadd077e 12 void test_thread(void const *args) { //Thread and function, pass data to the thread/function
cathal66 5:969aeadd077e 13 while (true) { //Super loop
cathal66 5:969aeadd077e 14 notify((const char*)args, 0); //function call, passes number and toggles data to the function
cathal66 5:969aeadd077e 15 Thread::wait(1000); //Thread wait 1 sec
cathal66 5:969aeadd077e 16 notify((const char*)args, 1); ////function call, pass two data to the function
cathal66 5:969aeadd077e 17 Thread::wait(1000); //Thread wait 1 sec
cathal66 5:969aeadd077e 18 } //end super loop
cathal66 5:969aeadd077e 19 } //end function
emilmont 1:0f886ffbe0c1 20
emilmont 1:0f886ffbe0c1 21 int main() {
cathal66 5:969aeadd077e 22 Thread t2(test_thread, (void *)"Th 2"); //start thread t2
cathal66 5:969aeadd077e 23 Thread t3(test_thread, (void *)"Th 3"); //start thread t3
emilmont 1:0f886ffbe0c1 24
cathal66 5:969aeadd077e 25 test_thread((void *)"Th 1"); //function call
cathal66 5:969aeadd077e 26 } //end main