You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2020/10/07 14:51:58 UTC

[incubator-nuttx] 01/02: arch/xtensa/esp32: Implement system reset. Both CPUs are soft-reset with a call to board_reset. This is actually a Core Reset, so both cores and all registers are reset. The only exception is RTC.

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

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

commit c20c8c6dd5bf40058ef78ad761833a55014d9c06
Author: Abdelatif Guettouche <ab...@espressif.com>
AuthorDate: Tue Sep 29 14:38:32 2020 +0100

    arch/xtensa/esp32: Implement system reset.
    Both CPUs are soft-reset with a call to board_reset.  This is actually a
    Core Reset, so both cores and all registers are reset.  The only
    exception is RTC.
    
    Signed-off-by: Abdelatif Guettouche <ab...@espressif.com>
---
 arch/xtensa/Kconfig                              |  1 +
 arch/xtensa/src/esp32/Make.defs                  |  1 +
 arch/xtensa/src/esp32/esp32_systemreset.c        | 54 ++++++++++++++++++++
 boards/xtensa/esp32/esp32-core/src/Makefile      |  3 ++
 boards/xtensa/esp32/esp32-core/src/esp32_reset.c | 63 ++++++++++++++++++++++++
 5 files changed, 122 insertions(+)

diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index 7ee94b5..3b9d2ef 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -15,6 +15,7 @@ config ARCH_CHIP_ESP32
 	select XTENSA_HAVE_INTERRUPTS
 	select ARCH_HAVE_MULTICPU
 	select ARCH_HAVE_MODULE_TEXT
+	select ARCH_HAVE_RESET
 	select ARCH_TOOLCHAIN_GNU
 	---help---
 		The ESP32 is a dual-core system from Espressif with two Harvard
diff --git a/arch/xtensa/src/esp32/Make.defs b/arch/xtensa/src/esp32/Make.defs
index 9ef9f65..2c9c32c 100644
--- a/arch/xtensa/src/esp32/Make.defs
+++ b/arch/xtensa/src/esp32/Make.defs
@@ -53,6 +53,7 @@ CMN_CSRCS += xtensa_puts.c xtensa_releasepending.c xtensa_releasestack.c
 CMN_CSRCS += xtensa_reprioritizertr.c xtensa_schedsigaction.c
 CMN_CSRCS += xtensa_sigdeliver.c xtensa_stackframe.c xtensa_udelay.c
 CMN_CSRCS += xtensa_unblocktask.c xtensa_usestack.c
+CMN_CSRCS += esp32_systemreset.c
 
 # Configuration-dependent common XTENSA files
 
diff --git a/arch/xtensa/src/esp32/esp32_systemreset.c b/arch/xtensa/src/esp32/esp32_systemreset.c
new file mode 100644
index 0000000..c19dfa9
--- /dev/null
+++ b/arch/xtensa/src/esp32/esp32_systemreset.c
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32/esp32_systemreset.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 <stdint.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/board.h>
+
+#include "xtensa.h"
+#include "hardware/esp32_rtccntl.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_systemreset
+ *
+ * Description:
+ *   Internal reset logic.
+ *
+ ****************************************************************************/
+
+void up_systemreset(void)
+{
+  putreg32(RTC_CNTL_SW_SYS_RST, RTC_CNTL_OPTIONS0_REG);
+
+  /* Wait for the reset */
+
+  for (; ; );
+}
diff --git a/boards/xtensa/esp32/esp32-core/src/Makefile b/boards/xtensa/esp32/esp32-core/src/Makefile
index e5b6f45..6b08aec 100644
--- a/boards/xtensa/esp32/esp32-core/src/Makefile
+++ b/boards/xtensa/esp32/esp32-core/src/Makefile
@@ -43,6 +43,9 @@ CSRCS = esp32_boot.c esp32_bringup.c
 
 ifeq ($(CONFIG_LIB_BOARDCTL),y)
 CSRCS += esp32_appinit.c
+ifeq ($(CONFIG_BOARDCTL_RESET),y)
+CSRCS += esp32_reset.c
+endif
 endif
 
 ifeq ($(CONFIG_ESP32_SPI),y)
diff --git a/boards/xtensa/esp32/esp32-core/src/esp32_reset.c b/boards/xtensa/esp32/esp32-core/src/esp32_reset.c
new file mode 100644
index 0000000..cd11e22
--- /dev/null
+++ b/boards/xtensa/esp32/esp32-core/src/esp32_reset.c
@@ -0,0 +1,63 @@
+/****************************************************************************
+ * boards/xtensa/esp32/esp32-core/src/esp32_reset.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 <nuttx/arch.h>
+#include <nuttx/board.h>
+
+#ifdef CONFIG_BOARDCTL_RESET
+
+/****************************************************************************
+ * Public functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_reset
+ *
+ * Description:
+ *   Reset board.  Support for this function is required by board-level
+ *   logic if CONFIG_BOARDCTL_RESET is selected.
+ *
+ * Input Parameters:
+ *   status - Status information provided with the reset event.  This
+ *            meaning of this status information is board-specific.  If not
+ *            used by a board, the value zero may be provided in calls to
+ *            board_reset().
+ *
+ * Returned Value:
+ *   If this function returns, then it was not possible to power-off the
+ *   board due to some constraints.  The return value in this case is a
+ *   board-specific reason for the failure to shutdown.
+ *
+ ****************************************************************************/
+
+int board_reset(int status)
+{
+  up_systemreset();
+
+  return 0;
+}
+
+#endif /* CONFIG_BOARDCTL_RESET */