95 lines
2.3 KiB
C
95 lines
2.3 KiB
C
/*----------------------------------------------------------------------------
|
|
* CMSIS-RTOS 'main' function template
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
#include "RTE_Components.h"
|
|
#include CMSIS_device_header
|
|
#include "cmsis_os2.h"
|
|
#include "EventRecorder.h"
|
|
|
|
const osThreadAttr_t thread1_attr = {
|
|
.priority = osPriorityNormal, // Set initial thread priority to high
|
|
.name = "BLOCKER"
|
|
};
|
|
|
|
const osThreadAttr_t thread2_attr = {
|
|
.priority = osPriorityAboveNormal4,
|
|
.name = "RESUMER"
|
|
};
|
|
|
|
const osThreadAttr_t thread3_attr = {
|
|
.priority = osPriorityAboveNormal,
|
|
.name = "DUMMY_WAITER"
|
|
};
|
|
|
|
const osThreadAttr_t thread4_attr = {
|
|
.priority = osPriorityLow,
|
|
.name = "DO_NOTHING"
|
|
};
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
* Application main thread
|
|
*---------------------------------------------------------------------------*/
|
|
__NO_RETURN static void Thread_1 (void *args) {
|
|
osThreadId_t* id = (osThreadId_t*)args;
|
|
osStatus_t status;
|
|
for (;;) {
|
|
osThreadState_t state = osThreadGetState(*id);
|
|
if(state != osThreadBlocked) { // Thread run
|
|
osThreadSuspend(*id);
|
|
}
|
|
status = osDelay(50);
|
|
}
|
|
}
|
|
|
|
__NO_RETURN static void Thread_2(void *args) {
|
|
osThreadId_t* id = (osThreadId_t*)args;
|
|
osStatus_t status;
|
|
for(;;) {
|
|
osThreadState_t state = osThreadGetState(*id);
|
|
if(state == osThreadBlocked) { // Thread suspended
|
|
osThreadResume(*id);
|
|
}
|
|
status = osDelay(20);
|
|
}
|
|
}
|
|
|
|
__NO_RETURN static void Thread_3(void *args) {
|
|
(void)args;
|
|
uint32_t i = 0;
|
|
osStatus_t status;
|
|
for(;;) {
|
|
i = (i+1) % 10;
|
|
status = osDelay(i);
|
|
}
|
|
}
|
|
|
|
__NO_RETURN static void Thread_4(void *args) {
|
|
(void)args;
|
|
osStatus_t status;
|
|
for(;;) {}
|
|
}
|
|
|
|
int main (void) {
|
|
|
|
// System Initialization
|
|
SystemCoreClockUpdate();
|
|
EventRecorderInitialize(EventRecordAll, 1U);
|
|
|
|
osThreadId_t thread1;
|
|
osThreadId_t thread2;
|
|
osThreadId_t thread3;
|
|
osThreadId_t thread4;
|
|
|
|
osKernelInitialize(); // Initialize CMSIS-RTOS
|
|
|
|
thread1 = osThreadNew(Thread_1, &thread4, &thread1_attr);
|
|
thread2 = osThreadNew(Thread_2, &thread4, &thread2_attr);
|
|
thread3 = osThreadNew(Thread_3, NULL, &thread3_attr);
|
|
thread4 = osThreadNew(Thread_4, NULL, &thread4_attr);
|
|
|
|
osKernelStart(); // Start thread execution
|
|
for (;;) {}
|
|
}
|