HeapCrash / Challenges / OS sanity watchdog hooks

OS sanity watchdog hooks

To supervise 'the OS itself', this FreeRTOS build feeds the watchdog from kernel hooks. A task stuck in a busy loop at high priority never triggers a reset. After a stack overflow one unit kept running for a day with corrupted state. Memory from deleted tasks sometimes isn't freed.

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.

void vApplicationTickHook(void)
{
    IWDG->KR = 0xAAAA;
}

void vApplicationIdleHook(void)
{
    static TickType_t last;
    if (xTaskGetTickCount() - last > 1000) {
        last = xTaskGetTickCount();
        printf("idle ok\n");
        vTaskDelay(pdMS_TO_TICKS(10));
    }
}

void vApplicationStackOverflowHook(TaskHandle_t t, char *name)
{
    printf("stack overflow in %s\n", name);
}

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