]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/tests/rtos/cmsis/mutex/main.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / tests / rtos / cmsis / mutex / main.cpp
1 #include "mbed.h"
2 #include "cmsis_os.h"
3
4 osMutexId stdio_mutex;
5 osMutexDef(stdio_mutex);
6
7 void notify(const char* name, int state) {
8 osMutexWait(stdio_mutex, osWaitForever);
9 printf("%s: %d\n\r", name, state);
10 osMutexRelease(stdio_mutex);
11 }
12
13 void test_thread(void const *args) {
14 while (true) {
15 notify((const char*)args, 0); osDelay(1000);
16 notify((const char*)args, 1); osDelay(1000);
17 }
18 }
19
20 void t2(void const *argument) {test_thread("Th 2");}
21 osThreadDef(t2, osPriorityNormal, DEFAULT_STACK_SIZE);
22
23 void t3(void const *argument) {test_thread("Th 3");}
24 osThreadDef(t3, osPriorityNormal, DEFAULT_STACK_SIZE);
25
26 int main() {
27 stdio_mutex = osMutexCreate(osMutex(stdio_mutex));
28
29 osThreadCreate(osThread(t2), NULL);
30 osThreadCreate(osThread(t3), NULL);
31
32 test_thread((void *)"Th 1");
33 }
Imprint / Impressum