From c09d2cda67a9cb4c9ff21c5c1a13162979dcf17c Mon Sep 17 00:00:00 2001 From: Steins7 Date: Tue, 14 May 2024 14:51:50 +0200 Subject: [PATCH] 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 --- srv/task.c | 58 +++++++++++++++++++++++++++++------------------------- srv/task.h | 2 +- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/srv/task.c b/srv/task.c index 0baba14..72efc46 100644 --- a/srv/task.c +++ b/srv/task.c @@ -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(); } + diff --git a/srv/task.h b/srv/task.h index 361da76..435cca3 100644 --- a/srv/task.h +++ b/srv/task.h @@ -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);