finish lab

This commit is contained in:
Rémi Heredero 2024-02-26 14:54:31 +01:00
parent 23ffd43eb8
commit 053fcabc63

78
main.c
View File

@ -6,27 +6,68 @@
#include CMSIS_device_header #include CMSIS_device_header
#include "cmsis_os2.h" #include "cmsis_os2.h"
#include "EventRecorder.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 * Application main thread
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
__NO_RETURN static void app_main (void *argument) { __NO_RETURN static void Thread_1 (void *args) {
(void)argument; osThreadId_t* id = (osThreadId_t*)args;
// ... osStatus_t status;
for (;;) {} for (;;) {
osThreadState_t state = osThreadGetState(*id);
if(state != osThreadBlocked) { // Thread run
osThreadSuspend(*id);
}
status = osDelay(50);
}
} }
void task1(void *args) { __NO_RETURN static void Thread_2(void *args) {
(void)args; osThreadId_t* id = (osThreadId_t*)args;
for(;;) {} osStatus_t status;
for(;;) {
osThreadState_t state = osThreadGetState(*id);
if(state == osThreadBlocked) { // Thread suspended
osThreadResume(*id);
}
status = osDelay(20);
}
} }
__NO_RETURN static void task2(void *args) { __NO_RETURN static void Thread_3(void *args) {
(void)args; (void)args;
for(;;) {} uint32_t i = 0;
osStatus_t status;
for(;;) {
i = (i+1) % 10;
status = osDelay(i);
}
} }
__NO_RETURN static void task3(void *args) { __NO_RETURN static void Thread_4(void *args) {
(void)args; (void)args;
osStatus_t status;
for(;;) {} for(;;) {}
} }
@ -36,11 +77,18 @@ int main (void) {
SystemCoreClockUpdate(); SystemCoreClockUpdate();
EventRecorderInitialize(EventRecordAll, 1U); EventRecorderInitialize(EventRecordAll, 1U);
osThreadId_t thread1;
osThreadId_t thread2;
osThreadId_t thread3;
osThreadId_t thread4;
osKernelInitialize(); // Initialize CMSIS-RTOS osKernelInitialize(); // Initialize CMSIS-RTOS
thread1 = osThreadNew(app_main, NULL, NULL); // Create application main thread
osThreadNew(task1, NULL, NULL); thread1 = osThreadNew(Thread_1, &thread4, &thread1_attr);
osThreadNew(task2, NULL, NULL); thread2 = osThreadNew(Thread_2, &thread4, &thread2_attr);
osThreadNew(task3, NULL, NULL); thread3 = osThreadNew(Thread_3, NULL, &thread3_attr);
osKernelStart(); // Start thread execution thread4 = osThreadNew(Thread_4, NULL, &thread4_attr);
osKernelStart(); // Start thread execution
for (;;) {} for (;;) {}
} }