lilos
A wee RTOS using async
Rust.
Quick links:
Now that Hubris has gotten some attention, people sometimes ask me if my personal projects are powered by Hubris.
The answer is: no, in general, they are not. My personal projects use my other
operating system, lilos
, which predates Hubris and takes a fundamentally
different approach. It has dramatically lower resource requirements and allows
more styles of concurrency.
A brief summary
lilos
is an embedded operating system written in Rust and designed to power
Rust-based firmware. lilos
is focused on applications that need to do many
things independently and concurrently – managing many streams of data, say, or
processing events from lots of hardware interfaces. Instead of conventional
threads, lilos
uses the Rust async fn
feature to transform code into state
machines that can be executed from a shared stack.
I’m proud of the fact that lilos
is, as far as I’m aware, the first and only
Rust async runtime with an entirely cancellation-safe API!
Currently, lilos
supports ARM Cortex-M-series microcontrollers, though I
intend to port it to RISC-V as soon as I find a good dev board.
I’ve had lilos
deployed in applications since mid-2019, running continuously.
A typical application of mine has between 4 and 16 separate tasks, running in
around 8 kiB of RAM on an inexpensive microcontroller, and processing hardware
events with tight and predictable response times (typically in the tens of
microseconds). To do that with a conventional operating system, you’d either
need more RAM, or you’d have to unroll your concurrent program into a great big
state machine by hand. lilos
and Rust work together to build that great big
state machine for you, making the code easier to write, read, and maintain.
lilos
has been used for:
- The firmware for my Keypad:GO! widget, which is the main open-source application,
- Large-scale distributed LED animation control with sub-millisecond time sync across the network,
- Battery management and solar charge control,
- A smartwatch (alternate PineTime firmware),
- Driver user interface for a home-brew electric vehicle,
- Myriad little widgets I’ve built for things like managing lights.
Where to learn more
I’ve already written a lot about lilos
, so for now I won’t try and repeat it
all here. Instead, here’s a curated set of links if you want to learn more about
the system or try it out yourself.
- The
lilos
intro guide provides a more detailed overview of the system, discussion of the APIs, and a cookbook for approaching some common tasks. - You can drop
lilos
into any existing Rust firmware project by runningcargo add lilos
, because it’s on crates.io. (Actually using it requires writing some code; see the intro guide.) - The documentation for the operating system APIs is pretty comprehensive.
- The repo on github contains worked examples for various microcontrollers, in addition to the OS source code.
- I’ve written several blog posts that use
lilos
, such as:- Composed concurrency in drivers, where I show that “concurrency” is about much more than just threads.
- Writing a basic
async
debugger, where I discuss an early prototype debugger forlilos
. - For more, see posts tagged with #lilos