KittyOS: Writing A Toy OS For The ATmega168 From Scratch

Writing an operating system for a computing platform is one of those non-trivial tasks few people actually need to do, regardless of whether it’s for a small microcontroller or a larger general-purpose computer. Many of us spend a large amount of our time working on producing robust code for embedded systems, occasionally diving deeper into the abstraction when we’re stuck on a problem. Quite often this work is sitting on top of an RTOS, which we consider a solved problem. [Jonathan Diamond] had picked up a fair bit of knowledge of some of the low-level AVR black magic, as well as some details of how operating systems work internally, and so decided to have a crack a building a toy operating system called KittyOS, for the learning experience alone.

[Jonathan] hastens to add that this is not a practical OS, but a learning platform that needs a few more bells and whistles added to be useful. Aimed at the 8-bit AVR ATmega168 with its mere 16kB of flash and 1kB of SRAM, the diminutive chip can still perform more than well enough to host the rudimentary OS — up to four application tasks, and some basic system call support.

Already, KittyOS sports preemptive multitasking, with prioritization and support for applications written in C. Hardware support is a bit limited, with just serial I/O and a spot of GPIO, but that’s more than enough for a demonstrator. Applications can be loaded into any of the four available slots, with per-slot run state control, using the Python-based host interface. The post is a long one, with an absolute ton of the gory details we love around these parts, and we’re very glad [Jonathan] took the time to make a proper write-up as well as a demonstration video, which can be found after the break.

There have been many such DIY operating systems gracing these pages over the years, like ZARDOS, which is aimed at the Arduino Mega/UNO boards. Getting a bit more complex, we’ve seen Snowdrop, which was written in pure x86 and even sports a BASIC interpreter. Finally, we should mention our guide to RTOS and how to choose the ideal one for your needs.

6 thoughts on “KittyOS: Writing A Toy OS For The ATmega168 From Scratch

  1. Back in my undergrad, 30+ years ago, I took a course in real time systems in which we each wrote our own RTOS to run on some weird microcontroller.

    I believe the multitasking was preemptive but I could be wrong. I remember we had a choice to implement either signalling or semaphores. Timers, and general interrupt handling, as well as an application to run on it were mandatory.

    There weren’t enough microcontrollers for the whole class, so a classmate and I did all our development as early in the semester as possible, when the lab was empty. Great topic, lousy prof.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.