2011-02-25 11:14:45     How to continue to have watchdog working during sleep ?

Document created by Aaronwu Employee on Aug 26, 2013
Version 1Show Document
  • View in full screen mode

2011-02-25 11:14:45     How to continue to have watchdog working during sleep ?


Message: 98441   


Hi all,


On a project, I want to use the watchdog but I want it to work even during standby mode.


My board has a job to do every 10 minutes. This job takes 2 minutes. Because the system is supplied with photovoltaic cell, I need to lower the consumption to the maximum.


These products will be in very inaccessible places, thus they must never freeze !!! If a crash or a problem occur, they must reboot automatically.


It's why I need the watchdog. But I noted that the watchdog don't work during standby mode of the processor !!


And I want it to work, if for example there is a sdram corruption during sleep, the board can crash at wakeup before the watchdog is reenabled.


I looked in the driver ( driver/watchdog/bfin_wdt.c) and I found 2 functions called during suspend and resume : bfin_wdt_suspend and bfin_wdt_resume).


I changed the #ifdef CONFIG_PM with #if 0 to have these function declared as NULL and never called, but I have the same behavior, when I put the processor in standby (with rtcwake -s 600 command for example), it doesn't reboot after the watchdog timeout (20s for example).


My goal is to have the watchdog timeout longer than my periodic cycle, to reboot if the processor hang up in standby mode or in run mode.


Any idea why the watchdog don't continue to work in standby mode ?










2011-02-28 21:06:08     Re: How to continue to have watchdog working during sleep ?

Aaron Wu (CHINA)

Message: 98479   


So assume you have enabled the watchdog timer and it works in the normal mode instead of sleep mode as expected? If not yet try to find if there is something helpful:   docs.blackfin.uclinux.org/doku.php?id=watchdog




2011-03-03 01:18:59     Re: How to continue to have watchdog working during sleep ?

Mike Frysinger (UNITED STATES)

Message: 98617   


the current standard from what i can see is that the watchdog drivers are supposed to shutdown when suspending


what i think is actually happening is that you're using the default sleep mode -- CONFIG_PM_BFIN_SLEEP_DEEPER.  so when you go into standby (which is the only mode where the on-chip watchdog will work since it needs SCLK to stay on), the SCLK is turned down to the slowest speed possible (like 3.3 MHz as the kernel documentation says).


since the watchdog timer is based on SCLK and not wall clock, the 20 seconds timeout turns into something like 300 seconds.


so the hardware is operating correctly, and is doing so as documented (albeit, the pieces are spread out a bit).


you could apply a patch like so to the Blackfin watchdog so it is not disabled only when going into standby mode:

@@ -304,10 +306,13 @@ static int state_before_suspend;


static int bfin_wdt_suspend(struct platform_device *pdev, pm_message_t state)


-       stampit();

+       stamp("state=%i", state.event);


-       state_before_suspend = bfin_wdt_running();

-       bfin_wdt_stop();

+       if (state.event != PM_EVENT_SUSPEND) {

+               state_before_suspend = bfin_wdt_running();

+               bfin_wdt_stop();

+       } else

+               state_before_suspend = 0;


        return 0;



then in your kernel power settings, select CONFIG_PM_BFIN_SLEEP instead of CONFIG_PM_BFIN_SLEEP_DEEPER.  the SCLK will remain at the same level as normal when the system is sleeping (in standby mode).


if you wanted to keep the power savings that "sleep deeper" gets you, then you would have to modify arch/blackfin/mach-common/dpmc_modes.S:_sleep_deeper to reprogram WDOG_CNT based on the new SCLK timings after the PLL_DIV register is written.




2011-03-03 04:52:37     Re: How to continue to have watchdog working during sleep ?


Message: 98627   


Aaron : yes watchdog is enabled in kernel and work as expected when board is not sleeping


Mike : I already tried to do nothing in the bfin_wdt_suspend to not stop the watchog during sleep. But watchdog doesn't work too. But maybe it's because of the different sclk frequency and thus longer watchdog timeout. If it's really the case it's not a problem for me if watchdog reset I longer, the important thing is to have a reset and don't freeze eternally.


But I carefully read the bf537 hardware manual and now I have a big doubt :


Chapter 17 / page 954 I can read :


Often, the watchdog timer is also programmed to let the processor wake

up from sleep mode after a programmable period of time.


Because I use "rtcwake -s XX" to put the processor in sleep mode for XX seconds, maybe the watchdog can't be used as watchdog during sleep because it is used to wake up the processor after XX seconds elapsed ?










2011-03-03 04:58:33     Re: How to continue to have watchdog working during sleep ?

Mike Frysinger (UNITED STATES)

Message: 98628   


what you quote is talking about WDOG_CTL:WDEV=10 which is not how Linux uses it.  it always runs with WDOG_CTL:WDEV=00.


in either case, the watchdog is functioning even when CCLK is disabled (i.e. standby).