]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/tests/rtos/cmsis/semaphore/main.cpp
Merge commit 'f6d56675f9f981c5464f0ca7a1fbb0162154e8c5'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / tests / rtos / cmsis / semaphore / main.cpp
1 #include "mbed.h"
2 #include "cmsis_os.h"
3
4 osSemaphoreId two_slots;
5 osSemaphoreDef(two_slots);
6
7 void test_thread(void const *name) {
8 while (true) {
9 osSemaphoreWait(two_slots, osWaitForever);
10 printf("%s\n\r", (const char*)name);
11 osDelay(1000);
12 osSemaphoreRelease(two_slots);
13 }
14 }
15
16 void t2(void const *argument) {test_thread("Th 2");}
17 osThreadDef(t2, osPriorityNormal, DEFAULT_STACK_SIZE);
18
19 void t3(void const *argument) {test_thread("Th 3");}
20 osThreadDef(t3, osPriorityNormal, DEFAULT_STACK_SIZE);
21
22 int main (void) {
23 two_slots = osSemaphoreCreate(osSemaphore(two_slots), 2);
24
25 osThreadCreate(osThread(t2), NULL);
26 osThreadCreate(osThread(t3), NULL);
27
28 test_thread((void *)"Th 1");
29 }
Imprint / Impressum