Pages

Thursday, 8 May 2014

A(rduino) OS - Simple pre-emptive Arduino Scheduler

A(rduino)OS (AOS) is an attempt to write a simple pre-emptive scheduler - mostly to learn about how such system works but it's a fully functional implementation which can be used in a practical way good as well. First of all, if you have no theoretical background about context switching I would recommend to have a look on a great description regarding schedulers published by avrfreaks:


AOS depends on libpca - it uses some routines from it in order to avoid code duplication. It is completely written in C from scratch with a little of assembler (in order to realize context switching). It comes with a documentation and some examples as well, which is hosted along with the repository on github:


Overview

Most of the pre-emptive schedulers (besides cooperative schedulers) is implements and is driven around a "tick" - an interrupt which happens periodically with a programmed frequency and which is responsible for context switching. In other words, assuming that there are two tasks in the system: taskA and taskB and taskA is currently running, once the tick interrupt happens it will check how much time taskA has already consumed and will switch to taskB if taskA has used all of it's assigned slot.

Context switch reprograms most of the CPU registers and re-positions the stack pointer - which means that every individual task has it's own memory area dedicated for the stack.

I strongly encourage you to give it a try. The doxygen documentation contains a description on how to prepare the project and use the system. In the near future I'm going to try to provide some more practical examples of using this scheduler.

No comments:

Post a Comment