Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@1:7aa2ff92570b, 2012-07-13 (annotated)
- Committer:
- emilmont
- Date:
- Fri Jul 13 14:44:49 2012 +0000
- Revision:
- 1:7aa2ff92570b
- Parent:
- 0:2375cd56688e
First implementation
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| emilmont | 1:7aa2ff92570b | 1 | #include "mbed.h" |
| emilmont | 1:7aa2ff92570b | 2 | #include "cmsis_os.h" |
| emilmont | 1:7aa2ff92570b | 3 | |
| emilmont | 1:7aa2ff92570b | 4 | osSemaphoreId two_slots; |
| emilmont | 1:7aa2ff92570b | 5 | osSemaphoreDef(two_slots); |
| emilmont | 1:7aa2ff92570b | 6 | |
| emilmont | 1:7aa2ff92570b | 7 | void test_thread(void const *name) { |
| emilmont | 1:7aa2ff92570b | 8 | while (true) { |
| emilmont | 1:7aa2ff92570b | 9 | osSemaphoreWait(two_slots, osWaitForever); |
| emilmont | 1:7aa2ff92570b | 10 | printf("%s\n\r", (const char*)name); |
| emilmont | 1:7aa2ff92570b | 11 | osDelay(1000); |
| emilmont | 1:7aa2ff92570b | 12 | osSemaphoreRelease(two_slots); |
| emilmont | 1:7aa2ff92570b | 13 | } |
| emilmont | 1:7aa2ff92570b | 14 | } |
| emilmont | 1:7aa2ff92570b | 15 | |
| emilmont | 1:7aa2ff92570b | 16 | void t2(void const *argument) {test_thread("Th 2");} |
| emilmont | 1:7aa2ff92570b | 17 | osThreadDef(t2, osPriorityNormal, DEFAULT_STACK_SIZE); |
| emilmont | 1:7aa2ff92570b | 18 | |
| emilmont | 1:7aa2ff92570b | 19 | void t3(void const *argument) {test_thread("Th 3");} |
| emilmont | 1:7aa2ff92570b | 20 | osThreadDef(t3, osPriorityNormal, DEFAULT_STACK_SIZE); |
| emilmont | 1:7aa2ff92570b | 21 | |
| emilmont | 1:7aa2ff92570b | 22 | int main (void) { |
| emilmont | 1:7aa2ff92570b | 23 | two_slots = osSemaphoreCreate(osSemaphore(two_slots), 2); |
| emilmont | 1:7aa2ff92570b | 24 | |
| emilmont | 1:7aa2ff92570b | 25 | osThreadCreate(osThread(t2), NULL); |
| emilmont | 1:7aa2ff92570b | 26 | osThreadCreate(osThread(t3), NULL); |
| emilmont | 1:7aa2ff92570b | 27 | |
| emilmont | 1:7aa2ff92570b | 28 | test_thread((void *)"Th 1"); |
| emilmont | 1:7aa2ff92570b | 29 | } |
