BlinkPlusRtk

Overview

This example program implements an extended version of the “blinker”. It makes use of the kernel to run two threads per core.

Using Out, each thread periodically prints a message to the core-specific serial terminal. The message of each thread starts with “ci-tj”, where i = core number, j = thread number.

Description

The program is implemented using two modules:

  • BlinkPlusRtkC0 for core 0
  • BlinkPlusRtkC1 for core 1

Core 0 (BlinkPlusRtkC0):

  • Run the same code in two threads, at different periods, deliberately not in sync:
    • thread 0: 980 ms
    • thread 1: 740 ms
  • Print a counter and the elapsed time since the last run, in microseconds.
  • Scheduler interval is 10 ms (tick time).

Core 1 (BlinkPlusRtkC1):

  • Thread 0:
    • blink the LED
    • use a (non-blocking) delay in lieu of a period (just to demo, not a good design decision for this use case)
  • Thread 1:
    • Do some “computation” (the two WHILE loops), with a total run-time longer than the scheduler interval, so that the ready threads could not all be run within the scheduling interval.
    • Kernel.Next splits the “computation” over two runs, bringing it down to about half. The thread will takes two periods to do its “computations”.
    • The partial run times for each “computation” are printed, as is the total time, in microseconds.
    • Scheduler interval is 4 ms.

See Text Output and Input about the implementation of module Out for two cores.

Output Terminals

See Set-up, two-terminal set-up.

Build and Run

Repository

  • libv2: for RP2040/Pico and RP2350/Pico2: BlinkPlusRtk
  • lib (v1): this version is no longer being maintained: BlinkPlusRtk