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

commit c429438f0d835870f788acadf455811cbd991c4e
Author: Peter Bee <[email protected]>
AuthorDate: Tue Feb 6 15:01:12 2024 +0800

    arch/arm: add up_systempoweroff()
    
    Co-authored-by: Neo Xu <[email protected]>
    
    Signed-off-by: Peter Bee <[email protected]>
---
 arch/arm/src/armv7-a/arm_cpu_psci.c       | 50 ++++++++++++++++++++++++
 arch/arm64/src/common/CMakeLists.txt      |  2 +-
 arch/arm64/src/common/Make.defs           |  2 +-
 arch/arm64/src/common/arm64_cpu_psci.c    | 50 ++++++++++++++++++++++++
 arch/arm64/src/common/arm64_systemreset.c | 63 -------------------------------
 include/nuttx/arch.h                      | 12 ++++++
 6 files changed, 114 insertions(+), 65 deletions(-)

diff --git a/arch/arm/src/armv7-a/arm_cpu_psci.c 
b/arch/arm/src/armv7-a/arm_cpu_psci.c
index ef494e647e..3cd4df1c57 100644
--- a/arch/arm/src/armv7-a/arm_cpu_psci.c
+++ b/arch/arm/src/armv7-a/arm_cpu_psci.c
@@ -230,3 +230,53 @@ int arm_psci_init(const char *method)
 
   return psci_detect();
 }
+
+/***************************************************************************
+ * Name: up_systempoweroff
+ *
+ * Description:
+ *   Internal, arm poweroff logic.
+ *
+ ***************************************************************************/
+
+void up_systempoweroff(void)
+{
+  int ret;
+
+  /* Set up for the system poweroff */
+
+  ret = psci_cpu_off();
+  if (ret)
+    {
+      sinfo("Failed to power off CPU, error code: %d\n", ret);
+    }
+
+  /* Wait for power off */
+
+  for (; ; );
+}
+
+/***************************************************************************
+ * Name: up_systemreset
+ *
+ * Description:
+ *   Internal, arm reset logic.
+ *
+ ***************************************************************************/
+
+void up_systemreset(void)
+{
+  int ret;
+
+  /* Set up for the system reset */
+
+  ret = psci_cpu_reset();
+  if (ret)
+    {
+      sinfo("Failed to reset CPU, error code: %d\n", ret);
+    }
+
+  /* Wait for the reset */
+
+  for (; ; );
+}
diff --git a/arch/arm64/src/common/CMakeLists.txt 
b/arch/arm64/src/common/CMakeLists.txt
index 8180691a60..86be271a90 100644
--- a/arch/arm64/src/common/CMakeLists.txt
+++ b/arch/arm64/src/common/CMakeLists.txt
@@ -64,7 +64,7 @@ if(CONFIG_ARCH_HAVE_MPU)
 endif()
 
 if(CONFIG_ARM64_PSCI)
-  list(APPEND SRCS arm64_cpu_psci.c arm64_systemreset.c)
+  list(APPEND SRCS arm64_cpu_psci.c)
 endif()
 
 if(CONFIG_SMP)
diff --git a/arch/arm64/src/common/Make.defs b/arch/arm64/src/common/Make.defs
index 0e7411b6d5..14f7eb1193 100644
--- a/arch/arm64/src/common/Make.defs
+++ b/arch/arm64/src/common/Make.defs
@@ -76,7 +76,7 @@ CMN_CSRCS += arm64_mpu.c
 endif
 
 ifeq ($(CONFIG_ARM64_PSCI),y)
-CMN_CSRCS += arm64_cpu_psci.c arm64_systemreset.c
+CMN_CSRCS += arm64_cpu_psci.c
 endif
 
 ifeq ($(CONFIG_SMP),y)
diff --git a/arch/arm64/src/common/arm64_cpu_psci.c 
b/arch/arm64/src/common/arm64_cpu_psci.c
index 50c47656b0..068158e56a 100644
--- a/arch/arm64/src/common/arm64_cpu_psci.c
+++ b/arch/arm64/src/common/arm64_cpu_psci.c
@@ -232,3 +232,53 @@ int arm64_psci_init(const char * method)
 
   return psci_detect();
 }
+
+/***************************************************************************
+ * Name: up_systempoweroff
+ *
+ * Description:
+ *   Internal, arm64 poweroff logic.
+ *
+ ***************************************************************************/
+
+void up_systempoweroff(void)
+{
+  int ret;
+
+  /* Set up for the system poweroff */
+
+  ret = psci_cpu_off();
+  if (ret)
+    {
+      serr("Failed to power off CPU, error code: %d\n", ret);
+    }
+
+  /* Wait for power off */
+
+  for (; ; );
+}
+
+/***************************************************************************
+ * Name: up_systemreset
+ *
+ * Description:
+ *   Internal, arm64 reset logic.
+ *
+ ***************************************************************************/
+
+void up_systemreset(void)
+{
+  int ret;
+
+  /* Set up for the system reset */
+
+  ret = psci_cpu_reset();
+  if (ret)
+    {
+      serr("Failed to reset CPU, error code: %d\n", ret);
+    }
+
+  /* Wait for the reset */
+
+  for (; ; );
+}
diff --git a/arch/arm64/src/common/arm64_systemreset.c 
b/arch/arm64/src/common/arm64_systemreset.c
deleted file mode 100644
index 86c97ca198..0000000000
--- a/arch/arm64/src/common/arm64_systemreset.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************************
- * arch/arm64/src/common/arm64_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 <debug.h>
-
-#include <nuttx/arch.h>
-#include <nuttx/board.h>
-
-#include "arm64_internal.h"
-#include "arm64_cpu_psci.h"
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_systemreset
- *
- * Description:
- *   Internal, arm64 reset logic.
- *
- ****************************************************************************/
-
-void up_systemreset(void)
-{
-  int ret;
-
-  /* Set up for the system reset */
-
-  ret = psci_cpu_reset();
-  if (ret)
-    {
-      sinfo("Failed to reset CPU, error code: %d\n", ret);
-    }
-
-  /* Wait for the reset */
-
-  for (; ; );
-}
diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h
index 11971e54cd..8ae0303b8f 100644
--- a/include/nuttx/arch.h
+++ b/include/nuttx/arch.h
@@ -213,6 +213,18 @@ pid_t up_fork(void);
 
 void up_initialize(void);
 
+/****************************************************************************
+ * Name: up_systempoweroff
+ *
+ * Description:
+ *   The function up_systempoweroff() will power down the MCU.  Optional!
+ *   Availability of this function is dependent upon the architecture
+ *   support.
+ *
+ ****************************************************************************/
+
+void up_systempoweroff(void) noreturn_function;
+
 /****************************************************************************
  * Name: up_systemreset
  *

Reply via email to