Oberon RTK

BlinkPlus

The "hello world" for MCUs

Description

This program implements the mandatory "blinker", however with a twist: it uses kernel threads to make things a bit more interesting than the usual non-terminating loop with a timer delay.

Kernel Threads

There are three periodically timed threads:

  • one heartbeat thread that blinks an LED on the board (heartbeat);

  • two threads that write to the serial terminal (periodic).

The periods of the threads are set to values that are multiples of the kernel's basic tick period, which is 10 milliseconds. As the values chosen demonstrate, it is easy to set any thread period, just as a real controlled system may require.

The two periodic threads also calculate and print the time (in microseconds) since they last ran, confirming the kernel's correct periodic scheduling.

The threads are programmed as non-terminating loops, as is usual for a control system.

Kernel threads are implemented using coroutines. Each thread is an independent run-time entity, each with its own stack, hence all state held in local variables is always preserved between invocations of the thread.

Start-up and Run-time

After the program gets control, run installs the kernel using Kernel.Install, which sets up and initialises the kernel's data structures, which include a RECORD for each thread.

Then the threads are instantiated, which means to allocate a procedure to the corresponding thread RECORD using Kernel.Allocate. As the example shows, the same procedure can be allocated to more than one thread, since each thread has its own stack.

Kernel.Enable(<thread>) sets the thread to be eligible for scheduling, but at this point the scheduler is not yet running.

To get the program off the ground, the kernel is started with Kernel.Run, which starts the scheduler. The scheduler itself is a coroutine as well. It transfers control to threads, which in turn transfer control back, implementing cooperative scheduling.

Further Reading

Repository

  • <repo>/examples/v3.1/rpi/pico/BlinkPlus
  • <repo>/examples/v3.1/rpi/pico2/BlinkPlus
  • <repo>/examples/v3.1/stm/h573i-dk/BlinkPlus
  • <repo>/examples/v3.1/stm/u585i-iot/BlinkPlus

Last updated: 17 May 2026