watchdog timer

Hello Zephyr experts,

I am having problem with the function wdt_disable(const struct device *dev);

There is no problem in setup and feed the watchdog.

wdt = device_get_binding(WDT);     // watchdog device binding succesfully

wdt_channel_id = wdt_install_timeout(wdt, &wdt_config);    // installed watchdog timer successfully
wdt_setup(wdt, WDT_OPT_PAUSE_HALTED_BY_DBG);     // set up and start the watchdog. successfully
for(;;) 
{
     /* Able to feed the dog with no timeout and reset */
     wdt_feed(wdt, wdt_channel_id);   // feed the dog periodically 
     sleep_second(5);                          // sleep 5 seconds
    /* if user wants to disable the watchdog, wdt_disable() return an error = -1 */
    if ( user_command == "disable watchdog") {
         rc = wdt_disable(wdt);      // disable watchdog, but it failed with error code -1.     <--------  What went wrong ??????
           

    }

This is what I found from

zephyr/misc/generated/syscalls_links/include/drivers/watchdog.h

/**

 * @brief Disable watchdog instance.

 *

 * This function disables the watchdog instance and automatically uninstalls all

 * timeouts. To set up a new watchdog, install timeouts and call wdt_setup()

 * again. Not all watchdogs can be restarted after they are disabled.

 *

 * @param dev Pointer to the device structure for the driver instance.

 *

 * @retval 0 If successful.

 * @retval -EFAULT If watchdog instance is not enabled.

 * @retval -EPERM If watchdog can not be disabled directly by application code.

 */

__syscall int wdt_disable(const struct device *dev);

static inline int z_impl_wdt_disable(const struct device *dev)

{

        const struct wdt_driver_api *api =

                (const struct wdt_driver_api *)dev->api;

        return api->disable(dev);

}

   
}
Parents
  • Hello Joseph!

    What you are trying to do here is disabling the watchdog from the application, which is against its purpose. The purpose of a watchdog is to ensure that your program continuously feeds it in order to verify that your program runs as it should. I wouldn't recommend disabling it in runtime, and it is not something the function should allow you to either. Error -1 is the "Not Owner" error, it is not letting you.

    If you want to experiment with using the watchdog I would recommend you to move the if statement to rather turn the watchdog on if the user_command == "enable watchdog", instead of turning it off.

    Best regards,

    Elfving

Reply
  • Hello Joseph!

    What you are trying to do here is disabling the watchdog from the application, which is against its purpose. The purpose of a watchdog is to ensure that your program continuously feeds it in order to verify that your program runs as it should. I wouldn't recommend disabling it in runtime, and it is not something the function should allow you to either. Error -1 is the "Not Owner" error, it is not letting you.

    If you want to experiment with using the watchdog I would recommend you to move the if statement to rather turn the watchdog on if the user_command == "enable watchdog", instead of turning it off.

    Best regards,

    Elfving

Children
No Data
Related