Remove priority parameter from tasks

In the end, priorities are only usefull in preemptive systems. Here, it would
only garentee the execution order, which we don't care about most of the time
This commit is contained in:
Steins7 2024-05-14 14:51:50 +02:00
parent 34fb4dac76
commit c09d2cda67
2 changed files with 32 additions and 28 deletions

View File

@ -11,6 +11,7 @@
#include "task.h"
#include "../drv/stk.h"
#include "error.h"
#include "debug.h"
//--local definitions-----------------------------------------------------------
@ -21,7 +22,6 @@ struct TaskContext {
Task function;
uint32_t delay_ms;
uint8_t state;
uint8_t priority;
};
void task_callback(void);
@ -39,36 +39,38 @@ void task_start_scheduler(void)
{
while (1) {
uint32_t delay = UINT32_MAX;
for (uint8_t priority = 0; priority < UINT8_MAX; ++priority) {
bool task_runned = false;
for (uint8_t i = 0; i < task_nb; ++i) {
if (task_list[i].function != nullptr) {
if (task_list[i].priority == priority) {
if (task_list[i].delay_ms == 0) {
task_runned = true;
struct TaskReturn ret
= task_list[i].function(task_list[i].state);
if (ret.state == _TASK_COUNT_EXIT) {
task_list[i].function = nullptr;
} else {
task_list[i].delay_ms = ret.delay_ms;
task_list[i].state = ret.state;
}
}
if (delay > task_list[i].delay_ms) {
delay = task_list[i].delay_ms;
}
bool task_runned = false;
for (uint8_t i = 0; i < task_nb; ++i) {
if (task_list[i].function != nullptr) {
if (task_list[i].delay_ms == 0) {
task_runned = true;
debug_trace("%u", 1);
debug_trace("%u", i + 2);
struct TaskReturn ret
= task_list[i].function(task_list[i].state);
debug_trace("%u", i + 2);
debug_trace("%u", 1);
if (ret.state == _TASK_COUNT_EXIT) {
task_list[i].function = nullptr;
} else {
task_list[i].delay_ms = ret.delay_ms;
task_list[i].state = ret.state;
}
}
}
if (task_runned) {
break;
if (delay > task_list[i].delay_ms) {
delay = task_list[i].delay_ms;
}
}
}
if (task_runned) {
break;
}
if (delay > 0) {
debug_trace("%u", 1);
debug_trace("%u", 0);
stk_configure(delay * 1000, task_callback);
stk_start();
__asm("wfi");
@ -83,13 +85,16 @@ void task_start_scheduler(void)
task_list[i].delay_ms -= delay;
}
}
debug_trace("%u", 0);
debug_trace("%u", 1);
}
}
//never returns
}
void task_start(Task task, uint8_t priority)
void task_start(Task task)
{
for (uint8_t i = 0; i < MAX_TASK_NB; ++i) {
if (task_list[i].function == nullptr) {
@ -97,7 +102,6 @@ void task_start(Task task, uint8_t priority)
task_list[i].function = task;
task_list[i].delay_ms = 0;
task_list[i].state = 0;
task_list[i].priority = priority;
++task_nb;
return;
@ -133,9 +137,9 @@ bool task_is_running(Task task)
}
//--local functions-------------------------------------------------------------
void task_callback(void) {
stk_stop();
}

View File

@ -48,7 +48,7 @@ typedef struct TaskReturn(*Task)(uint8_t);
void task_start_scheduler(void);
void task_start(Task task, uint8_t priority);
void task_start(Task task);
void task_stop(Task task);
bool task_is_running(Task task);