You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/01/06 12:02:31 UTC

[nuttx] branch master updated: watchdog:use 'V' to stop watchdog

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 96ec6983db watchdog:use 'V' to stop watchdog
96ec6983db is described below

commit 96ec6983dba0bd694d09b819ec8ebf67d06bb966
Author: anjiahao <an...@xiaomi.com>
AuthorDate: Mon Dec 26 19:28:34 2022 +0800

    watchdog:use 'V' to stop watchdog
    
    Signed-off-by: anjiahao <an...@xiaomi.com>
---
 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 d5416f4969..b0a86dd0bf 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 989ca1ec78..cea342583a 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;
 }
 
 /****************************************************************************