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

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

commit ba8808103102bd8b896cf8d02bf0df1a57b7bb1a
Author: Brennan Ashton <[email protected]>
AuthorDate: Thu Dec 31 12:22:53 2020 -0800

    BL602: Add support for system reboot modes
    
    Signed-off-by: Brennan Ashton <[email protected]>
---
 arch/risc-v/Kconfig                            |   1 +
 arch/risc-v/src/bl602/Make.defs                |   2 +-
 arch/risc-v/src/bl602/bl602_systemreset.c      | 128 +++++++++++++++++++++++++
 arch/risc-v/src/bl602/bl602_systemreset.h      |  83 ++++++++++++++++
 boards/risc-v/bl602/bl602evb/src/Makefile      |   3 +
 boards/risc-v/bl602/bl602evb/src/bl602_reset.c |  59 ++++++++++++
 6 files changed, 275 insertions(+), 1 deletion(-)

diff --git a/arch/risc-v/Kconfig b/arch/risc-v/Kconfig
index 87e63f8..290fd35 100644
--- a/arch/risc-v/Kconfig
+++ b/arch/risc-v/Kconfig
@@ -47,6 +47,7 @@ config ARCH_CHIP_GAP8
 config ARCH_CHIP_BL602
        bool "BouffaloLab BL602"
        select ARCH_RV32IM
+       select ARCH_HAVE_RESET
        ---help---
                BouffaloLab BL602(rv32imfc)
 
diff --git a/arch/risc-v/src/bl602/Make.defs b/arch/risc-v/src/bl602/Make.defs
index 1d1b231..d1a363b 100644
--- a/arch/risc-v/src/bl602/Make.defs
+++ b/arch/risc-v/src/bl602/Make.defs
@@ -59,7 +59,7 @@ ifeq ($(CONFIG_ONESHOT),y)
 CHIP_CSRCS  += bl602_oneshot_lowerhalf.c
 endif
 
-CHIP_CSRCS += bl602_glb.c bl602_gpio.c bl602_hbn.c
+CHIP_CSRCS += bl602_glb.c bl602_gpio.c bl602_hbn.c bl602_systemreset.c
 
 # INCLUDES += ${shell $(INCDIR) "$(CC)" 
$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)hardware}
 
diff --git a/arch/risc-v/src/bl602/bl602_systemreset.c 
b/arch/risc-v/src/bl602/bl602_systemreset.c
new file mode 100644
index 0000000..388a1a5
--- /dev/null
+++ b/arch/risc-v/src/bl602/bl602_systemreset.c
@@ -0,0 +1,128 @@
+/****************************************************************************
+ * arch/risc-v/src/bl602/bl602_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 "riscv_arch.h"
+
+#include "hardware/bl602_glb.h"
+#include "hardware/bl602_hbn.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: bl602_chip_reset
+ *
+ * Description:
+ *   Control the different reset modes
+ *
+ * Input Parameters:
+ *   mask - Reset bitmask use these defines
+ *          SWRST_CFG2_CTRL_SYS_RESET, SWRST_CFG2_CTRL_CPU_RESET,
+ *          SWRST_CFG2_CTRL_PWRON_RST
+ *
+ ****************************************************************************/
+
+static void bl602_chip_reset(uint32_t mask)
+{
+  /* Reset the root clock */
+
+  modifyreg32(BL602_HBN_GLB, HBN_GLB_HBN_ROOT_CLK_SEL_MASK, 0);
+
+  /* Clear root clock dividers */
+
+  modifyreg32(
+      BL602_CLK_CFG0,
+      CLK_CFG0_REG_BCLK_DIV_MASK | CLK_CFG0_REG_HCLK_DIV_MASK,
+      0
+  );
+
+  /* This register should be cleared on changes to root clock.
+   * details of this register are not documented, but is clear from ROM
+   */
+
+  putreg32(0, 0x40000ffc);
+
+  /* Trigger reset */
+
+  modifyreg32(
+      BL602_SWRST_CFG2,
+      (SWRST_CFG2_CTRL_SYS_RESET | SWRST_CFG2_CTRL_CPU_RESET | \
+       SWRST_CFG2_CTRL_PWRON_RST),
+      mask
+  );
+
+  /* Wait for the reset */
+
+  for (; ; );
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_systemreset
+ *
+ * Description:
+ *   Internal reset logic.
+ *
+ ****************************************************************************/
+
+void up_systemreset(void)
+{
+  bl602_chip_reset(SWRST_CFG2_CTRL_SYS_RESET | SWRST_CFG2_CTRL_CPU_RESET);
+}
+
+/****************************************************************************
+ * Name: bl602_cpu_reset
+ *
+ * Description:
+ *   Reset only the CPU
+ *
+ ****************************************************************************/
+
+void bl602_cpu_reset(void)
+{
+  bl602_chip_reset(SWRST_CFG2_CTRL_CPU_RESET);
+}
+
+/****************************************************************************
+ * Name: bl602_por_reset
+ *
+ * Description:
+ *   Trigger Power-on-Reset
+ *
+ ****************************************************************************/
+
+void bl602_por_reset(void)
+{
+  bl602_chip_reset(
+    SWRST_CFG2_CTRL_SYS_RESET | \
+    SWRST_CFG2_CTRL_CPU_RESET | \
+    SWRST_CFG2_CTRL_PWRON_RST);
+}
diff --git a/arch/risc-v/src/bl602/bl602_systemreset.h 
b/arch/risc-v/src/bl602/bl602_systemreset.h
new file mode 100644
index 0000000..28fe032
--- /dev/null
+++ b/arch/risc-v/src/bl602/bl602_systemreset.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+ * arch/risc-v/src/bl602/bl602_hbn.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_RISCV_SRC_BL602_BL602_SYSTEMREST_H
+#define __ARCH_RISCV_SRC_BL602_BL602_SYSTEMREST_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define bl602_sys_reset() up_systemreset()
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: bl602_cpu_reset
+ *
+ * Description:
+ *   Reset only the CPU
+ *
+ ****************************************************************************/
+
+void bl602_cpu_reset(void);
+
+/****************************************************************************
+ * Name: bl602_por_reset
+ *
+ * Description:
+ *   Trigger Power-on-Reset
+ *
+ ****************************************************************************/
+
+void bl602_por_reset(void);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __ARCH_RISCV_SRC_BL602_BL602_SYSTEMREST_H */
diff --git a/boards/risc-v/bl602/bl602evb/src/Makefile 
b/boards/risc-v/bl602/bl602evb/src/Makefile
index 8fdb2cc..5b9a2bc 100644
--- a/boards/risc-v/bl602/bl602evb/src/Makefile
+++ b/boards/risc-v/bl602/bl602evb/src/Makefile
@@ -24,6 +24,9 @@ CSRCS  = bl602_bringup.c bl602_boot.c
 
 ifeq ($(CONFIG_LIB_BOARDCTL),y)
 CSRCS += bl602_appinit.c
+ifeq ($(CONFIG_BOARDCTL_RESET),y)
+  CSRCS += bl602_reset.c
+endif
 endif
 
 include $(TOPDIR)/boards/Board.mk
diff --git a/boards/risc-v/bl602/bl602evb/src/bl602_reset.c 
b/boards/risc-v/bl602/bl602evb/src/bl602_reset.c
new file mode 100644
index 0000000..9342bb3
--- /dev/null
+++ b/boards/risc-v/bl602/bl602evb/src/bl602_reset.c
@@ -0,0 +1,59 @@
+/****************************************************************************
+ * boards/risc-v/bl602/evb/src/bl602_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>
+
+/****************************************************************************
+ * 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 int this case is a
+ *   board-specific reason for the failure to shutdown.
+ *
+ ****************************************************************************/
+
+int board_reset(int status)
+{
+  up_systemreset();
+  return 0;
+}
+

Reply via email to