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 2022/02/25 02:51:33 UTC

[incubator-nuttx] 02/03: esp32s3-devkit: Initialize Oneshot timer on bringup

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/incubator-nuttx.git

commit 71e872739769b87b3409d3a19ab358a7bb414be0
Author: Gustavo Henrique Nihei <gu...@espressif.com>
AuthorDate: Wed Feb 23 14:44:07 2022 -0300

    esp32s3-devkit: Initialize Oneshot timer on bringup
    
    Signed-off-by: Gustavo Henrique Nihei <gu...@espressif.com>
---
 .../xtensa/esp32s3/common/src/esp32s3_board_tim.c  | 65 +++++++++++++++++++++-
 .../esp32s3-devkit/configs/oneshot/defconfig       | 58 +++++++++++++++++++
 2 files changed, 122 insertions(+), 1 deletion(-)

diff --git a/boards/xtensa/esp32s3/common/src/esp32s3_board_tim.c b/boards/xtensa/esp32s3/common/src/esp32s3_board_tim.c
index 9419d3f..216a091 100644
--- a/boards/xtensa/esp32s3/common/src/esp32s3_board_tim.c
+++ b/boards/xtensa/esp32s3/common/src/esp32s3_board_tim.c
@@ -27,10 +27,21 @@
 #include <sys/types.h>
 #include <debug.h>
 
+#ifdef CONFIG_ONESHOT
+#include <nuttx/timers/oneshot.h>
+#ifdef CONFIG_CPULOAD_ONESHOT
+#include <nuttx/clock.h>
+#endif
+#endif
+
 #include "esp32s3_board_tim.h"
 #include "esp32s3_tim.h"
 #include "esp32s3_tim_lowerhalf.h"
 
+#ifdef CONFIG_ONESHOT
+#include "esp32s3_oneshot.h"
+#endif
+
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
@@ -40,6 +51,47 @@
  ****************************************************************************/
 
 /****************************************************************************
+ * Name: config_oneshot_timer
+ *
+ * Description:
+ *   Configure the oneshot timer driver.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned
+ *   to indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ONESHOT
+static int config_oneshot_timer(int timer, uint16_t resolution)
+{
+  int ret = OK;
+  struct oneshot_lowerhalf_s *os_lower = NULL;
+
+  os_lower = oneshot_initialize(timer, resolution);
+  if (os_lower == NULL)
+    {
+      syslog(LOG_ERR, "Failed to initialize oneshot timer.\n");
+      return -EBUSY;
+    }
+
+#if defined(CONFIG_CPULOAD_ONESHOT)
+  /* Configure the oneshot timer to support CPU load measurement */
+
+  nxsched_oneshot_extclk(os_lower);
+#else
+  ret = oneshot_register("/dev/oneshot", os_lower);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "Failed to register oneshot device: %d\n", ret);
+    }
+#endif /* CONFIG_CPULOAD_ONESHOT */
+
+  return ret;
+}
+#endif
+
+/****************************************************************************
  * Name: board_tim_init
  *
  * Description:
@@ -55,7 +107,7 @@ int board_tim_init(void)
 {
   int ret = OK;
 
-#if defined(CONFIG_ESP32S3_TIMER0)
+#if defined(CONFIG_ESP32S3_TIMER0) && !defined(CONFIG_ONESHOT)
   ret = esp32s3_timer_initialize("/dev/timer0", ESP32S3_TIMER0);
   if (ret < 0)
     {
@@ -87,5 +139,16 @@ int board_tim_init(void)
     }
 #endif
 
+#if defined(CONFIG_ONESHOT) && defined(CONFIG_ESP32S3_TIMER0)
+  /* Now register one oneshot driver */
+
+  ret = config_oneshot_timer(ESP32S3_TIMER0, ONESHOT_RESOLUTION_US);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "Failed to initialize oneshot timer: %d\n", ret);
+    }
+
+#endif /* CONFIG_ONESHOT */
+
   return ret;
 }
diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/configs/oneshot/defconfig b/boards/xtensa/esp32s3/esp32s3-devkit/configs/oneshot/defconfig
new file mode 100644
index 0000000..4b40d85
--- /dev/null
+++ b/boards/xtensa/esp32s3/esp32s3-devkit/configs/oneshot/defconfig
@@ -0,0 +1,58 @@
+#
+# This file is autogenerated: PLEASE DO NOT EDIT IT.
+#
+# You can use "make menuconfig" to make any modifications to the installed .config file.
+# You can then do "make savedefconfig" to generate a new defconfig file that includes your
+# modifications.
+#
+# CONFIG_ARCH_LEDS is not set
+# CONFIG_NSH_ARGCAT is not set
+# CONFIG_NSH_CMDOPT_HEXDUMP is not set
+# CONFIG_NSH_CMDPARMS is not set
+CONFIG_ALARM_ARCH=y
+CONFIG_ARCH="xtensa"
+CONFIG_ARCH_BOARD="esp32s3-devkit"
+CONFIG_ARCH_BOARD_ESP32S3_DEVKIT=y
+CONFIG_ARCH_CHIP="esp32s3"
+CONFIG_ARCH_CHIP_ESP32S3=y
+CONFIG_ARCH_CHIP_ESP32S3WROOM1=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARCH_XTENSA=y
+CONFIG_BOARD_LOOPSPERMSEC=16717
+CONFIG_BUILTIN=y
+CONFIG_DEBUG_FULLOPT=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_ESP32S3_ONESHOT=y
+CONFIG_ESP32S3_TIMER0=y
+CONFIG_ESP32S3_TIMER1=y
+CONFIG_ESP32S3_TIMER2=y
+CONFIG_ESP32S3_TIMER3=y
+CONFIG_ESP32S3_UART0=y
+CONFIG_EXAMPLES_ONESHOT=y
+CONFIG_EXAMPLES_TIMER=y
+CONFIG_FS_PROCFS=y
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+CONFIG_IDLETHREAD_STACKSIZE=3072
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_INTELHEX_BINARY=y
+CONFIG_MM_REGIONS=3
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_LINELEN=64
+CONFIG_NSH_READLINE=y
+CONFIG_ONESHOT=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAM_SIZE=114688
+CONFIG_RAM_START=0x20000000
+CONFIG_RAW_BINARY=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_WAITPID=y
+CONFIG_START_DAY=6
+CONFIG_START_MONTH=12
+CONFIG_START_YEAR=2011
+CONFIG_SYSTEM_NSH=y
+CONFIG_TIMER=y
+CONFIG_TIMER_ARCH=y
+CONFIG_UART0_SERIAL_CONSOLE=y