Simvik

Kick only when everyone is alive

Feed the watchdog only if every required task has checked in since the last kick. A medium embedded C problem (Watchdogs), run and graded in the browser.

medium · Watchdogs · watchdog · supervisor · rtos

Each task sets its own bit in alive when it completes a cycle. A supervisor runs periodically and decides whether to kick the watchdog.

Write supervisor_tick(alive, required, kick_fn):

  • if every bit set in required is also set in *alive, call kick_fn() once,
  • then, kick or not, clear *alive so tasks must check in again next period,
  • return true if it kicked.

A hung task never sets its bit, so the watchdog is allowed to expire and reset the system.

Starter code

bool supervisor_tick(uint8_t *alive, uint8_t required, void (*kick_fn)(void)) {
  kick_fn();
  return true;
}

Example tests

Everyone checked in

uint8_t alive = 0x07;
bool k = supervisor_tick(&alive, 0x07, kick);
show(k, alive);

Expected output:

kicked=1 kicks=1 alive=0x00

One task is missing

uint8_t alive = 0x05;
bool k = supervisor_tick(&alive, 0x07, kick);
show(k, alive);

Expected output:

kicked=0 kicks=0 alive=0x00

Learn it first

  • Watchdog timer · Independent and windowed watchdogs, and feeding them correctly.

More Watchdogs problems