You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/09/21 12:55:14 UTC

[GitHub] [incubator-nuttx] saramonteiro opened a new pull request #4586: xtensa/esp32-s2: Adds oneshot device driver support

saramonteiro opened a new pull request #4586:
URL: https://github.com/apache/incubator-nuttx/pull/4586


   ## Summary
   
   This PR adds support for oneshot device driver and wrapper for ESP32-S2.
   
   ## Impact
   
   New feature.
   
   ## Test
   
   Oneshot example.


-- 
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-unsubscribe@nuttx.apache.org

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



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4586: xtensa/esp32-s2: Adds oneshot device driver support

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4586:
URL: https://github.com/apache/incubator-nuttx/pull/4586#discussion_r714265354



##########
File path: arch/xtensa/src/esp32s2/esp32s2_oneshot.h
##########
@@ -0,0 +1,204 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32s2/esp32s2_oneshot.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_XTENSA_SRC_ESP32S2_ONESHOT_H
+#define __ARCH_XTENSA_SRC_ESP32S2_ONESHOT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <time.h>
+
+#include "esp32s2_tim.h"
+
+#ifdef CONFIG_ESP32S2_ONESHOT
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* This describes the callback function that will be invoked when the oneshot
+ * timer expires.  The oneshot fires, the client will receive:
+ *
+ *   arg - The opaque argument provided when the interrupt was registered
+ */
+
+typedef void (*oneshot_handler_t)(void *arg);
+
+/* The oneshot client must allocate an instance of this structure and call
+ * esp32s2_oneshot_initialize() before using the oneshot facilities.  The
+ * client should not access the contents of this structure directly since
+ * the contents are subject to change.
+ */
+
+struct esp32s2_oneshot_s
+{
+  uint8_t chan;                         /* The timer/counter in use */
+  volatile bool running;                /* True: the timer is running */
+  struct esp32s2_tim_dev_s        *tim; /* Pointer returned by
+                                         * esp32s2_tim_init() */
+  volatile oneshot_handler_t   handler; /* Oneshot expiration callback */
+  volatile void                   *arg; /* The argument that will accompany
+                                         * the callback */
+  uint32_t                  resolution; /* us */
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_initialize
+ *
+ * Description:
+ *   Initialize the oneshot timer wrapper.
+ *
+ * Input Parameters:
+ *   oneshot    Allocated instance of the oneshot state structure.
+ *   chan       Timer counter channel to be used.
+ *   resolution The required resolution of the timer in units of
+ *              microseconds.  NOTE that the range is restricted to the
+ *              range of uint16_t (excluding zero).
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned
+ *   on failure.
+ *
+ ****************************************************************************/
+
+int esp32s2_oneshot_initialize(struct esp32s2_oneshot_s *oneshot,
+                               int chan, uint16_t resolution);
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_max_delay
+ *
+ * Description:
+ *   Determine the maximum delay of the one-shot timer (in microseconds).
+ *
+ * Input Parameters:
+ *   oneshot    Allocated instance of the oneshot state structure.
+ *   chan       The location in which to return the maximum delay in us.

Review comment:
       ```suggestion
    *
    * Output Parameters:
    *   usec    The maximum delay in us.
   ```
   Incorrect mention to `chan` param. And `usec` is an output parameter here.




-- 
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-unsubscribe@nuttx.apache.org

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



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4586: xtensa/esp32-s2: Adds oneshot device driver support

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4586:
URL: https://github.com/apache/incubator-nuttx/pull/4586#discussion_r714265354



##########
File path: arch/xtensa/src/esp32s2/esp32s2_oneshot.h
##########
@@ -0,0 +1,204 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32s2/esp32s2_oneshot.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_XTENSA_SRC_ESP32S2_ONESHOT_H
+#define __ARCH_XTENSA_SRC_ESP32S2_ONESHOT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <time.h>
+
+#include "esp32s2_tim.h"
+
+#ifdef CONFIG_ESP32S2_ONESHOT
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* This describes the callback function that will be invoked when the oneshot
+ * timer expires.  The oneshot fires, the client will receive:
+ *
+ *   arg - The opaque argument provided when the interrupt was registered
+ */
+
+typedef void (*oneshot_handler_t)(void *arg);
+
+/* The oneshot client must allocate an instance of this structure and call
+ * esp32s2_oneshot_initialize() before using the oneshot facilities.  The
+ * client should not access the contents of this structure directly since
+ * the contents are subject to change.
+ */
+
+struct esp32s2_oneshot_s
+{
+  uint8_t chan;                         /* The timer/counter in use */
+  volatile bool running;                /* True: the timer is running */
+  struct esp32s2_tim_dev_s        *tim; /* Pointer returned by
+                                         * esp32s2_tim_init() */
+  volatile oneshot_handler_t   handler; /* Oneshot expiration callback */
+  volatile void                   *arg; /* The argument that will accompany
+                                         * the callback */
+  uint32_t                  resolution; /* us */
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_initialize
+ *
+ * Description:
+ *   Initialize the oneshot timer wrapper.
+ *
+ * Input Parameters:
+ *   oneshot    Allocated instance of the oneshot state structure.
+ *   chan       Timer counter channel to be used.
+ *   resolution The required resolution of the timer in units of
+ *              microseconds.  NOTE that the range is restricted to the
+ *              range of uint16_t (excluding zero).
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned
+ *   on failure.
+ *
+ ****************************************************************************/
+
+int esp32s2_oneshot_initialize(struct esp32s2_oneshot_s *oneshot,
+                               int chan, uint16_t resolution);
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_max_delay
+ *
+ * Description:
+ *   Determine the maximum delay of the one-shot timer (in microseconds).
+ *
+ * Input Parameters:
+ *   oneshot    Allocated instance of the oneshot state structure.
+ *   chan       The location in which to return the maximum delay in us.

Review comment:
       ```suggestion
    *
    * Output Parameters:
    *   usec       The location in which to return the maximum delay in us.
   ```
   Incorrect mention to `chan` param. And `usec` is an output parameter here.




-- 
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-unsubscribe@nuttx.apache.org

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



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4586: xtensa/esp32-s2: Adds oneshot device driver support

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4586:
URL: https://github.com/apache/incubator-nuttx/pull/4586#discussion_r714264376



##########
File path: arch/xtensa/src/esp32s2/esp32s2_oneshot.c
##########
@@ -0,0 +1,462 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32s2/esp32s2_oneshot.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 <sys/types.h>
+#include <stdbool.h>
+#include <string.h>
+#include <stdint.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/timers/oneshot.h>
+#include <nuttx/clock.h>
+
+#include "hardware/esp32s2_soc.h"
+
+#include "esp32s2_tim.h"
+#include "esp32s2_clockconfig.h"
+#include "esp32s2_oneshot.h"
+
+#ifdef CONFIG_ESP32S2_ONESHOT
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MAX_TIMER_COUNTER UINT64_MAX
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int esp32s2_oneshot_handler(int irq, void * context, void *arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_handler
+ *
+ * Description:
+ *   Oneshot interrupt Handler. When any oneshot timer interrupt
+ *   expires, this function will be triggered. It will forward the call to
+ *   the next level up.
+ *
+ * Input Parameters:
+ *   irq   - IRQ associated to that interrupt
+ *   arg -   A pointer to the argument provided when the interrupt was
+ *           registered.
+ *
+ * Returned Value:
+ *   Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+static int esp32s2_oneshot_handler(int irq, void * context,
+                                   void *arg)
+{
+  int ret = OK;
+  struct esp32s2_oneshot_s *oneshot =
+    (struct esp32s2_oneshot_s *)arg;
+
+  DEBUGASSERT(oneshot != NULL && oneshot->handler != NULL);
+
+  tmrinfo("Oneshot handler triggered\n");
+
+  /* Stop timer
+   * Note: It's not necessary to disable the alarm because
+   * it automatically disables each time it expires.
+   */
+
+  ESP32S2_TIM_STOP(oneshot->tim);
+
+  /* Disable interrupts */
+
+  ESP32S2_TIM_DISABLEINT(oneshot->tim);
+
+  /* Detach handler */
+
+  ret = ESP32S2_TIM_SETISR(oneshot->tim, NULL, NULL);
+
+  /* Call the callback */
+
+  oneshot->handler((void *)oneshot->arg);
+
+  /* Restore state */
+
+  oneshot->running = false;
+  oneshot->handler = NULL;
+  oneshot->arg = NULL;
+
+  /* Clear the Interrupt */
+
+  ESP32S2_TIM_ACKINT(oneshot->tim);
+
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_initialize
+ *
+ * Description:
+ *   Initialize the oneshot timer wrapper.
+ *
+ * Input Parameters:
+ *   oneshot    Caller allocated instance of the oneshot state structure.
+ *   chan       Timer counter channel to be used.
+ *   resolution The required resolution of the timer in units of
+ *              microseconds.  NOTE that the range is restricted to the
+ *              range of uint16_t (excluding zero).
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned
+ *   on failure.
+ *
+ ****************************************************************************/
+
+int esp32s2_oneshot_initialize(struct esp32s2_oneshot_s *oneshot,
+                               int chan, uint16_t resolution)
+{
+  int ret = OK;
+
+  tmrinfo("chan=%d resolution=%d usecs\n", chan, resolution);
+
+  DEBUGASSERT(oneshot != NULL);
+  DEBUGASSERT(resolution > 0);
+
+  oneshot->chan = chan;
+
+  oneshot->tim = esp32s2_tim_init(chan);
+  if (oneshot->tim == NULL)
+    {
+      tmrerr("ERROR: Failed to allocate TIM %d\n", chan);
+      ret = -EBUSY;
+    }
+  else
+    {
+      uint16_t pre;
+
+      /* Initialize the remaining fields in the state structure. */
+
+      oneshot->running    = false;
+      oneshot->handler    = NULL;
+      oneshot->arg        = NULL;
+      oneshot->resolution = resolution;
+
+      /* Ensure timer is disabled.
+       * Change the prescaler divider with the timer enabled can lead to
+       * unpredictable results.
+       */
+
+      ESP32S2_TIM_STOP(oneshot->tim);
+
+      ESP32S2_TIM_CLK_SRC(oneshot->tim, ESP32S2_TIM_APB_CLK);
+
+      /* Calculate the suitable prescaler according to the current apb
+       * frequency to generate a period equals to resolution.
+       */
+
+      pre = (esp_clk_apb_freq() * resolution) / USEC_PER_SEC;
+
+      /* Configure TIMER prescaler */
+
+      ESP32S2_TIM_SETPRE(oneshot->tim, pre);
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_max_delay
+ *
+ * Description:
+ *   Return the maximum delay supported by the timer.
+ *
+ * Input Parameters:
+ *   oneshot Caller allocated instance of the oneshot state structure. This
+ *           structure must have been previously initialized via a call to
+ *           esp32s2_oneshot_initialize();
+ *   usec    The maximum delay in us.
+ *
+ * Returned Value:
+ *   Zero (OK).
+ *
+ ****************************************************************************/
+
+int esp32s2_oneshot_max_delay(struct esp32s2_oneshot_s *oneshot,
+                              uint64_t *usec)
+{
+  DEBUGASSERT(oneshot != NULL && usec != NULL);
+
+  /* In theory, Maximum delay (us) = resolution (us) * MAX_TIMER_COUNTER
+   * But if the resolution is bigger than 1 us, the value will not fit
+   * in a uint64_t. So, this function assumes the max delay using a
+   * resolution of 1 us.
+   */
+
+  *usec = MAX_TIMER_COUNTER;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_start
+ *
+ * Description:
+ *   Start the oneshot timer
+ *
+ * Input Parameters:
+ *   oneshot Caller allocated instance of the oneshot state structure.  This
+ *           structure must have been previously initialized via a call to
+ *           esp32s2_oneshot_initialize();
+ *   handler The function to call when when the oneshot timer expires.
+ *   arg     An opaque argument that will accompany the callback.
+ *   ts      Provides the duration of the one shot timer.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned
+ *   on failure.
+ *
+ ****************************************************************************/
+
+int esp32s2_oneshot_start(struct esp32s2_oneshot_s *oneshot,
+                          oneshot_handler_t handler, void *arg,
+                          const struct timespec *ts)
+{
+  uint64_t timeout_us;
+  int ret = OK;
+
+  tmrinfo("handler=%p arg=%p, ts=(%lu, %lu)\n",
+          handler, arg, (unsigned long)ts->tv_sec,
+          (unsigned long)ts->tv_nsec);
+  DEBUGASSERT(oneshot != NULL);
+  DEBUGASSERT(handler != NULL);
+  DEBUGASSERT(ts != NULL);
+
+  if (oneshot->running)
+    {
+      tmrinfo("One shot timer already in use. Cancelling it ...\n");
+
+      /* If the oneshot timer was already started, cancel it and then
+       * restart.
+       */
+
+      esp32s2_oneshot_cancel(oneshot, NULL);
+    }
+
+  /* Save the new callback and its argument */
+
+  oneshot->handler = handler;
+  oneshot->arg     = arg;
+
+  /* Retrieve the duration from timespec in microsecond */
+
+  timeout_us = (uint64_t)ts->tv_sec * USEC_PER_SEC +
+               (uint64_t)(ts->tv_nsec / NSEC_PER_USEC);
+
+  /* Verify if it is a multiple of the configured resolution.
+   * In case it isn't, warn the user.
+   */
+
+  if ((timeout_us % oneshot->resolution) != 0)
+    {
+      tmrwarn("Warning: The interval is not multiple of the resolution.\n"
+               "Adjust the resolution in your bringup file.\n");
+    }
+
+  /* Set the timer */
+
+  /* Ensure timer is stopped */
+
+  ESP32S2_TIM_STOP(oneshot->tim);
+
+  /* Configure TIMER mode */
+
+  ESP32S2_TIM_SETMODE(oneshot->tim, ESP32S2_TIM_MODE_UP);
+
+  /* Clear TIMER counter value */
+
+  ESP32S2_TIM_CLEAR(oneshot->tim);
+
+  /* Disable autoreload */
+
+  ESP32S2_TIM_SETARLD(oneshot->tim, false);
+
+  /* Set the timeout */
+
+  ESP32S2_TIM_SETALRVL(oneshot->tim, timeout_us / oneshot->resolution);
+
+  /* Enable TIMER alarm */
+
+  ESP32S2_TIM_SETALRM(oneshot->tim, true);
+
+  /* Clear Interrupt Bits Status */
+
+  ESP32S2_TIM_ACKINT(oneshot->tim);
+
+  /* Set the interrupt */
+
+  /* Register the handler that calls the callback */
+
+  ret = ESP32S2_TIM_SETISR(oneshot->tim, esp32s2_oneshot_handler, oneshot);
+  if (ret == OK)
+    {
+      ESP32S2_TIM_ENABLEINT(oneshot->tim);
+
+      /* Finally, start the TIMER */
+
+      ESP32S2_TIM_START(oneshot->tim);
+
+      oneshot->running = true;
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_cancel
+ *
+ * Description:
+ *   Cancel the oneshot timer and return the time remaining on the timer.
+ *
+ * Input Parameters:
+ *   oneshot Caller allocated instance of the oneshot state structure.  This
+ *           structure must have been previously initialized via a call to
+ *           esp32s2_oneshot_initialize();
+ *   ts      The location in which to return the time remaining on the
+ *           oneshot timer.  A time of zero is returned if the timer is
+ *           not running.  ts may be zero in which case the time remaining
+ *           is not returned.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success.  A call to up_timer_cancel() when
+ *   the timer is not active should also return success; a negated errno
+ *   value is returned on any failure.
+ *
+ ****************************************************************************/
+
+int esp32s2_oneshot_cancel(struct esp32s2_oneshot_s *oneshot,
+                           struct timespec *ts)
+{
+  int ret = OK;
+  uint64_t current_us;
+  uint64_t remaining_us;
+  uint64_t timeout_us;
+  uint64_t counter_value;
+  uint64_t alarm_value;
+
+  DEBUGASSERT(oneshot);
+
+  if (oneshot->running == false)
+    {
+      tmrinfo("Trying to cancel a non started oneshot timer.\n");
+      ts->tv_sec  = 0;
+      ts->tv_nsec = 0;
+    }
+  else
+    {
+      /* Stop timer */
+
+      ESP32S2_TIM_STOP(oneshot->tim);
+
+      /* Disable int */
+
+      ESP32S2_TIM_DISABLEINT(oneshot->tim);
+
+      /* Detach handler */
+
+      ret = ESP32S2_TIM_SETISR(oneshot->tim, NULL, NULL);
+
+      if (ts != NULL)
+        {
+          /* Get the current counter value */
+
+          ESP32S2_TIM_GETCTR(oneshot->tim, &counter_value);
+
+          /* Get the current configured timeout */
+
+          ESP32S2_TIM_GETALRVL(oneshot->tim, &alarm_value);
+
+          current_us = counter_value * oneshot->resolution;
+          timeout_us = alarm_value   * oneshot->resolution;
+
+          /* Remaining time (us) = timeout (us) - current (us) */
+
+          remaining_us = timeout_us - current_us;
+          ts->tv_sec   = remaining_us / USEC_PER_SEC;
+          remaining_us = remaining_us - ts->tv_sec * USEC_PER_SEC;
+          ts->tv_nsec  = remaining_us * NSEC_PER_USEC;
+        }
+
+        oneshot->running  = false;
+        oneshot->handler  = NULL;
+        oneshot->arg      = NULL;
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_current
+ *
+ * Description:
+ *   Get the current time.
+ *
+ * Input Parameters:
+ *   oneshot Caller allocated instance of the oneshot state structure.  This
+ *           structure must have been previously initialized via a call to
+ *           esp32s2_oneshot_initialize();
+ *   usec    The maximum delay in us.

Review comment:
       ```suggestion
    *
    * Output Parameters:
    *   usec    The current time in us.
   ```
   `usec`is an output parameter here. Also, I believe the parameter description might be inaccurate.




-- 
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-unsubscribe@nuttx.apache.org

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



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4586: xtensa/esp32-s2: Adds oneshot device driver support

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4586:
URL: https://github.com/apache/incubator-nuttx/pull/4586#discussion_r714266999



##########
File path: arch/xtensa/src/esp32s2/esp32s2_oneshot.h
##########
@@ -0,0 +1,204 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32s2/esp32s2_oneshot.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_XTENSA_SRC_ESP32S2_ONESHOT_H
+#define __ARCH_XTENSA_SRC_ESP32S2_ONESHOT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <time.h>
+
+#include "esp32s2_tim.h"
+
+#ifdef CONFIG_ESP32S2_ONESHOT
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* This describes the callback function that will be invoked when the oneshot
+ * timer expires.  The oneshot fires, the client will receive:
+ *
+ *   arg - The opaque argument provided when the interrupt was registered
+ */
+
+typedef void (*oneshot_handler_t)(void *arg);
+
+/* The oneshot client must allocate an instance of this structure and call
+ * esp32s2_oneshot_initialize() before using the oneshot facilities.  The
+ * client should not access the contents of this structure directly since
+ * the contents are subject to change.
+ */
+
+struct esp32s2_oneshot_s
+{
+  uint8_t chan;                         /* The timer/counter in use */
+  volatile bool running;                /* True: the timer is running */
+  struct esp32s2_tim_dev_s        *tim; /* Pointer returned by
+                                         * esp32s2_tim_init() */
+  volatile oneshot_handler_t   handler; /* Oneshot expiration callback */
+  volatile void                   *arg; /* The argument that will accompany
+                                         * the callback */
+  uint32_t                  resolution; /* us */
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_initialize
+ *
+ * Description:
+ *   Initialize the oneshot timer wrapper.
+ *
+ * Input Parameters:
+ *   oneshot    Allocated instance of the oneshot state structure.
+ *   chan       Timer counter channel to be used.
+ *   resolution The required resolution of the timer in units of
+ *              microseconds.  NOTE that the range is restricted to the
+ *              range of uint16_t (excluding zero).
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned
+ *   on failure.
+ *
+ ****************************************************************************/
+
+int esp32s2_oneshot_initialize(struct esp32s2_oneshot_s *oneshot,
+                               int chan, uint16_t resolution);
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_max_delay
+ *
+ * Description:
+ *   Determine the maximum delay of the one-shot timer (in microseconds).
+ *
+ * Input Parameters:
+ *   oneshot    Allocated instance of the oneshot state structure.
+ *   chan       The location in which to return the maximum delay in us.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned
+ *   on failure.
+ *
+ ****************************************************************************/
+
+int esp32s2_oneshot_max_delay(struct esp32s2_oneshot_s *oneshot,
+                              uint64_t *usec);
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_start
+ *
+ * Description:
+ *   Start the oneshot timer
+ *
+ * Input Parameters:
+ *   oneshot Allocated instance of the oneshot state structure.  This
+ *           structure must have been previously initialized via a call to
+ *           esp32s2_oneshot_initialize();
+ *   handler The function to call when the oneshot timer expires.
+ *   arg     An opaque argument that will accompany the callback.
+ *   ts      Provides the duration of the one shot timer.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned
+ *   on failure.
+ *
+ ****************************************************************************/
+
+int esp32s2_oneshot_start(struct esp32s2_oneshot_s *oneshot,
+                          oneshot_handler_t handler, void *arg,
+                          const struct timespec *ts);
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_cancel
+ *
+ * Description:
+ *   Cancel the oneshot timer and return the time remaining on the timer.
+ *
+ *
+ * Input Parameters:
+ *   oneshot Allocated instance of the oneshot state structure.  This
+ *           structure must have been previously initialized via a call to
+ *           esp32s2_oneshot_initialize();
+ *   ts      The location in which to return the time remaining on the
+ *           oneshot timer.  A time of zero is returned if the timer is
+ *           not running.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success.  A call to up_timer_cancel() when
+ *   the timer is not active should also return success; a negated errno
+ *   value is returned on any failure.
+ *
+ ****************************************************************************/
+
+int esp32s2_oneshot_cancel(struct esp32s2_oneshot_s *oneshot,
+                           struct timespec *ts);
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_current
+ *
+ * Description:
+ *   Get the current time.
+ *
+ * Input Parameters:
+ *   oneshot Caller allocated instance of the oneshot state structure.  This
+ *           structure must have been previously initialized via a call to
+ *           esp32s2_oneshot_initialize();
+ *   usec    The maximum delay in us.

Review comment:
       ```suggestion
    *
    * Output Parameters:
    *   usec    The current time in us.
   ```




-- 
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-unsubscribe@nuttx.apache.org

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



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4586: xtensa/esp32-s2: Adds oneshot device driver support

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4586:
URL: https://github.com/apache/incubator-nuttx/pull/4586#discussion_r714261461



##########
File path: arch/xtensa/src/esp32s2/esp32s2_oneshot.c
##########
@@ -0,0 +1,462 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32s2/esp32s2_oneshot.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 <sys/types.h>
+#include <stdbool.h>
+#include <string.h>
+#include <stdint.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/timers/oneshot.h>
+#include <nuttx/clock.h>
+
+#include "hardware/esp32s2_soc.h"
+
+#include "esp32s2_tim.h"
+#include "esp32s2_clockconfig.h"
+#include "esp32s2_oneshot.h"
+
+#ifdef CONFIG_ESP32S2_ONESHOT
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MAX_TIMER_COUNTER UINT64_MAX
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int esp32s2_oneshot_handler(int irq, void * context, void *arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_handler
+ *
+ * Description:
+ *   Oneshot interrupt Handler. When any oneshot timer interrupt
+ *   expires, this function will be triggered. It will forward the call to
+ *   the next level up.
+ *
+ * Input Parameters:
+ *   irq   - IRQ associated to that interrupt
+ *   arg -   A pointer to the argument provided when the interrupt was
+ *           registered.
+ *
+ * Returned Value:
+ *   Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+static int esp32s2_oneshot_handler(int irq, void * context,
+                                   void *arg)
+{
+  int ret = OK;
+  struct esp32s2_oneshot_s *oneshot =
+    (struct esp32s2_oneshot_s *)arg;
+
+  DEBUGASSERT(oneshot != NULL && oneshot->handler != NULL);
+
+  tmrinfo("Oneshot handler triggered\n");
+
+  /* Stop timer
+   * Note: It's not necessary to disable the alarm because
+   * it automatically disables each time it expires.
+   */
+
+  ESP32S2_TIM_STOP(oneshot->tim);
+
+  /* Disable interrupts */
+
+  ESP32S2_TIM_DISABLEINT(oneshot->tim);
+
+  /* Detach handler */
+
+  ret = ESP32S2_TIM_SETISR(oneshot->tim, NULL, NULL);
+
+  /* Call the callback */
+
+  oneshot->handler((void *)oneshot->arg);
+
+  /* Restore state */
+
+  oneshot->running = false;
+  oneshot->handler = NULL;
+  oneshot->arg = NULL;
+
+  /* Clear the Interrupt */
+
+  ESP32S2_TIM_ACKINT(oneshot->tim);
+
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_initialize
+ *
+ * Description:
+ *   Initialize the oneshot timer wrapper.
+ *
+ * Input Parameters:
+ *   oneshot    Caller allocated instance of the oneshot state structure.
+ *   chan       Timer counter channel to be used.
+ *   resolution The required resolution of the timer in units of
+ *              microseconds.  NOTE that the range is restricted to the
+ *              range of uint16_t (excluding zero).
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned
+ *   on failure.
+ *
+ ****************************************************************************/
+
+int esp32s2_oneshot_initialize(struct esp32s2_oneshot_s *oneshot,
+                               int chan, uint16_t resolution)
+{
+  int ret = OK;
+
+  tmrinfo("chan=%d resolution=%d usecs\n", chan, resolution);
+
+  DEBUGASSERT(oneshot != NULL);
+  DEBUGASSERT(resolution > 0);
+
+  oneshot->chan = chan;
+
+  oneshot->tim = esp32s2_tim_init(chan);
+  if (oneshot->tim == NULL)
+    {
+      tmrerr("ERROR: Failed to allocate TIM %d\n", chan);
+      ret = -EBUSY;
+    }
+  else
+    {
+      uint16_t pre;
+
+      /* Initialize the remaining fields in the state structure. */
+
+      oneshot->running    = false;
+      oneshot->handler    = NULL;
+      oneshot->arg        = NULL;
+      oneshot->resolution = resolution;
+
+      /* Ensure timer is disabled.
+       * Change the prescaler divider with the timer enabled can lead to
+       * unpredictable results.
+       */
+
+      ESP32S2_TIM_STOP(oneshot->tim);
+
+      ESP32S2_TIM_CLK_SRC(oneshot->tim, ESP32S2_TIM_APB_CLK);
+
+      /* Calculate the suitable prescaler according to the current apb
+       * frequency to generate a period equals to resolution.
+       */
+
+      pre = (esp_clk_apb_freq() * resolution) / USEC_PER_SEC;
+
+      /* Configure TIMER prescaler */
+
+      ESP32S2_TIM_SETPRE(oneshot->tim, pre);
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_max_delay
+ *
+ * Description:
+ *   Return the maximum delay supported by the timer.
+ *
+ * Input Parameters:
+ *   oneshot Caller allocated instance of the oneshot state structure. This
+ *           structure must have been previously initialized via a call to
+ *           esp32s2_oneshot_initialize();
+ *   usec    The maximum delay in us.

Review comment:
       ```suggestion
    *
    * Output Parameters:
    *   usec    The location in which to return the maximum delay in us.
   ```
   `usec`is an output parameter here.
   Also, the description from the documentation on the header file seems more accurate.




-- 
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-unsubscribe@nuttx.apache.org

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



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4586: xtensa/esp32-s2: Adds oneshot device driver support

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4586:
URL: https://github.com/apache/incubator-nuttx/pull/4586#discussion_r714261461



##########
File path: arch/xtensa/src/esp32s2/esp32s2_oneshot.c
##########
@@ -0,0 +1,462 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32s2/esp32s2_oneshot.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 <sys/types.h>
+#include <stdbool.h>
+#include <string.h>
+#include <stdint.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/timers/oneshot.h>
+#include <nuttx/clock.h>
+
+#include "hardware/esp32s2_soc.h"
+
+#include "esp32s2_tim.h"
+#include "esp32s2_clockconfig.h"
+#include "esp32s2_oneshot.h"
+
+#ifdef CONFIG_ESP32S2_ONESHOT
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MAX_TIMER_COUNTER UINT64_MAX
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int esp32s2_oneshot_handler(int irq, void * context, void *arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_handler
+ *
+ * Description:
+ *   Oneshot interrupt Handler. When any oneshot timer interrupt
+ *   expires, this function will be triggered. It will forward the call to
+ *   the next level up.
+ *
+ * Input Parameters:
+ *   irq   - IRQ associated to that interrupt
+ *   arg -   A pointer to the argument provided when the interrupt was
+ *           registered.
+ *
+ * Returned Value:
+ *   Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+static int esp32s2_oneshot_handler(int irq, void * context,
+                                   void *arg)
+{
+  int ret = OK;
+  struct esp32s2_oneshot_s *oneshot =
+    (struct esp32s2_oneshot_s *)arg;
+
+  DEBUGASSERT(oneshot != NULL && oneshot->handler != NULL);
+
+  tmrinfo("Oneshot handler triggered\n");
+
+  /* Stop timer
+   * Note: It's not necessary to disable the alarm because
+   * it automatically disables each time it expires.
+   */
+
+  ESP32S2_TIM_STOP(oneshot->tim);
+
+  /* Disable interrupts */
+
+  ESP32S2_TIM_DISABLEINT(oneshot->tim);
+
+  /* Detach handler */
+
+  ret = ESP32S2_TIM_SETISR(oneshot->tim, NULL, NULL);
+
+  /* Call the callback */
+
+  oneshot->handler((void *)oneshot->arg);
+
+  /* Restore state */
+
+  oneshot->running = false;
+  oneshot->handler = NULL;
+  oneshot->arg = NULL;
+
+  /* Clear the Interrupt */
+
+  ESP32S2_TIM_ACKINT(oneshot->tim);
+
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_initialize
+ *
+ * Description:
+ *   Initialize the oneshot timer wrapper.
+ *
+ * Input Parameters:
+ *   oneshot    Caller allocated instance of the oneshot state structure.
+ *   chan       Timer counter channel to be used.
+ *   resolution The required resolution of the timer in units of
+ *              microseconds.  NOTE that the range is restricted to the
+ *              range of uint16_t (excluding zero).
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned
+ *   on failure.
+ *
+ ****************************************************************************/
+
+int esp32s2_oneshot_initialize(struct esp32s2_oneshot_s *oneshot,
+                               int chan, uint16_t resolution)
+{
+  int ret = OK;
+
+  tmrinfo("chan=%d resolution=%d usecs\n", chan, resolution);
+
+  DEBUGASSERT(oneshot != NULL);
+  DEBUGASSERT(resolution > 0);
+
+  oneshot->chan = chan;
+
+  oneshot->tim = esp32s2_tim_init(chan);
+  if (oneshot->tim == NULL)
+    {
+      tmrerr("ERROR: Failed to allocate TIM %d\n", chan);
+      ret = -EBUSY;
+    }
+  else
+    {
+      uint16_t pre;
+
+      /* Initialize the remaining fields in the state structure. */
+
+      oneshot->running    = false;
+      oneshot->handler    = NULL;
+      oneshot->arg        = NULL;
+      oneshot->resolution = resolution;
+
+      /* Ensure timer is disabled.
+       * Change the prescaler divider with the timer enabled can lead to
+       * unpredictable results.
+       */
+
+      ESP32S2_TIM_STOP(oneshot->tim);
+
+      ESP32S2_TIM_CLK_SRC(oneshot->tim, ESP32S2_TIM_APB_CLK);
+
+      /* Calculate the suitable prescaler according to the current apb
+       * frequency to generate a period equals to resolution.
+       */
+
+      pre = (esp_clk_apb_freq() * resolution) / USEC_PER_SEC;
+
+      /* Configure TIMER prescaler */
+
+      ESP32S2_TIM_SETPRE(oneshot->tim, pre);
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_max_delay
+ *
+ * Description:
+ *   Return the maximum delay supported by the timer.
+ *
+ * Input Parameters:
+ *   oneshot Caller allocated instance of the oneshot state structure. This
+ *           structure must have been previously initialized via a call to
+ *           esp32s2_oneshot_initialize();
+ *   usec    The maximum delay in us.

Review comment:
       ```suggestion
    *
    * Output Parameters:
    *   usec    The maximum delay in us.
   ```
   `usec`is an output parameter here.




-- 
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-unsubscribe@nuttx.apache.org

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



[GitHub] [incubator-nuttx] gustavonihei merged pull request #4586: xtensa/esp32-s2: Adds oneshot device driver support

Posted by GitBox <gi...@apache.org>.
gustavonihei merged pull request #4586:
URL: https://github.com/apache/incubator-nuttx/pull/4586


   


-- 
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-unsubscribe@nuttx.apache.org

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



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4586: xtensa/esp32-s2: Adds oneshot device driver support

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4586:
URL: https://github.com/apache/incubator-nuttx/pull/4586#discussion_r714262313



##########
File path: arch/xtensa/src/esp32s2/esp32s2_oneshot.c
##########
@@ -0,0 +1,462 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32s2/esp32s2_oneshot.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 <sys/types.h>
+#include <stdbool.h>
+#include <string.h>
+#include <stdint.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/timers/oneshot.h>
+#include <nuttx/clock.h>
+
+#include "hardware/esp32s2_soc.h"
+
+#include "esp32s2_tim.h"
+#include "esp32s2_clockconfig.h"
+#include "esp32s2_oneshot.h"
+
+#ifdef CONFIG_ESP32S2_ONESHOT
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MAX_TIMER_COUNTER UINT64_MAX
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int esp32s2_oneshot_handler(int irq, void * context, void *arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32s2_oneshot_handler
+ *
+ * Description:
+ *   Oneshot interrupt Handler. When any oneshot timer interrupt
+ *   expires, this function will be triggered. It will forward the call to
+ *   the next level up.
+ *
+ * Input Parameters:
+ *   irq   - IRQ associated to that interrupt
+ *   arg -   A pointer to the argument provided when the interrupt was
+ *           registered.
+ *
+ * Returned Value:
+ *   Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+static int esp32s2_oneshot_handler(int irq, void * context,
+                                   void *arg)

Review comment:
       ```suggestion
   static int esp32s2_oneshot_handler(int irq, void *context, void *arg)
   ```
   The `*` should be next to the identifier. And these two lines may be merged.

##########
File path: arch/xtensa/src/esp32s2/esp32s2_oneshot.c
##########
@@ -0,0 +1,462 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32s2/esp32s2_oneshot.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 <sys/types.h>
+#include <stdbool.h>
+#include <string.h>
+#include <stdint.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/timers/oneshot.h>
+#include <nuttx/clock.h>
+
+#include "hardware/esp32s2_soc.h"
+
+#include "esp32s2_tim.h"
+#include "esp32s2_clockconfig.h"
+#include "esp32s2_oneshot.h"
+
+#ifdef CONFIG_ESP32S2_ONESHOT
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MAX_TIMER_COUNTER UINT64_MAX
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int esp32s2_oneshot_handler(int irq, void * context, void *arg);

Review comment:
       ```suggestion
   static int esp32s2_oneshot_handler(int irq, void *context, void *arg);
   ```




-- 
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-unsubscribe@nuttx.apache.org

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