KEIS
Dependencies: C12832_lcd mbed-rtos mbed
Fork of rtos_mutex by
main.cpp@5:cdc855b58daf, 2013-09-25 (annotated)
- Committer:
- khayakawa
- Date:
- Wed Sep 25 05:05:24 2013 +0000
- Revision:
- 5:cdc855b58daf
- Parent:
- 1:0f886ffbe0c1
KEIS;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:0f886ffbe0c1 | 1 | #include "mbed.h" |
emilmont | 1:0f886ffbe0c1 | 2 | #include "rtos.h" |
khayakawa | 5:cdc855b58daf | 3 | #include "C12832_lcd.h" |
emilmont | 1:0f886ffbe0c1 | 4 | |
khayakawa | 5:cdc855b58daf | 5 | C12832_LCD lcd; |
khayakawa | 5:cdc855b58daf | 6 | Mutex lcd_mutex; |
emilmont | 1:0f886ffbe0c1 | 7 | |
khayakawa | 5:cdc855b58daf | 8 | void mu_write(const char* name) { |
khayakawa | 5:cdc855b58daf | 9 | Thread::wait(rand()/1000000); |
khayakawa | 5:cdc855b58daf | 10 | lcd_mutex.lock(); |
khayakawa | 5:cdc855b58daf | 11 | lcd.locate(0,3); |
khayakawa | 5:cdc855b58daf | 12 | lcd.printf("%s writing\n\r", name); |
khayakawa | 5:cdc855b58daf | 13 | Thread::wait(1000); |
khayakawa | 5:cdc855b58daf | 14 | lcd.cls(); |
khayakawa | 5:cdc855b58daf | 15 | lcd_mutex.unlock(); |
emilmont | 1:0f886ffbe0c1 | 16 | } |
emilmont | 1:0f886ffbe0c1 | 17 | |
emilmont | 1:0f886ffbe0c1 | 18 | void test_thread(void const *args) { |
emilmont | 1:0f886ffbe0c1 | 19 | while (true) { |
khayakawa | 5:cdc855b58daf | 20 | mu_write((const char*)args); |
emilmont | 1:0f886ffbe0c1 | 21 | } |
emilmont | 1:0f886ffbe0c1 | 22 | } |
emilmont | 1:0f886ffbe0c1 | 23 | |
emilmont | 1:0f886ffbe0c1 | 24 | int main() { |
khayakawa | 5:cdc855b58daf | 25 | lcd.cls(); |
emilmont | 1:0f886ffbe0c1 | 26 | Thread t2(test_thread, (void *)"Th 2"); |
emilmont | 1:0f886ffbe0c1 | 27 | Thread t3(test_thread, (void *)"Th 3"); |
khayakawa | 5:cdc855b58daf | 28 | Thread t4(test_thread, (void *)"Th 4"); |
emilmont | 1:0f886ffbe0c1 | 29 | |
emilmont | 1:0f886ffbe0c1 | 30 | test_thread((void *)"Th 1"); |
emilmont | 1:0f886ffbe0c1 | 31 | } |