5#include "../../Inc/Scheduler/Scheduler.h"
25#define WORK_QUEUE_SIZE 32
26#define WORKER_STACK_SIZE 1024
27#define WORKER_PRIORITY (tskIDLE_PRIORITY + 2)
35 if (xQueueReceive(
workQueue, &workItem, portMAX_DELAY) == pdTRUE) {
38 TickType_t startTime = xTaskGetTickCount();
46 TickType_t executionTime = xTaskGetTickCount() - startTime;
47 TickType_t maxTime = pdMS_TO_TICKS(1000 / workItem.
updateable->
hz) / 2;
49 if (executionTime > maxTime) {
62 if (updateable != NULL &&
workQueue != NULL) {
65 .timestamp = xTaskGetTickCount()
69 BaseType_t xHigherPriorityTaskWoken = pdFALSE;
70 if (xQueueSendFromISR(
workQueue, &workItem, &xHigherPriorityTaskWoken) != pdTRUE) {
76 portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
101 for (
int i = 0; updatableArray[i] != NULL && i <
MAX_SENSORS; i++) {
104 if (updateable->
hz <= 0 || updateable->
hz >
MAX_HZ) {
111 TickType_t period = pdMS_TO_TICKS(1000 / updateable->
hz);
112 if (period == 0) period = 1;
119 TimerHandle_t timer = xTimerCreate(
159 vTaskStartScheduler();
203 UBaseType_t queueLength = uxQueueMessagesWaiting(
workQueue);
204 UBaseType_t queueSpaces = uxQueueSpacesAvailable(
workQueue);
212 TaskStatus_t taskStatus;
void SchedulerResumeUpdateable(const char *name)
static ScheduledUpdateable scheduledTasks[MAX_SENSORS]
static QueueHandle_t workQueue
void SchedulerCleanup(void)
#define WORKER_STACK_SIZE
void SchedulerInit(Scheduler *scheduler, Updateable *updatableArray[])
static TaskHandle_t workerTaskHandle
static void workerTask(void *pvParameters)
void SchedulerStop(Scheduler *scheduler)
void SchedulerRun(Scheduler *scheduler)
void SchedulerGetStats(void)
static void updateableTimerCallback(TimerHandle_t xTimer)
void SchedulerSuspendUpdateable(const char *name)
void TaskInit(Task *task, Updateable *updateable, int hz)
Initializes a task with the given sensor and update frequency.
void TaskExecute(Task *task)
Executes the task by calling the sensor's update function.