KM3NeT CLB
2.0
KM3NeT CLB v2 Embedded Software
|
The scheduler is an important piece in the embedded software.
The main function of the sys module will invoke schdRunForever()
at the end. schdRunForever()
, as the name says it, never returns.
This implies that any code you wish to run (called a task) periodically or at some event, you will need to add to the scheduler. Examples are network handlers, monitoring functions, software timers.
First a task needs to register itself. Usually this is done in the init routine of the specific module. Than it can optionally schedule itself to be run at an interval.
The following piece of code shows how to schedule a task which says 'one second please' every second:
What is important to note is that the module is a simple collaborative multitasking scheduler. This means that if you do not terminte your code, you will prevent other tasks from running, so never schedule a task to do this:
It is however possible to schedule a task to run for as long as it can, but it is not adviced:
Another use for the scheduler is to prevent long-running IRQ handlers. Since no other IRQs will be serviced as long as your IRQ handler is running, you do not wish to block the queue when a long running task needs to be performed on the data. For this we will use the schdRun(taskId)
function, which schedules the task for running at a later time.
For example, we have a fictional digitizer (ADC) which uses two buffers. Each second it gives a data ready IRQ, and than the data from one buffer can be processed, while it continues writing in the other.
This code will be executed as is shown in the image below: