This repository has been archived on 2024-10-30. You can view files and clone it, but cannot push or open issues or pull requests.
PTR-RTX5/main.c

95 lines
2.3 KiB
C
Raw Normal View History

2024-02-26 12:55:42 +00:00
/*----------------------------------------------------------------------------
* CMSIS-RTOS 'main' function template
*---------------------------------------------------------------------------*/
#include "RTE_Components.h"
#include CMSIS_device_header
#include "cmsis_os2.h"
#include "EventRecorder.h"
2024-02-26 13:54:31 +00:00
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"
};
2024-02-26 12:55:42 +00:00
/*----------------------------------------------------------------------------
* Application main thread
*---------------------------------------------------------------------------*/
2024-02-26 13:54:31 +00:00
__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);
}
2024-02-26 12:55:42 +00:00
}
2024-02-26 13:54:31 +00:00
__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);
}
2024-02-26 12:55:42 +00:00
}
2024-02-26 13:54:31 +00:00
__NO_RETURN static void Thread_3(void *args) {
2024-02-26 12:55:42 +00:00
(void)args;
2024-02-26 13:54:31 +00:00
uint32_t i = 0;
osStatus_t status;
for(;;) {
i = (i+1) % 10;
status = osDelay(i);
}
2024-02-26 12:55:42 +00:00
}
2024-02-26 13:54:31 +00:00
__NO_RETURN static void Thread_4(void *args) {
2024-02-26 12:55:42 +00:00
(void)args;
2024-02-26 13:54:31 +00:00
osStatus_t status;
2024-02-26 12:55:42 +00:00
for(;;) {}
}
int main (void) {
// System Initialization
SystemCoreClockUpdate();
EventRecorderInitialize(EventRecordAll, 1U);
2024-02-26 13:54:31 +00:00
osThreadId_t thread1;
osThreadId_t thread2;
osThreadId_t thread3;
osThreadId_t thread4;
2024-02-26 12:55:42 +00:00
osKernelInitialize(); // Initialize CMSIS-RTOS
2024-02-26 13:54:31 +00:00
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
2024-02-26 12:55:42 +00:00
for (;;) {}
}