This is an automated email from the ASF dual-hosted git repository. archer pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 20098f3b34c2f6537072236d00e6598e3550c2d8 Author: Yanfeng Liu <p-liuyanfe...@xiaomi.com> AuthorDate: Wed Feb 5 19:39:00 2025 +0800 arch/arm: add semihosting poweroff This adds semihosting based poweroff to arm/common. It uses semihosting operation SYS_EXIT (0x18) with parameter AppExit (0x20026). Signed-off-by: Yanfeng Liu <p-liuyanfe...@xiaomi.com> --- arch/arm/Kconfig | 6 ++++ arch/arm/src/common/CMakeLists.txt | 1 + arch/arm/src/common/Make.defs | 2 +- arch/arm/src/common/arm_poweroff.c | 71 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 71031f5dae..3cb35a1d58 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1437,6 +1437,12 @@ config DEBUG_SECUREFAULT output is sometimes helpful when debugging difficult usage fault problems, but may be more than you typically want to see. +config ARM_SEMIHOSTING_POWEROFF + bool "Semihosting POWEROFF support" + default n + ---help--- + Enable use of semihosting function to poweroff target. + config ARM_SEMIHOSTING_SYSLOG bool "Semihosting SYSLOG support" select SYSLOG_REGISTER diff --git a/arch/arm/src/common/CMakeLists.txt b/arch/arm/src/common/CMakeLists.txt index 4353c82435..77cb13a4d0 100644 --- a/arch/arm/src/common/CMakeLists.txt +++ b/arch/arm/src/common/CMakeLists.txt @@ -40,6 +40,7 @@ set(SRCS arm_stackframe.c arm_usestack.c arm_fork.c + arm_poweroff.c ${ARCH_TOOLCHAIN_PATH}/fork.S) if(NOT CONFIG_ALARM_ARCH AND NOT CONFIG_TIMER_ARCH) diff --git a/arch/arm/src/common/Make.defs b/arch/arm/src/common/Make.defs index 1694083e28..7818eef46e 100644 --- a/arch/arm/src/common/Make.defs +++ b/arch/arm/src/common/Make.defs @@ -26,7 +26,7 @@ CMN_CSRCS += arm_allocateheap.c arm_createstack.c arm_exit.c CMN_CSRCS += arm_getintstack.c arm_initialize.c arm_lowputs.c CMN_CSRCS += arm_nputs.c arm_releasestack.c arm_registerdump.c CMN_CSRCS += arm_stackframe.c arm_modifyreg.c -CMN_CSRCS += arm_usestack.c arm_fork.c +CMN_CSRCS += arm_usestack.c arm_fork.c arm_poweroff.c ifneq ($(CONFIG_ALARM_ARCH),y) ifneq ($(CONFIG_TIMER_ARCH),y) diff --git a/arch/arm/src/common/arm_poweroff.c b/arch/arm/src/common/arm_poweroff.c new file mode 100644 index 0000000000..9481c464c9 --- /dev/null +++ b/arch/arm/src/common/arm_poweroff.c @@ -0,0 +1,71 @@ +/*************************************************************************** + * arch/arm/src/common/arm_poweroff.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 <debug.h> + +#include "arch/syscall.h" + +#ifdef CONFIG_ARM_SEMIHOSTING_POWEROFF + +/*************************************************************************** + * Preprocessor Definitions + ***************************************************************************/ + +/* per https://github.com/ARM-software/abi-aa semihosting.pdf 2024Q3 */ + +#define ARMSMH_OPNUM_SYSEXIT 0x18 +#define ARMSMH_PARAM_APPEXIT 0x20026 + +/*************************************************************************** + * Public Functions + ***************************************************************************/ + +/*************************************************************************** + * Name: up_systempoweroff + * + * Description: + * Semihosting EXIT based poweroff logic. + * + ***************************************************************************/ + +void up_systempoweroff(void) +{ + int ret; + + /* Set up for the system poweroff */ + + ret = smh_call(ARMSMH_OPNUM_SYSEXIT, ARMSMH_PARAM_APPEXIT); + if (ret) + { + sinfo("Failed to power off CPU, error code: %d\n", ret); + } + + /* Wait for power off */ + + for (; ; ); +} +#endif /* CONFIG_ARM_SEMIHOSTING_POWEROFF */ \ No newline at end of file