finish lab
This commit is contained in:
parent
23ffd43eb8
commit
053fcabc63
76
main.c
76
main.c
@ -6,27 +6,68 @@
|
||||
#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 app_main (void *argument) {
|
||||
(void)argument;
|
||||
// ...
|
||||
for (;;) {}
|
||||
__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);
|
||||
}
|
||||
}
|
||||
|
||||
void task1(void *args) {
|
||||
(void)args;
|
||||
for(;;) {}
|
||||
__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 task2(void *args) {
|
||||
__NO_RETURN static void Thread_3(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;
|
||||
osStatus_t status;
|
||||
for(;;) {}
|
||||
}
|
||||
|
||||
@ -36,11 +77,18 @@ int main (void) {
|
||||
SystemCoreClockUpdate();
|
||||
EventRecorderInitialize(EventRecordAll, 1U);
|
||||
|
||||
osThreadId_t thread1;
|
||||
osThreadId_t thread2;
|
||||
osThreadId_t thread3;
|
||||
osThreadId_t thread4;
|
||||
|
||||
osKernelInitialize(); // Initialize CMSIS-RTOS
|
||||
thread1 = osThreadNew(app_main, NULL, NULL); // Create application main thread
|
||||
osThreadNew(task1, NULL, NULL);
|
||||
osThreadNew(task2, NULL, NULL);
|
||||
osThreadNew(task3, NULL, NULL);
|
||||
|
||||
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 (;;) {}
|
||||
}
|
||||
|
Reference in New Issue
Block a user