From 96ec6983dba0bd694d09b819ec8ebf67d06bb966 Mon Sep 17 00:00:00 2001 From: anjiahao Date: Mon, 26 Dec 2022 19:28:34 +0800 Subject: [PATCH] watchdog:use 'V' to stop watchdog Signed-off-by: anjiahao --- drivers/timers/Kconfig | 6 ++++++ drivers/timers/watchdog.c | 43 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/drivers/timers/Kconfig b/drivers/timers/Kconfig index d5416f49693..b0a86dd0bf5 100644 --- a/drivers/timers/Kconfig +++ b/drivers/timers/Kconfig @@ -354,6 +354,12 @@ config WATCHDOG_DEVPATH Please, check how your specific chip or board uses this symbol. FYI: It's NOT used by the Auto-monitor feature. +config CONFIG_WATCHDOG_MAGIC_V + bool "Watchdog Device Magic num" + default Y + ---help--- + The watchdog can be stopped by writing 'V' to the watchdog's device node + menuconfig WATCHDOG_AUTOMONITOR bool "Auto-monitor" ---help--- diff --git a/drivers/timers/watchdog.c b/drivers/timers/watchdog.c index 989ca1ec78e..cea342583a1 100644 --- a/drivers/timers/watchdog.c +++ b/drivers/timers/watchdog.c @@ -436,7 +436,48 @@ static ssize_t wdog_read(FAR struct file *filep, FAR char *buffer, static ssize_t wdog_write(FAR struct file *filep, FAR const char *buffer, size_t buflen) { - return 0; +#ifdef CONFIG_WATCHDOG_MAGIC_V + FAR struct inode *inode = filep->f_inode; + FAR struct watchdog_upperhalf_s *upper; + FAR struct watchdog_lowerhalf_s *lower; + int err = 0; + int i; + + upper = inode->i_private; + DEBUGASSERT(upper != NULL); + lower = upper->lower; + DEBUGASSERT(lower != NULL); + + nxmutex_lock(&upper->lock); + + for (i = 0; i < buflen; i++) + { + if (buffer[i] == 'V') + { +#ifdef CONFIG_WATCHDOG_AUTOMONITOR + watchdog_automonitor_stop(upper); +#else + err = lower->ops->stop(lower); +#endif + break; + } + } + + if (i == buflen) + { + err = lower->ops->keepalive(lower); + } + + nxmutex_unlock(&upper->lock); + + if (err < 0) + { + return err; + } + +#endif + + return buflen; } /****************************************************************************