Messaging

Description

This example program shows the messaging among threads on different cores. Inter-core messaging is explained here. The central framework module is Messages.

The threads print to the two usual terminals, which is boring, but allows to observe their behaviour.

As the messaging infrastructure is installed before any program threads are allocated, the corresponding FIFO handler is thread 0, that is, our program threads start at 1.

Apart from the usual blinker on core 0 (thread 1), there are four threads, two per core:

  • Core 0:
    • thread 2: await two wakeup messages from thread 1 on core 1, just print received message data
    • thread 3: await a wakeup message from thread 1 on core 1, then
      • prepare some random data in a buffer shared with thread 2 on core 1
      • message thread 2 on core 1 that the data is ready
      • await the “data received” message from thread 2 on core 1
  • Core 1:
    • thread 1: periodically wake up threads 2 and 3 on core 0, as outlined above
    • thread 2: await “data ready” message from thread 3 on core 0, then
      • read data from buffer, print data
      • send “data received” message to thread 3 on core 0

Program Modules

  • MessagingC0: core 0 program
  • MessagingC1: core 1 program
  • MessagingCom: shared definitions and facilities for the other two modules
    • allocation of ids for the Messages.SndRcv used by the threads
    • message numbers
    • the data buffer for thread 3 on core 0 and thread 2 on core 1
    • the messaging format and utilities for the threads, built upon module Messages
    • output utilities

Set-up

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

Build and Run

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

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

Repository