uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
|
Background task scheduler. More...
#include <stdint.h>
Go to the source code of this file.
Macros | |
#define | F_TIMER 20000 |
Frequency of the CPU timer used in by the task scheduler in [Hz]. More... | |
#define | F_TASK_FAST F_TIMER |
High priority task: Called every 50 us (20 kHz) More... | |
#define | F_TASK_MID (F_TASK_FAST / 20) |
Medium priority task: Called every 1 ms (1 kHz) More... | |
#define | F_TASK_SLOW (F_TASK_MID / 10) |
Low priority task: Called every 10 ms (100 Hz) More... | |
Typedefs | |
typedef void(* | background_task_t) (void) |
Data type for background task pointers. More... | |
Functions | |
void | process_background_tasks (void) |
Invokes registered background tasks if certain conditions are met. More... | |
void | init_background_tasks (background_task_t high_freq_tasks[], uint8_t high_freq_tasks_size, background_task_t mid_freq_tasks[], uint8_t mid_freq_tasks_size, background_task_t low_freq_tasks[], uint8_t low_freq_tasks_size) |
Initializes the background task scheduler. More... | |
Background task scheduler.
#define F_TASK_FAST F_TIMER |
High priority task: Called every 50 us (20 kHz)
#define F_TASK_MID (F_TASK_FAST / 20) |
Medium priority task: Called every 1 ms (1 kHz)
#define F_TASK_SLOW (F_TASK_MID / 10) |
Low priority task: Called every 10 ms (100 Hz)
#define F_TIMER 20000 |
Frequency of the CPU timer used in by the task scheduler in [Hz].
typedef void(* background_task_t) (void) |
Data type for background task pointers.
void init_background_tasks | ( | background_task_t | high_freq_tasks[], |
uint8_t | high_freq_tasks_size, | ||
background_task_t | mid_freq_tasks[], | ||
uint8_t | mid_freq_tasks_size, | ||
background_task_t | low_freq_tasks[], | ||
uint8_t | low_freq_tasks_size | ||
) |
Initializes the background task scheduler.
Configures CPU timer 0 to provide the main clock for the background task scheduler and registers the tasks to be invoked cyclically. The tasks are grouped into three levels of priority. High priority tasks are executed more frequently.
high_freq_tasks | an array of function pointers to high frequency tasks |
high_freq_tasks_size | number of high frequency tasks |
mid_freq_tasks | an array of function pointers to medium frequency tasks |
mid_freq_tasks_size | number of medium frequency tasks |
low_freq_tasks | an array of function pointers to low frequency tasks |
low_freq_tasks_size | number of low frequency tasks |
void process_background_tasks | ( | void | ) |
Invokes registered background tasks if certain conditions are met.
This procedure must be called in the main loop of the program. If the CPU timer interrupt flag of CPU timer 0 is active, it is reset and the prescaler counters are incremented. If one of the prescalers reaches its target value, it is reset as well and the corresponding tasks are executed one by one.