KRNL - An Arduino Kernel

Browse files incl examples : list folder: krnl

Download zipfile for install


I have found it interesting to develop an open source realtime kernel (KRNL) for the Arduino platform:

  • open source

  • well suited for teaching

    • easy to read and understand source

    • priority to straight code instead insane optimization(which will make it nearly unreadable)

  • well suited for serious duties - but with no warranty what so ever

  • easy to use

    • just import library krnl and you are ready

  • automatic recognition of architeture

    • supports all atmega variants I have had available (168,328,1280,2560 - uno, duemillanove, mega 1280 and 2560)

  • Suited for scheduability test after RMA

    • Krnl traps miss of deadlines and issue a breakout to user space so ypu can trap

    • See krnl/html-w-examples for krnl code and examples (browse under files

Some characteristics:

  • preemptive scheduling

    • Basic heart beat at 1 kHz. KRNL can have heeartbeat in quants of milli seconds

    • krnl uses timer2 so PWM based on timer2 is not possible(you can change it)

    • static priority scheme

  • support task, semaphores, message queues

    • All elements shall be allocated prior to start of KeRNeL

  • support user ISRs and external interrupts

  • Directory krnl shall be within your libraries directory .. sketchbook/libraries

  • You have to restart your arduino environment

A small example

See templates for a number of commented runable examples which illustrates very well different mockups.

Access to code



git clone
  • ( 2018 added immediate ceiling protocol on semaphores (version 20180313)

  • ( updated june 2015 with new features for handling tight fixed frequency execution)

krnl consists of two files krnl.h and krnl.cpp which you shall save in directory sketchbook/libraries/krnl

or click here - beware wuite many lines of code

(click for krnl.h code)

(click for krnl.c code)

And some examples

And the rest

krnl howto for Arduino

The proper place to put them in your Arduino environment:

  • sketchbook/libraries/krnl/.

  • sketchbook/libraries/krnl/krnl.cpp

Please note the cpp naming and that directory in libraries has same name as the cpp file

For using it in your code start with sketch>Import Libray>Contributed and select krnl

Then it will add a standard include <krnl.h> in your sketch and you are rdy to go

  1. make directory krnl in …/sketchbook/libraries

  2. copy krnl.h to ../sketchbook/libraries/krnl/krnl.h

  3. copy krnl.c to ../sketchbook/libraries/krnl/krnl.cpp

Start Arduino SW

select Sketch -> Import Library -> krnl

It will add

If you want to have the examples I have provided (not all are bug free I think) then you have to …

  1. make directory ../sketchbook/krnl

  2. copy the examples in this directory

You can now find them in File->Sketchbook->krnl->“examples…”

For getting a copy for yourself:

might not be uptodate

git clone git://



A task shift takes approx 21 usec. See perf.html for the test program


See config

KeRNeL discover type of your board so no need to change setup by hand in krnl.h

See config for a short intro to configuration and RAM usage.

happy hacking