Midnight Sun Firmware
Loading...
Searching...
No Matches
tasks.h
1#pragma once
2
3/************************************************************************************************
4 * @file tasks.h
5 *
6 * @brief Header file for the RTOS tasks wrapper
7 *
8 * @date 2024-10-27
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stdbool.h>
14#include <stddef.h>
15
16/* Inter-component Headers */
17#include "FreeRTOS.h"
18#include "semphr.h"
19#include "task.h"
20
21/* Intra-component Headers */
22#include "status.h"
23
39#define TASK(task_name, task_stack_size) \
40 /* forward declaration so we can reference it in the Task */ \
41 static void _s_task_impl_##task_name(void *); \
42 static StackType_t _s_stack_##task_name[task_stack_size]; \
43 /* use a compound literal so users can use it as a pointer */ \
44 Task *task_name = &((Task){ \
45 .task_func = _s_task_impl_##task_name, .name = #task_name, .stack = _s_stack_##task_name, .stack_size = task_stack_size, .handle = NULL, /* will be initialized by tasks_init_task */ \
46 }); \
47 static void _s_task_impl_##task_name(void *context)
48
52#define MAX_NUM_TASKS 15
53
57#define TASK_PRIORITY(prio) ((TaskPriority)prio)
58
63#define WAIT_TASK_TIMEOUT_MS 1000
64
69#define TASK_MIN_STACK_SIZE configMINIMAL_STACK_SIZE
70
75#define TASK_STACK_256 ((size_t)256)
76#define TASK_STACK_512 ((size_t)512)
77#define TASK_STACK_1024 ((size_t)1024)
78#define TASK_STACK_2048 ((size_t)2048)
79#define TASK_STACK_4096 ((size_t)4096)
80
81typedef UBaseType_t TaskPriority;
82
83typedef struct Task {
84 TaskHandle_t handle;
85 TaskFunction_t task_func;
86 char *name;
87 StackType_t *stack;
88 size_t stack_size;
89 StaticTask_t tcb;
90 void *context;
91} Task;
92
101StatusCode tasks_init_task(Task *task, TaskPriority priority, void *context);
102
107void tasks_start(void);
108
115
123StatusCode wait_tasks(uint16_t num_tasks);
124
130
void tasks_start(void)
Start the FreeRTOS scheduler to run the tasks that were previously initialized.
Definition: tasks.c:73
StatusCode wait_tasks(uint16_t num_tasks)
Waits for num_tasks of RTOS tasks to finish.
Definition: tasks.c:93
StatusCode tasks_init_task(Task *task, TaskPriority priority, void *context)
Initialize a task that was previously declared with TASK().
Definition: tasks.c:40
StatusCode send_task_end(void)
A wrapper to give to the semaphore, to be called by tasks when they complete.
Definition: tasks.c:103
StatusCode tasks_init(void)
Initialize the task module.
Definition: tasks.c:82
StatusCode
StatusCodes for various errors.
Definition: status.h:27
Definition: tasks.h:83