Energy Manager App
Dependencies: C12832_lcd LM75B mbed-rtos mbed
Fork of rtos_mutex by
main.cpp@1:0f886ffbe0c1, 2012-07-13 (annotated)
- Committer:
- emilmont
- Date:
- Fri Jul 13 10:34:00 2012 +0000
- Revision:
- 1:0f886ffbe0c1
- Parent:
- 0:9325f4cd8c1e
- Child:
- 6:3b2a6cb895a9
First implementation
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" |
emilmont | 1:0f886ffbe0c1 | 3 | |
emilmont | 1:0f886ffbe0c1 | 4 | Mutex stdio_mutex; |
emilmont | 1:0f886ffbe0c1 | 5 | |
emilmont | 1:0f886ffbe0c1 | 6 | void notify(const char* name, int state) { |
emilmont | 1:0f886ffbe0c1 | 7 | stdio_mutex.lock(); |
emilmont | 1:0f886ffbe0c1 | 8 | printf("%s: %d\n\r", name, state); |
emilmont | 1:0f886ffbe0c1 | 9 | stdio_mutex.unlock(); |
emilmont | 1:0f886ffbe0c1 | 10 | } |
emilmont | 1:0f886ffbe0c1 | 11 | |
emilmont | 1:0f886ffbe0c1 | 12 | void test_thread(void const *args) { |
emilmont | 1:0f886ffbe0c1 | 13 | while (true) { |
emilmont | 1:0f886ffbe0c1 | 14 | notify((const char*)args, 0); Thread::wait(1000); |
emilmont | 1:0f886ffbe0c1 | 15 | notify((const char*)args, 1); Thread::wait(1000); |
emilmont | 1:0f886ffbe0c1 | 16 | } |
emilmont | 1:0f886ffbe0c1 | 17 | } |
emilmont | 1:0f886ffbe0c1 | 18 | |
emilmont | 1:0f886ffbe0c1 | 19 | int main() { |
emilmont | 1:0f886ffbe0c1 | 20 | Thread t2(test_thread, (void *)"Th 2"); |
emilmont | 1:0f886ffbe0c1 | 21 | Thread t3(test_thread, (void *)"Th 3"); |
emilmont | 1:0f886ffbe0c1 | 22 | |
emilmont | 1:0f886ffbe0c1 | 23 | test_thread((void *)"Th 1"); |
emilmont | 1:0f886ffbe0c1 | 24 | } |