![]() |
Midnight Sun Firmware
|
RTOS helper libraries. More...
Classes | |
| struct | Semaphore |
| Semaphore object with handle and buffer. More... | |
| struct | Queue |
| Queue storage and access struct. More... | |
| struct | SoftTimer |
| Soft timer storage. More... | |
| struct | SoftwareWatchdog |
| Software Watchdog Timer structure Uses a SoftTimer internally to track timeouts. 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 |
| Maximum time permitted to wait for a semaphore or mutex. | |
| #define | BLOCK_INDEFINITELY UINT16_MAX |
| #define | INVALID_EVENT 32 |
| #define | QUEUE_DELAY_BLOCKING 0xFFFFFFFFU |
| Maximum delay time to block current thread. | |
| #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 struct Semaphore | Semaphore |
| Semaphore object with handle and buffer. | |
| typedef Semaphore | Mutex |
| typedef uint8_t | Event |
| typedef TimerHandle_t | SoftTimerId |
| Redefine FreeRTOS TimerHandle_t to SoftTimerId. | |
| typedef void(* | SoftTimerCallback) (SoftTimerId id) |
| Software timer callback function. | |
| 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 | ms_mutex_init (Mutex *mutex) |
| Initializes a mutex using provided static entity. More... | |
| StatusCode | ms_mutex_lock (Mutex *mutex, uint16_t ms_to_wait) |
| Locks a Mutex. More... | |
| StatusCode | ms_mutex_unlock (Mutex *mutex) |
| Unlocks a Mutex. More... | |
| StatusCode | ms_sem_init (Semaphore *sem, uint32_t max_count, uint32_t initial_count) |
| Initializes counting semaphore with max and initial count. More... | |
| StatusCode | ms_sem_wait (Semaphore *sem, uint32_t timeout_ms) |
| Obtains previously initiated semaphore and decrements the counting semaphore. More... | |
| StatusCode | ms_sem_post (Semaphore *sem) |
| Releases a semaphore and increments the counting semaphore. 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 | software_timer_init (uint32_t duration_ms, SoftTimerCallback callback, SoftTimer *timer) |
| Creates a new software timer without starting it. More... | |
| StatusCode | software_timer_start (SoftTimer *timer) |
| Starts an initialized software timer. More... | |
| StatusCode | software_timer_init_and_start (uint32_t duration_ms, SoftTimerCallback callback, SoftTimer *timer) |
| Initializes and starts a software timer. More... | |
| StatusCode | software_timer_cancel (SoftTimer *timer) |
| Cancels a running software timer. More... | |
| StatusCode | software_timer_reset (SoftTimer *timer) |
| Restarts a software timer. More... | |
| bool | software_timer_inuse (SoftTimer *timer) |
| Checks if a software timer is currently active. More... | |
| uint32_t | software_timer_remaining_time (SoftTimer *timer) |
| Gets the remaining time on a software timer. More... | |
| StatusCode | software_watchdog_init (SoftwareWatchdog *watchdog, uint32_t period_ms, SoftTimerCallback fault_callback) |
| Initializes the software watchdog timer. More... | |
| StatusCode | software_watchdog_kick (SoftwareWatchdog *watchdog) |
| "Kicks" (resets) the watchdog timer to prevent timeout More... | |
| StatusCode | software_watchdog_stop (SoftwareWatchdog *watchdog) |
| Stops and disables the watchdog timer. 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 ms_mutex_init | ( | Mutex * | mutex | ) |
Initializes a mutex using provided static entity.
| mutex | Mutex handle |
| StatusCode ms_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 ms_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 |
| StatusCode ms_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 ms_sem_post | ( | Semaphore * | sem | ) |
| StatusCode ms_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 |
| 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 send_task_end | ( | void | ) |
A wrapper to give to the semaphore, to be called by tasks when they complete.
| StatusCode software_timer_cancel | ( | SoftTimer * | timer | ) |
Cancels a running software timer.
| timer | Pointer to the timer instance |
| StatusCode software_timer_init | ( | uint32_t | duration_ms, |
| SoftTimerCallback | callback, | ||
| SoftTimer * | timer | ||
| ) |
Creates a new software timer without starting it.
| duration_ms | Duration of the timer in milliseconds |
| callback | Callback function to execute when the timer expires |
| timer | Pointer to the timer instance |
| StatusCode software_timer_init_and_start | ( | uint32_t | duration_ms, |
| SoftTimerCallback | callback, | ||
| SoftTimer * | timer | ||
| ) |
Initializes and starts a software timer.
| duration_ms | Duration of the timer in milliseconds |
| callback | Callback function to execute when the timer expires |
| timer | Pointer to the timer instance |
| bool software_timer_inuse | ( | SoftTimer * | timer | ) |
Checks if a software timer is currently active.
| timer | Pointer to the timer instance |
| uint32_t software_timer_remaining_time | ( | SoftTimer * | timer | ) |
Gets the remaining time on a software timer.
| timer | Pointer to the timer instance |
| StatusCode software_timer_reset | ( | SoftTimer * | timer | ) |
Restarts a software timer.
| timer | Pointer to the timer instance |
| StatusCode software_timer_start | ( | SoftTimer * | timer | ) |
Starts an initialized software timer.
| timer | Pointer to the timer instance |
| StatusCode software_watchdog_init | ( | SoftwareWatchdog * | watchdog, |
| uint32_t | period_ms, | ||
| SoftTimerCallback | fault_callback | ||
| ) |
Initializes the software watchdog timer.
| watchdog | Pointer to the watchdog instance |
| period_ms | Timeout period in milliseconds |
| fault_callback | Function to call if watchdog is not kicked before timeout |
| StatusCode software_watchdog_kick | ( | SoftwareWatchdog * | watchdog | ) |
"Kicks" (resets) the watchdog timer to prevent timeout
| watchdog | Pointer to the watchdog instance |
| StatusCode software_watchdog_stop | ( | SoftwareWatchdog * | watchdog | ) |
Stops and disables the watchdog timer.
| watchdog | Pointer to the watchdog instance |
| 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