Skip to content

pietern/avr-tasks

Repository files navigation

avr-tasks

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.

Example

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.

Why?

  • To be able to execute arbitrary code while waiting for I/O but be interrupted when I/O does happen.

How?

  • 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.

Hacking

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:

TODO

  • 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 call task_yield() from that handler. Maybe have some condition variable like apparatus to associate event X with task Y waiting for that event.

License

MIT (see LICENSE).

About

Multitasking library for the Atmel AVR processor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages