cembeddedwatchdogbare-metalirq

What (and why) is the most safe way to use a internal hardware watchdog in a scheduled bare-metal embedded app?


I've already used internal hardware watchdogs in several OS-less embedded applications (with static schedulers).

What I do is:

I think this is a minimalist but safe approach.

Is there any best practice? (personal experience or verified sources)

I've heard/seen people doing different things like kicking the dog more than once in different tasks, or kicking only if all tasks have been called within a timeout,...


Solution

  • Your question is a bit subjective, but there is something of an industry de facto standard for real-time applications, which goes like this:

    This is the toughest requirement - ideally the dog doesn't know anything about your various tasks but is kept away from application logic.

    In practice this might be hard to do for some systems - suppose you have flash bootloaders and similar which by their nature simply must take long time. Then you might have to do dirty stuff like placing watchdog kicks inside a specific driver. But it is a best practice to strive for.

    So ideally you have this at the very top level of your application:

    void main (void)
    {
      /* init stuff */
    
      for(;;)
      {
        kick_dog();
        result = execute();
        error_handler(result);
      }
    }
    

    As a side-effect of this policy, it eliminates the risk of having "talented" people end up kicking the dog from inside a ISR.