Watchdog Prototype 1


This example program shows a prototype for a watchdog implementation across the two cores. It uses both cores, each with its kernel.

There’s only one watchdog hardware device in the RP2040, hence it does not suffice to periodically reload the counter from one core, as the other might be in locked in a faulty loop. Therefore, we use a monitoring thread per core. The one on core 0 controls the hardware device, and listens to messages from the corresponding on core 1.

Core 0 Threads (Module WatchdogP1C0)

  • Thread 0: the usual blinker, period-triggered, “heartbeat” indicator.
  • Thread 1: print to terminal, showing the reset by the watchdog.
  • Thread 2: watchdog thread: listen to periodic messages from the watchdog thread on core 1, trigger the watchdog if missing; periodically reload the watchdog counter to prevent it from triggering a reset.

Core 1 Threads (Module WatchdogP1C1)

  • Thread 0: watchdog countdown, cause the watchdog to trigger.
  • Thread 1: watchdog thread: send periodic messages to the watchdog thread on core 0.

The watchdog monitoring could easily be integrated into the kernel and scheduler, but for this prototype is kept out of it. Which may be the better and more modular solution anyway.

Output Terminals

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

Build and Run

Build module WatchdogP1C0 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.