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: 940 ms
    • thread 1: 740 ms
  • Print a counter and the elapsed time since the last run, in microseconds.

Core 1 (BlinkPlusRtkC1):

  • Thread 0:
    • blink the LED
    • use a (non-blocking) delay in lieu of a period (just to demo, not good design decision for this use case)
  • Thread 1:
    • Do some “computation” (the two WHILE loops), with a run-time just above 5 milliseconds, ie. longer than the scheduler interval, so that the ready threads could potentially not all be run within the scheduling interval.
    • Uncomment ‘Kernel.Next’ to split the “computation” over two runs, bringing it down to about half. Notice the (small) overhead of the kernel/scheduler. However, the scheduling is now OK again, since all ready threads can run within the scheduling interval. Of course the thread will now take two periods to do its “computations”.
    • The partial run times for each “computation” are printed, as is the total time, in microseconds.

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

Build module BlinkPlusRtkC0 with Astrobe, and create and upload the UF2 file using abin2uf2.

Set Astrobe’s memory options as listed, and the library search path as explained.

Repository