-
Notifications
You must be signed in to change notification settings - Fork 34
Home
Cliff L. Biffle edited this page Apr 3, 2011
·
5 revisions
LILOS is a bare-bones OS for the Atmel AVR processor (currently the ATmega328p). It's designed to be simple, and to use no dynamic memory. It provides:
- Lightweight cooperative multitasking -- 37 bytes of RAM for a minimal task.
- Inter-task communication and synchronization based on message passing.
- Convenience libraries for using GPIO pins and the USART.
A tiny LILOS program that simply toggles pin B5 looks like this:
#include <lilos/gpio.hh>
#include <lilos/task.hh>
TASK(blinky, 32) {
lilos::Pin led = PIN(B, 5);
while (1) {
led.toggle();
}
}
NORETURN main() {
lilos::schedule(blinky);
lilos::startTasking();
}
Of course, a single task program isn't a great use for LILOS. A better example might echo characters on the USART while it toggles an LED:
#include <lilos/gpio.hh>
#include <lilos/task.hh>
#include <lilos/usart.hh>
TASK(blinky, 32) {
lilos::Pin led = PIN(B, 5);
while (1) {
led.toggle();
lilos::yield();
}
}
TASK(echo, 32) {
lilos::usart_init<38400>();
while (1) {
lilos::usart_send(lilos::usart_recv());
}
}
NORETURN main() {
lilos::schedule(blinky);
lilos::schedule(echo);
lilos::startTasking();
}
Many LILOS functions, like lilos::usart_recv
above, cause the calling task to
block. When a task blocks, other tasks get CPU time. Our blink
task
never uses any blocking calls, so we have to include an explicit lilos::yield
call to give echo
time.