A simple, non-preemptive, cooperative task scheduler.
- Place
OS_TaskTimer()inSysTick_Handlerof 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_timeparameter. - When a task
STOPPED, it is dropped from the list to save memory. If need to pause a taskSUSPENDit, and change its state toBLOCKEDto resume. - A task function must return its period (
uint32_tvalue) 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.