pkarashchenko commented on a change in pull request #5698:
URL: https://github.com/apache/incubator-nuttx/pull/5698#discussion_r822162875



##########
File path: arch/xtensa/src/esp32s2/esp32s2_wdt_lowerhalf.c
##########
@@ -0,0 +1,741 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32s2/esp32s2_wdt_lowerhalf.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/clock.h>
+#include <nuttx/timers/watchdog.h>
+
+#include "xtensa.h"
+#include "esp32s2_wdt.h"
+#include "esp32s2_wdt_lowerhalf.h"
+#include "hardware/esp32s2_soc.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* MWDT clock period in microseconds */
+
+#define MWDT_CLK_PERIOD_US        (500)
+
+/* Number of MWDT cycles per microseconds */
+
+#define MWDT_CYCLES_PER_MS        (USEC_PER_MSEC / MWDT_CLK_PERIOD_US)
+
+/* Convert MWDT timeout cycles to milliseconds */
+
+#define MWDT_TIMEOUT_MS(t)        ((t) * MWDT_CYCLES_PER_MS)
+
+/* Maximum number of MWDT cycles supported for timeout */
+
+#define MWDT_MAX_TIMEOUT_MS       (UINT32_MAX / MWDT_CYCLES_PER_MS)
+
+/* MWDT clock prescaler value */
+
+#define MWDT_CLK_PRESCALER_VALUE  (MWDT_CLK_PERIOD_US * NSEC_PER_USEC / 12.5)
+
+/* Maximum number of cycles supported for a RWDT stage timeout */
+
+#define RWDT_FULL_STAGE           (UINT32_MAX)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+enum wdt_peripheral_e
+{
+  RTC,
+  TIMER
+};
+
+/* This structure provides the private representation of the "lower-half"
+ * driver state structure.  This structure must be cast-compatible with the
+ * well-known watchdog_lowerhalf_s structure.
+ */
+
+struct esp32s2_wdt_lowerhalf_s
+{
+  const struct watchdog_ops_s *ops;        /* Lower-half operations */
+  struct esp32s2_wdt_dev_s *wdt;           /* ESP32-S2 watchdog driver */
+  uint32_t timeout;                        /* The current timeout */
+  enum wdt_peripheral_e peripheral;        /* Indicates if it is from RTC or 
Timer Module */
+  uint32_t lastreset;                      /* The last reset time */
+  bool started;                            /* True: Timer has been started */
+  xcpt_t handler;                          /* User Handler */
+  void *upper;                             /* Pointer to watchdog_upperhalf_s 
*/
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Interrupt handling *******************************************************/
+
+static int    wdt_handler(int irq, void *context, void *arg);
+
+/* "Lower-half" driver methods **********************************************/
+
+static int    wdt_lh_start(struct watchdog_lowerhalf_s *lower);
+static int    wdt_lh_stop(struct watchdog_lowerhalf_s *lower);
+static int    wdt_lh_keepalive(struct watchdog_lowerhalf_s *lower);
+static int    wdt_lh_getstatus(struct watchdog_lowerhalf_s *lower,
+                               struct watchdog_status_s *status);
+static int    wdt_lh_settimeout(struct watchdog_lowerhalf_s *lower,
+                                uint32_t timeout);
+static xcpt_t wdt_lh_capture(struct watchdog_lowerhalf_s *lower,
+                             xcpt_t handler);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* "Lower-half" driver methods */
+
+static const struct watchdog_ops_s g_esp32s2_wdg_ops =
+{
+  .start      = wdt_lh_start,
+  .stop       = wdt_lh_stop,
+  .keepalive  = wdt_lh_keepalive,
+  .getstatus  = wdt_lh_getstatus,
+  .settimeout = wdt_lh_settimeout,
+  .capture    = wdt_lh_capture,
+  .ioctl      = NULL,
+};
+
+#ifdef CONFIG_ESP32S2_MWDT0
+/* MWDT0 lower-half */
+
+static struct esp32s2_wdt_lowerhalf_s g_esp32s2_mwdt0_lowerhalf =
+{
+  .ops = &g_esp32s2_wdg_ops,
+};
+#endif
+
+#ifdef CONFIG_ESP32S2_MWDT1
+/* MWDT1 lower-half */
+
+static struct esp32s2_wdt_lowerhalf_s g_esp32s2_mwdt1_lowerhalf =
+{
+  .ops = &g_esp32s2_wdg_ops,
+};
+#endif
+
+#ifdef CONFIG_ESP32S2_RWDT
+/* RWDT lower-half */
+
+static struct esp32s2_wdt_lowerhalf_s g_esp32s2_rwdt_lowerhalf =
+{
+  .ops = &g_esp32s2_wdg_ops,
+};
+#endif
+
+/****************************************************************************
+ * Name: wdt_lh_start
+ *
+ * Description:
+ *   Start the watchdog timer, register a callback if there is one and
+ *   enables interrupt, otherwise, configure it to reset system on
+ *   expiration.
+ *
+ * Input Parameters:
+ *   lower - A pointer the publicly visible representation of the
+ *           "lower-half" driver state structure.
+ *
+ * Returned Values:
+ *   Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+static int wdt_lh_start(struct watchdog_lowerhalf_s *lower)
+{
+  struct esp32s2_wdt_lowerhalf_s *priv =
+    (struct esp32s2_wdt_lowerhalf_s *)lower;
+  int ret = OK;
+
+  wdinfo("Entry: wdt_lh_start\n");
+
+  DEBUGASSERT(priv);
+
+  if (priv->started)
+    {
+      /* Return EBUSY to indicate that the timer was already running */
+
+      ret = -EBUSY;
+      goto errout;
+    }
+
+  /* If WDT was not started yet */
+
+  else
+    {
+      irqstate_t flags;
+
+      priv->started = true;
+
+      /* Unlock WDT */
+
+      ESP32S2_WDT_UNLOCK(priv->wdt);
+
+      /* No User Handler */
+
+      if (priv->handler == NULL)
+        {
+             /* Then configure it to reset on wdt expiration */
+
+            if (priv->peripheral == TIMER)
+              {
+                ESP32S2_WDT_STG_CONF(priv->wdt, ESP32S2_WDT_STAGE0,
+                                     ESP32S2_WDT_STAGE_ACTION_RESET_SYSTEM);
+              }
+            else
+              {
+                ESP32S2_WDT_STG_CONF(priv->wdt, ESP32S2_WDT_STAGE0,
+                                     ESP32S2_WDT_STAGE_ACTION_RESET_RTC);
+              }

Review comment:
       I'm not sure why style check does not catch this




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to