diff --git a/boards/modalai/voxl2/README.md b/boards/modalai/voxl2/README.md new file mode 100644 index 0000000000..0004f8e28c --- /dev/null +++ b/boards/modalai/voxl2/README.md @@ -0,0 +1,91 @@ +# PX4 on VOXL 2 + +VOXL 2 from ModalAI can be used as a companion computer to a flight control board +but it can also run PX4 directly. + +## Overview + +When running PX4 directly on the QRB5165 SoC it runs partially on the Sensor Low Power Island (SLPI) DSP (aka sdsp) and partially on the application processor (ARM64 / aarch64). +The portion running on the DSP hosts the flight critical portions of PX4 such as +the IMU, barometer, magnetometer, GPS, ESC, and power management drivers, and the +state estimation. The DSP acts as the real time portion of the system. Non flight +critical applications such as Mavlink, logging, and commander are running on the +ARM CPU cluster (aka apps proc). The DSP and ARM CPU cluster communicate via a +Qualcomm proprietary shared memory interface. + +## Build environment + +In order to build for this platform both the Qualcomm Hexagon (DSP) toolchain and the Linaro ARM64 toolchain need to be installed. The (nearly) complete setup including the ARM64 toolchain is provided in the base Docker image provided by ModalAI, but since ModalAI is not allowed to redistribute the Qualcomm Hexagon DSP SDK this must be added by the end user. + +The full instructions are available here: +- https://gitlab.com/voxl-public/rb5-flight/rb5-flight-px4-build-docker + +## Build overview + +- Clone the repo (Don't forget to update and initialize all submodules) +- In the top level directory +``` +px4$ boards/modalai/voxl2/run-docker.sh +root@9373fa1401b8:/usr/local/workspace# boards/modalai/voxl2/clean.sh +root@9373fa1401b8:/usr/local/workspace# boards/modalai/voxl2/build-posix.sh +root@9373fa1401b8:/usr/local/workspace# boards/modalai/voxl2/build-qurt.sh +root@9373fa1401b8:/usr/local/workspace# exit +``` + +## Install and run on VOXL 2 + +Once the DSP and Linux images have been built they can be installed on a VOXL 2 +board using ADB. There is a script to do this. +``` +px4$ boards/modalai/voxl2/install-voxl.sh +``` + +## Running PX4 on VOXL 2 + +After installing PX4 on the board, open a terminal on VOXL 2 using ADB shell. +PX4 can be run using a start script. +``` +root@m0054:/# voxl-px4 +Found DSP signature file +/ +INFO [px4] mlockall() enabled. PX4's virtual address space is locked into RAM. +INFO [px4] assuming working directory is rootfs, no symlinks needed. + +______ __ __ ___ +| ___ \ \ \ / / / | +| |_/ / \ V / / /| | +| __/ / \ / /_| | +| | / /^\ \ \___ | +\_| \/ \/ |_/ + +px4 starting. + +INFO [px4] Calling startup script: /bin/sh /etc/modalai/voxl-px4.config 0 +INFO [muorb] muorb protobuf initalize method succeeded +INFO [px4] Startup script returned successfully +pxh> +``` + +## Tips + +Start with a VOXL 2 that only has the system image installed, not the SDK + +In order to see DSP specific debug messages the mini-dm tool in the Hexagon SDK +can be used: +``` +modalai@modalai-XPS-15-9570:/local/mnt/workspace/Qualcomm/Hexagon_SDK/4.1.0.4/tools/debug/mini-dm/Ubuntu18$ sudo ./mini-dm +[sudo] password for modalai: +Running mini-dm version: 3.2 +Completed processing command line --- +Connecting to the only usbport connected +mini-dm is waiting for a DMSS connection... +DMSS is connected. Running mini-dm... +------------Mini-dm is ready to log------------- +[08500/02] 06:21.030 0069:01: SDSP: Creating new instance. 0355 sns_flight_controller_sensor. +[08500/02] 06:21.030 0069:01: SDSP: Creating data streams 0292 sns_flight_controller_sensor_ +[08500/02] 06:21.030 0069:01: SDSP: Configuring devices 0305 sns_flight_controller_sensor_ +[08500/02] 06:21.030 0069:01: SDSP: Flight controller sensor instance initialized 0344 sns_flight_controller_sensor_ +[08500/01] 06:21.092 0069:01: SDSP: Hello, world! 0000 test +[08500/02] 06:21.092 006a:01: SDSP: CPU Utilization: 0.04, wait percentage 99.94 0162 sns_flight_controller_sensor. +[08500/02] 06:21.092 006a:01: SDSP: Got interrupt registered event 0082 sns_flight_controller_sensor_ +``` diff --git a/boards/modalai/voxl2/build-posix.sh b/boards/modalai/voxl2/build-posix.sh new file mode 100755 index 0000000000..675cec87fe --- /dev/null +++ b/boards/modalai/voxl2/build-posix.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +echo "*** Starting posix build ***" + +source /home/build-env.sh + +make modalai_voxl2_default + +cat build/modalai_voxl2_default/src/lib/version/build_git_version.h + + +echo "*** End of posix build ***" diff --git a/boards/modalai/voxl2/build-qurt.sh b/boards/modalai/voxl2/build-qurt.sh new file mode 100755 index 0000000000..2e29d4f28e --- /dev/null +++ b/boards/modalai/voxl2/build-qurt.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "*** Starting qurt build ***" + +source /home/build-env.sh + +make modalai_voxl2_qurt + +cat build/modalai_voxl2_default/src/lib/version/build_git_version.h + +echo "*** End of qurt build ***" diff --git a/boards/modalai/voxl2/clean.sh b/boards/modalai/voxl2/clean.sh new file mode 100755 index 0000000000..51cef9c3f2 --- /dev/null +++ b/boards/modalai/voxl2/clean.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# Clean out the build artifacts +source /home/build-env.sh +make clean diff --git a/boards/modalai/voxl2/cmake/voxl2_posix.cmake b/boards/modalai/voxl2/cmake/voxl2_posix.cmake new file mode 100644 index 0000000000..2f4b12420d --- /dev/null +++ b/boards/modalai/voxl2/cmake/voxl2_posix.cmake @@ -0,0 +1,54 @@ +############################################################################ +# +# Copyright (c) 2022 ModalAI, Inc. 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. +# +############################################################################ +# +# Overview: +# Voxl2 PX4 is built in 2 parts, the part that runs on the +# application (apps) processor, and the library that is loaded on the DSP. +# +############################################################################ + +include(px4_git) + +list(APPEND CMAKE_MODULE_PATH + "${PX4_SOURCE_DIR}/platforms/posix/cmake" +) + +# set(DISABLE_PARAMS_MODULE_SCOPING TRUE) + +add_definitions(-DORB_COMMUNICATOR) + +set(CONFIG_PARAM_SERVER "1") + +add_definitions( -D__PX4_LINUX ) + +include(CMakeParseArguments) diff --git a/boards/modalai/voxl2/cmake/voxl2_qurt.cmake b/boards/modalai/voxl2/cmake/voxl2_qurt.cmake new file mode 100644 index 0000000000..948fca5f16 --- /dev/null +++ b/boards/modalai/voxl2/cmake/voxl2_qurt.cmake @@ -0,0 +1,43 @@ +############################################################################ +# +# Copyright (c) 2022 ModalAI, Inc. All rights reserved. +# +############################################################################ +# +# This cmake config builds for QURT which is the operating system running on +# the DSP side of VOXL 2 +# +# Required environment variables: +# HEXAGON_TOOLS_ROOT +# HEXAGON_SDK_ROOT +# +############################################################################ + +if ("$ENV{HEXAGON_SDK_ROOT}" STREQUAL "") + message(FATAL_ERROR "Enviroment variable HEXAGON_SDK_ROOT must be set") +else() + set(HEXAGON_SDK_ROOT $ENV{HEXAGON_SDK_ROOT}) +endif() + +if ("$ENV{HEXAGON_TOOLS_ROOT}" STREQUAL "") + message(FATAL_ERROR "Environment variable HEXAGON_TOOLS_ROOT must be set") +else() + set(HEXAGON_TOOLS_ROOT $ENV{HEXAGON_TOOLS_ROOT}) +endif() + +include(px4_git) + +list(APPEND CMAKE_MODULE_PATH + "${PX4_SOURCE_DIR}/platforms/qurt/cmake" +) + +include(Toolchain-qurt) +include(qurt_reqs) + +include_directories(${HEXAGON_SDK_INCLUDES}) + +add_definitions(-DORB_COMMUNICATOR) + +set(CONFIG_PARAM_CLIENT "1") + +set(DISABLE_PARAMS_MODULE_SCOPING TRUE) diff --git a/boards/modalai/voxl2/default.px4board b/boards/modalai/voxl2/default.px4board new file mode 100644 index 0000000000..66858b22bb --- /dev/null +++ b/boards/modalai/voxl2/default.px4board @@ -0,0 +1,4 @@ +CONFIG_PLATFORM_POSIX=y +CONFIG_BOARD_LINUX=y +CONFIG_BOARD_TOOLCHAIN="aarch64-linux-gnu" +CONFIG_MODULES_MUORB_APPS=y diff --git a/boards/modalai/voxl2/install-voxl.sh b/boards/modalai/voxl2/install-voxl.sh new file mode 100755 index 0000000000..a316c3691b --- /dev/null +++ b/boards/modalai/voxl2/install-voxl.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Push qurt image to voxl2 +adb push build/modalai_voxl2_qurt/platforms/qurt/libpx4.so /usr/lib/rfsa/adsp + +# Push posix image to voxl2 +adb push build/modalai_voxl2_default/bin/px4 /usr/bin + +# Push scripts to voxl2 +adb push build/modalai_voxl2_default/bin/px4-alias.sh /usr/bin +adb push boards/modalai/voxl2/voxl-px4 /usr/bin +adb shell chmod a+x /usr/bin/px4-alias.sh +adb shell chmod a+x /usr/bin/voxl-px4 + +# Push configuration file +adb shell mkdir -p /etc/modalai +adb push boards/modalai/voxl2/voxl-px4.config /etc/modalai + +adb shell sync diff --git a/boards/modalai/voxl2/qurt.px4board b/boards/modalai/voxl2/qurt.px4board new file mode 100644 index 0000000000..d1f4ebc048 --- /dev/null +++ b/boards/modalai/voxl2/qurt.px4board @@ -0,0 +1,3 @@ +CONFIG_PLATFORM_QURT=y +CONFIG_BOARD_TOOLCHAIN="qurt" +CONFIG_MODULES_MUORB_SLPI=y diff --git a/boards/modalai/voxl2/run-docker.sh b/boards/modalai/voxl2/run-docker.sh new file mode 100755 index 0000000000..4df40769de --- /dev/null +++ b/boards/modalai/voxl2/run-docker.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Run this from the px4 project top level directory +docker run -it --rm -v `pwd`:/usr/local/workspace rb5-flight-px4-build-docker diff --git a/boards/modalai/voxl2/src/CMakeLists.txt b/boards/modalai/voxl2/src/CMakeLists.txt new file mode 100644 index 0000000000..b2ef3aacd2 --- /dev/null +++ b/boards/modalai/voxl2/src/CMakeLists.txt @@ -0,0 +1,37 @@ +############################################################################ +# +# Copyright (c) 2022 ModalAI, Inc. 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. +# +############################################################################ + +add_library(drivers_board + board_config.h + init.c + ) diff --git a/boards/modalai/voxl2/src/board_config.h b/boards/modalai/voxl2/src/board_config.h new file mode 100644 index 0000000000..2b077f9d8e --- /dev/null +++ b/boards/modalai/voxl2/src/board_config.h @@ -0,0 +1,51 @@ +/**************************************************************************** + * + * Copyright (c) 2022 ModalAI, Inc. 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. + * + ****************************************************************************/ + +/** + * @file board_config.h + * + * VOXL2 internal definitions + */ + +#pragma once + +#define BOARD_HAS_NO_RESET +#define BOARD_HAS_NO_BOOTLOADER + +/* + * I2C buses + */ +#define PX4_NUMBER_I2C_BUSES 3 + +#include +#include diff --git a/boards/modalai/voxl2/src/init.c b/boards/modalai/voxl2/src/init.c new file mode 100644 index 0000000000..f9a71ffaa2 --- /dev/null +++ b/boards/modalai/voxl2/src/init.c @@ -0,0 +1,35 @@ +/**************************************************************************** + * + * Copyright (C) 2022 ModalAI, Inc. 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. + * + ****************************************************************************/ +#include "board_config.h" + +// Place holder for VOXL2-specific early startup code diff --git a/boards/modalai/voxl2/voxl-px4 b/boards/modalai/voxl2/voxl-px4 new file mode 100644 index 0000000000..c529456d22 --- /dev/null +++ b/boards/modalai/voxl2/voxl-px4 @@ -0,0 +1,36 @@ +#!/bin/bash + +# Make sure that the SLPI DSP test signature is there otherwise px4 cannot run +# on the DSP +if /bin/ls /usr/lib/rfsa/adsp/testsig-*.so &> /dev/null; then + /bin/echo "Found DSP signature file" +else + /bin/echo "Error, could not find DSP signature file" + # Look for the DSP signature generation script + if [ -f /share/modalai/qrb5165-slpi-test-sig/generate-test-sig.sh ]; then + /bin/echo "Attempting to generate the DSP signature file" + # Automatically generate the test signature so that px4 can run on SLPI DSP + /share/modalai/qrb5165-slpi-test-sig/generate-test-sig.sh + else + /bin/echo "Could not find the DSP signature file generation script" + fi + exit 0 +fi + +# Make sure to setup all of the needed px4 aliases. +cd /usr/bin +/bin/ln -f -s px4 px4-muorb +/bin/ln -f -s px4 px4-uorb +cd - + +DAEMON=" " + +while getopts "d" flag +do + case "${flag}" in + # Use -d to put PX4 into daemon mode + d) DAEMON="-d";; + esac +done + +px4 $DAEMON -s /etc/modalai/voxl-px4.config diff --git a/boards/modalai/voxl2/voxl-px4.config b/boards/modalai/voxl2/voxl-px4.config new file mode 100755 index 0000000000..a0ab82f1ed --- /dev/null +++ b/boards/modalai/voxl2/voxl-px4.config @@ -0,0 +1,6 @@ +#!/bin/sh +# PX4 commands need the 'px4-' prefix in bash. +# (px4-alias.sh is expected to be in the PATH) +. px4-alias.sh + +muorb start diff --git a/cmake/kconfig.cmake b/cmake/kconfig.cmake index 37b500e284..377da1ddd5 100644 --- a/cmake/kconfig.cmake +++ b/cmake/kconfig.cmake @@ -34,7 +34,7 @@ if(EXISTS ${BOARD_DEFCONFIG}) # Depend on BOARD_DEFCONFIG so that we reconfigure on config change set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${BOARD_DEFCONFIG}) - if(${LABEL} MATCHES "default" OR ${LABEL} MATCHES "recovery" OR ${LABEL} MATCHES "bootloader" OR ${LABEL} MATCHES "canbootloader") + if(${LABEL} MATCHES "default" OR ${LABEL} MATCHES "qurt" OR ${LABEL} MATCHES "recovery" OR ${LABEL} MATCHES "bootloader" OR ${LABEL} MATCHES "canbootloader") # Generate boardconfig from saved defconfig execute_process(COMMAND ${CMAKE_COMMAND} -E env ${COMMON_KCONFIG_ENV_SETTINGS} ${DEFCONFIG_PATH} ${BOARD_DEFCONFIG} @@ -228,6 +228,10 @@ if(EXISTS ${BOARD_DEFCONFIG}) # platform-specific include path include_directories(${PX4_SOURCE_DIR}/platforms/${PX4_PLATFORM}/src/px4/common/include) + + if(PLATFORM STREQUAL "qurt") + include(${PX4_SOURCE_DIR}/boards/modalai/voxl2/cmake/voxl2_qurt.cmake) + endif() endif() if(ARCHITECTURE) diff --git a/cmake/px4_add_library.cmake b/cmake/px4_add_library.cmake index 7dc7b6cfd0..08eb456b83 100644 --- a/cmake/px4_add_library.cmake +++ b/cmake/px4_add_library.cmake @@ -44,7 +44,11 @@ function(px4_add_library target) target_compile_definitions(${target} PRIVATE MODULE_NAME="${target}") # all PX4 libraries have access to parameters and uORB - add_dependencies(${target} uorb_headers parameters) + # TODO: Exclusion of qurt is temporary until these modules + # build cleanly. + if(NOT ${PLATFORM} MATCHES "qurt") + add_dependencies(${target} uorb_headers parameters) + endif() target_link_libraries(${target} PRIVATE prebuild_targets) set_property(GLOBAL APPEND PROPERTY PX4_MODULE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/platforms/common/uORB/uORBManager.hpp b/platforms/common/uORB/uORBManager.hpp index 682e6047ef..3546adc4de 100644 --- a/platforms/common/uORB/uORBManager.hpp +++ b/platforms/common/uORB/uORBManager.hpp @@ -409,7 +409,7 @@ public: * @param instance ORB instance * @return OK if the topic exists, PX4_ERROR otherwise. */ - static int orb_exists(const struct orb_metadata *meta, int instance); + int orb_exists(const struct orb_metadata *meta, int instance); /** * Set the minimum interval between which updates are seen for a subscription. diff --git a/platforms/posix/CMakeLists.txt b/platforms/posix/CMakeLists.txt index 8ec2f14df8..b1da0a37af 100644 --- a/platforms/posix/CMakeLists.txt +++ b/platforms/posix/CMakeLists.txt @@ -101,6 +101,14 @@ endif() if("${PX4_BOARD}" MATCHES "beaglebone_blue") target_link_libraries(px4 PRIVATE robotics_cape) +elseif("${PX4_BOARD}" MATCHES "modalai_voxl2") + # libfc_sensor.so is provided in the Docker build environment + target_link_libraries(px4 PRIVATE + /home/libfc_sensor.so + px4_layer + ${module_libraries} + ) + elseif("${PX4_BOARD}" MATCHES "emlid_navio2") target_link_libraries(px4 PRIVATE atomic) diff --git a/platforms/posix/cmake/Toolchain-aarch64-linux-gnu.cmake b/platforms/posix/cmake/Toolchain-aarch64-linux-gnu.cmake index 99e9d643be..2a7cb6c8a3 100644 --- a/platforms/posix/cmake/Toolchain-aarch64-linux-gnu.cmake +++ b/platforms/posix/cmake/Toolchain-aarch64-linux-gnu.cmake @@ -1,13 +1,22 @@ # arm-linux-gnueabihf-gcc toolchain +set(triple aarch64-linux-gnu) + +if("${PX4_BOARD}" MATCHES "modalai_voxl2") + set(CMAKE_LIBRARY_ARCHITECTURE ${ARM_CROSS_GCC_ROOT}/bin/${triple}) + set(TOOLCHAIN_PREFIX ${ARM_CROSS_GCC_ROOT}/bin/${triple}) + set(ARM_CROSS_GCC_ROOT $ENV{ARM_CROSS_GCC_ROOT}) + set(HEXAGON_ARM_SYSROOT $ENV{HEXAGON_ARM_SYSROOT}) + set(CMAKE_EXE_LINKER_FLAGS "-Wl,-gc-sections -Wl,-rpath-link,${HEXAGON_ARM_SYSROOT}/usr/lib/aarch64-linux-gnu -Wl,-rpath-link,${HEXAGON_ARM_SYSROOT}/lib/aarch64-linux-gnu") +else() + set(CMAKE_LIBRARY_ARCHITECTURE ${triple}) + set(TOOLCHAIN_PREFIX ${triple}) +endif() + set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR arm) set(CMAKE_SYSTEM_VERSION 1) -set(triple aarch64-linux-gnu) -set(CMAKE_LIBRARY_ARCHITECTURE ${triple}) -set(TOOLCHAIN_PREFIX ${triple}) - set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) set(CMAKE_C_COMPILER_TARGET ${triple}) diff --git a/platforms/qurt/CMakeLists.txt b/platforms/qurt/CMakeLists.txt new file mode 100644 index 0000000000..ca3a6b5301 --- /dev/null +++ b/platforms/qurt/CMakeLists.txt @@ -0,0 +1,41 @@ +############################################################################ +# +# Copyright (c) 2022 ModalAI, Inc. 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. +# +############################################################################ + +set(module_libraries modules__muorb__slpi) + +QURT_LIB(LIB_NAME px4 + SOURCES + ${PX4_SOURCE_DIR}/platforms/qurt/unresolved_symbols.c + LINK_LIBS + ${module_libraries} + ) diff --git a/platforms/qurt/cmake/Toolchain-qurt.cmake b/platforms/qurt/cmake/Toolchain-qurt.cmake new file mode 100644 index 0000000000..7822d683cb --- /dev/null +++ b/platforms/qurt/cmake/Toolchain-qurt.cmake @@ -0,0 +1,71 @@ +# +# Copyright (c) 2022 ModalAI, Inc. 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 ATLFlight 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. +# + +include(CMakeForceCompiler) + +set(V_ARCH "v66") +set(CROSSDEV "hexagon-") + +set(HEXAGON_BIN ${HEXAGON_TOOLS_ROOT}/bin) + +set(CMAKE_C_COMPILER ${HEXAGON_BIN}/${CROSSDEV}clang) +set(CMAKE_CXX_COMPILER ${HEXAGON_BIN}/${CROSSDEV}clang++) + +set(CMAKE_AR ${HEXAGON_BIN}/${CROSSDEV}ar CACHE FILEPATH "Archiver") + SET(CMAKE_CXX_ARCHIVE_CREATE " qcD ") + SET(CMAKE_C_ARCHIVE_CREATE " qcD ") +set(CMAKE_RANLIB ${HEXAGON_BIN}/${CROSSDEV}ranlib) +set(CMAKE_OBJDUMP ${HEXAGON_BIN}/${CROSSDEV}objdump) +set(CMAKE_OBJCOPY ${HEXAGON_BIN}/${CROSSDEV}objcopy) +set(HEXAGON_LINK ${HEXAGON_BIN}/${CROSSDEV}link) + +set(HEXAGON_ARCH_FLAGS + -march=hexagon + -mcpu=hexagonv66) + +set(CMAKE_SKIP_RPATH TRUE CACHE BOOL SKIP_RPATH FORCE) + +# where is the target environment +set(CMAKE_FIND_ROOT_PATH get_file_component(${C_COMPILER} PATH)) + +set(CMAKE_C_COMPILER_ID, "Clang") +set(CMAKE_CXX_COMPILER_ID, "Clang") + +# search for programs in the build host directories +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + +# for libraries and headers in the target directories +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +macro(__linux_compiler_gnu lang) + set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "") +endmacro() diff --git a/platforms/qurt/cmake/px4_impl_os.cmake b/platforms/qurt/cmake/px4_impl_os.cmake new file mode 100644 index 0000000000..b7906c495a --- /dev/null +++ b/platforms/qurt/cmake/px4_impl_os.cmake @@ -0,0 +1,185 @@ +############################################################################ +# +# Copyright (c) 2022 ModalAI, Inc. 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. +# +############################################################################ + +#============================================================================= +# +# Defined functions in this file +# +# OS Specific Functions +# +# * px4_qurt_generate_builtin_commands +# +# Required OS Inteface Functions +# +# * px4_os_add_flags +# * px4_os_determine_build_chip +# * px4_os_prebuild_targets +# + +#============================================================================= +# +# px4_qurt_generate_builtin_commands +# +# This function generates the builtin_commands.c src for qurt +# +# Usage: +# px4_qurt_generate_builtin_commands( +# MODULE_LIST +# OUT ) +# +# Input: +# MODULE_LIST : list of modules +# +# Output: +# OUT : stem of generated apps.cpp/apps.h ("apps"). +# +# Example: +# px4_qurt_generate_builtin_commands( +# OUT MODULE_LIST px4_simple_app) +# +function(px4_qurt_generate_builtin_commands) + px4_parse_function_args( + NAME px4_qurt_generate_builtin_commands + ONE_VALUE OUT + MULTI_VALUE MODULE_LIST + REQUIRED MODULE_LIST OUT + ARGN ${ARGN}) + + set(builtin_apps_string) + set(builtin_apps_decl_string) + set(command_count 0) + foreach(module ${MODULE_LIST}) + foreach(property MAIN STACK_MAIN PRIORITY) + get_target_property(${property} ${module} ${property}) + endforeach() + if (MAIN) + set(builtin_apps_string + "${builtin_apps_string}\tapps[\"${MAIN}\"] = ${MAIN}_main;\n") + set(builtin_apps_decl_string + "${builtin_apps_decl_string}int ${MAIN}_main(int argc, char *argv[]);\n") + math(EXPR command_count "${command_count}+1") + endif() + endforeach() + configure_file(${PX4_SOURCE_DIR}/platforms/common/apps.cpp.in ${OUT}.cpp) + configure_file(${PX4_SOURCE_DIR}/platforms/common/apps.h.in ${OUT}.h) +endfunction() + +#============================================================================= +# +# px4_os_add_flags +# +# Set the qurt build flags. +# +# Usage: +# px4_os_add_flags() +# +function(px4_os_add_flags) + + set(DSPAL_ROOT platforms/qurt/dspal) + include_directories( + ${DSPAL_ROOT}/include + ${DSPAL_ROOT}/sys + ${DSPAL_ROOT}/sys/sys + + platforms/posix/include + platforms/qurt/include + ) + + add_definitions( + -D__PX4_POSIX + -D__PX4_QURT + ) + + add_compile_options( + -fPIC + -fmath-errno + + -Wno-unknown-warning-option + -Wno-cast-align + ) + + # Clear -rdynamic flag which fails for hexagon + set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS) + set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) + +endfunction() + +#============================================================================= +# +# px4_os_determine_build_chip +# +# Sets PX4_CHIP and PX4_CHIP_MANUFACTURER. +# +# Usage: +# px4_os_determine_build_chip() +# +function(px4_os_determine_build_chip) + + # always use generic chip and chip manufacturer + set(PX4_CHIP "generic" CACHE STRING "PX4 Chip" FORCE) + set(PX4_CHIP_MANUFACTURER "generic" CACHE STRING "PX4 Chip Manufacturer" FORCE) + +endfunction() + +#============================================================================= +# +# px4_os_prebuild_targets +# +# This function generates os dependent targets +# +# Usage: +# px4_os_prebuild_targets( +# OUT +# BOARD +# ) +# +# Input: +# BOARD : board +# +# Output: +# OUT : the target list +# +# Example: +# px4_os_prebuild_targets(OUT target_list BOARD px4_fmu-v2) +# +function(px4_os_prebuild_targets) + px4_parse_function_args( + NAME px4_os_prebuild_targets + ONE_VALUE OUT BOARD + REQUIRED OUT + ARGN ${ARGN}) + + add_library(prebuild_targets INTERFACE) + add_dependencies(prebuild_targets DEPENDS uorb_headers) + +endfunction() diff --git a/platforms/qurt/cmake/qurt_reqs.cmake b/platforms/qurt/cmake/qurt_reqs.cmake new file mode 100644 index 0000000000..ce0670d003 --- /dev/null +++ b/platforms/qurt/cmake/qurt_reqs.cmake @@ -0,0 +1,222 @@ +############################################################################ +# +# Copyright (c) 2022 ModalAI, Inc. 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. +# +############################################################################ + +set(HEXAGON_SDK_INCLUDES + ${HEXAGON_SDK_ROOT}/incs + ${HEXAGON_SDK_ROOT}/incs/stddef + ${HEXAGON_SDK_ROOT}/rtos/qurt/computev66/include/qurt + # ${HEXAGON_SDK_ROOT}/rtos/qurt/computev66/include/posix + ${HEXAGON_SDK_ROOT}/tools/HEXAGON_Tools/8.4.05/Tools/target/hexagon/include + ) + +set(TOOLSLIB ${HEXAGON_TOOLS_ROOT}/target/hexagon/lib/${V_ARCH}/G0/pic) + +set(HEXAGON_ARCH_FLAGS + -march=hexagon + -mcpu=hexagon${V_ARCH} + ) + +macro (list2string out in) + set(list ${ARGV}) + list(REMOVE_ITEM list ${out}) + foreach(item ${list}) + set(${out} "${${out}} ${item}") + endforeach() +endmacro(list2string) + +set(HEXAGON_START_LINK_FLAGS) +list2string(HEXAGON_START_LINK_FLAGS + ${HEXAGON_ARCH_FLAGS} + -shared + -call_shared + -G0 + ${TOOLSLIB}/initS.o + "-o " + -L${TOOLSLIB} + -Bsymbolic + ${TOOLSLIB}/libgcc.a + --wrap=malloc + --wrap=calloc + --wrap=free + --wrap=realloc + --wrap=memalign + --wrap=__stack_chk_fail + -lc + "-soname=" + ) + +set(HEXAGON_END_LINK_FLAGS) +list2string(HEXAGON_END_LINK_FLAGS + --start-group + -lgcc + --end-group + ${TOOLSLIB}/finiS.o + ) + +set(CMAKE_C_CREATE_SHARED_LIBRARY + "${HEXAGON_LINK} ${HEXAGON_START_LINK_FLAGS} --start-group --whole-archive --end-group ${HEXAGON_END_LINK_FLAGS}") + +set(CMAKE_CXX_CREATE_SHARED_LIBRARY + "${HEXAGON_LINK} ${HEXAGON_START_LINK_FLAGS} --start-group ${TOOLSLIB}/libc++.so.1 ${TOOLSLIB}/libc++abi.so.1 ${HEXAGON_SDK_ROOT}/libs/weak_refs/ship/hexagon_toolv84/weak_refs.so --end-group --start-group --whole-archive --end-group ${HEXAGON_END_LINK_FLAGS}") + +set(DYNAMIC_LIBS -Wl,${TOOLSLIB}/libc++.a) + +# Base CPU flags for each of the supported architectures. +set(ARCHCPUFLAGS + -m${V_ARCH} + -G0 + ) + +add_definitions( + -D __QURT + -D _PROVIDE_POSIX_TIME_DECLS + -D _TIMER_T + -D _HAS_C9X + -D restrict=__restrict__ + -D noreturn_function= + ) + +# Language-specific flags +set(ARCHCFLAGS + -D__CUSTOM_FILE_IO__ + ) + +set(ARCHCXXFLAGS + -DCONFIG_WCHAR_BUILTIN + -D__CUSTOM_FILE_IO__ + ) + +exec_program(${CMAKE_CXX_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR} ARGS -print-libgcc-file-name OUTPUT_VARIABLE LIBGCC) +exec_program(${CMAKE_CXX_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR} ARGS -print-file-name=libm.a OUTPUT_VARIABLE LIBM) +set(EXTRA_LIBS ${EXTRA_LIBS} ${LIBM}) + +# Full optimization and Link Time Optimization (LTO) +set(QURT_OPTIMIZATION_FLAGS -O3 -flto) + +# Flags we pass to the C compiler +list2string(CFLAGS + ${ARCHCFLAGS} + ${ARCHCPUFLAGS} + ${QURT_OPTIMIZATION_FLAGS} + ${HEXAGON_INCLUDE_DIRS} + ) + +# Flags we pass to the C++ compiler +list2string(CXXFLAGS + -Wno-inconsistent-missing-override + ${ARCHCXXFLAGS} + ${ARCHCPUFLAGS} + ${QURT_OPTIMIZATION_FLAGS} + ${HEXAGON_INCLUDE_DIRS} + ) + +# Set cmake flags +list2string(QURT_CMAKE_C_FLAGS + ${CMAKE_C_FLAGS} + ${CFLAGS} + ) + +set(CMAKE_C_FLAGS "${QURT_CMAKE_C_FLAGS}") + +list2string(QURT_CMAKE_CXX_FLAGS + ${CMAKE_CXX_FLAGS} + ${CXXFLAGS} + ) + +set(CMAKE_CXX_FLAGS ${QURT_CMAKE_CXX_FLAGS}) + +# Flags we pass to the linker +# CMake make test builds of apps to validate the compiler +# These settings enable CMake to build the required test apps +list2string(CMAKE_EXE_LINKER_FLAGS + -m${V_ARCH} + -mG0lib + -G0 + -fpic + -shared + -Wl,-Bsymbolic + -Wl,--wrap=malloc + -Wl,--wrap=calloc + -Wl,--wrap=free + -Wl,--wrap=realloc + -Wl,--wrap=memalign + -Wl,--wrap=__stack_chk_fail + ${DYNAMIC_LIBS} + -lc + ${EXTRALDFLAGS} + ) + +include (CMakeParseArguments) + +# Process DSP files +function (QURT_LIB) + set(options) + set(oneValueArgs LIB_NAME) + set(multiValueArgs SOURCES LINK_LIBS INCS FLAGS) + cmake_parse_arguments(QURT_LIB "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) + + include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ) + + if ("${QURT_LIB_SOURCES}" STREQUAL "") + message(FATAL_ERROR "QURT_LIB called without SOURCES") + else() + # Build lib that is run on the DSP + add_library(${QURT_LIB_LIB_NAME} SHARED + ${QURT_LIB_SOURCES} + ) + + if (NOT "${QURT_LIB_FLAGS}" STREQUAL "") + set_target_properties(${QURT_LIB_LIB_NAME} PROPERTIES COMPILE_FLAGS "${QURT_LIB_FLAGS}") + endif() + + if (NOT "${QURT_LIB_INCS}" STREQUAL "") + target_include_directories(${QURT_LIB_LIB_NAME} PUBLIC ${QURT_LIB_INCS}) + endif() + + target_link_libraries(${QURT_LIB_LIB_NAME} + ${QURT_LIB_LINK_LIBS} + ) + endif() + + set(DSPLIB_TARGET_PATH "/usr/lib/rfsa/adsp/") + + # Add a rule to load the files onto the target that run in the DSP + add_custom_target(lib${QURT_LIB_LIB_NAME}-load + DEPENDS ${QURT_LIB_LIB_NAME} + COMMAND adb wait-for-device + COMMAND adb push lib${QURT_LIB_LIB_NAME}.so ${DSPLIB_TARGET_PATH} + COMMAND echo "Pushed lib${QURT_LIB_LIB_NAME}.so and dependencies to ${DSPLIB_TARGET_PATH}" + ) +endfunction() diff --git a/platforms/qurt/src/px4/CMakeLists.txt b/platforms/qurt/src/px4/CMakeLists.txt new file mode 100644 index 0000000000..ae7babf0b7 --- /dev/null +++ b/platforms/qurt/src/px4/CMakeLists.txt @@ -0,0 +1,34 @@ +############################################################################ +# +# Copyright (c) 2022 ModalAI, Inc. 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. +# +############################################################################ + +# Placeholder diff --git a/platforms/qurt/unresolved_symbols.c b/platforms/qurt/unresolved_symbols.c new file mode 100644 index 0000000000..5511c7879a --- /dev/null +++ b/platforms/qurt/unresolved_symbols.c @@ -0,0 +1,30 @@ + +#include + +void qurt_free(void *ptr); + +__attribute__((visibility("default"))) void free(void *ptr) +{ + qurt_free(ptr); + // ptr = 0; +} + +__attribute__((visibility("default"))) void *malloc(size_t size) +{ + return (void *) 0; +} + +__attribute__((visibility("default"))) void *calloc(size_t nmemb, size_t size) +{ + return (void *) 0; +} + +__attribute__((visibility("default"))) void *realloc(void *ptr, size_t size) +{ + return (void *) 0; +} + +__attribute__((visibility("default"))) int nanosleep(const struct timespec *req, struct timespec *rem) +{ + return -1; +} diff --git a/src/include/visibility.h b/src/include/visibility.h index 43a32d534d..bc38ffb8a1 100644 --- a/src/include/visibility.h +++ b/src/include/visibility.h @@ -91,11 +91,13 @@ /* We can't poison clock_settime/clock_gettime because they are * used in DriverFramework. */ -#if !defined(__PX4_NUTTX) +#if !defined(__PX4_NUTTX) && !defined(__PX4_QURT) #include // We can't include this for NuttX otherwise we get conflicts for read/write // symbols in cannode. -#endif // !defined(__PX4_NUTTX) +// We can't include this for Qurt because it uses it's own thread primitives +#endif // !defined(__PX4_NUTTX) && !defined(__PX4_QURT) +#define system_pthread_cond_timedwait pthread_cond_timedwait /* We can't poison pthread_cond_timedwait because it seems to be used in the * include. */ diff --git a/src/lib/parameters/CMakeLists.txt b/src/lib/parameters/CMakeLists.txt index 3777844df7..609e0a2b4f 100644 --- a/src/lib/parameters/CMakeLists.txt +++ b/src/lib/parameters/CMakeLists.txt @@ -82,6 +82,7 @@ endif() if(CONFIG_BOARD_IO) set(board_with_io_arg --board-with-io) endif() + add_custom_command(OUTPUT ${generated_serial_params_file} ${generated_module_params_file} COMMAND ${CMAKE_COMMAND} -E make_directory ${generated_params_dir} COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/serial/generate_config.py diff --git a/src/modules/muorb/Kconfig b/src/modules/muorb/Kconfig new file mode 100644 index 0000000000..22790832e9 --- /dev/null +++ b/src/modules/muorb/Kconfig @@ -0,0 +1,3 @@ +menu "MUORB" +rsource "*/Kconfig" +endmenu #MUORB diff --git a/src/modules/muorb/apps/CMakeLists.txt b/src/modules/muorb/apps/CMakeLists.txt new file mode 100644 index 0000000000..c6166b003e --- /dev/null +++ b/src/modules/muorb/apps/CMakeLists.txt @@ -0,0 +1,42 @@ +############################################################################ +# +# Copyright (c) 2022 ModalAI, Inc. 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. +# +############################################################################ + +px4_add_module( + MODULE modules__muorb__apps + MAIN muorb + COMPILE_FLAGS + -Wno-cast-align # TODO: fix and enable + SRCS + uORBAppsProtobufChannel.cpp + muorb_main.cpp + ) diff --git a/src/modules/muorb/apps/Kconfig b/src/modules/muorb/apps/Kconfig new file mode 100644 index 0000000000..05a94bec67 --- /dev/null +++ b/src/modules/muorb/apps/Kconfig @@ -0,0 +1,5 @@ +menuconfig MODULES_MUORB_APPS + bool "apps" + default n + ---help--- + Enable support for muorb apps diff --git a/src/modules/muorb/apps/fc_sensor.h b/src/modules/muorb/apps/fc_sensor.h new file mode 100644 index 0000000000..242a5a708b --- /dev/null +++ b/src/modules/muorb/apps/fc_sensor.h @@ -0,0 +1,69 @@ +/**************************************************************************** + * + * Copyright (C) 2022 ModalAI, Inc. 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. + * + ****************************************************************************/ + +#ifndef FC_SENSOR_H +#define FC_SENSOR_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +typedef void (*fc_receive_cb)(const char *topic, + const uint8_t *data, + uint32_t length_in_bytes); +typedef void (*fc_advertise_cb)(const char *topic); +typedef void (*fc_add_subscription_cb)(const char *topic); +typedef void (*fc_remove_subscription_cb)(const char *topic); + +typedef struct { + fc_receive_cb rx_callback; + fc_advertise_cb ad_callback; + fc_add_subscription_cb sub_callback; + fc_remove_subscription_cb remove_sub_callback; +} fc_callbacks; + +int fc_sensor_initialize(bool enable_debug_messages, fc_callbacks *callbacks); +int fc_sensor_advertise(const char *topic); +int fc_sensor_subscribe(const char *topic); +int fc_sensor_unsubscribe(const char *topic); +int fc_sensor_send_data(const char *topic, + const uint8_t *data, + uint32_t length_in_bytes); +#ifdef __cplusplus +} +#endif + +#endif // FC_SENSOR_H diff --git a/src/modules/muorb/apps/muorb_main.cpp b/src/modules/muorb/apps/muorb_main.cpp new file mode 100644 index 0000000000..cc5ce657a6 --- /dev/null +++ b/src/modules/muorb/apps/muorb_main.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** + * + * Copyright (c) 2022 ModalAI, Inc. 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. + * + ****************************************************************************/ + +#include +#include "uORBAppsProtobufChannel.hpp" + +extern "C" { __EXPORT int muorb_main(int argc, char *argv[]); } + +static void usage() +{ + PX4_INFO("Usage: muorb 'start', 'stop', 'status'"); +} + +static bool enable_debug = false; + +int +muorb_main(int argc, char *argv[]) +{ + if (argc < 2) { + usage(); + return -EINVAL; + } + + // TODO: Add an optional start parameter to control debug messages + if (!strcmp(argv[1], "start")) { + if (uORB::AppsProtobufChannel::isInstance()) { + PX4_WARN("muorb already started"); + + } else { + // Register the protobuf channel with UORB. + uORB::AppsProtobufChannel *channel = uORB::AppsProtobufChannel::GetInstance(); + + if (channel) { + if (channel->Initialize(enable_debug)) { + return OK; + } + } + } + + } else if (!strcmp(argv[1], "stop")) { + if (uORB::AppsProtobufChannel::isInstance() == false) { + PX4_WARN("muorb not running"); + } + + return OK; + + } else if (!strcmp(argv[1], "status")) { + if (uORB::AppsProtobufChannel::isInstance()) { + PX4_INFO("muorb initialized"); + + } else { + PX4_INFO("muorb not running"); + } + + return OK; + } + + usage(); + return -EINVAL; +} diff --git a/src/modules/muorb/apps/uORBAppsProtobufChannel.cpp b/src/modules/muorb/apps/uORBAppsProtobufChannel.cpp new file mode 100644 index 0000000000..8327e53c28 --- /dev/null +++ b/src/modules/muorb/apps/uORBAppsProtobufChannel.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** + * + * Copyright (C) 2022 ModalAI, Inc. 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. + * + ****************************************************************************/ + +#include "uORBAppsProtobufChannel.hpp" +#include + +#include "fc_sensor.h" + +// Initialize the static members +uORB::AppsProtobufChannel *uORB::AppsProtobufChannel::_InstancePtr = nullptr; + +void uORB::AppsProtobufChannel::ReceiveCallback(const char *topic, + const uint8_t *data, + uint32_t length_in_bytes) +{ + if (strcmp(topic, "slpi_debug") == 0) { + PX4_INFO("SLPI: %s", (const char *) data); + + } else if (strcmp(topic, "slpi_error") == 0) { + PX4_ERR("SLPI: %s", (const char *) data); + + } else { + PX4_INFO("Got received data callback for topic %s", topic); + } +} + +void uORB::AppsProtobufChannel::AdvertiseCallback(const char *topic) +{ + PX4_INFO("Got advertisement callback for topic %s", topic); +} + +void uORB::AppsProtobufChannel::SubscribeCallback(const char *topic) +{ + PX4_INFO("Got subscription callback for topic %s", topic); +} + +void uORB::AppsProtobufChannel::UnsubscribeCallback(const char *topic) +{ + PX4_INFO("Got remove subscription callback for topic %s", topic); +} + +bool uORB::AppsProtobufChannel::Initialize(bool enable_debug) +{ + fc_callbacks cb = {&ReceiveCallback, &AdvertiseCallback, + &SubscribeCallback, &UnsubscribeCallback + }; + + if (fc_sensor_initialize(enable_debug, &cb) != 0) { + PX4_ERR("Error calling the muorb protobuf initalize method"); + + } else { + PX4_INFO("muorb protobuf initalize method succeeded"); + } + + return true; +} diff --git a/src/modules/muorb/apps/uORBAppsProtobufChannel.hpp b/src/modules/muorb/apps/uORBAppsProtobufChannel.hpp new file mode 100644 index 0000000000..e93eb38783 --- /dev/null +++ b/src/modules/muorb/apps/uORBAppsProtobufChannel.hpp @@ -0,0 +1,87 @@ +/**************************************************************************** + * + * Copyright (C) 2022 ModalAI, Inc. 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. + * + ****************************************************************************/ + +#ifndef _uORBAppsProtobufChannel_hpp_ +#define _uORBAppsProtobufChannel_hpp_ + +#include +#include +#include + +namespace uORB +{ +class AppsProtobufChannel; +} + +class uORB::AppsProtobufChannel +{ +public: + /** + * static method to get the IChannel Implementor. + */ + static uORB::AppsProtobufChannel *GetInstance() + { + if (_InstancePtr == nullptr) { + _InstancePtr = new uORB::AppsProtobufChannel(); + } + + return _InstancePtr; + } + + /** + * Static method to check if there is an instance. + */ + static bool isInstance() + { + return (_InstancePtr != nullptr); + } + + bool Initialize(bool enable_debug); + +private: // data members + static uORB::AppsProtobufChannel *_InstancePtr; + +private://class members. + /// constructor. + AppsProtobufChannel() {}; + + static void ReceiveCallback(const char *topic, + const uint8_t *data, + uint32_t length_in_bytes); + static void AdvertiseCallback(const char *topic); + static void SubscribeCallback(const char *topic); + static void UnsubscribeCallback(const char *topic); + +}; + +#endif /* _uORBAppsProtobufChannel_hpp_ */ diff --git a/src/modules/muorb/slpi/CMakeLists.txt b/src/modules/muorb/slpi/CMakeLists.txt new file mode 100644 index 0000000000..951b273ec6 --- /dev/null +++ b/src/modules/muorb/slpi/CMakeLists.txt @@ -0,0 +1,37 @@ +############################################################################ +# +# Copyright (c) 2022 ModalAI, Inc. 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. +# +############################################################################ + +px4_add_library(modules__muorb__slpi + uORBProtobufChannel.cpp +) +#target_include_directories(modules__muorb__slpi PRIVATE ${PX4_SOURCE_DIR}/src/modules/uORB) diff --git a/src/modules/muorb/slpi/Kconfig b/src/modules/muorb/slpi/Kconfig new file mode 100644 index 0000000000..10ee5913b8 --- /dev/null +++ b/src/modules/muorb/slpi/Kconfig @@ -0,0 +1,5 @@ +menuconfig MODULES_MUORB_SLPI + bool "muorb_slpi" + default n + ---help--- + Enable support for muorb slpi diff --git a/src/modules/muorb/slpi/uORBProtobufChannel.cpp b/src/modules/muorb/slpi/uORBProtobufChannel.cpp new file mode 100644 index 0000000000..ed65ca1a82 --- /dev/null +++ b/src/modules/muorb/slpi/uORBProtobufChannel.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** + * + * Copyright (C) 2022 ModalAI, Inc. 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. + * + ****************************************************************************/ +#include "uORBProtobufChannel.hpp" + +// TODO: Move this out of here once we have it placed properly +extern "C" void HAP_debug(const char *msg, int level, const char *filename, int line); + +int px4muorb_orb_initialize(fc_func_ptrs *func_ptrs, int32_t clock_offset_us) +{ + HAP_debug("Hello, world!", 1, "test", 0); + + return 0; +} + +int px4muorb_topic_advertised(const char *topic_name) +{ + return 0; +} + +int px4muorb_add_subscriber(const char *topic_name) +{ + return 0; +} + +int px4muorb_remove_subscriber(const char *topic_name) +{ + return 0; +} + +int px4muorb_send_topic_data(const char *topic_name, const uint8_t *data, + int data_len_in_bytes) +{ + return 0; +} diff --git a/src/modules/muorb/slpi/uORBProtobufChannel.hpp b/src/modules/muorb/slpi/uORBProtobufChannel.hpp new file mode 100644 index 0000000000..104d478bf0 --- /dev/null +++ b/src/modules/muorb/slpi/uORBProtobufChannel.hpp @@ -0,0 +1,80 @@ +/**************************************************************************** + * + * Copyright (C) 2022 ModalAI, Inc. 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. + * + ****************************************************************************/ +#ifndef _uORBProtobufChannel_hpp_ +#define _uORBProtobufChannel_hpp_ + +#include +#include + +//#include + +// TODO: This has to be defined in the slpi_proc build and in the PX4 build. +// Make it accessible from one file to both builds. +typedef struct { + int (*advertise_func_ptr)(const char *topic_name); + int (*subscribe_func_ptr)(const char *topic_name); + int (*unsubscribe_func_ptr)(const char *topic_name); + int (*topic_data_func_ptr)(const char *name, const uint8_t *data, int data_len_in_bytes); + // device::SPI::_config_spi_bus_func_t config_spi_bus; + // device::SPI::_spi_transfer_func_t spi_transfer; + int (*_config_spi_bus_func_t)(); + int (*_spi_transfer_func_t)(int, const uint8_t *, uint8_t *, const unsigned); + // device::I2C::_config_i2c_bus_func_t config_i2c_bus; + // device::I2C::_set_i2c_address_func_t set_i2c_address; + // device::I2C::_i2c_transfer_func_t i2c_transfer; + int (*_config_i2c_bus_func_t)(uint8_t, uint8_t, uint32_t); + int (*_set_i2c_address_func_t)(int, uint8_t); + int (*_i2c_transfer_func_t)(int, const uint8_t *, const unsigned, uint8_t *, const unsigned); + // open_uart_func_t open_uart_func; + // write_uart_func_t write_uart_func; + // read_uart_func_t read_uart_func; + int (*open_uart_func_t)(uint8_t, uint32_t); + int (*write_uart_func_t)(int, const void *, size_t); + int (*read_uart_func_t)(int, void *, size_t); + int (*register_interrupt_callback)(int (*)(int, void *, void *), void *arg); +} fc_func_ptrs; + +extern "C" { + + int px4muorb_orb_initialize(fc_func_ptrs *func_ptrs, int32_t clock_offset_us) __EXPORT; + + int px4muorb_topic_advertised(const char *name) __EXPORT; + + int px4muorb_add_subscriber(const char *name) __EXPORT; + + int px4muorb_remove_subscriber(const char *name) __EXPORT; + + int px4muorb_send_topic_data(const char *name, const uint8_t *data, int data_len_in_bytes) __EXPORT; +} + +#endif /* _uORBProtobufChannel_hpp_ */