ApplicationWatchdog and System.sleep, is there a guaranteed behavior?

How will an ApplicationWatchdog interact with System.sleep? I setup a watchdog with:

ApplicationWatchdog wd(60000, System.reset);

I call

System.sleep(D1, RISING, 180);
wd.checkin();

What will happen during the 3 minute sleep or immediately after? Will the watchdog trip during the sleep? Will the watchdog immediately trip on wakeup? Do I have a window in which to call ApplicationWatchdog::checkin?

I tried this, and it it appears that the watchdog does not trip, and the application wakes up, checks in, and goes on just fine. But is this behavior guaranteed?

Application Watchdog is run in a FreeRTOS timer which will not be running during a Stop Mode sleep.
So there will definetly be no tripping during sleep.
And the behaviour after wake depends on the state of the AWD timer prior the sleep statement (i.e. how far on the timout was before going to sleep).

Well, the sleep is 180 seconds, and the wd is set to trip in 60. So, does it really matter what the state of timer is? The sleep will definitely take longer than the watchdog. (Assuming D1 doesn’t rise, which it won’t since I have it grounded.)

As said the thread that will push the timer forward will be stopped on sleep and restarted on wake, continuing to count on from where it had been stopped earlier, so yes it does matter :wink:

In other words, you are setting the wd to trip after 60 seconds of actively running your code - the sleep time does not count as your code is not running.

Ahh, thanks for the clarification. I understand now. Problem solved.

1 Like