amit ate
/
Wthread_mutex_blinky
Mutex Example
Fork of rtos_mutex by
Revision 7:ff2e3fbefea7, committed 2017-01-20
- Comitter:
- thinkfire
- Date:
- Fri Jan 20 11:51:11 2017 +0000
- Parent:
- 6:1ae0d86d2020
- Commit message:
- tested
Changed in this revision
diff -r 1ae0d86d2020 -r ff2e3fbefea7 main.cpp --- a/main.cpp Fri Jan 13 19:49:29 2017 +0000 +++ b/main.cpp Fri Jan 20 11:51:11 2017 +0000 @@ -1,25 +1,54 @@ #include "mbed.h" +#include "rtos.h" + +DigitalOut led1(LED1); +DigitalOut led2(LED2); + +Mutex led_mutex; -Mutex stdio_mutex; -Thread t2; -Thread t3; - -void notify(const char* name, int state) { - stdio_mutex.lock(); - printf("%s: %d\n\r", name, state); - stdio_mutex.unlock(); +void delay(void){ +for(int i=0;i<65000;i++){ + for(int j=0;j<100;j++) + { + } + } } - -void test_thread(void const *args) { + +void test_thread1(void const *args) { while (true) { - notify((const char*)args, 0); wait(1); - notify((const char*)args, 1); wait(1); + led_mutex.lock(); + printf("thd1 toogling\n"); + led1 = !led1; + delay(); + led_mutex.unlock(); + Thread::wait(1000); } } +void test_thread2(void const *args) { + while (true) { + led_mutex.lock(); + printf("thd2 toogling\n"); + led1 = !led1; + delay(); + led_mutex.unlock(); + Thread::wait(1000); + } +} +void test_thread(void const *args) { + while (true) { + led_mutex.lock(); + printf("main toogling\n"); + led1 = !led1; + delay(); + led_mutex.unlock(); + Thread::wait(1000); + } +} + int main() { - t2.start(callback(test_thread, (void *)"Th 2")); - t3.start(callback(test_thread, (void *)"Th 3")); - - test_thread((void *)"Th 1"); -} + Thread t2(test_thread1, (void *)"Th 1"); + Thread t3(test_thread2, (void *)"Th 2"); + + test_thread((void *)"main"); +} \ No newline at end of file
diff -r 1ae0d86d2020 -r ff2e3fbefea7 mbed-os.lib --- a/mbed-os.lib Fri Jan 13 19:49:29 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://github.com/ARMmbed/mbed-os/#2885c1b41e63158cb6faf5f107cd821ae06ef26c
diff -r 1ae0d86d2020 -r ff2e3fbefea7 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Fri Jan 20 11:51:11 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
diff -r 1ae0d86d2020 -r ff2e3fbefea7 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Jan 20 11:51:11 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/ad3be0349dc5 \ No newline at end of file