uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
Macros | Typedefs | Functions
background_tasks.h File Reference

Background task scheduler. More...

#include <stdint.h>
Include dependency graph for background_tasks.h:
This graph shows which files directly or indirectly include this file:

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...
 

Detailed Description

Background task scheduler.

Macro Definition Documentation

◆ F_TASK_FAST

#define F_TASK_FAST   F_TIMER

High priority task: Called every 50 us (20 kHz)

◆ F_TASK_MID

#define F_TASK_MID   (F_TASK_FAST / 20)

Medium priority task: Called every 1 ms (1 kHz)

◆ F_TASK_SLOW

#define F_TASK_SLOW   (F_TASK_MID / 10)

Low priority task: Called every 10 ms (100 Hz)

◆ F_TIMER

#define F_TIMER   20000

Frequency of the CPU timer used in by the task scheduler in [Hz].

Typedef Documentation

◆ background_task_t

typedef void(* background_task_t) (void)

Data type for background task pointers.

Function Documentation

◆ init_background_tasks()

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.

Parameters
high_freq_tasksan array of function pointers to high frequency tasks
high_freq_tasks_sizenumber of high frequency tasks
mid_freq_tasksan array of function pointers to medium frequency tasks
mid_freq_tasks_sizenumber of medium frequency tasks
low_freq_tasksan array of function pointers to low frequency tasks
low_freq_tasks_sizenumber of low frequency tasks
See also
F_TASK_FAST
F_TASK_MID
F_TASK_SLOW

◆ process_background_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.

See also
F_TASK_FAST
F_TASK_MID
F_TASK_SLOW