From b73ccfcc9251e39a06533cea58cfe77fab4bf669 Mon Sep 17 00:00:00 2001 From: Stephan Linz Date: Tue, 21 Nov 2023 11:54:00 +0100 Subject: [PATCH 1/3] zephyr: convert to new C header prefix since v3.1 All Zephyr public headers have been moved to `include/zephyr`, meaning they need to be prefixed with `` when included. Signed-off-by: Stephan Linz --- .../debug_utils/src/arch/arm/u_sections_zephyr.h | 8 +++++++- .../debug_utils/src/zephyr/u_dump_threads.c | 9 ++++++++- port/platform/zephyr/CMakeLists.txt | 2 +- port/platform/zephyr/app/u_main.c | 8 +++++++- .../zephyr/cfg/u_cfg_app_platform_specific.h | 14 +++++++++----- .../zephyr/cfg/u_cfg_test_platform_specific.h | 8 ++++++-- port/platform/zephyr/src/u_port.c | 9 ++++++++- port/platform/zephyr/src/u_port_clib.c | 9 ++++++++- port/platform/zephyr/src/u_port_debug.c | 8 +++++++- port/platform/zephyr/src/u_port_gatt.c | 16 +++++++++++++++- port/platform/zephyr/src/u_port_gpio.c | 15 +++++++++++---- port/platform/zephyr/src/u_port_i2c.c | 12 ++++++++++-- port/platform/zephyr/src/u_port_os.c | 9 ++++++++- port/platform/zephyr/src/u_port_private.c | 15 +++++++++++---- port/platform/zephyr/src/u_port_spi.c | 14 ++++++++++++-- port/platform/zephyr/src/u_port_uart.c | 12 ++++++++++-- port/test/u_port_test.c | 9 +++++++-- zephyr/test/u_main.c | 8 +++++++- 18 files changed, 152 insertions(+), 33 deletions(-) diff --git a/port/platform/common/debug_utils/src/arch/arm/u_sections_zephyr.h b/port/platform/common/debug_utils/src/arch/arm/u_sections_zephyr.h index 572b115b5..7acd89833 100644 --- a/port/platform/common/debug_utils/src/arch/arm/u_sections_zephyr.h +++ b/port/platform/common/debug_utils/src/arch/arm/u_sections_zephyr.h @@ -17,8 +17,14 @@ #ifndef _U_SECTIONS_ZEPHYR_H_ #define _U_SECTIONS_ZEPHYR_H_ +#include + /* No other #includes allowed here. */ -#include "linker/linker-defs.h" +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#else +#include +#endif /** @file * @brief This file is internally used to map Zephyr linker sections. diff --git a/port/platform/common/debug_utils/src/zephyr/u_dump_threads.c b/port/platform/common/debug_utils/src/zephyr/u_dump_threads.c index 271ec4bd3..3fc96e291 100644 --- a/port/platform/common/debug_utils/src/zephyr/u_dump_threads.c +++ b/port/platform/common/debug_utils/src/zephyr/u_dump_threads.c @@ -17,7 +17,14 @@ /** @file * @brief Thread dumper for Zephyr. */ -#include "kernel.h" + +#include + +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#else +#include +#endif /* ---------------------------------------------------------------- * COMPILE-TIME MACROS diff --git a/port/platform/zephyr/CMakeLists.txt b/port/platform/zephyr/CMakeLists.txt index a35a1ced6..335a22683 100644 --- a/port/platform/zephyr/CMakeLists.txt +++ b/port/platform/zephyr/CMakeLists.txt @@ -78,7 +78,7 @@ zephyr_include_directories( cfg src ${UBXLIB_BASE}/port/clib - ${ZEPHYR_BASE}/include/zephyr + ${ZEPHYR_BASE}/include ) # Add any compile options that came out of ubxlib.cmake diff --git a/port/platform/zephyr/app/u_main.c b/port/platform/zephyr/app/u_main.c index e46028f3a..b1fa265b7 100644 --- a/port/platform/zephyr/app/u_main.c +++ b/port/platform/zephyr/app/u_main.c @@ -42,7 +42,13 @@ #include "u_port_debug.h" #include "u_port_os.h" -#include "kernel.h" +#include + +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#else +#include +#endif #ifdef CONFIG_ARCH_POSIX #include "posix_board_if.h" diff --git a/port/platform/zephyr/cfg/u_cfg_app_platform_specific.h b/port/platform/zephyr/cfg/u_cfg_app_platform_specific.h index ce69216e6..cf6cd18c7 100644 --- a/port/platform/zephyr/cfg/u_cfg_app_platform_specific.h +++ b/port/platform/zephyr/cfg/u_cfg_app_platform_specific.h @@ -17,14 +17,18 @@ #ifndef _U_CFG_APP_PLATFORM_SPECIFIC_H_ #define _U_CFG_APP_PLATFORM_SPECIFIC_H_ -/* This inclusion is required to get the UART CTS/RTS pin assignments - * from the Zephyr device tree. +/* This inclusion is required to get the Zephyr version. */ -#include "devicetree.h" +#include -/* This inclusion is required to get the Zephyr version. +/* This inclusion is required to get the UART CTS/RTS pin assignments + * from the Zephyr device tree. */ -#include "version.h" +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#else +#include +#endif /** @file * @brief This header file contains configuration information for diff --git a/port/platform/zephyr/cfg/u_cfg_test_platform_specific.h b/port/platform/zephyr/cfg/u_cfg_test_platform_specific.h index acc425194..9250e59fd 100644 --- a/port/platform/zephyr/cfg/u_cfg_test_platform_specific.h +++ b/port/platform/zephyr/cfg/u_cfg_test_platform_specific.h @@ -26,10 +26,14 @@ * for the module is likely different to that from the MCU: check the * data sheet for the module to determine the mapping. */ -#include "devicetree.h" +#include // For KERNEL_VERSION_MAJOR +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#else +#include +#endif #include "u_runner.h" #include "u_port_clib_platform_specific.h" // For rand -#include "version.h" // For KERNEL_VERSION_MAJOR /** @file * @brief Porting layer and configuration items passed in at application diff --git a/port/platform/zephyr/src/u_port.c b/port/platform/zephyr/src/u_port.c index d23b6065b..0e3d38d04 100644 --- a/port/platform/zephyr/src/u_port.c +++ b/port/platform/zephyr/src/u_port.c @@ -42,8 +42,15 @@ #include "u_port_event_queue_private.h" #include "u_port_private.h" -#include "kernel.h" +#include + +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#include +#else +#include #include +#endif /* ---------------------------------------------------------------- * COMPILE-TIME MACROS diff --git a/port/platform/zephyr/src/u_port_clib.c b/port/platform/zephyr/src/u_port_clib.c index bd184c71d..e9be938c5 100644 --- a/port/platform/zephyr/src/u_port_clib.c +++ b/port/platform/zephyr/src/u_port_clib.c @@ -24,7 +24,14 @@ # include "u_cfg_override.h" // For a customer's configuration override #endif -#include "random/rand32.h" +#include + +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#else +#include +#endif + #include "string.h" #include "u_assert.h" diff --git a/port/platform/zephyr/src/u_port_debug.c b/port/platform/zephyr/src/u_port_debug.c index 18954c839..a505d7d3a 100644 --- a/port/platform/zephyr/src/u_port_debug.c +++ b/port/platform/zephyr/src/u_port_debug.c @@ -33,7 +33,13 @@ #include "u_error_common.h" -#include "sys/printk.h" +#include + +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#else +#include +#endif /* ---------------------------------------------------------------- * COMPILE-TIME MACROS diff --git a/port/platform/zephyr/src/u_port_gatt.c b/port/platform/zephyr/src/u_port_gatt.c index 219c476c3..26fbc3bdb 100644 --- a/port/platform/zephyr/src/u_port_gatt.c +++ b/port/platform/zephyr/src/u_port_gatt.c @@ -24,10 +24,18 @@ #ifdef CONFIG_BT +#include + +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#include +#include +#else #include #include - #include +#endif + #include #include "stddef.h" // NULL, size_t etc. @@ -44,9 +52,15 @@ #include "u_port_os.h" #include "u_port_event_queue.h" +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#include +#include +#else #include #include #include +#endif #include "string.h" // For memcpy() diff --git a/port/platform/zephyr/src/u_port_gpio.c b/port/platform/zephyr/src/u_port_gpio.c index 7070cf7bf..3539dddd7 100644 --- a/port/platform/zephyr/src/u_port_gpio.c +++ b/port/platform/zephyr/src/u_port_gpio.c @@ -31,10 +31,17 @@ #include "u_port_os.h" // Needed by u_port_private.h #include "u_port_gpio.h" -#include "kernel.h" -#include "device.h" -#include "drivers/gpio.h" -#include "version.h" +#include + +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#include +#include +#else +#include +#include +#include +#endif #include "u_port_private.h" // Down here because it needs to know about the Zephyr device tree diff --git a/port/platform/zephyr/src/u_port_i2c.c b/port/platform/zephyr/src/u_port_i2c.c index b3b4c60ee..b7bad6805 100644 --- a/port/platform/zephyr/src/u_port_i2c.c +++ b/port/platform/zephyr/src/u_port_i2c.c @@ -18,11 +18,20 @@ * @brief Implementation of the port I2C API for the Zephyr platform. */ +#include + +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#include +#include +#include +#else #include #include +#include #include +#endif -#include #include #include "stddef.h" @@ -37,7 +46,6 @@ #include "u_port_os.h" #include "u_cfg_os_platform_specific.h" #include "u_port_i2c.h" -#include "version.h" /* ---------------------------------------------------------------- * COMPILE-TIME MACROS diff --git a/port/platform/zephyr/src/u_port_os.c b/port/platform/zephyr/src/u_port_os.c index 7407ef761..90557d535 100644 --- a/port/platform/zephyr/src/u_port_os.c +++ b/port/platform/zephyr/src/u_port_os.c @@ -75,8 +75,15 @@ #include "u_port.h" #include "u_port_os.h" +#include + +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#include +#else #include -#include "device.h" +#include +#endif #include "u_port_private.h" // Down here because it needs to know about the Zephyr device tree diff --git a/port/platform/zephyr/src/u_port_private.c b/port/platform/zephyr/src/u_port_private.c index 98448fba3..3206d9ab8 100644 --- a/port/platform/zephyr/src/u_port_private.c +++ b/port/platform/zephyr/src/u_port_private.c @@ -33,10 +33,17 @@ #include "u_port_heap.h" #include "u_port_event_queue.h" -#include "kernel.h" -#include "device.h" -#include "drivers/gpio.h" -#include "version.h" +#include + +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#include +#include +#else +#include +#include +#include +#endif #include "u_port_private.h" // Down here because it needs to know about the Zephyr device tree diff --git a/port/platform/zephyr/src/u_port_spi.c b/port/platform/zephyr/src/u_port_spi.c index 49190135d..22f81838b 100644 --- a/port/platform/zephyr/src/u_port_spi.c +++ b/port/platform/zephyr/src/u_port_spi.c @@ -20,13 +20,24 @@ * @brief Implementation of the port SPI API for the Zephyr platform. */ +#include + +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#include +#include +#include +#include +#include +#else #include #include +#include #include #include #include +#endif -#include #include #include "stddef.h" @@ -44,7 +55,6 @@ #include "u_port_spi.h" #include "u_port_private.h" #include "u_cfg_os_platform_specific.h" -#include "version.h" /* ---------------------------------------------------------------- * COMPILE-TIME MACROS diff --git a/port/platform/zephyr/src/u_port_uart.c b/port/platform/zephyr/src/u_port_uart.c index 826e0ce1b..4c1e554d9 100644 --- a/port/platform/zephyr/src/u_port_uart.c +++ b/port/platform/zephyr/src/u_port_uart.c @@ -26,11 +26,20 @@ # include "u_cfg_override.h" // For a customer's configuration override #endif +#include + +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#include +#include +#include +#else #include #include +#include #include +#endif -#include #include #include "stddef.h" // NULL, size_t etc. @@ -50,7 +59,6 @@ #include "u_port_os.h" #include "u_port_event_queue.h" #include "u_port_uart.h" -#include "version.h" #include "string.h" // For memcpy() diff --git a/port/test/u_port_test.c b/port/test/u_port_test.c index 94a41d3d6..f21152d5b 100644 --- a/port/test/u_port_test.c +++ b/port/test/u_port_test.c @@ -75,8 +75,13 @@ #include "u_test_util_resource_check.h" -#ifdef CONFIG_IRQ_OFFLOAD -# include // To test semaphore from ISR in zephyr +#ifdef CONFIG_IRQ_OFFLOAD // To test semaphore from ISR in zephyr +#include +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#else +#include +#endif #endif /* ---------------------------------------------------------------- diff --git a/zephyr/test/u_main.c b/zephyr/test/u_main.c index ffdb7e915..9718b7065 100644 --- a/zephyr/test/u_main.c +++ b/zephyr/test/u_main.c @@ -26,7 +26,13 @@ #include "u_cfg_app_platform_specific.h" -#include "kernel.h" +#include + +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#include +#else +#include +#endif /* ---------------------------------------------------------------- * COMPILE-TIME MACROS From 7caa8b8dca89914ebd0ae226987d2b36b3a59708 Mon Sep 17 00:00:00 2001 From: Stephan Linz Date: Tue, 21 Nov 2023 11:54:00 +0100 Subject: [PATCH 2/3] zephyr: convert to new SYS_INIT callback since v3.4 `SYS_INIT` callback no longer requires a `device` argument. The new callback signature is `int f(void)`. Signed-off-by: Stephan Linz --- port/platform/zephyr/src/u_port.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/port/platform/zephyr/src/u_port.c b/port/platform/zephyr/src/u_port.c index 0e3d38d04..23bf3d78e 100644 --- a/port/platform/zephyr/src/u_port.c +++ b/port/platform/zephyr/src/u_port.c @@ -189,9 +189,14 @@ int32_t uPortGetTimezoneOffsetSeconds() return offset; } +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,4,0) +static int ubxlib_preinit(void) +{ +#else static int ubxlib_preinit(const struct device *arg) { ARG_UNUSED(arg); +#endif k_thread_system_pool_assign(k_current_get()); return 0; From 5beb45d8cfda61a05ec0ad5a03496f99080f70ab Mon Sep 17 00:00:00 2001 From: Stephan Linz Date: Tue, 21 Nov 2023 11:54:00 +0100 Subject: [PATCH 3/3] zephyr: use new random API header since v3.5 Random API header `` is deprecated in favor of ``. The old header will be removed in future releases and its usage should be avoided. Signed-off-by: Stephan Linz --- port/platform/zephyr/src/u_port_clib.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/port/platform/zephyr/src/u_port_clib.c b/port/platform/zephyr/src/u_port_clib.c index e9be938c5..80fd3cdf7 100644 --- a/port/platform/zephyr/src/u_port_clib.c +++ b/port/platform/zephyr/src/u_port_clib.c @@ -27,7 +27,11 @@ #include #if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,1,0) +#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,5,0) +#include +#else #include +#endif #else #include #endif