Multitasking library for the Atmel AVR processor.
- Preemptive.
- Uses TIMER0 for scheduler ticks (default: 2ms per tick).
- Supports as many tasks as you can fit in RAM (default: 256 bytes per task).
- Expects to be run on an ATmega328p.
- For missing features, see TODO below.
An example can be found in blink.c. This program blinks the LED connected to pin 13, with the actual blinking and the blink rate controlled by two different tasks.
Find more examples in the examples directory.
- To be able to execute arbitrary code while waiting for I/O but be interrupted when I/O does happen.
- Every task is offset at some point in the stack.
- On task interruption, all relevant registers are pushed onto its stack.
- A scheduler figures out which task to run next.
- On task resume, all its context is popped off of its stack.
The code was made to run on an ATmega328p, without portability in mind. The code can probably be ported to other variants without much effort. As I only have ATmega328p devices (Arduino's), I don't have an incentive to do this work. Pull requests are welcome.
Links to a few resources I used:
- Multitasking on an AVR -- outline for context save/restore routines
- avr-gcc -- details about the compiler
- AVR instruction set
- Communication / synchronization between tasks
- Add task status field for run/sleep/wait/etc...
- If waiting for I/O, how will a task be woken up? Likely through ISR not known
to
task.c
. Maybe just calltask_yield()
from that handler. Maybe have some condition variable like apparatus to associate event X with task Y waiting for that event.
MIT (see LICENSE
).