From 68a4c31a7650e69639ca7856f20aea71067e1afb Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Tue, 13 Oct 2020 10:55:24 +0300 Subject: [PATCH] Add nuttx userspace reset and reboot request functions Add functions for reset and reboot, which can be called from user space in nuttx kernel and protected build Signed-off-by: Jukka Laitinen --- platforms/nuttx/src/px4/common/CMakeLists.txt | 1 + .../common/include/px4_platform/board_reset.h | 53 ++++++++++++++++ platforms/nuttx/src/px4/common/usr_reset.cpp | 61 +++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 platforms/nuttx/src/px4/common/include/px4_platform/board_reset.h create mode 100644 platforms/nuttx/src/px4/common/usr_reset.cpp diff --git a/platforms/nuttx/src/px4/common/CMakeLists.txt b/platforms/nuttx/src/px4/common/CMakeLists.txt index 1a72d340aa..ca5de70b72 100644 --- a/platforms/nuttx/src/px4/common/CMakeLists.txt +++ b/platforms/nuttx/src/px4/common/CMakeLists.txt @@ -75,6 +75,7 @@ if (NOT DEFINED CONFIG_BUILD_FLAT AND "${PX4_PLATFORM}" MATCHES "nuttx") usr_hrt.cpp ${PX4_SOURCE_DIR}/platforms/posix/src/px4/common/print_load.cpp ${PX4_SOURCE_DIR}/platforms/posix/src/px4/common/cpuload.cpp + usr_reset.cpp ) set(LIBS_USER diff --git a/platforms/nuttx/src/px4/common/include/px4_platform/board_reset.h b/platforms/nuttx/src/px4/common/include/px4_platform/board_reset.h new file mode 100644 index 0000000000..086dfec6a2 --- /dev/null +++ b/platforms/nuttx/src/px4/common/include/px4_platform/board_reset.h @@ -0,0 +1,53 @@ +/**************************************************************************** + * + * Copyright (c) 2020 Technology Innovation Institute. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ +#pragma once + +#if defined(CONFIG_BUILD_FLAT) + +static inline int board_reset_request(int status) +{ + return board_reset(status); +} + +static inline int board_poweroff_request(int status) +{ + return board_power_off(status); +} + +#else + +__EXPORT int board_reset_request(int status); +__EXPORT int board_poweroff_request(int status); + +#endif + diff --git a/platforms/nuttx/src/px4/common/usr_reset.cpp b/platforms/nuttx/src/px4/common/usr_reset.cpp new file mode 100644 index 0000000000..1114c72643 --- /dev/null +++ b/platforms/nuttx/src/px4/common/usr_reset.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** + * + * Copyright (C) 2020 Technology Innovation Institute. All rights reserved. + * Author: @author Jukka Laitinen + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file usr_reset.cpp + * Implementation of nuttx userspace reset api + */ + +#include + +__EXPORT int board_reset_request(int status) +{ +#if defined(CONFIG_BOARDCTL_RESET) + boardctl(BOARDIOC_RESET, status); +#endif + + /* Was not able to reset */ + return -1; +} + + +__EXPORT int board_poweroff_request(int status) +{ +#if defined(CONFIG_BOARDCTL_POWEROFF) + boardctl(BOARDIOC_POWEROFF, status); +#endif + + /* Was not able to power off */ + return -1; +}