Midnight Sun Firmware
|
RTOS helper libraries. More...
Classes | |
struct | Queue |
Queue storage and access struct. More... | |
struct | Semaphore |
Semaphore object with handle and buffer. More... | |
struct | Task |
Macros | |
#define | delay_s(time) delay_ms((time)*1000) |
Blocking delay for some amount of time in seconds. More... | |
#define | BLOCK_INDEFINITELY UINT16_MAX |
#define | INVALID_EVENT 32 |
#define | QUEUE_DELAY_BLOCKING portMAX_DELAY |
#define | BLOCK_INDEFINITELY UINT16_MAX |
Maximum time permitted to wait for a semaphore or mutex. | |
#define | TASK(task_name, task_stack_size) |
Define a task function. This should go in a source file (.c). More... | |
#define | MAX_NUM_TASKS 15 |
Maximum amount of RTOS tasks supported at a time. | |
#define | TASK_PRIORITY(prio) ((TaskPriority)prio) |
Convienience priority to make code more readable. | |
#define | WAIT_TASK_TIMEOUT_MS 1000 |
Define wait timeout as 1 second, tasks cycle executino should not take longer than a second. | |
#define | TASK_MIN_STACK_SIZE configMINIMAL_STACK_SIZE |
Minimum stack size a task can have. If you pass in something smaller than the min size, a warning will be issued. | |
#define | TASK_STACK_256 ((size_t)256) |
Common stack sizes. If your task is failing for strange reasons, bump the stack size one size up. | |
#define | TASK_STACK_512 ((size_t)512) |
#define | TASK_STACK_1024 ((size_t)1024) |
#define | TASK_STACK_2048 ((size_t)2048) |
#define | TASK_STACK_4096 ((size_t)4096) |
Typedefs | |
typedef uint8_t | Event |
typedef struct Semaphore | Semaphore |
Semaphore object with handle and buffer. | |
typedef Semaphore | Mutex |
typedef UBaseType_t | TaskPriority |
typedef struct Task | Task |
Functions | |
void | delay_ms (uint32_t time_ms) |
Blocking delay for some amount of time in milliseconds. More... | |
void | non_blocking_delay_ms (uint32_t time_ms) |
Non-blocking delay for some amount of time in milliseconds. More... | |
StatusCode | event_from_notification (uint32_t *notification, Event *event) |
Get the highest priority event available and clears it. More... | |
bool | notify_check_event (uint32_t *notification, Event event) |
Checks if the notification is available in the event. More... | |
StatusCode | notify_get (uint32_t *notification) |
Get the current notification value for the calilng task without a timeout. More... | |
StatusCode | notify_wait (uint32_t *notification, uint32_t ms_to_wait) |
Get the current notification value for the calilng task with a maximum timeout. More... | |
StatusCode | notify (Task *task, Event event) |
Notify a specific task with an event. More... | |
void | notify_from_isr (Task *task, Event event) |
Sends an event notification from an ISR to a task. More... | |
StatusCode | queue_init (Queue *queue) |
Create a queue with the parameters specified in settings. More... | |
StatusCode | queue_send (Queue *queue, const void *item, uint32_t delay_ms) |
Place an item into the queue, delaying for delay_ms before timing out. More... | |
StatusCode | queue_send_from_isr (Queue *queue, const void *item, BaseType_t *higher_prio_woken) |
Place an item into the queue from an ISR. More... | |
StatusCode | queue_receive (Queue *queue, void *buf, uint32_t delay_ms) |
Retrieve an item from the queue, delaying for delay_ms before timing out. More... | |
StatusCode | queue_receive_from_isr (Queue *queue, void *buf, BaseType_t *higher_prio_woken) |
Retrieve an item from the queue, delaying for delay_ms before timing out. More... | |
StatusCode | queue_peek (Queue *queue, void *buf, uint32_t delay_ms) |
Receive an item from the queue without removing it. More... | |
void | queue_reset (Queue *queue) |
Reset all data in the queue. More... | |
uint32_t | queue_get_num_items (Queue *queue) |
Retrieve the total number of spaces in the queue. More... | |
uint32_t | queue_get_spaces_available (Queue *queue) |
Retrieve the space left in the queue. More... | |
StatusCode | mutex_init (Mutex *mutex) |
Initializes a mutex using provided static entity. More... | |
StatusCode | mutex_lock (Mutex *mutex, uint16_t ms_to_wait) |
Locks a Mutex. More... | |
StatusCode | mutex_unlock (Mutex *mutex) |
Unlocks a Mutex. More... | |
StatusCode | sem_init (Semaphore *sem, uint32_t max_count, uint32_t initial_count) |
Initializes counting semaphore with max and initial count. More... | |
StatusCode | sem_wait (Semaphore *sem, uint32_t timeout_ms) |
Obtains previously initiated semaphore and decrements the counting semaphore. More... | |
StatusCode | sem_post (Semaphore *sem) |
Releases a semaphore and increments the counting semaphore. More... | |
StatusCode | tasks_init_task (Task *task, TaskPriority priority, void *context) |
Initialize a task that was previously declared with TASK(). More... | |
void | tasks_start (void) |
Start the FreeRTOS scheduler to run the tasks that were previously initialized. More... | |
StatusCode | tasks_init (void) |
Initialize the task module. More... | |
StatusCode | wait_tasks (uint16_t num_tasks) |
Waits for num_tasks of RTOS tasks to finish. More... | |
StatusCode | send_task_end (void) |
A wrapper to give to the semaphore, to be called by tasks when they complete. More... | |
RTOS helper libraries.
#define delay_s | ( | time | ) | delay_ms((time)*1000) |
Blocking delay for some amount of time in seconds.
time_ms | Amount of time to delay for |
#define TASK | ( | task_name, | |
task_stack_size | |||
) |
Define a task function. This should go in a source file (.c).
The generated function has the following signature: void _s_your_task_function(void *context) where context is the context pointer passed to tasks_init_task.
task_name | is the name of your task, which should match any previous DECLARE_TASK declarations. |
task_stack_size | is the depth of your task's stack - use your judgement to choose. |
void delay_ms | ( | uint32_t | time_ms | ) |
Blocking delay for some amount of time in milliseconds.
time_ms | Amount of time to delay for |
StatusCode event_from_notification | ( | uint32_t * | notification, |
Event * | event | ||
) |
Get the highest priority event available and clears it.
Call this function in a while loop to clear all events
notification | Notification value that is cleared and returned |
event | Event value that is updated to the highest priority |
StatusCode mutex_init | ( | Mutex * | mutex | ) |
Initializes a mutex using provided static entity.
mutex | Mutex handle |
StatusCode mutex_lock | ( | Mutex * | mutex, |
uint16_t | ms_to_wait | ||
) |
Locks a Mutex.
The locking task is responsible for unlocking the mutex Waits ms_to_wait milliseconds if mutex is already locked, then times out Using BLOCK_INDEFINITELY will cause this method to wait forever on mutex becoming available
mutex | Mutex handle |
ms_to_wait | Amount of time to wait for mutex |
StatusCode mutex_unlock | ( | Mutex * | mutex | ) |
Unlocks a Mutex.
The task which locks the mutex MUST also be the one to unlock it Caller specifies whether the method is being called from a task or interrupt handler higher_priority_task_woken informs the caller whether a higher priority task has become unblocked
mutex | Mutex handle |
void non_blocking_delay_ms | ( | uint32_t | time_ms | ) |
Non-blocking delay for some amount of time in milliseconds.
time_ms | Amount of time to delay for |
StatusCode notify | ( | Task * | task, |
Event | event | ||
) |
Notify a specific task with an event.
task | Pointer to the task to notify |
event | Numeric value used to signal task |
bool notify_check_event | ( | uint32_t * | notification, |
Event | event | ||
) |
Checks if the notification is available in the event.
notification | Pointer to the notification to |
void notify_from_isr | ( | Task * | task, |
Event | event | ||
) |
Sends an event notification from an ISR to a task.
task | Pointer to the task to notify |
event | Numeric value used to signal task |
StatusCode notify_get | ( | uint32_t * | notification | ) |
Get the current notification value for the calilng task without a timeout.
notification | Pointer to a notification value that is updated upon success |
StatusCode notify_wait | ( | uint32_t * | notification, |
uint32_t | ms_to_wait | ||
) |
Get the current notification value for the calilng task with a maximum timeout.
notification | Pointer to a notification value that is polled |
ms_to_wait | Time in milliseconds to wait for a notification before timing out |
uint32_t queue_get_num_items | ( | Queue * | queue | ) |
Retrieve the total number of spaces in the queue.
queue | Pointer to queue handle |
uint32_t queue_get_spaces_available | ( | Queue * | queue | ) |
Retrieve the space left in the queue.
queue | Pointer to queue handle |
StatusCode queue_init | ( | Queue * | queue | ) |
Create a queue with the parameters specified in settings.
queue | Pointer to queue handle |
StatusCode queue_peek | ( | Queue * | queue, |
void * | buf, | ||
uint32_t | delay_ms | ||
) |
Receive an item from the queue without removing it.
queue | Pointer to queue handle |
item | Pointer to the buffer to fill from the queue |
delay_ms | Time in milliseconds to wait for data in the queue before timing out |
StatusCode queue_receive | ( | Queue * | queue, |
void * | buf, | ||
uint32_t | delay_ms | ||
) |
Retrieve an item from the queue, delaying for delay_ms before timing out.
queue | Pointer to queue handle |
item | Pointer to the buffer to fill from the queue |
delay_ms | Time in milliseconds to wait for data in the queue before timing out |
StatusCode queue_receive_from_isr | ( | Queue * | queue, |
void * | buf, | ||
BaseType_t * | higher_prio_woken | ||
) |
Retrieve an item from the queue, delaying for delay_ms before timing out.
queue | Pointer to queue handle |
item | Pointer to the buffer to fill from the queue |
higher_prio_woken | Boolean to indicate a context switch after exiting the ISR |
void queue_reset | ( | Queue * | queue | ) |
Reset all data in the queue.
queue | Pointer to queue handle |
StatusCode queue_send | ( | Queue * | queue, |
const void * | item, | ||
uint32_t | delay_ms | ||
) |
Place an item into the queue, delaying for delay_ms before timing out.
queue | Pointer to queue handle |
item | Pointer to the item sent to the queue |
delay_ms | Time in milliseconds to wait for space in the queue before timing out |
StatusCode queue_send_from_isr | ( | Queue * | queue, |
const void * | item, | ||
BaseType_t * | higher_prio_woken | ||
) |
Place an item into the queue from an ISR.
queue | Pointer to queue handle |
item | Pointer to the item sent to the queue |
higher_prio_woken | Boolean to indicate a context switch after exiting the ISR |
StatusCode sem_init | ( | Semaphore * | sem, |
uint32_t | max_count, | ||
uint32_t | initial_count | ||
) |
Initializes counting semaphore with max and initial count.
sem | Semaphore handle |
max_count | Maximum count for counting semaphore |
initial_count | Initial count value to set the counting semaphore |
StatusCode sem_post | ( | Semaphore * | sem | ) |
Releases a semaphore and increments the counting semaphore.
Note that this must not be used from ISR An error can occur if there is no space on the queue
sem | Semaphore handle |
StatusCode sem_wait | ( | Semaphore * | sem, |
uint32_t | timeout_ms | ||
) |
Obtains previously initiated semaphore and decrements the counting semaphore.
Waits timeout_ms milliseconds for the semaphore to become available
sem | Semaphore handle |
timeout_ms | Amount of time to wait for the semaphore |
StatusCode send_task_end | ( | void | ) |
A wrapper to give to the semaphore, to be called by tasks when they complete.
StatusCode tasks_init | ( | void | ) |
Initialize the task module.
Must be called before tasks are initialized or the scheduler is started.
StatusCode tasks_init_task | ( | Task * | task, |
TaskPriority | priority, | ||
void * | context | ||
) |
Initialize a task that was previously declared with TASK().
task | Task handle |
priority | The task priority: higher number is higher priority, and the maximum |
context | Pointer to arguments that are passed to the task is configNUM_TASK_PRIORITIES - 1. |
void tasks_start | ( | void | ) |
Start the FreeRTOS scheduler to run the tasks that were previously initialized.
This function should not return!
StatusCode wait_tasks | ( | uint16_t | num_tasks | ) |
Waits for num_tasks of RTOS tasks to finish.
num_tasks | Number of task completions to wait for |
Takes num_tasks from end task semaphore, tracking the number of tasks completed