A simple, non-preemptive, cooperative task scheduler.
- Place
OS_TaskTimer()
inSysTick_Handler
of the ARM system or any other 1ms period timer interrupt, this is the heart beat of the scheduler. - Call
OS_TaskExecution()
inmain()
within awhile(true)
loop after creation of necessary tasks. It executes tasks in list/queue in a sequential manner. Task executions times are continuously checked, as task execution time reaches to the global os time (seeOS_GetOsTime()
), it is executed. - A task can be inserted to list/queue using
OS_TaskCreate(...)
function. A task can be scheduled to be executed for a later time by thedefer_time
parameter. - When a task
STOPPED
, it is dropped from the list to save memory. If need to pause a taskSUSPEND
it, and change its state toBLOCKED
to resume. - A task function must return its period (
uint32_t
value) which is used to update task next execution time and period info. Hence a task can dynamically arrange period/next execution time of itself. - A demo project can be found here.
Referenced from avr-simple-scheduler by ferenc-nemeth.
Origin repo at github.com/eardali.
Distributed under the terms of the MIT license.