HeapCrash / Challenges / Task check-in watchdog

Task check-in watchdog

After a field lock-up, a supervisor task feeds the independent watchdog only when every task has checked in during the last 500 ms. A hung comms task still never triggers a reset, units left on an idle menu reboot within seconds, and under heavy load there are rare unexplained resets.

The code

Embedded C for Cortex-M. It compiles. There are 3 real bugs in it: the kind that pass a bench test and fail in the field.

#define ALIVE_SENSOR (1u << 0)
#define ALIVE_COMMS  (1u << 1)
#define ALIVE_UI     (1u << 2)
#define ALIVE_ALL    (ALIVE_SENSOR | ALIVE_COMMS | ALIVE_UI)

static volatile uint32_t alive;

void task_checkin(uint32_t bit)
{
    alive |= bit;
}

void supervisor_task(void *p)
{
    for (;;) {
        vTaskDelay(pdMS_TO_TICKS(500));
        if ((alive & ALIVE_ALL) == ALIVE_ALL) {
            IWDG->KR = 0xAAAA;
        }
        alive = 0;
    }
}

void USART3_IRQHandler(void)
{
    comms_rx_byte((uint8_t)USART3->RDR);
    task_checkin(ALIVE_COMMS);
}

void ui_task(void *p)
{
    for (;;) {
        ui_event_t e;
        xQueueReceive(ui_q, &e, portMAX_DELAY);
        task_checkin(ALIVE_UI);
        ui_handle(&e);
    }
}

What an interviewer expects

The bugs, reference fixes and the follow-up question are in the practice app, after you've tried it.

Companies that test this

Matched on the skills each company's embedded roles emphasise.

Related challenges

Flag the lines, say what breaks, then fix it and build it with clang in your browser.

Find the bugs