diff --git a/platforms/common/include/px4_platform_common/board_common.h b/platforms/common/include/px4_platform_common/board_common.h index b96379b2275..f93e18ecdc5 100644 --- a/platforms/common/include/px4_platform_common/board_common.h +++ b/platforms/common/include/px4_platform_common/board_common.h @@ -390,6 +390,7 @@ typedef enum PX4_SOC_ARCH_ID_t { PX4_SOC_ARCH_ID_NXPS32K146 = 0x0007, PX4_SOC_ARCH_ID_NXPS32K344 = 0x0008, PX4_SOC_ARCH_ID_NXPIMXRT1176 = 0x0009, + PX4_SOC_ARCH_ID_ERBIUM = 0x000A, PX4_SOC_ARCH_ID_EAGLE = 0x1001, PX4_SOC_ARCH_ID_QURT = 0x1002, diff --git a/platforms/nuttx/cmake/Platform/Generic-riscv-none-elf-gcc-rv64imfc.cmake b/platforms/nuttx/cmake/Platform/Generic-riscv-none-elf-gcc-rv64imfc.cmake new file mode 100644 index 00000000000..bb6c823bb02 --- /dev/null +++ b/platforms/nuttx/cmake/Platform/Generic-riscv-none-elf-gcc-rv64imfc.cmake @@ -0,0 +1,8 @@ + +# -mno-fdiv: AIFoundry ET-Minion (Erbium) has no hardware for FDIV.S and +# FSQRT.S; they raise an M-code emulation exception. +set(cpu_flags "-march=rv64imfc_zicsr_zifencei -mabi=lp64f -mcmodel=medany -mno-fdiv") + +set(CMAKE_C_FLAGS "${cpu_flags}" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS "${cpu_flags}" CACHE STRING "" FORCE) +set(CMAKE_ASM_FLAGS "${cpu_flags} -D__ASSEMBLY__" CACHE STRING "" FORCE) diff --git a/platforms/nuttx/cmake/Toolchain-riscv-none-elf.cmake b/platforms/nuttx/cmake/Toolchain-riscv-none-elf.cmake new file mode 100644 index 00000000000..27b80f9779e --- /dev/null +++ b/platforms/nuttx/cmake/Toolchain-riscv-none-elf.cmake @@ -0,0 +1,44 @@ +# riscv64-unknown-elf toolchain + +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_VERSION 1) + +set(triple riscv-none-elf) +set(CMAKE_LIBRARY_ARCHITECTURE ${triple}) +set(TOOLCHAIN_PREFIX ${triple}) + +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_C_COMPILER_TARGET ${triple}) + +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_CXX_COMPILER_TARGET ${triple}) + +set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}-gcc) + +# needed for test compilation +set(CMAKE_EXE_LINKER_FLAGS_INIT "--specs=nosys.specs") + +# compiler tools +find_program(CMAKE_AR ${TOOLCHAIN_PREFIX}-gcc-ar) +find_program(CMAKE_GDB ${TOOLCHAIN_PREFIX}-gdb) +find_program(CMAKE_LD ${TOOLCHAIN_PREFIX}-ld) +find_program(CMAKE_LINKER ${TOOLCHAIN_PREFIX}-ld) +find_program(CMAKE_NM ${TOOLCHAIN_PREFIX}-gcc-nm) +find_program(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}-objcopy) +find_program(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}-objdump) +find_program(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}-gcc-ranlib) +find_program(CMAKE_STRIP ${TOOLCHAIN_PREFIX}-strip) + +set(CMAKE_FIND_ROOT_PATH get_file_component(${CMAKE_C_COMPILER} PATH)) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +# os tools +foreach(tool grep make) + string(TOUPPER ${tool} TOOL) + find_program(${TOOL} ${tool}) + if(NOT ${TOOL}) + message(FATAL_ERROR "could not find ${tool}") + endif() +endforeach() diff --git a/platforms/nuttx/cmake/px4_impl_os.cmake b/platforms/nuttx/cmake/px4_impl_os.cmake index 77ee76aa54a..8acc69ee8c5 100644 --- a/platforms/nuttx/cmake/px4_impl_os.cmake +++ b/platforms/nuttx/cmake/px4_impl_os.cmake @@ -178,6 +178,9 @@ function(px4_os_determine_build_chip) elseif(CONFIG_ARCH_CHIP_ESP32) set(CHIP_MANUFACTURER "espressif") set(CHIP "esp32") + elseif(CONFIG_ARCH_CHIP_ERBIUM) + set(CHIP_MANUFACTURER "aifoundry") + set(CHIP "erbium") else() message(FATAL_ERROR "Could not determine chip architecture from NuttX config. You may have to add it.") endif() diff --git a/platforms/nuttx/src/px4/aifoundry/CMakeLists.txt b/platforms/nuttx/src/px4/aifoundry/CMakeLists.txt new file mode 100644 index 00000000000..867e1cc5361 --- /dev/null +++ b/platforms/nuttx/src/px4/aifoundry/CMakeLists.txt @@ -0,0 +1,34 @@ +############################################################################ +# +# Copyright (c) 2026 PX4 Development Team. 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_subdirectory(${PX4_CHIP}) diff --git a/platforms/nuttx/src/px4/aifoundry/erbium/CMakeLists.txt b/platforms/nuttx/src/px4/aifoundry/erbium/CMakeLists.txt new file mode 100644 index 00000000000..a3e69d5d28a --- /dev/null +++ b/platforms/nuttx/src/px4/aifoundry/erbium/CMakeLists.txt @@ -0,0 +1,37 @@ +############################################################################ +# +# Copyright (c) 2026 PX4 Development Team. 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_subdirectory(board_critmon) +add_subdirectory(board_reset) +add_subdirectory(hrt) +add_subdirectory(version) diff --git a/platforms/nuttx/src/px4/aifoundry/erbium/board_critmon/CMakeLists.txt b/platforms/nuttx/src/px4/aifoundry/erbium/board_critmon/CMakeLists.txt new file mode 100644 index 00000000000..c39cf56c2c0 --- /dev/null +++ b/platforms/nuttx/src/px4/aifoundry/erbium/board_critmon/CMakeLists.txt @@ -0,0 +1,36 @@ +############################################################################ +# +# Copyright (c) 2026 PX4 Development Team. 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(arch_board_critmon + board_critmon.c +) diff --git a/platforms/nuttx/src/px4/aifoundry/erbium/board_critmon/board_critmon.c b/platforms/nuttx/src/px4/aifoundry/erbium/board_critmon/board_critmon.c new file mode 100644 index 00000000000..d748fd2da48 --- /dev/null +++ b/platforms/nuttx/src/px4/aifoundry/erbium/board_critmon/board_critmon.c @@ -0,0 +1,59 @@ +/**************************************************************************** + * + * Copyright (c) 2026 PX4 Development Team. 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_critmon.c + * + * Critical section and IRQ monitor time base: the HRT in microseconds. + */ + +#include + +#if defined(CONFIG_SCHED_CRITMONITOR) || defined(CONFIG_SCHED_IRQMONITOR) + +#include +#include +#include + +uint32_t up_critmon_gettime(void) +{ + return (uint32_t)hrt_absolute_time(); +} + +void up_critmon_convert(uint32_t elapsed, FAR struct timespec *ts) +{ + ts->tv_sec = elapsed / 1000000; + ts->tv_nsec = (elapsed % 1000000) * 1000; +} + +#endif /* CONFIG_SCHED_CRITMONITOR || CONFIG_SCHED_IRQMONITOR */ diff --git a/platforms/nuttx/src/px4/aifoundry/erbium/board_reset/CMakeLists.txt b/platforms/nuttx/src/px4/aifoundry/erbium/board_reset/CMakeLists.txt new file mode 100644 index 00000000000..c70dd01cbcc --- /dev/null +++ b/platforms/nuttx/src/px4/aifoundry/erbium/board_reset/CMakeLists.txt @@ -0,0 +1,38 @@ +############################################################################ +# +# Copyright (c) 2026 PX4 Development Team. 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(arch_board_reset + board_reset.c +) + +target_link_libraries(arch_board_reset PRIVATE nuttx_arch) diff --git a/platforms/nuttx/src/px4/aifoundry/erbium/board_reset/board_reset.c b/platforms/nuttx/src/px4/aifoundry/erbium/board_reset/board_reset.c new file mode 100644 index 00000000000..8662ff2fa6f --- /dev/null +++ b/platforms/nuttx/src/px4/aifoundry/erbium/board_reset/board_reset.c @@ -0,0 +1,65 @@ +/**************************************************************************** + * + * Copyright (c) 2026 PX4 Development Team. 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_reset.c + * + * Board reset for the AIFoundry Erbium Minion, through the system soft + * reset bit of the system registers. + */ + +#include + +#include + +#include + +#include "hardware/erbium_memorymap.h" + +#define ERBIUM_SYSREG_SOFT_RESET (ERBIUM_SYSREG_BASE + 0x28) +#define ERBIUM_SYSREG_SOFT_RESET_SYSTEM (1u << 0) + +#ifdef CONFIG_BOARDCTL_RESET +int board_reset(int status) +{ + (void)status; + + *(volatile uint32_t *)ERBIUM_SYSREG_SOFT_RESET = ERBIUM_SYSREG_SOFT_RESET_SYSTEM; + + for (;;) { + __asm__ __volatile__("wfi"); + } + + return 0; +} +#endif /* CONFIG_BOARDCTL_RESET */ diff --git a/platforms/nuttx/src/px4/aifoundry/erbium/hrt/CMakeLists.txt b/platforms/nuttx/src/px4/aifoundry/erbium/hrt/CMakeLists.txt new file mode 100644 index 00000000000..d18904cc49f --- /dev/null +++ b/platforms/nuttx/src/px4/aifoundry/erbium/hrt/CMakeLists.txt @@ -0,0 +1,36 @@ +############################################################################ +# +# Copyright (c) 2026 PX4 Development Team. 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(arch_hrt + hrt.c +) diff --git a/platforms/nuttx/src/px4/aifoundry/erbium/hrt/hrt.c b/platforms/nuttx/src/px4/aifoundry/erbium/hrt/hrt.c new file mode 100644 index 00000000000..81a937a8a61 --- /dev/null +++ b/platforms/nuttx/src/px4/aifoundry/erbium/hrt/hrt.c @@ -0,0 +1,252 @@ +/**************************************************************************** + * + * Copyright (c) 2026 PX4 Development Team. 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 hrt.c + * + * High-resolution timer for the AIFoundry Erbium Minion. + * + * hrt_absolute_time() reads the machine timer (mtime) directly. Callouts + * run in a high-priority task instead of an interrupt handler: the NuttX + * RISC-V trap path does not save the floating-point registers, so callouts, + * which may use floating point, must not run in interrupt context. The + * task wakes at least once per millisecond, which bounds callout latency. + */ + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include "hardware/erbium_memorymap.h" + +#if (CONFIG_ERBIUM_MTIMER_FREQ % 1000000) != 0 +# error "CONFIG_ERBIUM_MTIMER_FREQ must be a multiple of 1 MHz" +#endif + +#define HRT_MTIME_TICKS_PER_US (CONFIG_ERBIUM_MTIMER_FREQ / 1000000) +#define HRT_TASK_STACKSIZE 1536 +#define HRT_MAX_SLEEP_US 1000 + +static struct sq_queue_s callout_queue; +static bool hrt_initialized; + +const uint16_t latency_bucket_count = LATENCY_BUCKET_COUNT; +const uint16_t latency_buckets[LATENCY_BUCKET_COUNT] = {1, 2, 5, 10, 20, 50, 100, 1000}; +__EXPORT uint32_t latency_counters[LATENCY_BUCKET_COUNT + 1]; + +static void hrt_call_enter(struct hrt_call *entry); +static void hrt_call_invoke(void); + +hrt_abstime hrt_absolute_time(void) +{ + return *(volatile uint64_t *)ERBIUM_MTIME_BASE / HRT_MTIME_TICKS_PER_US; +} + +void hrt_store_absolute_time(volatile hrt_abstime *time) +{ + irqstate_t flags = px4_enter_critical_section(); + *time = hrt_absolute_time(); + px4_leave_critical_section(flags); +} + +static int hrt_task(int argc, char *argv[]) +{ + for (;;) { + hrt_call_invoke(); + + irqstate_t flags = px4_enter_critical_section(); + struct hrt_call *next = (struct hrt_call *)sq_peek(&callout_queue); + hrt_abstime now = hrt_absolute_time(); + hrt_abstime delay = HRT_MAX_SLEEP_US; + + if (next != NULL && next->deadline > now && next->deadline - now < delay) { + delay = next->deadline - now; + + } else if (next != NULL && next->deadline <= now) { + delay = 0; + } + + px4_leave_critical_section(flags); + + if (delay > 0) { + usleep(delay); + } + } + + return 0; +} + +void hrt_init(void) +{ + if (hrt_initialized) { + return; + } + + sq_init(&callout_queue); + hrt_initialized = true; + + if (task_create("hrt", SCHED_PRIORITY_MAX, HRT_TASK_STACKSIZE, hrt_task, NULL) < 0) { + PANIC(); + } +} + +void hrt_call_after(struct hrt_call *entry, hrt_abstime delay, hrt_callout callout, void *arg) +{ + hrt_call_every(entry, delay, 0, callout, arg); +} + +void hrt_call_at(struct hrt_call *entry, hrt_abstime calltime, hrt_callout callout, void *arg) +{ + irqstate_t flags = px4_enter_critical_section(); + + sq_rem(&entry->link, &callout_queue); + entry->deadline = calltime; + entry->period = 0; + entry->callout = callout; + entry->arg = arg; + hrt_call_enter(entry); + + px4_leave_critical_section(flags); +} + +void hrt_call_every(struct hrt_call *entry, hrt_abstime delay, hrt_abstime interval, + hrt_callout callout, void *arg) +{ + irqstate_t flags = px4_enter_critical_section(); + + sq_rem(&entry->link, &callout_queue); + entry->deadline = hrt_absolute_time() + delay; + entry->period = interval; + entry->callout = callout; + entry->arg = arg; + hrt_call_enter(entry); + + px4_leave_critical_section(flags); +} + +bool hrt_called(struct hrt_call *entry) +{ + return entry->deadline == 0; +} + +void hrt_cancel(struct hrt_call *entry) +{ + irqstate_t flags = px4_enter_critical_section(); + + sq_rem(&entry->link, &callout_queue); + entry->deadline = 0; + entry->period = 0; + + px4_leave_critical_section(flags); +} + +void hrt_call_init(struct hrt_call *entry) +{ + memset(entry, 0, sizeof(*entry)); +} + +void hrt_call_delay(struct hrt_call *entry, hrt_abstime delay) +{ + entry->deadline = hrt_absolute_time() + delay; +} + +/* Insert an entry in deadline order. Called with the critical section held. */ + +static void hrt_call_enter(struct hrt_call *entry) +{ + struct hrt_call *call = (struct hrt_call *)sq_peek(&callout_queue); + + if (call == NULL || entry->deadline < call->deadline) { + sq_addfirst(&entry->link, &callout_queue); + return; + } + + struct hrt_call *next; + + while ((next = (struct hrt_call *)sq_next(&call->link)) != NULL && + next->deadline <= entry->deadline) { + call = next; + } + + sq_addafter(&call->link, &entry->link, &callout_queue); +} + +static void hrt_call_invoke(void) +{ + for (;;) { + irqstate_t flags = px4_enter_critical_section(); + struct hrt_call *call = (struct hrt_call *)sq_peek(&callout_queue); + hrt_abstime now = hrt_absolute_time(); + + if (call == NULL || call->deadline > now) { + px4_leave_critical_section(flags); + return; + } + + sq_rem(&call->link, &callout_queue); + hrt_abstime deadline = call->deadline; + call->deadline = 0; + hrt_callout callout = call->callout; + void *arg = call->arg; + + px4_leave_critical_section(flags); + + if (callout != NULL) { + callout(arg); + } + + flags = px4_enter_critical_section(); + + /* Re-arm a periodic call unless the callout rescheduled it */ + + if (call->period != 0 && call->deadline == 0) { + call->deadline = deadline + call->period; + + if (call->deadline <= now) { + call->deadline = now + call->period; + } + + hrt_call_enter(call); + } + + px4_leave_critical_section(flags); + } +} diff --git a/platforms/nuttx/src/px4/aifoundry/erbium/include/px4_arch/micro_hal.h b/platforms/nuttx/src/px4/aifoundry/erbium/include/px4_arch/micro_hal.h new file mode 100644 index 00000000000..e715200263a --- /dev/null +++ b/platforms/nuttx/src/px4/aifoundry/erbium/include/px4_arch/micro_hal.h @@ -0,0 +1,84 @@ +/**************************************************************************** + * + * Copyright (c) 2026 PX4 Development Team. 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 + +#include + +#include + +#include +#include +#include + +__BEGIN_DECLS + +#define PX4_SOC_ARCH_ID PX4_SOC_ARCH_ID_ERBIUM +#define PX4_FLASH_BASE 0x40000000 +#define PX4_NUMBER_I2C_BUSES 1 +#define PX4_BUS_OFFSET 0 + +/* Erbium has no battery-backed SRAM */ + +#define PX4_BBSRAM_SIZE 2048 +#define PX4_HF_GETDESC_IOCTL 0 + +/* Erbium has no unique-ID register; board_identity.c returns a fixed ID */ + +#define PX4_CPU_UUID_BYTE_LENGTH 12 +#define PX4_CPU_UUID_WORD32_LENGTH (PX4_CPU_UUID_BYTE_LENGTH/sizeof(uint32_t)) +#define PX4_CPU_MFGUID_BYTE_LENGTH PX4_CPU_UUID_BYTE_LENGTH + +#define PX4_CPU_UUID_WORD32_UNIQUE_H 2 +#define PX4_CPU_UUID_WORD32_UNIQUE_M 1 +#define PX4_CPU_UUID_WORD32_UNIQUE_L 0 + +#define PX4_CPU_UUID_WORD32_FORMAT_SIZE (PX4_CPU_UUID_WORD32_LENGTH-1+(2*PX4_CPU_UUID_BYTE_LENGTH)+1) +#define PX4_CPU_MFGUID_FORMAT_SIZE ((2*PX4_CPU_MFGUID_BYTE_LENGTH)+1) + +/* No GPIO driver yet */ + +static inline int px4_arch_configgpio(uint32_t pinset) { (void)pinset; return 0; } +static inline int px4_arch_unconfiggpio(uint32_t pinset) { (void)pinset; return 0; } +static inline bool px4_arch_gpioread(uint32_t pinset) { (void)pinset; return false; } +static inline void px4_arch_gpiowrite(uint32_t pinset, bool value) { (void)pinset; (void)value; } +static inline int px4_arch_gpiosetevent(uint32_t pinset, bool r, bool f, bool e, xcpt_t func, void *arg) +{ + (void)pinset; (void)r; (void)f; (void)e; (void)func; (void)arg; + return 0; +} + +#define px4_cache_aligned_data() +#define px4_cache_aligned_alloc malloc + +__END_DECLS diff --git a/platforms/nuttx/src/px4/aifoundry/erbium/version/CMakeLists.txt b/platforms/nuttx/src/px4/aifoundry/erbium/version/CMakeLists.txt new file mode 100644 index 00000000000..e19f3e50393 --- /dev/null +++ b/platforms/nuttx/src/px4/aifoundry/erbium/version/CMakeLists.txt @@ -0,0 +1,37 @@ +############################################################################ +# +# Copyright (c) 2026 PX4 Development Team. 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(arch_version + board_identity.c + board_mcu_version.c +) diff --git a/platforms/nuttx/src/px4/aifoundry/erbium/version/board_identity.c b/platforms/nuttx/src/px4/aifoundry/erbium/version/board_identity.c new file mode 100644 index 00000000000..0661cbbfeb4 --- /dev/null +++ b/platforms/nuttx/src/px4/aifoundry/erbium/version/board_identity.c @@ -0,0 +1,147 @@ +/** + * @file board_identity.c + * Implementation of the Erbium board identity API + * Implementation of the Erbium board identity API + */ + +#include +#include +#include + +/* Erbium has no unique-ID register. All Erbium boards report the fixed + * 12-byte ID "ERBIUMMINION" until an ID from OTP is used. + */ + +static const uint32_t erbium_uuid[3] = { + 'E' << 0 | 'R' << 8 | 'B' << 16 | 'I' << 24, + 'U' << 0 | 'M' << 8 | 'M' << 16 | 'I' << 24, + 'N' << 0 | 'I' << 8 | 'O' << 16 | 'N' << 24 +}; + +#define CPU_UUID_BYTE_FORMAT_ORDER {3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8} +#define SWAP_UINT32(x) (((x) >> 24) | (((x) & 0x00ff0000) >> 8) | (((x) & 0x0000ff00) << 8) | ((x) << 24)) + +static const uint16_t soc_arch_id = PX4_SOC_ARCH_ID; + +/* A type suitable for holding the reordering array for the byte format of the UUID + */ + +typedef const uint8_t uuid_uint8_reorder_t[PX4_CPU_UUID_BYTE_LENGTH]; + + +void board_get_uuid(uuid_byte_t uuid_bytes) +{ + uuid_uint8_reorder_t reorder = CPU_UUID_BYTE_FORMAT_ORDER; + union { + uuid_byte_t b; + uuid_uint32_t w; + } id; + + /* Copy the serial from the chips non-write memory */ + + board_get_uuid32(id.w); + + /* swap endianess */ + + for (int i = 0; i < PX4_CPU_UUID_BYTE_LENGTH; i++) { + uuid_bytes[i] = id.b[reorder[i]]; + } +} + +__EXPORT void board_get_uuid32(uuid_uint32_t uuid_words) +{ + const uint32_t *chip_uuid = erbium_uuid; + + for (unsigned i = 0; i < PX4_CPU_UUID_WORD32_LENGTH; i++) { + uuid_words[i] = chip_uuid[i]; + } +} + +int board_get_uuid32_formated(char *format_buffer, int size, + const char *format, + const char *seperator) +{ + uuid_uint32_t uuid; + board_get_uuid32(uuid); + int offset = 0; + int sep_size = seperator ? strlen(seperator) : 0; + + for (unsigned i = 0; (offset < size - 1) && (i < PX4_CPU_UUID_WORD32_LENGTH); i++) { + offset += snprintf(&format_buffer[offset], size - offset, format, uuid[i]); + + if (sep_size && (offset < size - sep_size - 1) && (i < PX4_CPU_UUID_WORD32_LENGTH - 1)) { + strncat(&format_buffer[offset], seperator, size - offset); + offset += sep_size; + } + } + + return 0; +} + +int board_get_mfguid(mfguid_t mfgid) +{ + const uint32_t *chip_uuid = erbium_uuid; + uint8_t *rv = &mfgid[0]; + + for (unsigned i = 0; i < PX4_CPU_UUID_WORD32_LENGTH; i++) { + uint32_t uuid_bytes = SWAP_UINT32(chip_uuid[(PX4_CPU_UUID_WORD32_LENGTH - 1) - i]); + memcpy(rv, &uuid_bytes, sizeof(uint32_t)); + rv += sizeof(uint32_t); + } + + return PX4_CPU_MFGUID_BYTE_LENGTH; +} + +int board_get_mfguid_formated(char *format_buffer, int size) +{ + mfguid_t mfguid; + + board_get_mfguid(mfguid); + int offset = 0; + + for (unsigned i = 0; offset < size && i < PX4_CPU_MFGUID_BYTE_LENGTH; i++) { + offset += snprintf(&format_buffer[offset], size - offset, "%02x", mfguid[i]); + } + + return offset; +} + +int board_get_px4_guid(px4_guid_t px4_guid) +{ + uint8_t *pb = (uint8_t *) &px4_guid[0]; + *pb++ = (soc_arch_id >> 8) & 0xff; + *pb++ = (soc_arch_id & 0xff); + + for (unsigned i = 0; i < PX4_GUID_BYTE_LENGTH - (sizeof(soc_arch_id) + PX4_CPU_UUID_BYTE_LENGTH); i++) { + *pb++ = 0; + } + + const uint32_t *chip_uuid = erbium_uuid; + + for (unsigned i = 0; i < PX4_CPU_UUID_WORD32_LENGTH; i++) { + uint32_t uuid_bytes = SWAP_UINT32(chip_uuid[(PX4_CPU_UUID_WORD32_LENGTH - 1) - i]); + memcpy(pb, &uuid_bytes, sizeof(uint32_t)); + pb += sizeof(uint32_t); + } + + return PX4_GUID_BYTE_LENGTH; +} + +int board_get_px4_guid_formated(char *format_buffer, int size) +{ + px4_guid_t px4_guid; + board_get_px4_guid(px4_guid); + int offset = 0; + + /* size should be 2 per byte + 1 for termination + * So it needs to be odd + */ + size = size & 1 ? size : size - 1; + + /* Discard from MSD */ + for (unsigned i = PX4_GUID_BYTE_LENGTH - size / 2; offset < size && i < PX4_GUID_BYTE_LENGTH; i++) { + offset += snprintf(&format_buffer[offset], size - offset, "%02x", px4_guid[i]); + } + + return offset; +} diff --git a/platforms/nuttx/src/px4/aifoundry/erbium/version/board_mcu_version.c b/platforms/nuttx/src/px4/aifoundry/erbium/version/board_mcu_version.c new file mode 100644 index 00000000000..8c22f8be3b7 --- /dev/null +++ b/platforms/nuttx/src/px4/aifoundry/erbium/version/board_mcu_version.c @@ -0,0 +1,50 @@ +/**************************************************************************** + * + * Copyright (c) 2026 PX4 Development Team. 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_mcu_version.c + */ + +#include + +int board_mcu_version(char *rev, const char **revstr, const char **errata) +{ + *rev = '0'; + *revstr = "Erbium Minion"; + + if (errata != NULL) { + *errata = NULL; + } + + return 0; +}