Skip to content
Antonio Giacomelli edited this page Dec 4, 2025 · 378 revisions

RK0 Wiki

RK0 is built for MCU-based control systems where deterministic behaviour is critical. Determinism and clear semantics are core design guidelines. It provides an O(1) preemptive, priority-based scheduler.

  • Two complementary programming models are supported:

    • Shared-memory (procedural) – the classic model: tasks synchronise via semaphores, event flags and condition variables to share data and coordinate execution. Mutexes support fully transitive priority inheritance.

    • Message-passing – tasks exchange data through message queues, ports, and mailboxes, between 'isolated' contexts. Ports leverage priority boosting/demotion for a client-server model.

  • The Most-Recent Message Protocol is a 1-to-many, purpose-built message passing mechanism to avoid stale data on control-loops.

  • Fixed-size memory pools avoid fragmentation and unpredictable memory latency.

  • Timers (delay, periodic, bounded waiting and callout) are optimised for precision and low-overhead (O(1)).


Configuring the kernel

  • core/kconfig.h has defines to enable/disable features and other crucial configurations.

  • It is a must that the number of tasks in your application matches the number defined in RK_CONF_N_USRTASKS, as well as the lowest effective priority task number (the highest number) matches what is defined in RK_CONF_MIN_PRIO (maximum priority is 31).

  • If you are using application timers, the stack size of the system task that runs the callouts might need to be adjusted on RK_CONF_TIMHANDLER_STACKSIZE - remember this value is in WORDs (a word has 4 bytes). If you are including any hook on the IdleTask, also adjust RK_CONF_IDLE_STACKSIZE. These values must be a multiple of 8, and that is a general rule for stack sizes.

  • To declare the objects needed for a task you can use the convenience macro RK_DECLARE_TASK() - check kapi.h for more information. Importantly convenience macros that start with RK_ do not need a trailing ; at its end, because they are not supposed to be seen as functions (some do not even take arguments). Macros that start with a K_ are function-like macros.


More info

  • Sections explaining QEMU building system and its integration to VSCode on macOS, Windows and Linux are available on the Wiki links.

  • A comprehensive Docbook explains the kernel mechanisms, design rationale and usage examples.

  • Complete designs (QEMU and Nucleo boards) are available and are useful to understand how structure your code.

Clone this wiki locally