Maxim nexpaq / nexpaq_dev
Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 0:6c56fb4bc5f0 1 #include "mbed.h"
nexpaq 0:6c56fb4bc5f0 2 #include "cmsis_os.h"
nexpaq 0:6c56fb4bc5f0 3
nexpaq 0:6c56fb4bc5f0 4 #if defined(MBED_RTOS_SINGLE_THREAD)
nexpaq 0:6c56fb4bc5f0 5 #error [NOT_SUPPORTED] test not supported
nexpaq 0:6c56fb4bc5f0 6 #endif
nexpaq 0:6c56fb4bc5f0 7
nexpaq 0:6c56fb4bc5f0 8 osMutexId stdio_mutex;
nexpaq 0:6c56fb4bc5f0 9 osMutexDef(stdio_mutex);
nexpaq 0:6c56fb4bc5f0 10
nexpaq 0:6c56fb4bc5f0 11 void notify(const char* name, int state) {
nexpaq 0:6c56fb4bc5f0 12 osMutexWait(stdio_mutex, osWaitForever);
nexpaq 0:6c56fb4bc5f0 13 printf("%s: %d\n\r", name, state);
nexpaq 0:6c56fb4bc5f0 14 osMutexRelease(stdio_mutex);
nexpaq 0:6c56fb4bc5f0 15 }
nexpaq 0:6c56fb4bc5f0 16
nexpaq 0:6c56fb4bc5f0 17 void test_thread(void const *args) {
nexpaq 0:6c56fb4bc5f0 18 while (true) {
nexpaq 0:6c56fb4bc5f0 19 notify((const char*)args, 0); osDelay(1000);
nexpaq 0:6c56fb4bc5f0 20 notify((const char*)args, 1); osDelay(1000);
nexpaq 0:6c56fb4bc5f0 21 }
nexpaq 0:6c56fb4bc5f0 22 }
nexpaq 0:6c56fb4bc5f0 23
nexpaq 0:6c56fb4bc5f0 24 void t2(void const *argument) {test_thread("Th 2");}
nexpaq 0:6c56fb4bc5f0 25 osThreadDef(t2, osPriorityNormal, DEFAULT_STACK_SIZE);
nexpaq 0:6c56fb4bc5f0 26
nexpaq 0:6c56fb4bc5f0 27 void t3(void const *argument) {test_thread("Th 3");}
nexpaq 0:6c56fb4bc5f0 28 osThreadDef(t3, osPriorityNormal, DEFAULT_STACK_SIZE);
nexpaq 0:6c56fb4bc5f0 29
nexpaq 0:6c56fb4bc5f0 30 int main() {
nexpaq 0:6c56fb4bc5f0 31 stdio_mutex = osMutexCreate(osMutex(stdio_mutex));
nexpaq 0:6c56fb4bc5f0 32
nexpaq 0:6c56fb4bc5f0 33 osThreadCreate(osThread(t2), NULL);
nexpaq 0:6c56fb4bc5f0 34 osThreadCreate(osThread(t3), NULL);
nexpaq 0:6c56fb4bc5f0 35
nexpaq 0:6c56fb4bc5f0 36 test_thread((void *)"Th 1");
nexpaq 0:6c56fb4bc5f0 37 }