diff --git a/Kconfig.zephyr b/Kconfig.zephyr index f97819896d94..68abf89b42fc 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -536,11 +536,10 @@ config NO_OPTIMIZATIONS endchoice config LTO - bool "Link Time Optimization [EXPERIMENTAL]" + bool "Link Time Optimization" depends on !(GEN_ISR_TABLES || GEN_IRQ_VECTOR_TABLE) || ISR_TABLES_LOCAL_DECLARATION depends on !NATIVE_LIBRARY depends on !CODE_DATA_RELOCATION - select EXPERIMENTAL help This option enables Link Time Optimization. diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index cc7cb9a14116..a77bbf643c04 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -1156,6 +1156,23 @@ Release Notes: tests: - drivers.clock +"Drivers: Comparator": + status: maintained + maintainers: + - bjarki-andreasen + files: + - drivers/comparator/ + - dts/bindings/comparator/ + - include/zephyr/drivers/comparator.h + - include/zephyr/drivers/comparator/ + - tests/drivers/build_all/comparator/ + - tests/drivers/comparator/ + - doc/hardware/peripherals/comparator.rst + labels: + - "area: Comparator" + tests: + - drivers.comparator + "Drivers: Console": status: odd fixes files: diff --git a/arch/arm/core/cortex_m/fault.c b/arch/arm/core/cortex_m/fault.c index 4cc01f87129a..4e604ba8033c 100644 --- a/arch/arm/core/cortex_m/fault.c +++ b/arch/arm/core/cortex_m/fault.c @@ -743,7 +743,7 @@ static inline bool z_arm_is_pc_valid(uintptr_t pc) return true; } -#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_itcm)) /* Is it in the ITCM */ if ((((uintptr_t)&__itcm_start) <= pc) && (pc < ((uintptr_t)&__itcm_end))) { return true; diff --git a/arch/arm/core/cortex_m/pm_s2ram.S b/arch/arm/core/cortex_m/pm_s2ram.S index f9c82b4069b6..27c2a1e96a71 100644 --- a/arch/arm/core/cortex_m/pm_s2ram.S +++ b/arch/arm/core/cortex_m/pm_s2ram.S @@ -70,7 +70,9 @@ SECTION_FUNC(TEXT, arch_pm_s2ram_suspend) /* * Mark entering suspend to RAM. */ - bl pm_s2ram_mark_set + mov r1, lr + bl pm_s2ram_mark_set + mov lr, r1 /* * Call the system_off function passed as parameter. This should never @@ -86,7 +88,9 @@ SECTION_FUNC(TEXT, arch_pm_s2ram_suspend) /* * Reset the marking of suspend to RAM, return is ignored. */ - bl pm_s2ram_mark_check_and_clear + mov r1, lr + bl pm_s2ram_mark_check_and_clear + mov lr, r1 /* Move system_off back to r0 as return value */ mov r0, r4 @@ -99,16 +103,13 @@ GTEXT(arch_pm_s2ram_resume) SECTION_FUNC(TEXT, arch_pm_s2ram_resume) /* * Check if reset occurred after suspending to RAM. - * Store LR to ensure we can continue boot when we are not suspended - * to RAM. In addition to LR, R0 is pushed too, to ensure "SP mod 8 = 0", - * as stated by ARM rule 6.2.1.2 for AAPCS32. */ - push {r0, lr} - bl pm_s2ram_mark_check_and_clear - cmp r0, #0x1 - pop {r0, lr} - beq resume - bx lr + mov r1, lr + bl pm_s2ram_mark_check_and_clear + mov lr, r1 + cmp r0, #0x1 + beq resume + bx lr resume: /* diff --git a/arch/arm/core/cortex_m/pm_s2ram.c b/arch/arm/core/cortex_m/pm_s2ram.c index 2657d48dc32a..b7fe5d9b6260 100644 --- a/arch/arm/core/cortex_m/pm_s2ram.c +++ b/arch/arm/core/cortex_m/pm_s2ram.c @@ -22,20 +22,44 @@ __noinit _cpu_context_t _cpu_context; */ static __noinit uint32_t marker; -void pm_s2ram_mark_set(void) +void __attribute__((naked)) pm_s2ram_mark_set(void) { - marker = MAGIC; + __asm__ volatile( + /* Set the marker to MAGIC value */ + "str %[_magic_val], [%[_marker]]\n" + + "bx lr\n" + : + : [_magic_val] "r"(MAGIC), [_marker] "r"(&marker) + : "r1", "r4", "memory"); } -bool pm_s2ram_mark_check_and_clear(void) +bool __attribute__((naked)) pm_s2ram_mark_check_and_clear(void) { - if (marker == MAGIC) { - marker = 0; + __asm__ volatile( + /* Set return value to 0 */ + "mov r0, #0\n" + + /* Check the marker */ + "ldr r3, [%[_marker]]\n" + "cmp r3, %[_magic_val]\n" + "bne exit\n" + + /* + * Reset the marker + */ + "str r0, [%[_marker]]\n" - return true; - } + /* + * Set return value to 1 + */ + "mov r0, #1\n" - return false; + "exit:\n" + "bx lr\n" + : + : [_magic_val] "r"(MAGIC), [_marker] "r"(&marker) + : "r0", "r1", "r3", "r4", "memory"); } #endif /* CONFIG_PM_S2RAM_CUSTOM_MARKING */ diff --git a/boards/arm/v2m_musca_b1/pinmux.c b/boards/arm/v2m_musca_b1/pinmux.c index 443d462eb212..2a2c44d62b93 100644 --- a/boards/arm/v2m_musca_b1/pinmux.c +++ b/boards/arm/v2m_musca_b1/pinmux.c @@ -40,7 +40,7 @@ static void arm_musca_b1_pinmux_defaults(void) scc[IOMUX_ALTF1_OUTSEL] = 0xffff; scc[IOMUX_ALTF1_OENSEL] = 0xffff; -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart0)) /* clear bit 0/1 for GPIO0/1 to steer from ALTF1 */ scc[IOMUX_MAIN_INSEL] &= ~(BIT(0) | BIT(1)); scc[IOMUX_MAIN_OUTSEL] &= ~(BIT(0) | BIT(1)); diff --git a/boards/arm/v2m_musca_s1/pinmux.c b/boards/arm/v2m_musca_s1/pinmux.c index a1a1a4ad2523..3affa53dadf4 100644 --- a/boards/arm/v2m_musca_s1/pinmux.c +++ b/boards/arm/v2m_musca_s1/pinmux.c @@ -40,7 +40,7 @@ static void arm_musca_s1_pinmux_defaults(void) scc[IOMUX_ALTF1_OUTSEL] = 0xffff; scc[IOMUX_ALTF1_OENSEL] = 0xffff; -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart0)) /* clear bit 0/1 for GPIO0/1 to steer from ALTF1 */ scc[IOMUX_MAIN_INSEL] &= ~(BIT(0) | BIT(1)); scc[IOMUX_MAIN_OUTSEL] &= ~(BIT(0) | BIT(1)); diff --git a/boards/digilent/arty_a7/board.c b/boards/digilent/arty_a7/board.c index 984cd34ab43a..0e087c212b42 100644 --- a/boards/digilent/arty_a7/board.c +++ b/boards/digilent/arty_a7/board.c @@ -16,7 +16,7 @@ LOG_MODULE_REGISTER(board, CONFIG_LOG_DEFAULT_LEVEL); #define DAPLINK_QSPI_MUX_NODE DT_NODELABEL(daplink_qspi_mux) -#if DT_NODE_HAS_STATUS(DAPLINK_QSPI_MUX_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(DAPLINK_QSPI_MUX_NODE) int board_daplink_qspi_mux_select(enum board_daplink_qspi_mux_mode mode) { struct gpio_dt_spec mux = GPIO_DT_SPEC_GET(DAPLINK_QSPI_MUX_NODE, mux_gpios); @@ -77,4 +77,4 @@ static int board_init(void) } SYS_INIT(board_init, POST_KERNEL, CONFIG_BOARD_INIT_PRIORITY); -#endif /* DT_NODE_HAS_STATUS(DAPLINK_QSPI_MUX_NODE, okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DAPLINK_QSPI_MUX_NODE) */ diff --git a/boards/native/nrf_bsim/CMakeLists.txt b/boards/native/nrf_bsim/CMakeLists.txt index 6aeb3f01634f..244133c1bd6a 100644 --- a/boards/native/nrf_bsim/CMakeLists.txt +++ b/boards/native/nrf_bsim/CMakeLists.txt @@ -56,6 +56,7 @@ zephyr_include_directories( common common/cmsis ${NSI_DIR}/common/src/include + ${ZEPHYR_BASE}/soc/nordic/common ) zephyr_library_include_directories( diff --git a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20-ipc_conf.dtsi b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20-ipc_conf.dtsi index a17889fe0b02..94cda5e8ee2e 100644 --- a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20-ipc_conf.dtsi +++ b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20-ipc_conf.dtsi @@ -9,6 +9,7 @@ cpusec_cpuapp_ipc: ipc-1-2 { compatible = "zephyr,ipc-icmsg"; status = "disabled"; + dcache-alignment = <32>; mboxes = <&cpusec_bellboard 12>, <&cpuapp_bellboard 0>; }; @@ -16,12 +17,14 @@ cpusec_cpurad_ipc: ipc-1-3 { compatible = "zephyr,ipc-icmsg"; status = "disabled"; + dcache-alignment = <32>; mboxes = <&cpusec_bellboard 18>, <&cpurad_bellboard 0>; }; cpuapp_cpurad_ipc: ipc-2-3 { compatible = "zephyr,ipc-icbmsg"; + dcache-alignment = <32>; status = "disabled"; mboxes = <&cpuapp_bellboard 18>, <&cpurad_bellboard 12>; @@ -30,6 +33,7 @@ cpuapp_cpusys_ipc: ipc-2-12 { compatible = "zephyr,ipc-icmsg"; status = "disabled"; + dcache-alignment = <32>; mboxes = <&cpuapp_bellboard 6>, <&cpusys_vevif 12>; }; @@ -37,6 +41,7 @@ cpuapp_cpuppr_ipc: ipc-2-13 { compatible = "zephyr,ipc-icmsg"; status = "disabled"; + dcache-alignment = <32>; mboxes = <&cpuapp_bellboard 13>, <&cpuppr_vevif 12>; }; @@ -44,6 +49,7 @@ cpuapp_cpuflpr_ipc: ipc-2-14 { compatible = "zephyr,ipc-icmsg"; status = "disabled"; + dcache-alignment = <32>; mboxes = <&cpuapp_bellboard 14>, <&cpuflpr_vevif 16>; }; @@ -51,6 +57,7 @@ cpurad_cpusys_ipc: ipc-3-12 { compatible = "zephyr,ipc-icmsg"; status = "disabled"; + dcache-alignment = <32>; mboxes = <&cpurad_bellboard 6>, <&cpusys_vevif 18>; }; diff --git a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_0_8_0.dtsi b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_0_8_0.dtsi new file mode 100644 index 000000000000..940ac4d23916 --- /dev/null +++ b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_0_8_0.dtsi @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/delete-node/ &suit_storage_partition; + +/ { + reserved-memory { + suit_storage_partition: memory@e1eb000 { + reg = <0xe1eb000 DT_SIZE_K(24)>; + }; + }; +}; diff --git a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp_0_8_0.overlay b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp_0_8_0.overlay new file mode 100644 index 000000000000..dfee18c5b6f0 --- /dev/null +++ b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp_0_8_0.overlay @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "nrf54h20dk_nrf54h20_0_8_0.dtsi" diff --git a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuflpr_0_8_0.overlay b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuflpr_0_8_0.overlay new file mode 100644 index 000000000000..dfee18c5b6f0 --- /dev/null +++ b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuflpr_0_8_0.overlay @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "nrf54h20dk_nrf54h20_0_8_0.dtsi" diff --git a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuppr_0_8_0.overlay b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuppr_0_8_0.overlay new file mode 100644 index 000000000000..dfee18c5b6f0 --- /dev/null +++ b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuppr_0_8_0.overlay @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "nrf54h20dk_nrf54h20_0_8_0.dtsi" diff --git a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpurad_0_8_0.overlay b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpurad_0_8_0.overlay new file mode 100644 index 000000000000..dfee18c5b6f0 --- /dev/null +++ b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpurad_0_8_0.overlay @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "nrf54h20dk_nrf54h20_0_8_0.dtsi" diff --git a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp.dts b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp.dts index fbe74a822240..9b62eafea174 100644 --- a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp.dts +++ b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp.dts @@ -32,7 +32,6 @@ qspi-quad-mode; #include "nrf70_common.dtsi" - #include "nrf70_common_coex.dtsi" #include "nrf70_common_5g.dtsi" }; }; diff --git a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_nrf7001.dts b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_nrf7001.dts index 1d78dddbe68a..8d955c67fc72 100644 --- a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_nrf7001.dts +++ b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_nrf7001.dts @@ -32,6 +32,5 @@ qspi-quad-mode; #include "nrf70_common.dtsi" - #include "nrf70_common_coex.dtsi" }; }; diff --git a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_nrf7001_ns.dts b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_nrf7001_ns.dts index cbbd46dff8be..5ff28accf3fc 100644 --- a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_nrf7001_ns.dts +++ b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_nrf7001_ns.dts @@ -35,6 +35,5 @@ qspi-quad-mode; #include "nrf70_common.dtsi" - #include "nrf70_common_coex.dtsi" }; }; diff --git a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_ns.dts b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_ns.dts index ed2193847959..0deb8ccc1bf5 100644 --- a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_ns.dts +++ b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_ns.dts @@ -35,7 +35,6 @@ qspi-quad-mode; #include "nrf70_common.dtsi" - #include "nrf70_common_coex.dtsi" #include "nrf70_common_5g.dtsi" }; }; diff --git a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpunet.dts b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpunet.dts index 823c9fafacba..faea5ee69e3e 100644 --- a/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpunet.dts +++ b/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpunet.dts @@ -82,11 +82,14 @@ <21 0 &gpio1 3 0>; /* D15 */ }; - nrf70: coex { + nrf_radio_coex: coex { status = "okay"; - compatible = "nordic,nrf70-coex"; + compatible = "nordic,nrf7002-coex"; - #include "nrf70_common_coex.dtsi" + req-gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>; + status0-gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>; + grant-gpios = <&gpio0 24 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW)>; + swctrl1-gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>; }; /* These aliases are provided for compatibility with samples */ diff --git a/boards/nordic/nrf7002dk/nrf70_common.dtsi b/boards/nordic/nrf7002dk/nrf70_common.dtsi index f40f8ad9bb74..cd9cd23bb892 100644 --- a/boards/nordic/nrf7002dk/nrf70_common.dtsi +++ b/boards/nordic/nrf7002dk/nrf70_common.dtsi @@ -7,6 +7,7 @@ iovdd-ctrl-gpios = <&gpio0 31 GPIO_ACTIVE_HIGH>; bucken-gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>; host-irq-gpios = <&gpio0 23 GPIO_ACTIVE_HIGH>; +srrf-switch-gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>; wifi-max-tx-pwr-2g-dsss = <21>; wifi-max-tx-pwr-2g-mcs0 = <16>; diff --git a/boards/nordic/nrf7002dk/nrf70_common_coex.dtsi b/boards/nordic/nrf7002dk/nrf70_common_coex.dtsi deleted file mode 100644 index 03f22c3edbaa..000000000000 --- a/boards/nordic/nrf7002dk/nrf70_common_coex.dtsi +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -req-gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>; -status0-gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>; -grant-gpios = <&gpio0 24 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW)>; -swctrl1-gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>; -srrf-switch-gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>; diff --git a/boards/nordic/nrf9160dk/board.c b/boards/nordic/nrf9160dk/board.c index adf137df196e..c8e680c45397 100644 --- a/boards/nordic/nrf9160dk/board.c +++ b/boards/nordic/nrf9160dk/board.c @@ -32,7 +32,7 @@ LOG_MODULE_REGISTER(board_control, CONFIG_BOARD_NRF9160DK_LOG_LEVEL); GET_PORT(reset_input, gpios, 0) == 0 && \ GET_PIN(reset_input, gpios, 0) == 18) #define USE_RESET_GPIO \ - (DT_NODE_HAS_STATUS(DT_NODELABEL(reset_input), okay) && \ + (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(reset_input)) && \ !RESET_INPUT_IS_PINRESET) struct switch_cfg { @@ -47,7 +47,7 @@ struct switch_cfg { #endif }; -#define ROUTING_ENABLED(_name) DT_NODE_HAS_STATUS(DT_NODELABEL(_name), okay) +#define ROUTING_ENABLED(_name) DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(_name)) #define SWITCH_CFG(_name, _idx) \ { \ .gpio = GET_DEV(_name, control_gpios, _idx), \ diff --git a/boards/nordic/nrf9160dk/nrf52840_reset.c b/boards/nordic/nrf9160dk/nrf52840_reset.c index e639b5765b73..aa9f9d4b6203 100644 --- a/boards/nordic/nrf9160dk/nrf52840_reset.c +++ b/boards/nordic/nrf9160dk/nrf52840_reset.c @@ -12,7 +12,7 @@ #define RESET_NODE DT_NODELABEL(nrf52840_reset) -#if DT_NODE_HAS_STATUS(RESET_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(RESET_NODE) #define RESET_GPIO_CTRL DT_GPIO_CTLR(RESET_NODE, gpios) #define RESET_GPIO_PIN DT_GPIO_PIN(RESET_NODE, gpios) @@ -65,4 +65,4 @@ int bt_hci_transport_setup(const struct device *h4) return 0; } -#endif /* DT_NODE_HAS_STATUS(RESET_NODE, okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(RESET_NODE) */ diff --git a/boards/nordic/nrf9280pdk/nrf9280pdk_nrf9280-ipc_conf.dtsi b/boards/nordic/nrf9280pdk/nrf9280pdk_nrf9280-ipc_conf.dtsi index 944dd7fb6abd..0588e8d08018 100644 --- a/boards/nordic/nrf9280pdk/nrf9280pdk_nrf9280-ipc_conf.dtsi +++ b/boards/nordic/nrf9280pdk/nrf9280pdk_nrf9280-ipc_conf.dtsi @@ -9,6 +9,7 @@ cpusec_cpuapp_ipc: ipc-1-2 { compatible = "zephyr,ipc-icmsg"; status = "disabled"; + dcache-alignment = <32>; mboxes = <&cpusec_bellboard 12>, <&cpuapp_bellboard 0>; }; @@ -16,12 +17,14 @@ cpusec_cpurad_ipc: ipc-1-3 { compatible = "zephyr,ipc-icmsg"; status = "disabled"; + dcache-alignment = <32>; mboxes = <&cpusec_bellboard 18>, <&cpurad_bellboard 0>; }; cpuapp_cpurad_ipc: ipc-2-3 { compatible = "zephyr,ipc-icbmsg"; + dcache-alignment = <32>; status = "disabled"; mboxes = <&cpuapp_bellboard 18>, <&cpurad_bellboard 12>; @@ -30,6 +33,7 @@ cpuapp_cpusys_ipc: ipc-2-12 { compatible = "zephyr,ipc-icmsg"; status = "disabled"; + dcache-alignment = <32>; mboxes = <&cpuapp_bellboard 6>, <&cpusys_vevif 12>; }; @@ -37,6 +41,7 @@ cpuapp_cpuppr_ipc: ipc-2-13 { compatible = "zephyr,ipc-icmsg"; status = "disabled"; + dcache-alignment = <32>; mboxes = <&cpuapp_bellboard 13>, <&cpuppr_vevif 12>; }; @@ -44,6 +49,7 @@ cpurad_cpusys_ipc: ipc-3-12 { compatible = "zephyr,ipc-icmsg"; status = "disabled"; + dcache-alignment = <32>; mboxes = <&cpurad_bellboard 6>, <&cpusys_vevif 18>; }; diff --git a/boards/nordic/thingy53/thingy53_nrf5340_cpunet.dts b/boards/nordic/thingy53/thingy53_nrf5340_cpunet.dts index aa4d4df909c4..3003d4924ce5 100644 --- a/boards/nordic/thingy53/thingy53_nrf5340_cpunet.dts +++ b/boards/nordic/thingy53/thingy53_nrf5340_cpunet.dts @@ -72,7 +72,9 @@ #gpio-cells = <2>; gpio-map-mask = <0xffffffff 0xffffffc0>; gpio-map-pass-thru = <0 0x3f>; - gpio-map = <8 0 &gpio0 5 0>, /* P8, P0.05/AIN1 */ + gpio-map = <5 0 &gpio1 1 0>, /* P5, P1.01/GRANT */ + <6 0 &gpio1 0 0>, /* P6, P1.00/REQ */ + <8 0 &gpio0 5 0>, /* P8, P0.05/AIN1 */ <9 0 &gpio0 4 0>, /* P9, P0.04/AIN0 */ <15 0 &gpio0 8 0>, /* P15, P0.08/TRACEDATA3 */ <16 0 &gpio0 9 0>, /* P16, P0.09/TRACEDATA2 */ diff --git a/boards/nxp/frdm_mcxa156/board.c b/boards/nxp/frdm_mcxa156/board.c index 98801c47a1a2..84347c4715ca 100644 --- a/boards/nxp/frdm_mcxa156/board.c +++ b/boards/nxp/frdm_mcxa156/board.c @@ -66,52 +66,52 @@ static int frdm_mcxa156_init(void) CLOCK_SetClockDiv(kCLOCK_DivAHBCLK, 1U); /* !< Set AHBCLKDIV divider to value 1 */ CLOCK_SetClockDiv(kCLOCK_DivFRO_HF_DIV, 1U); /* !< Set FROHFDIV divider to value 1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(porta), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(porta)) RESET_ReleasePeripheralReset(kPORT0_RST_SHIFT_RSTn); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(portb), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(portb)) RESET_ReleasePeripheralReset(kPORT1_RST_SHIFT_RSTn); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(portc), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(portc)) RESET_ReleasePeripheralReset(kPORT2_RST_SHIFT_RSTn); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(portd), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(portd)) RESET_ReleasePeripheralReset(kPORT3_RST_SHIFT_RSTn); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(porte), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(porte)) RESET_ReleasePeripheralReset(kPORT4_RST_SHIFT_RSTn); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio0)) RESET_ReleasePeripheralReset(kGPIO0_RST_SHIFT_RSTn); CLOCK_EnableClock(kCLOCK_GateGPIO0); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) RESET_ReleasePeripheralReset(kGPIO1_RST_SHIFT_RSTn); CLOCK_EnableClock(kCLOCK_GateGPIO1); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio2)) RESET_ReleasePeripheralReset(kGPIO2_RST_SHIFT_RSTn); CLOCK_EnableClock(kCLOCK_GateGPIO2); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio3)) RESET_ReleasePeripheralReset(kGPIO3_RST_SHIFT_RSTn); CLOCK_EnableClock(kCLOCK_GateGPIO3); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio4)) RESET_ReleasePeripheralReset(kGPIO4_RST_SHIFT_RSTn); CLOCK_EnableClock(kCLOCK_GateGPIO4); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpuart0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpuart0)) CLOCK_SetClockDiv(kCLOCK_DivLPUART0, 1u); CLOCK_AttachClk(kFRO12M_to_LPUART0); #endif diff --git a/boards/nxp/frdm_mcxn236/board.c b/boards/nxp/frdm_mcxn236/board.c index 8f0d1fd79767..fbaf20ccd65f 100644 --- a/boards/nxp/frdm_mcxn236/board.c +++ b/boards/nxp/frdm_mcxn236/board.c @@ -88,84 +88,84 @@ static int frdm_mcxn236_init(void) /* Set AHBCLKDIV divider to value 1 */ CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexcomm1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm1)) CLOCK_SetClkDiv(kCLOCK_DivFlexcom1Clk, 1u); CLOCK_AttachClk(kFRO12M_to_FLEXCOMM1); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexcomm2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm2)) CLOCK_SetClkDiv(kCLOCK_DivFlexcom2Clk, 1u); CLOCK_AttachClk(kFRO12M_to_FLEXCOMM2); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexcomm3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm3)) CLOCK_SetClkDiv(kCLOCK_DivFlexcom3Clk, 1u); CLOCK_AttachClk(kFRO12M_to_FLEXCOMM3); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexcomm4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm4)) CLOCK_SetClkDiv(kCLOCK_DivFlexcom4Clk, 1u); CLOCK_AttachClk(kFRO12M_to_FLEXCOMM4); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexcomm5), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm5)) CLOCK_SetClkDiv(kCLOCK_DivFlexcom5Clk, 1u); CLOCK_AttachClk(kFRO12M_to_FLEXCOMM5); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(os_timer), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(os_timer)) CLOCK_AttachClk(kCLK_1M_to_OSTIMER); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio0)) CLOCK_EnableClock(kCLOCK_Gpio0); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) CLOCK_EnableClock(kCLOCK_Gpio1); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio2)) CLOCK_EnableClock(kCLOCK_Gpio2); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio3)) CLOCK_EnableClock(kCLOCK_Gpio3); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio4)) CLOCK_EnableClock(kCLOCK_Gpio4); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio5), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio5)) CLOCK_EnableClock(kCLOCK_Gpio5); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(wwdt0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(wwdt0)) CLOCK_SetClkDiv(kCLOCK_DivWdt0Clk, 1u); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ctimer0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ctimer0)) CLOCK_SetClkDiv(kCLOCK_DivCtimer0Clk, 1U); CLOCK_AttachClk(kPLL0_to_CTIMER0); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ctimer1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ctimer1)) CLOCK_SetClkDiv(kCLOCK_DivCtimer1Clk, 1U); CLOCK_AttachClk(kPLL0_to_CTIMER1); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ctimer2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ctimer2)) CLOCK_SetClkDiv(kCLOCK_DivCtimer2Clk, 1U); CLOCK_AttachClk(kPLL0_to_CTIMER2); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ctimer3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ctimer3)) CLOCK_SetClkDiv(kCLOCK_DivCtimer3Clk, 1U); CLOCK_AttachClk(kPLL0_to_CTIMER3); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ctimer4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ctimer4)) CLOCK_SetClkDiv(kCLOCK_DivCtimer4Clk, 1U); CLOCK_AttachClk(kPLL0_to_CTIMER4); #endif diff --git a/boards/nxp/frdm_mcxn947/board.c b/boards/nxp/frdm_mcxn947/board.c index 37ec5f4dd6d4..db21a4ae1947 100644 --- a/boards/nxp/frdm_mcxn947/board.c +++ b/boards/nxp/frdm_mcxn947/board.c @@ -127,7 +127,7 @@ static int frdm_mcxn947_init(void) CLOCK_SetupExtClocking(BOARD_XTAL0_CLK_HZ); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexcan0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcan0)) /* Set up PLL1 for 80 MHz FlexCAN clock */ const pll_setup_t pll1Setup = { .pllctrl = SCG_SPLLCTRL_SOURCE(1U) | SCG_SPLLCTRL_SELI(27U) | @@ -146,50 +146,50 @@ static int frdm_mcxn947_init(void) CLOCK_SetClkDiv(kCLOCK_DivPLL1Clk0, 1U); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexcomm1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm1)) CLOCK_SetClkDiv(kCLOCK_DivFlexcom1Clk, 1u); CLOCK_AttachClk(kFRO12M_to_FLEXCOMM1); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexcomm2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm2)) CLOCK_SetClkDiv(kCLOCK_DivFlexcom2Clk, 1u); CLOCK_AttachClk(kFRO12M_to_FLEXCOMM2); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexcomm4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm4)) CLOCK_SetClkDiv(kCLOCK_DivFlexcom4Clk, 1u); CLOCK_AttachClk(kFRO12M_to_FLEXCOMM4); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(os_timer), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(os_timer)) CLOCK_AttachClk(kCLK_1M_to_OSTIMER); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio0)) CLOCK_EnableClock(kCLOCK_Gpio0); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) CLOCK_EnableClock(kCLOCK_Gpio1); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio2)) CLOCK_EnableClock(kCLOCK_Gpio2); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio3)) CLOCK_EnableClock(kCLOCK_Gpio3); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio4)) CLOCK_EnableClock(kCLOCK_Gpio4); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio5), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio5)) CLOCK_EnableClock(kCLOCK_Gpio5); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(dac0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dac0)) SPC_EnableActiveModeAnalogModules(SPC0, kSPC_controlDac0); CLOCK_SetClkDiv(kCLOCK_DivDac0Clk, 1u); CLOCK_AttachClk(kFRO_HF_to_DAC0); @@ -197,7 +197,7 @@ static int frdm_mcxn947_init(void) CLOCK_EnableClock(kCLOCK_Dac0); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(dac1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dac1)) SPC_EnableActiveModeAnalogModules(SPC0, kSPC_controlDac1); CLOCK_SetClkDiv(kCLOCK_DivDac1Clk, 1u); CLOCK_AttachClk(kFRO_HF_to_DAC1); @@ -205,7 +205,7 @@ static int frdm_mcxn947_init(void) CLOCK_EnableClock(kCLOCK_Dac1); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(enet), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(enet)) CLOCK_AttachClk(kNONE_to_ENETRMII); CLOCK_EnableClock(kCLOCK_Enet); SYSCON0->PRESETCTRL2 = SYSCON_PRESETCTRL2_ENET_RST_MASK; @@ -214,41 +214,41 @@ static int frdm_mcxn947_init(void) SYSCON->ENET_PHY_INTF_SEL = SYSCON_ENET_PHY_INTF_SEL_PHY_SEL(1); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(wwdt0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(wwdt0)) CLOCK_SetClkDiv(kCLOCK_DivWdt0Clk, 1u); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ctimer0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ctimer0)) CLOCK_SetClkDiv(kCLOCK_DivCtimer0Clk, 1U); CLOCK_AttachClk(kPLL0_to_CTIMER0); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ctimer1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ctimer1)) CLOCK_SetClkDiv(kCLOCK_DivCtimer1Clk, 1U); CLOCK_AttachClk(kPLL0_to_CTIMER1); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ctimer2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ctimer2)) CLOCK_SetClkDiv(kCLOCK_DivCtimer2Clk, 1U); CLOCK_AttachClk(kPLL0_to_CTIMER2); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ctimer3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ctimer3)) CLOCK_SetClkDiv(kCLOCK_DivCtimer3Clk, 1U); CLOCK_AttachClk(kPLL0_to_CTIMER3); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ctimer4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ctimer4)) CLOCK_SetClkDiv(kCLOCK_DivCtimer4Clk, 1U); CLOCK_AttachClk(kPLL0_to_CTIMER4); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexcan0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcan0)) CLOCK_SetClkDiv(kCLOCK_DivFlexcan0Clk, 1U); CLOCK_AttachClk(kPLL1_CLK0_to_FLEXCAN0); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usdhc0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usdhc0)) CLOCK_SetClkDiv(kCLOCK_DivUSdhcClk, 1u); CLOCK_AttachClk(kFRO_HF_to_USDHC); #endif @@ -260,17 +260,17 @@ static int frdm_mcxn947_init(void) enable_cache64(); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(vref), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(vref)) CLOCK_EnableClock(kCLOCK_Vref); SPC_EnableActiveModeAnalogModules(SPC0, kSPC_controlVref); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpadc0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpadc0)) CLOCK_SetClkDiv(kCLOCK_DivAdc0Clk, 1U); CLOCK_AttachClk(kFRO_HF_to_ADC0); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usb1), okay) && CONFIG_USB_DC_NXP_EHCI +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usb1)) && CONFIG_USB_DC_NXP_EHCI usb_phy_config_struct_t usbPhyConfig = { BOARD_USB_PHY_D_CAL, BOARD_USB_PHY_TXCAL45DP, BOARD_USB_PHY_TXCAL45DM, }; @@ -312,13 +312,13 @@ static int frdm_mcxn947_init(void) USB_EhciPhyInit(kUSB_ControllerEhci0, BOARD_XTAL0_CLK_HZ, &usbPhyConfig); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpcmp0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpcmp0)) CLOCK_SetClkDiv(kCLOCK_DivCmp0FClk, 1U); CLOCK_AttachClk(kFRO12M_to_CMP0F); SPC_EnableActiveModeAnalogModules(SPC0, (kSPC_controlCmp0 | kSPC_controlCmp0Dac)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lptmr0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lptmr0)) /* * Clock Select Decides what input source the lptmr will clock from @@ -340,9 +340,9 @@ static int frdm_mcxn947_init(void) CLOCK_SetupClockCtrl(kCLOCK_CLKIN_ENA_FM_USBH_LPT); #endif /* DT_PROP(DT_NODELABEL(lptmr0), clk_source) */ -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(lptmr0), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lptmr0)) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexio0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexio0)) CLOCK_SetClkDiv(kCLOCK_DivFlexioClk, 1u); CLOCK_AttachClk(kPLL0_to_FLEXIO); #endif diff --git a/boards/shields/nrf7002eb/nrf7002eb.overlay b/boards/shields/nrf7002eb/nrf7002eb.overlay index d580a2efb8c0..7f9074da9d0c 100644 --- a/boards/shields/nrf7002eb/nrf7002eb.overlay +++ b/boards/shields/nrf7002eb/nrf7002eb.overlay @@ -24,6 +24,7 @@ bucken-gpios = <&edge_connector 9 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; iovdd-ctrl-gpios = <&edge_connector 9 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; host-irq-gpios = <&edge_connector 19 GPIO_ACTIVE_HIGH>; + srrf-switch-gpios = <&gpio1 13 GPIO_ACTIVE_HIGH>; wlan0: wlan0 { compatible = "nordic,wlan"; diff --git a/boards/shields/nrf7002eb/nrf7002eb_coex.overlay b/boards/shields/nrf7002eb/nrf7002eb_coex.overlay index a8925c255675..09bfb6e1906a 100644 --- a/boards/shields/nrf7002eb/nrf7002eb_coex.overlay +++ b/boards/shields/nrf7002eb/nrf7002eb_coex.overlay @@ -4,10 +4,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "nrf7002eb.overlay" +/ { + nrf_radio_coex: coex { + compatible = "nordic,nrf7002-coex"; + status = "okay"; -&nrf70 { - status0-gpios = <&edge_connector 5 GPIO_ACTIVE_HIGH>; - req-gpios = <&edge_connector 6 GPIO_ACTIVE_HIGH>; - grant-gpios = <&edge_connector 15 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW)>; + status0-gpios = <&edge_connector 5 GPIO_ACTIVE_HIGH>; + req-gpios = <&edge_connector 6 GPIO_ACTIVE_HIGH>; + grant-gpios = <&edge_connector 15 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW)>; + }; }; diff --git a/boards/shields/nrf7002ek/Kconfig.shield b/boards/shields/nrf7002ek/Kconfig.shield index 7627ff96dbd4..5b52d5710f27 100644 --- a/boards/shields/nrf7002ek/Kconfig.shield +++ b/boards/shields/nrf7002ek/Kconfig.shield @@ -9,3 +9,6 @@ config SHIELD_NRF7002EK_NRF7001 config SHIELD_NRF7002EK_NRF7000 def_bool $(shields_list_contains,nrf7002ek_nrf7000) + +config SHIELD_NRF7002EK_COEX + def_bool $(shields_list_contains,nrf7002ek_coex) diff --git a/boards/shields/nrf7002ek/doc/index.rst b/boards/shields/nrf7002ek/doc/index.rst index 9f247be3501d..cfe08750f57b 100644 --- a/boards/shields/nrf7002ek/doc/index.rst +++ b/boards/shields/nrf7002ek/doc/index.rst @@ -47,24 +47,25 @@ SR Co-existence ############### The nRF7002 EK supports SR co-existence provided the host board supports it. The SR co-existence -pins are connected to the host board's GPIO pins. +pins are connected to the host board's GPIO pins. The interface is selected by setting +``--shield nrf7002ek_coex`` when invoking ``west build``. Two Kconfig options are available to enable SR co-existence: -- :kconfig:option:`CONFIG_NRF70_SR_COEX`: Enables SR co-existence. +- :kconfig:option:`CONFIG_NRF70_SR_COEX`: Enables SR co-existence driver. - :kconfig:option:`CONFIG_NRF70_SR_COEX_RF_SWITCH`: Control SR side RF switch. Shield Variants ############### -The nRF7002 EK is available in three variants: +The nRF7002 EK is available in four variants: - ``nrf7002ek``: The default variant. - ``nrf7002ek_nrf7001``: Variant for the nRF7001 SoC or nRF7002 SoC emulating nRF7001 - that supports only 2.4GHz Wi-Fi. + that supports only 2.4GHz Wi-Fi. - ``nrf7002ek_nrf7000``: Variant for the nRF7000 SoC or nRF7002 SoC emulating nRF7000 - that supports only 2.4GHz Wi-Fi. - + that supports only 2.4GHz Wi-Fi. +- ``nrf7002ek_coex``: Variant for the SR co-existence interface References ********** diff --git a/boards/shields/nrf7002ek/nrf7002ek_coex.overlay b/boards/shields/nrf7002ek/nrf7002ek_coex.overlay new file mode 100644 index 000000000000..60ff3ca6ea42 --- /dev/null +++ b/boards/shields/nrf7002ek/nrf7002ek_coex.overlay @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + nrf_radio_coex: coex { + compatible = "nordic,nrf7002-coex"; + status = "okay"; + + /* D2 */ + status0-gpios = <&arduino_header 8 GPIO_ACTIVE_HIGH>; + /* D3 */ + req-gpios = <&arduino_header 9 GPIO_ACTIVE_HIGH>; + /* D4 */ + grant-gpios = <&arduino_header 10 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW)>; + /* D6 */ + swctrl1-gpios = <&arduino_header 12 GPIO_ACTIVE_HIGH>; + }; +}; diff --git a/boards/shields/nrf7002ek/nrf7002ek_common.dtsi b/boards/shields/nrf7002ek/nrf7002ek_common.dtsi index 102e0078d5f3..c9bbbde4b926 100644 --- a/boards/shields/nrf7002ek/nrf7002ek_common.dtsi +++ b/boards/shields/nrf7002ek/nrf7002ek_common.dtsi @@ -12,15 +12,8 @@ iovdd-ctrl-gpios = <&arduino_header 6 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; bucken-gpios = <&arduino_header 7 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; /* D7 */ host-irq-gpios = <&arduino_header 13 GPIO_ACTIVE_HIGH>; + /* Short-range (SR) co-existence */ -/* D2 */ -status0-gpios = <&arduino_header 8 GPIO_ACTIVE_HIGH>; -/* D3 */ -req-gpios = <&arduino_header 9 GPIO_ACTIVE_HIGH>; -/* D4 */ -grant-gpios = <&arduino_header 10 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW)>; -/* D6 */ -swctrl1-gpios = <&arduino_header 12 GPIO_ACTIVE_HIGH>; /* D8 */ srrf-switch-gpios = <&arduino_header 14 GPIO_ACTIVE_HIGH>; diff --git a/boards/silabs/dev_kits/sltb004a/board.c b/boards/silabs/dev_kits/sltb004a/board.c index 43dd2a6b3b24..1b09177ce690 100644 --- a/boards/silabs/dev_kits/sltb004a/board.c +++ b/boards/silabs/dev_kits/sltb004a/board.c @@ -37,7 +37,7 @@ static int efr32mg_sltb004a_init(void) #define CCS811 DT_NODELABEL(ccs811) -#if DT_NODE_HAS_STATUS(CCS811, okay) +#if DT_NODE_HAS_STATUS_OKAY(CCS811) cfg = (struct supply_cfg){ .gpio = DEVICE_DT_GET(DT_GPIO_CTLR(CCS811, supply_gpios)), .pin = DT_GPIO_PIN(CCS811, supply_gpios), diff --git a/cmake/modules/FindHostTools.cmake b/cmake/modules/FindHostTools.cmake index 876a86934b14..1dfce4d3d4a1 100644 --- a/cmake/modules/FindHostTools.cmake +++ b/cmake/modules/FindHostTools.cmake @@ -116,4 +116,4 @@ set(HostTools_FOUND TRUE) set(HOSTTOOLS_FOUND TRUE) build_info(toolchain name VALUE ${ZEPHYR_TOOLCHAIN_VARIANT}) string(TOUPPER ${ZEPHYR_TOOLCHAIN_VARIANT} zephyr_toolchain_variant_upper) -build_info(toolchain path VALUE "${${zephyr_toolchain_variant_upper}_TOOLCHAIN_PATH}") +build_info(toolchain path PATH "${${zephyr_toolchain_variant_upper}_TOOLCHAIN_PATH}") diff --git a/cmake/modules/dts.cmake b/cmake/modules/dts.cmake index 94bb6482739c..705de97d8747 100644 --- a/cmake/modules/dts.cmake +++ b/cmake/modules/dts.cmake @@ -182,7 +182,7 @@ set(dts_files if(DTC_OVERLAY_FILE) zephyr_list(TRANSFORM DTC_OVERLAY_FILE NORMALIZE_PATHS OUTPUT_VARIABLE DTC_OVERLAY_FILE_AS_LIST) - build_info(devicetree user-files VALUE ${DTC_OVERLAY_FILE_AS_LIST}) + build_info(devicetree user-files PATH ${DTC_OVERLAY_FILE_AS_LIST}) list(APPEND dts_files ${DTC_OVERLAY_FILE_AS_LIST} @@ -192,7 +192,7 @@ endif() if(EXTRA_DTC_OVERLAY_FILE) zephyr_list(TRANSFORM EXTRA_DTC_OVERLAY_FILE NORMALIZE_PATHS OUTPUT_VARIABLE EXTRA_DTC_OVERLAY_FILE_AS_LIST) - build_info(devicetree extra-user-files VALUE ${EXTRA_DTC_OVERLAY_FILE_AS_LIST}) + build_info(devicetree extra-user-files PATH ${EXTRA_DTC_OVERLAY_FILE_AS_LIST}) list(APPEND dts_files ${EXTRA_DTC_OVERLAY_FILE_AS_LIST} @@ -390,6 +390,6 @@ elseif(stderr) endif() endif(DTC) -build_info(devicetree files VALUE ${dts_files}) -build_info(devicetree include-dirs VALUE ${DTS_ROOT_SYSTEM_INCLUDE_DIRS}) -build_info(devicetree bindings-dirs VALUE ${DTS_ROOT_BINDINGS}) +build_info(devicetree files PATH ${dts_files}) +build_info(devicetree include-dirs PATH ${DTS_ROOT_SYSTEM_INCLUDE_DIRS}) +build_info(devicetree bindings-dirs PATH ${DTS_ROOT_BINDINGS}) diff --git a/cmake/modules/extensions.cmake b/cmake/modules/extensions.cmake index 066e0422e49c..23c30789b735 100644 --- a/cmake/modules/extensions.cmake +++ b/cmake/modules/extensions.cmake @@ -3596,7 +3596,8 @@ function(topological_sort) endfunction() # Usage: -# build_info(... VALUE ...) +# build_info(... VALUE ... ) +# build_info(... PATH ... ) # # This function populates updates the build_info.yml info file with exchangable build information # related to the current build. @@ -3613,11 +3614,20 @@ endfunction() # ...: One of the pre-defined valid CMake keys supported by build info or vendor-specific. # See 'scripts/schemas/build-schema.yml' CMake section for valid tags. # VALUE ... : value(s) to place in the build_info.yml file. +# PATH ... : path(s) to place in the build_info.yml file. All paths are converted to CMake +# style. If no conversion is required, for example when paths are already +# guaranteed to be CMake style, then VALUE can also be used. function(build_info) + set(convert_path FALSE) set(arg_list ${ARGV}) list(FIND arg_list VALUE index) if(index EQUAL -1) - message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}(...) missing a required argument: VALUE") + list(FIND arg_list PATH index) + set(convert_path TRUE) + endif() + + if(index EQUAL -1) + message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}(...) missing a required argument: VALUE or PATH") endif() yaml_context(EXISTS NAME build_info result) @@ -3635,6 +3645,15 @@ function(build_info) list(SUBLIST arg_list ${index} -1 values) list(POP_FRONT values) + if(convert_path) + set(converted_values) + foreach(val ${values}) + cmake_path(SET cmake_path "${val}") + list(APPEND converted_values "${cmake_path}") + endforeach() + set(values "${converted_values}") + endif() + if(ARGV0 STREQUAL "vendor-specific") set(type VALUE) else() diff --git a/cmake/modules/kconfig.cmake b/cmake/modules/kconfig.cmake index 43e73511768b..97086cdf19d0 100644 --- a/cmake/modules/kconfig.cmake +++ b/cmake/modules/kconfig.cmake @@ -98,13 +98,13 @@ set(PARSED_KCONFIG_SOURCES_TXT ${PROJECT_BINARY_DIR}/kconfig/sources.txt) if(CONF_FILE) string(CONFIGURE "${CONF_FILE}" CONF_FILE_EXPANDED) string(REPLACE " " ";" CONF_FILE_AS_LIST "${CONF_FILE_EXPANDED}") - build_info(kconfig user-files VALUE ${CONF_FILE_AS_LIST}) + build_info(kconfig user-files PATH ${CONF_FILE_AS_LIST}) endif() if(EXTRA_CONF_FILE) string(CONFIGURE "${EXTRA_CONF_FILE}" EXTRA_CONF_FILE_EXPANDED) string(REPLACE " " ";" EXTRA_CONF_FILE_AS_LIST "${EXTRA_CONF_FILE_EXPANDED}") - build_info(kconfig extra-user-files VALUE ${EXTRA_CONF_FILE_AS_LIST}) + build_info(kconfig extra-user-files PATH ${EXTRA_CONF_FILE_AS_LIST}) endif() zephyr_file(CONF_FILES ${BOARD_EXTENSION_DIRS} KCONF board_extension_conf_files SUFFIX ${FILE_SUFFIX}) @@ -360,7 +360,7 @@ endif() if(CREATE_NEW_DOTCONFIG) set(input_configs_flags --handwritten-input-configs) set(input_configs ${merge_config_files} ${FORCED_CONF_FILE}) - build_info(kconfig files VALUE ${input_configs}) + build_info(kconfig files PATH ${input_configs}) else() set(input_configs ${DOTCONFIG} ${FORCED_CONF_FILE}) endif() diff --git a/doc/connectivity/bluetooth/api/connection_mgmt.rst b/doc/connectivity/bluetooth/api/connection_mgmt.rst index 3a3d8d02a827..1b7ea2788c3f 100644 --- a/doc/connectivity/bluetooth/api/connection_mgmt.rst +++ b/doc/connectivity/bluetooth/api/connection_mgmt.rst @@ -15,6 +15,14 @@ longer period of time, since this ensures that the object remains valid :c:func:`bt_conn_unref` API is to be used when releasing a reference to a connection. +A common mistake is to forget unreleasing a reference to a connection +object created by functions :c:func:`bt_conn_le_create` and +:c:func:`bt_conn_le_create_synced`. To protect against this, use the +:kconfig:option:`CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE` Kconfig option, +which forces these functions return an error if the connection pointer +passed to them is not NULL. This helps to spot such issues and avoid +sporadic bugs caused by not releasing the connection object. + An application may track connections by registering a :c:struct:`bt_conn_cb` struct using the :c:func:`bt_conn_cb_register` or :c:macro:`BT_CONN_CB_DEFINE` APIs. This struct lets the application diff --git a/doc/connectivity/bluetooth/bluetooth-le-host.rst b/doc/connectivity/bluetooth/bluetooth-le-host.rst index 3fad34256816..567961bc6495 100644 --- a/doc/connectivity/bluetooth/bluetooth-le-host.rst +++ b/doc/connectivity/bluetooth/bluetooth-le-host.rst @@ -274,6 +274,19 @@ over LE connections. A more detailed description of this layer and the API reference can be found in the :ref:`GATT API reference section `. +ATT timeout +----------- + +If the peer device does not respond to an ATT request (such as read or write) +within the ATT timeout, the host will automatically initiate a disconnect. This +simplifies error handling by reducing rare failure conditions to a common +disconnection, allowing developers to manage unexpected disconnects without +special cases for ATT timeouts. + +.. image:: img/att_timeout.svg + :align: center + :alt: ATT timeout + Mesh ==== diff --git a/doc/connectivity/bluetooth/img/att_timeout.svg b/doc/connectivity/bluetooth/img/att_timeout.svg new file mode 100644 index 000000000000..8b1f2832b6ed --- /dev/null +++ b/doc/connectivity/bluetooth/img/att_timeout.svg @@ -0,0 +1 @@ +participant%20App%0Aparticipant%20Host%0Aparticipant%20Peer%0A%0AApp%20-%3E%20Host%3A%20bt_gatt_read(cb)%0A%0A%0A%0AHost%20-%3E%20Peer%3A%20ATT_READ_REQ%0Aactivate%20Host%0Aspace%20-4.1%0Aaboxright%20left%20of%20Host%3A%200%20seconds%20%20%0Aspace%20-2.8%0APeer%20-x%20Host%3A%20ATT_READ_RSP%0Aaboxright%20left%20of%20Host%3A%2030%20seconds%20%20%0Aspace%20-5.4%0AHost%20-%3E%20Host%3A%20bt_conn_disconnect%0Aspace%20-2.8%0Adeactivate%20HostAppHostPeerbt_gatt_read(cb)ATT_READ_REQ0 seconds  ATT_READ_RSP30 seconds  bt_conn_disconnect \ No newline at end of file diff --git a/doc/connectivity/networking/api/wifi.rst b/doc/connectivity/networking/api/wifi.rst index 7803a4560559..1499f1c75ab3 100644 --- a/doc/connectivity/networking/api/wifi.rst +++ b/doc/connectivity/networking/api/wifi.rst @@ -38,21 +38,28 @@ module. $ cp client.pem samples/net/wifi/test_certs/ $ cp client-key.pem samples/net/wifi/test_certs/ $ cp ca.pem samples/net/wifi/test_certs/ - $ west build -p -b samples/net/wifi + $ cp client2.pem samples/net/wifi/test_certs/ + $ cp client-key2.pem samples/net/wifi/test_certs/ + $ cp ca2.pem samples/net/wifi/test_certs/ + $ west build -p -b samples/net/wifi -- -DEXTRA_CONF_FILE=overlay-enterprise.conf + +For using variable size network buffer, the following overlay file can be used: + +.. code-block:: bash + + $ west build -p -b samples/net/wifi -- -DEXTRA_CONF_FILE=overlay-enterprise-variable-bufs.conf + + To initiate Wi-Fi connection, the following command can be used: .. code-block:: console - uart:~$ wifi connect -s -k 5 -a anon -K whatever + uart:~$ wifi connect -s -c 149 -k 17 -w 2 -a client1 --key1-pwd whatever --key2-pwd whatever --eap-id1 id1 --eap-pwd1 pwd1 Server certificate is also provided in the same directory for testing purposes. Any AAA server can be used for testing purposes, for example, ``FreeRADIUS`` or ``hostapd``. -.. important:: - - The passphrase for the :file:`client-key.pem`` and the :file:`server-key.pem` is ``whatever``. - .. note:: The certificates are for testing purposes only and should not be used in production. diff --git a/doc/hardware/peripherals/comparator.rst b/doc/hardware/peripherals/comparator.rst new file mode 100644 index 000000000000..e0e634076617 --- /dev/null +++ b/doc/hardware/peripherals/comparator.rst @@ -0,0 +1,69 @@ +.. _comparator_api: + +Comparator +########## + +Overview +******** + +An analog comparator compares the voltages of two analog signals connected to its negative and +positive inputs. If the voltage at the positive input is higher than the negative input, the +comparator's output will be high, otherwise, it will be low. + +Comparators can typically set a trigger which triggers on output changes. This trigger can +either invoke a callback, or its status can be polled. + +Related configuration options: + +* :kconfig:option:`CONFIG_COMPARATOR` + +Configuration +************* + +Embedded comparators can typically be configured at runtime. When enabled, an initial +configuration must be provided using the devicetree. At runtime, comparators can have their +configuration updated using device driver specific APIs. The configuration will be applied +when the comparator is resumed. + +Power management +**************** + +Comparators are enabled using power management. When resumed, the comparator will actively +compare its inputs, producing an output and detecting edges. When suspended, the comparator +will be inactive. + +Comparator shell +**************** + +The comparator shell provides the ``comp`` command with a set of subcommands for the +:ref:`shell ` module. + +The ``comp`` shell command provides the following subcommands: + +* ``get_output`` See :c:func:`comparator_get_output` +* ``set_trigger`` See :c:func:`comparator_set_trigger` +* ``await_trigger`` Awaits trigger using the following flow: + * Set trigger callback using :c:func:`comparator_set_trigger_callback` + * Await callback or time out after default or optionally provided timeout + * Clear trigger callback using :c:func:`comparator_set_trigger_callback` +* ``trigger_is_pending`` See :c:func:`comparator_trigger_is_pending` + +Related configuration options: + +* :kconfig:option:`CONFIG_SHELL` +* :kconfig:option:`CONFIG_COMPARATOR_SHELL` +* :kconfig:option:`CONFIG_COMPARATOR_SHELL_AWAIT_TRIGGER_DEFAULT_TIMEOUT` +* :kconfig:option:`CONFIG_COMPARATOR_SHELL_AWAIT_TRIGGER_MAX_TIMEOUT` + +.. note:: + The power management shell can optionally be enabled alongside the comparator shell. + + Related configuration options: + + * :kconfig:option:`CONFIG_PM_DEVICE` + * :kconfig:option:`CONFIG_PM_DEVICE_SHELL` + +API Reference +************* + +.. doxygengroup:: comparator_interface diff --git a/doc/hardware/peripherals/index.rst b/doc/hardware/peripherals/index.rst index e2574e75993e..2a7405aced2b 100644 --- a/doc/hardware/peripherals/index.rst +++ b/doc/hardware/peripherals/index.rst @@ -18,6 +18,7 @@ Peripherals clock_control.rst can/index.rst charger.rst + comparator.rst coredump.rst counter.rst dac.rst diff --git a/doc/releases/migration-guide-4.0.rst b/doc/releases/migration-guide-4.0.rst index 3699a7fedcbb..3581625f8301 100644 --- a/doc/releases/migration-guide-4.0.rst +++ b/doc/releases/migration-guide-4.0.rst @@ -150,6 +150,11 @@ Sensors to support all JEDEC JC 42.4 compatible temperature sensors. It now uses the :dtcompatible:`jedec,jc-42.4-temp` compatible string instead to the ``microchip,mcp9808`` string. +* The ``nxp,`` prefixed properties in :dtcompatible:`nxp,kinetis-acmp` have been deprecated in favor + of properties without the prefix. The sensor based driver for the :dtcompatible:`nxp,kinetis-acmp` + has been updated to support both the new and deprecated property names. Uses of the deprecated + property names should be updated to the new property names. + Serial ====== diff --git a/doc/releases/release-notes-4.0.rst b/doc/releases/release-notes-4.0.rst index a6964e8a3c32..76eaa3ac62ff 100644 --- a/doc/releases/release-notes-4.0.rst +++ b/doc/releases/release-notes-4.0.rst @@ -96,6 +96,15 @@ Bluetooth * Added API :c:func:`bt_gatt_get_uatt_mtu` to get current Unenhanced ATT MTU of a given connection (experimental). + * The host now disconnects from the peer upon ATT timeout. + + * Added a warning to :c:func:`bt_conn_le_create` and :c:func:`bt_conn_le_create_synced` if + the connection pointer passed as an argument is not NULL. + + * Added Kconfig option :kconfig:option:`CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE` to enforce + :c:func:`bt_conn_le_create` and :c:func:`bt_conn_le_create_synced` return an error if the + connection pointer passed as an argument is not NULL. + * HCI Drivers Boards & SoC Support @@ -145,6 +154,14 @@ Drivers and Sensors * Clock control +* Comparator + + * Introduced comparator device driver subsystem selected with :kconfig:option:`CONFIG_COMPARATOR` + * Introduced comparator shell commands selected with :kconfig:option:`CONFIG_COMPARATOR_SHELL` + * Added support for Nordic nRF COMP (:dtcompatible:`nordic,nrf-comp`) + * Added support for Nordic nRF LPCOMP (:dtcompatible:`nordic,nrf-lpcomp`) + * Added support for NXP Kinetis ACMP (:dtcompatible:`nxp,kinetis-acmp`) + * Counter * DAC @@ -228,6 +245,8 @@ Drivers and Sensors * Serial * LiteX: Renamed the ``compatible`` from ``litex,uart0`` to :dtcompatible:`litex,uart`. + * Nordic: Removed ``CONFIG_UART_n_GPIO_MANAGEMENT`` Kconfig options (where n is an instance + index) which had no use after pinctrl driver was introduced. * SPI diff --git a/doc/services/ipc/ipc_service/backends/icbmsg_flows.svg b/doc/services/ipc/ipc_service/backends/icbmsg_flows.svg new file mode 100644 index 000000000000..f0ecb633a22a --- /dev/null +++ b/doc/services/ipc/ipc_service/backends/icbmsg_flows.svg @@ -0,0 +1,520 @@ + + + + + + + +
+
+
+ ICBMsg +
+ implementation +
+
+
+
+ + ICBMsg... + +
+
+ + + + +
+
+
+ ICBMsg +
+ implementation +
+
+
+
+ + ICBMsg... + +
+
+ + + + + +
+
+
+ ICBMsg +
+ user +
+
+
+
+ + ICBMs... + +
+
+ + + + + +
+
+
+ ICBMsg +
+ user +
+
+
+
+ + ICBMs... + +
+
+ + + + + +
+
+
+ Initiator +
+
+
+
+ + Initiator + +
+
+ + + + +
+
+
+ Follower +
+
+
+
+ + Follower + +
+
+ + + + + + + + + + +
+
+
+ register endpoint +
+ "example1" +
+
+
+
+ + register... + +
+
+ + + + + +
+
+
+ MSG_BOUND, +
+ name "example1", address 0x01 +
+
+
+
+ + MSG_BOUND... + +
+
+ + + + + + +
+
+
+ register endpoint +
+ "example1" +
+
+
+
+ + register... + +
+
+ + + + + +
+
+
+ MSG_RELEASE_BOUND, +
+ address 0x01 +
+
+
+
+ + MSG_RELEA... + +
+
+ + + + + + +
+
+
+ bound callback +
+
+
+
+ + bound cal... + +
+
+ + + + + +
+
+
+ bound callback +
+
+
+
+ + bound cal... + +
+
+ + + + + + +
+
+
+ register endpoint +
+ "example2" +
+
+
+
+ + register... + +
+
+ + + + + +
+
+
+ MSG_BOUND, +
+ name "example2", address 0x02 +
+
+
+
+ + MSG_BOUND... + +
+
+ + + + + + +
+
+
+ register endpoint +
+ "example2" +
+
+
+
+ + register... + +
+
+ + + + + +
+
+
+ MSG_RELEASE_BOUND, +
+ address 0x02 +
+
+
+
+ + MSG_RELEA... + +
+
+ + + + + + +
+
+
+ bound callback +
+
+
+
+ + bound cal... + +
+
+ + + + + +
+
+
+ bound callback +
+
+
+
+ + bound cal... + +
+
+ + + + +
+
+
+ The initiator starts first +
+
+
+
+ + The initiator starts first + +
+
+ + + + +
+
+
+ The follower starts first +
+
+
+
+ + The follower starts first + +
+
+ + + + + + + + +
+
+
+ send data on +
+ endpoint "example2" +
+
+
+
+ + send data... + +
+
+ + + + + +
+
+
+ MSG_DATA, +
+ address 0x02 +
+
+
+
+ + MSG_DATA,... + +
+
+ + + + + + +
+
+
+ return from callback +
+ or data release +
+
+
+
+ + return fr... + +
+
+ + + + + +
+
+
+ MSG_RELEASE_DATA +
+
+
+
+ + MSG_RELEA... + +
+
+ + + + + +
+
+
+ data callback +
+
+
+
+ + data call... + +
+
+ + + + +
+
+
+ Data message +
+
+
+
+ + Data message + +
+
+ +
+ + + + + Text is not SVG - cannot display + + + +
\ No newline at end of file diff --git a/doc/services/ipc/ipc_service/backends/icbmsg_memory.svg b/doc/services/ipc/ipc_service/backends/icbmsg_memory.svg new file mode 100644 index 000000000000..09fcfe2a6f94 --- /dev/null +++ b/doc/services/ipc/ipc_service/backends/icbmsg_memory.svg @@ -0,0 +1,266 @@ + + + + + + + +
+
+
+ ICMsg area +
+
+
+
+ + ICMsg area + +
+
+ + + + +
+
+
+ Blocks area +
+
+
+
+ + Blocks area + +
+
+ + + + +
+
+
+ Block 0 +
+
+
+
+ + Block 0 + +
+
+ + + + +
+
+
+ Block 1 +
+
+
+
+ + Block 1 + +
+
+ + + + +
+
+
+ Block 2 +
+
+
+
+ + Block 2 + +
+
+ + + + +
+
+
+ Block N-1 +
+
+
+
+ + Block N-1 + +
+
+ + + + + + +
+
+
+ Block 3 +
+
+
+
+ + Block 3 + +
+
+ + + + +
+
+
+ rx-region +
+
+
+
+ + rx-region + +
+
+ + + + +
+
+
+ tx-region +
+
+
+
+ + tx-region + +
+
+ + + + + + +
+
+
+ region_begin_aligned +
+
+
+
+ + region_begin_aligned + +
+
+ + + + +
+
+
+ blocks_area_address +
+
+
+
+ + blocks_area_address + +
+
+ + + + +
+
+
+ block_size +
+
+
+
+ + block_size + +
+
+ + + + +
+
+
+ region_end_aligned +
+
+
+
+ + region_end_aligned + +
+
+ + + + + + + + + + + + + +
+
+
+ The same organization as rx-region, but sizes and block count may be different. +
+
+
+
+ + The same organization as rx-region, but... + +
+
+ + +
+ + + + + Text is not SVG - cannot display + + + +
\ No newline at end of file diff --git a/doc/services/ipc/ipc_service/backends/icbmsg_message.svg b/doc/services/ipc/ipc_service/backends/icbmsg_message.svg new file mode 100644 index 000000000000..0252501480b3 --- /dev/null +++ b/doc/services/ipc/ipc_service/backends/icbmsg_message.svg @@ -0,0 +1,209 @@ + + + + + + + +
+
+
+ Block 0 +
+
+
+
+ + Block 0 + +
+
+ + + + +
+
+
+ Block 1 +
+
+
+
+ + Block 1 + +
+
+ + + + +
+
+
+ Block 2 +
+
+
+
+ + Block 2 + +
+
+ + + + +
+
+
+ Block N-1 +
+
+
+
+ + Block N-1 + +
+
+ + + + +
+
+
+ header +
+ (size of data) +
+
+
+
+ + header... + +
+
+ + + + +
+
+
+ data +
+
+
+
+ + data + +
+
+ + + + +
+
+
+ unused +
+
+
+
+ + unused + +
+
+ + + + +
+
+
+ Block 3 +
+
+
+
+ + Block 3 + +
+
+ + + + + + +
+
+
+ Blocks area +
+
+
+
+ + Blocks area + +
+
+ + + + +
+
+
+ Example of a message allocated +
+ on block 1 and 2 +
+
+
+
+ + Example of a message allocated... + +
+
+ + + + + +
+
+
+ 4 bytes +
+
+
+
+ + 4 bytes + +
+
+ + +
+ + + + + Text is not SVG - cannot display + + + +
\ No newline at end of file diff --git a/doc/services/ipc/ipc_service/backends/ipc_service_icbmsg.rst b/doc/services/ipc/ipc_service/backends/ipc_service_icbmsg.rst index f06f7587df60..b1f13d7566a8 100644 --- a/doc/services/ipc/ipc_service/backends/ipc_service_icbmsg.rst +++ b/doc/services/ipc/ipc_service/backends/ipc_service_icbmsg.rst @@ -40,12 +40,21 @@ Configuration The backend is configured using Kconfig and devicetree. When configuring the backend, do the following: +* If at least one of the cores uses data cache on shared memory, set the ``dcache-alignment`` value. + This must be the largest value of the invalidation or the write-back size for both sides of the communication. + You can skip it if none of the communication sides is using data cache on shared memory. * Define two memory regions and assign them to ``tx-region`` and ``rx-region`` of an instance. Ensure that the memory regions used for data exchange are unique (not overlapping any other region) and accessible by both domains (or CPUs). * Define the number of allocable blocks for each region with ``tx-blocks`` and ``rx-blocks``. * Define MBOX devices for sending a signal that informs the other domain (or CPU) of the written data. Ensure that the other domain (or CPU) can receive the signal. +.. caution:: + + Make sure that you set correct value of the ``dcache-alignment``. + At first, wrong value may not show any signs, which may give a false impression that everything works. + Unstable behavior will appear sooner or later. + See the following configuration example for one of the instances: .. code-block:: devicetree @@ -63,6 +72,7 @@ See the following configuration example for one of the instances: ipc { ipc0: ipc0 { compatible = "zephyr,ipc-icbmsg"; + dcache-alignment = <32>; tx-region = <&tx>; rx-region = <&rx>; tx-blocks = <16>; @@ -81,3 +91,300 @@ Samples ======= * :zephyr:code-sample:`ipc_multi_endpoint` + +Detailed Protocol Specification +=============================== + +The ICBMsg protocol transfers messages using dynamically allocated blocks of shared memory. +Internally, it uses ICMsg for control messages. + +Shared Memory Organization +-------------------------- + +The ICBMsg uses two shared memory regions, ``rx-region`` for message receiving, and ``tx-region`` for message transmission. +The regions do not need to be next to each other, placed in any specific order, or be of the same size. +Those regions are interchanged on each core. + +Each shared memory region is divided into following two parts: + +* **ICMsg area** - An area reserved by ICMsg instance and used to transfer the control messages. +* **Blocks area** - An area containing allocatable blocks carrying the content of the messages. + This area is divided into even-sized blocks aligned to cache boundaries. + +The location of each area is calculated to fulfill cache boundary requirements and allow optimal region usage. +It is calculated using the following algorithm: + +Inputs: + +* ``region_begin``, ``region_end`` - Boundaries of the region. +* ``local_blocks`` - Number of blocks in this region. +* ``remote_blocks`` - Number of blocks in the opposite region. +* ``alignment`` - Memory cache alignment. + +The algorithm: + +#. Align region boundaries to cache: + + * ``region_begin_aligned = ROUND_UP(region_begin, alignment)`` + * ``region_end_aligned = ROUND_DOWN(region_end, alignment)`` + * ``region_size_aligned = region_end_aligned - region_begin_aligned`` + +#. Calculate the minimum size required for ICMsg area ``icmsg_min_size``, which is a sum of: + + * ICMsg header size (refer to the ICMsg specification) + * ICMsg message size for 4 bytes of content (refer to the ICMsg specification) multiplied by ``local_blocks + remote_blocks + 2`` + +#. Calculate available size for block area. Note that the actual size may be smaller because of block alignment: + + ``blocks_area_available_size = region_size_aligned - icmsg_min_size`` + +#. Calculate single block size: + + ``block_size = ROUND_DOWN(blocks_area_available_size / local_blocks, alignment)`` + +#. Calculate actual block area size: + + ``blocks_area_size = block_size * local_blocks`` + +#. Calculate block area start address: + + ``blocks_area_begin = region_end_aligned - blocks_area_size`` + +The result: + +* ``region_begin_aligned`` - The start of ICMsg area. +* ``blocks_area_begin`` - End of ICMsg area and the start of block area. +* ``block_size`` - Single block size. +* ``region_end_aligned`` - End of blocks area. + +.. image:: icbmsg_memory.svg + :align: center + +| + +Message Transfer +---------------- + +The ICBMsg uses following two types of messages: + +* **Binding message** - Message exchanged during endpoint binding process (described below). +* **Data message** - Message carrying actual data from a user. + +They serve different purposes, but their lifetime and flow are the same. +The following steps describe it: + +#. The sender wants to send a message that contains ``K`` bytes. +#. The sender reserves blocks from his ``tx-region`` blocks area that can hold at least ``K + 4`` bytes. + The additional ``+ 4`` bytes are reserved for the header, which contains the exact size of the message. + The blocks must be continuous (one after another). + The sender is responsible for block allocation management. + It is up to the implementation to decide what to do if no blocks are available. +#. The sender fills the header with a 32-bit integer value, ``K`` (little-endian). +#. The sender fills the remaining part of the blocks with his data. + Unused space is ignored. +#. The sender sends an ``MSG_DATA`` or ``MSG_BOUND`` control message over ICMsg that contains starting block number (where the header is located). + Details about the control message are in the next section. +#. The control message travels to the receiver. +#. The receiver reads message size and data from his ``rx-region`` starting from the block number received in the control message. +#. The receiver processes the message. +#. The receiver sends ``MSG_RELEASE_DATA`` or ``MSG_RELEASE_BOUND`` control message over ICMsg containing the starting block number + (the same as inside received control message). +#. The control message travels back to the sender. +#. The sender releases the blocks starting from the block number provided in the control message. + The number of blocks to release can be calculated using a size from the header. + +.. image:: icbmsg_message.svg + :align: center + +| + +Control Messages +---------------- + +The control messages are transmitted over ICMsg. +Each control message contains three bytes. +The first byte tells what kind of message it is. + +The allocated size for ICMsg ensures that the maximum possible number of control messages will fit into its ring buffer, +so sending over the ICMsg will never fail because of buffer overflow. + +MSG_DATA +^^^^^^^^ + +.. list-table:: + :header-rows: 1 + + * - byte 0 + - byte 1 + - byte 2 + * - MSG_DATA + - endpoint address + - block number + * - 0x00 + - 0x00 ÷ 0xFD + - 0x00 ÷ N-1 + +The ``MSG_DATA`` control message indicates that a new data message was sent. +The data message starts with a header inside ``block number``. +The data message was sent over the endpoint specified in ``endpoint address``. +The endpoint binding procedure must be finished before sending this control message. + +MSG_RELEASE_DATA +^^^^^^^^^^^^^^^^ + +.. list-table:: + :header-rows: 1 + + * - byte 0 + - byte 1 + - byte 2 + * - MSG_RELEASE_DATA + - unused + - block number + * - 0x01 + - + - 0x00 ÷ N-1 + +The ``MSG_RELEASE_DATA`` control message is sent in response to ``MSG_DATA``. +It informs us that the data message starting with ``block number`` was received and is no longer needed. +When this control message is received, the blocks containing the message must be released. + +MSG_BOUND +^^^^^^^^^ + +.. list-table:: + :header-rows: 1 + + * - byte 0 + - byte 1 + - byte 2 + * - MSG_BOUND + - endpoint address + - block number + * - 0x02 + - 0x00 ÷ 0xFD + - 0x00 ÷ N-1 + +The ``MSG_BOUND`` control message is similar to the ``MSG_DATA`` except the blocks carry binding information. +See the next section for details on the binding procedure. + +MSG_RELEASE_BOUND +^^^^^^^^^^^^^^^^^ + +.. list-table:: + :header-rows: 1 + + * - byte 0 + - byte 1 + - byte 2 + * - MSG_RELEASE_BOUND + - endpoint address + - block number + * - 0x03 + - 0x00 ÷ 0xFD + - 0x00 ÷ N-1 + +The ``MSG_RELEASE_BOUND`` control message is sent in response to ``MSG_BOUND``. +It is similar to the ``MSG_RELEASE_DATA`` except the ``endpoint address`` is required. +See the next section for details on the binding procedure. + +Initialization +-------------- + +The ICBMsg initialization calls ICMsg to initialize. +When it is done, no further initialization is required. +Blocks can be left uninitialized. + +After ICBMsg initialization, you are ready for the endpoint binding procedure. + +Endpoint Binding +----------------- + +So far, the protocol is symmetrical. +Each side of the connection was the same. +The binding process is not symmetrical. +There are following two roles: + +* **Initiator** - It assigns endpoint addresses and sends binding messages. +* **Follower** - It waits for a binding message. + +The roles are determined based on the addresses of the ``rx-region`` and ``tx-region``. + +* If ``address of rx-region < address of tx-region``, then it is initiator. +* If ``address of rx-region > address of tx-region``, then it is follower. + +The binding process needs an endpoint name and is responsible for following two things: + +* To establish a common endpoint address, +* To make sure that two sides are ready to exchange messages over that endpoint. + +After ICMsg is initialized, both sides can start the endpoint binding. +There are no restrictions on the order in which the sides start the endpoint binding. + +Initiator Binding Procedure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The initiator sends a binding message. +It contains a single null-terminated string with an endpoint name. +As usual, it is preceded by a message header containing the message size (including null-terminator). + +Example of the binding message for ``example`` endpoint name: + +.. list-table:: + :header-rows: 1 + + * - Header + - Endpoint name + - Null-terminator + * - bytes 0-3 + - bytes 4-10 + - byte 11 + * - 0x00000008 + - ``example`` + - 0x00 + +The binding message is sent using the ``MSG_BOUND`` control message and released with the ``MSG_RELEASE_BOUND`` control message. + +The endpoint binding procedure from the initiator's point of view is the following: + +#. The initiator assigns an endpoint address to this endpoint. +#. The initiator sends a binding message containing the endpoint name and address. +#. The initiator waits for any message from the follower using this endpoint address. + Usually, it will be ``MSG_RELEASE_BOUND``, but ``MSG_DATA`` is also allowed. +#. The initiator is bound to an endpoint, and it can send data messages using this endpoint. + +Follower Binding Procedure +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +If the follower receives a binding message before it starts the binding procedure on that endpoint, it should store the message for later. +It should not send the ``MSG_RELEASE_BOUND`` yet. + +The endpoint binding procedure from the follower's point of view is the following: + +#. The follower waits for a binding message containing its endpoint name. + The message may be a newly received message or a message stored before the binding procedure started. +#. The follower stores the endpoint address assigned to this endpoint by the initiator. +#. The follower sends the ``MSG_RELEASE_BOUND`` control message. +#. The follower is bound to an endpoint, and it can send data messages using this endpoint. + +Example sequence diagrams +------------------------- + +The following diagram shows a few examples of how the messages flow between two ends. +There is a binding of two endpoints and one fully processed data message exchange. + +.. image:: icbmsg_flows.svg + :align: center + +| + +Protocol Versioning +------------------- + +The protocol allows improvements in future versions. +The newer implementations should be able to work with older ones in backward compatible mode. +To allow it, the current protocol version has the following restrictions: + +* If the receiver receives a longer control message, it should use only the first three bytes and ignore the remaining. +* If the receiver receives a control message starting with a byte that does not match any of the messages described here, it should ignore it. +* If the receiver receives a binding message with additional bytes at the end, it should ignore the additional bytes. diff --git a/doc/services/ipc/ipc_service/backends/ipc_service_icmsg.rst b/doc/services/ipc/ipc_service/backends/ipc_service_icmsg.rst index 1b1298df49b1..251a332027a4 100644 --- a/doc/services/ipc/ipc_service/backends/ipc_service_icmsg.rst +++ b/doc/services/ipc/ipc_service/backends/ipc_service_icmsg.rst @@ -24,6 +24,9 @@ Configuration The backend is configured via Kconfig and devicetree. When configuring the backend, do the following: +* If at least one of the cores uses data cache on shared memory, set the ``dcache-alignment`` value. + This must be the largest value of the invalidation or the write-back size for both sides of the communication. + You can skip it if none of the communication sides is using data cache on shared memory. * Define two memory regions and assign them to ``tx-region`` and ``rx-region`` of an instance. Ensure that the memory regions used for data exchange are unique (not overlapping any other region) and accessible by both domains @@ -32,6 +35,12 @@ When configuring the backend, do the following: domain (or CPU) that data has been written. Ensure that the other domain (or CPU) is able to receive the signal. +.. caution:: + + Make sure that you set correct value of the ``dcache-alignment``. + At first, wrong value may not show any signs, which may give a false impression that everything works. + Unstable behavior will appear sooner or later. + See the following configuration example for one of the instances: .. code-block:: devicetree @@ -49,6 +58,7 @@ See the following configuration example for one of the instances: ipc { ipc0: ipc0 { compatible = "zephyr,ipc-icmsg"; + dcache-alignment = <32>; tx-region = <&tx>; rx-region = <&rx>; mboxes = <&mbox 0>, <&mbox 1>; @@ -84,3 +94,111 @@ Samples ======= - :zephyr:code-sample:`ipc-icmsg` + +Detailed Protocol Specification +=============================== + +The ICMsg uses two shared memory regions and two MBOX channels. +The region and channel pair are used to transfer messages in one direction. +The other pair is symmetric and transfers messages in the opposite direction. +For this reason, the specification below focuses on one such pair. +The other pair is identical. + +The ICMsg provides just one endpoint per instance. + +Shared Memory Region Organization +--------------------------------- + +If data caching is enabled, the shared memory region provided to ICMsg must be aligned according to the cache requirement. +If cache is not enabled, the required alignment is 4 bytes. + +The shared memory region is entirely used by a single FIFO. +It contains read and write indexes followed by the data buffer. +The detailed structure is contained in the following table: + +.. list-table:: + :header-rows: 1 + + * - Field name + - Size (bytes) + - Byte order + - Description + * - ``rd_idx`` + - 4 + - little‑endian + - Index of the first incoming byte in the ``data`` field. + * - ``padding`` + - depends on cache alignment + - n/a + - Padding added to align ``wr_idx`` to the cache alignment. + * - ``wr_idx`` + - 4 + - little‑endian + - Index of the byte after the last incoming byte in the ``data`` field. + * - ``data`` + - everything to the end of the region + - n/a + - Circular buffer containing actual bytes to transfer. + +This is usual FIFO with a circular buffer: + +* The Indexes (``rd_idx`` and ``wr_idx``) are wrapped around when they reach the end of the ``data`` buffer. +* The FIFO is empty if ``rd_idx == wr_idx``. +* The FIFO has one byte less capacity than the ``data`` buffer length. + +Packets +------- + +Packets are sent over the FIFO described in the above section. +One packet can be wrapped around if it occurs at the end of the FIFO buffer. + +The following is the packet structure: + +.. list-table:: + :header-rows: 1 + + * - Field name + - Size (bytes) + - Byte order + - Description + * - ``len`` + - 2 + - big‑endian + - Length of the ``data`` field. + * - ``reserved`` + - 2 + - n/a + - Reserved for the future use. + It must be 0 for the current protocol version. + * - ``data`` + - ``len`` + - n/a + - Packet data. + * - ``padding`` + - 0‑3 + - n/a + - Padding is added to align the total packet size to 4 bytes. + +The packet send procedure is the following: + +#. Check if the packet fits into the buffer. +#. Write the packet to ``data`` FIFO buffer starting at ``wr_idx``. + Wrap it if needed. +#. Write a new value of the ``wr_idx``. +#. Notify the receiver over the MBOX channel. + +Initialization +-------------- + +The initialization sequence is the following: + +#. Set the ``wr_idx`` and ``rd_idx`` to zero. +#. Push a single packet to FIFO containing magic data: ``45 6d 31 6c 31 4b 30 72 6e 33 6c 69 34``. + The MBOX is not used yet. +#. Initialize the MBOX. +#. Repeat the notification over the MBOX channel using some interval, for example, 1 ms. +#. Wait for an incoming packet containing the magic data. + It will arrive over the other pair (shared memory region and MBOX). +#. Stop repeating the MBOX notification. + +After this, the ICMsg is bound, and it is ready to transfer packets. diff --git a/doc/services/storage/zms/zms.rst b/doc/services/storage/zms/zms.rst index 36469f2b1434..02fed3cf77c4 100644 --- a/doc/services/storage/zms/zms.rst +++ b/doc/services/storage/zms/zms.rst @@ -103,7 +103,7 @@ Mounting the storage starts by getting the flash parameters, checking that the f properties are correct (sector_size, sector_count ...) then calling the zms_init function to make the storage ready. -To mount the NVS filesystem some elements in the zms_fs structure must be initialized. +To mount the filesystem some elements in the zms_fs structure must be initialized. .. code-block:: c @@ -155,8 +155,8 @@ ZMS free space calculation ZMS can also return the free space remaining in the partition. However, this operation is very time consuming and needs to browse all valid ATEs in all sectors of the partition and for each valid ATE try to find if an older one exist. -We do not recommend applications to use this function very often at runtime as it could slow -very much the calling thread +It is not recommended for application to use this function often, as it is time consuming and +could slow down the calling thread. The cycle counter ================= @@ -201,9 +201,9 @@ An entry has 16 bytes divided between these variables : struct zms_ate { uint8_t crc8; /* crc8 check of the entry */ - uint8_t cycle_cnt; /* cycle counter for non erasable devices */ - uint32_t id; /* data id */ + uint8_t cycle_cnt; /* cycle counter for non-erasable devices */ uint16_t len; /* data len within sector */ + uint32_t id; /* data id */ union { uint8_t data[8]; /* used to store small size data */ struct { @@ -218,21 +218,22 @@ An entry has 16 bytes divided between these variables : }; } __packed; -.. note:: The data CRC is checked only when the whole data of the element is read. - The data CRC is not checked for a partial read, as it is computed for the complete set of data. +.. note:: The CRC of the data is checked only when the whole the element is read. + The CRC of the data is not checked for a partial read, as it is computed for the whole element. -.. note:: Enabling the data CRC feature on a previously existing ZMS content without - data CRC will make all existing data invalid. +.. note:: Enabling the CRC feature on previously existing ZMS content without CRC enabled + will make all existing data invalid. .. _free-space: Available space for user data (key-value pairs) *********************************************** -For both scenarios ZMS should have always an empty sector to be able to perform the garbage -collection. -So if we suppose that 4 sectors exist in a partition, ZMS will only use 3 sectors to store -Key-value pairs and keep always one (rotating sector) empty to be able to launch GC. +For both scenarios ZMS should always have an empty sector to be able to perform the +garbage collection (GC). +So, if we suppose that 4 sectors exist in a partition, ZMS will only use 3 sectors to store +Key-value pairs and keep one sector empty to be able to launch GC. +The empty sector will rotate between the 4 sectors in the partition. .. note:: The maximum single data length that could be written at once in a sector is 64K (This could change in future versions of ZMS) @@ -240,8 +241,8 @@ Key-value pairs and keep always one (rotating sector) empty to be able to launch Small data values ================= -For small data values (<= 8 bytes), the data is stored within the entry (ATE) itself and no data -is written at the top of the sector. +Values smaller than 8 bytes will be stored within the entry (ATE) itself, without writing data +at the top of the sector. ZMS has an entry size of 16 bytes which means that the maximum available space in a partition to store data is computed in this scenario as : @@ -265,7 +266,7 @@ Large data values ================= Large data values ( > 8 bytes) are stored separately at the top of the sector. -In this case it is hard to estimate the free available space as this depends on the size of +In this case, it is hard to estimate the free available space, as this depends on the size of the data. But we can take into account that for N bytes of data (N > 8 bytes) an additional 16 bytes of ATE must be added at the bottom of the sector. @@ -286,17 +287,17 @@ This storage system is optimized for devices that do not require an erase. Using storage systems that rely on an erase-value (NVS as an example) will need to emulate the erase with write operations. This will cause a significant decrease in the life expectancy of these devices and will cause more delays for write operations and for initialization. -ZMS introduces a cycle count mechanism that avoids emulating erase operation for these devices. +ZMS uses a cycle count mechanism that avoids emulating erase operation for these devices. It also guarantees that every memory location is written only once for each cycle of sector write. -As an example, to erase a 4096 bytes sector on a non erasable device using NVS, 256 flash writes +As an example, to erase a 4096 bytes sector on a non-erasable device using NVS, 256 flash writes must be performed (supposing that write-block-size=16 bytes), while using ZMS only 1 write of 16 bytes is needed. This operation is 256 times faster in this case. Garbage collection operation is also adding some writes to the memory cell life expectancy as it is moving some blocks from one sector to another. To make the garbage collector not affect the life expectancy of the device it is recommended -to dimension correctly the partition size. Its size should be the double of the maximum size of +to correctly dimension the partition size. Its size should be the double of the maximum size of data (including extra headers) that could be written in the storage. See :ref:`free-space`. @@ -307,10 +308,10 @@ Device lifetime calculation Storage devices whether they are classical Flash or new technologies like RRAM/MRAM has a limited life expectancy which is determined by the number of times memory cells can be erased/written. Flash devices are erased one page at a time as part of their functional behavior (otherwise -memory cells cannot be overwritten) and for non erasable storage devices memory cells can be +memory cells cannot be overwritten) and for non-erasable storage devices memory cells can be overwritten directly. -A typical scenario is shown here to calculate the life expectancy of a device. +A typical scenario is shown here to calculate the life expectancy of a device: Let's suppose that we store an 8 bytes variable using the same ID but its content changes every minute. The partition has 4 sectors with 1024 bytes each. Each write of the variable requires 16 bytes of storage. @@ -361,9 +362,9 @@ Existing features ================= Version1 -------- -- Supports non erasable devices (only one write operation to erase a sector) +- Supports non-erasable devices (only one write operation to erase a sector) - Supports large partition size and sector size (64 bits address space) -- Supports large IDs width (32 bits) to store ID/Value pairs +- Supports 32-bit IDs to store ID/Value pairs - Small sized data ( <= 8 bytes) are stored in the ATE itself - Built-in Data CRC32 (included in the ATE) - Versionning of ZMS (to handle future evolution) @@ -375,7 +376,7 @@ Future features - Add multiple format ATE support to be able to use ZMS with different ATE formats that satisfies requirements from application - Add the possibility to skip garbage collector for some application usage where ID/value pairs - are written periodically and do not exceed half of the partition size (ther is always an old + are written periodically and do not exceed half of the partition size (there is always an old entry with the same ID). - Divide IDs into namespaces and allocate IDs on demand from application to handle collisions between IDs used by different subsystems or samples. @@ -394,9 +395,9 @@ functionality: :ref:`NVS ` and :ref:`FCB `. Which one to use in your application will depend on your needs and the hardware you are using, and this section provides information to help make a choice. -- If you are using a non erasable technology device like RRAM or MRAM, :ref:`ZMS ` is definitely the - best fit for your storage subsystem as it is designed very well to avoid emulating erase for - these devices and replace it by a single write call. +- If you are using a non-erasable technology device like RRAM or MRAM, :ref:`ZMS ` is definitely the + best fit for your storage subsystem as it is designed to avoid emulating erase operation using + large block writes for these devices and replaces it with a single write call. - For devices with large write_block_size and/or needs a sector size that is different than the classical flash page size (equal to erase_block_size), :ref:`ZMS ` is also the best fit as there is the possibility to customize these parameters and add the support of these devices in ZMS. @@ -414,6 +415,41 @@ verified to make sure that the application could work with one subsystem or the both solutions could be implemented, the best choice should be based on the calculations of the life expectancy of the device described in this section: :ref:`wear-leveling`. +Recommendations to increase performance +*************************************** + +Sector size and count +===================== + +- The total size of the storage partition should be well dimensioned to achieve the best + performance for ZMS. + All the information regarding the effectively available free space in ZMS can be found + in the documentation. See :ref:`free-space`. + We recommend choosing a storage partition that can hold double the size of the key-value pairs + that will be written in the storage. +- The size of a sector needs to be dimensioned to hold the maximum data length that will be stored. + Increasing the size of a sector will slow down the garbage collection operation which will + occur less frequently. + Decreasing its size, in the opposite, will make the garbage collection operation faster + which will occur more frequently. +- For some subsystems like :ref:`Settings `, all path-value pairs are split into two ZMS entries (ATEs). + The header needed by the two entries should be accounted when computing the needed storage space. +- Using small data to store in the ZMS entries can increase the performance, as this data is + written within the entry header. + For example, for the :ref:`Settings ` subsystem, choosing a path name that is + less than or equal to 8 bytes can make reads and writes faster. + +Dimensioning cache +================== + +- When using ZMS API directly, the recommended cache size should be, at least, equal to + the number of different entries that will be written in the storage. +- Each additional cache entry will add 8 bytes to your RAM usage. Cache size should be carefully + chosen. +- If you use ZMS through :ref:`Settings `, you have to take into account that each Settings entry is + divided into two ZMS entries. The recommended cache size should be, at least, twice the number + of Settings entries. + Sample ****** diff --git a/doc/zephyr.doxyfile.in b/doc/zephyr.doxyfile.in index 05b541c517d9..9245f5989254 100644 --- a/doc/zephyr.doxyfile.in +++ b/doc/zephyr.doxyfile.in @@ -279,9 +279,7 @@ TAB_SIZE = 8 # with the commands \{ and \} for these it is advised to use the version @{ and # @} or use a double escape (\\{ and \\}) -ALIASES = "rst=\verbatim embed:rst:leading-asterisk" \ - endrst=\endverbatim \ - "kconfig{1}=\htmlonly \1 \endhtmlonly \xmlonly embed:rst:inline :kconfig:option:`\1` \endxmlonly" \ +ALIASES = "kconfig{1}=\verbatim \1 \endverbatim" \ "req{1}=\ref ZEPH_\1 \"ZEPH-\1\"" \ "satisfy{1}=\xrefitem satisfy \"Satisfies requirement\" \"Requirement Implementation\" \1" \ "verify{1}=\xrefitem verify \"Verifies requirement\" \"Requirement Verification\" \1" \ @@ -289,14 +287,14 @@ ALIASES = "rst=\verbatim embed:rst:leading-asterisk" \ "kconfig_dep{2}=\attention Available only when the following Kconfig options are enabled: \kconfig{\1}, \kconfig{\2}." \ "kconfig_dep{3}=\attention Available only when the following Kconfig options are enabled: \kconfig{\1}, \kconfig{\2}, \kconfig{\3}." \ "funcprops=\par \"Function properties (list may not be complete)\"" \ - "reschedule=\htmlonly reschedule \endhtmlonly \xmlonly embed:rst:inline :ref:`api_term_reschedule` \endxmlonly" \ - "sleep=\htmlonly sleep \endhtmlonly \xmlonly embed:rst:inline :ref:`api_term_sleep` \endxmlonly" \ - "no_wait=\htmlonly no-wait \endhtmlonly \xmlonly embed:rst:inline :ref:`api_term_no-wait` \endxmlonly" \ - "isr_ok=\htmlonly isr-ok \endhtmlonly \xmlonly embed:rst:inline :ref:`api_term_isr-ok` \endxmlonly" \ - "pre_kernel_ok=\htmlonly pre-kernel-ok \endhtmlonly \xmlonly embed:rst:inline :ref:`api_term_pre-kernel-ok` \endxmlonly" \ - "async=\htmlonly async \endhtmlonly \xmlonly embed:rst:inline :ref:`api_term_async` \endxmlonly" \ + "reschedule=\qualifier reschedule" \ + "sleep=\qualifier sleep" \ + "no_wait=\qualifier no-wait" \ + "isr_ok=\qualifier isr-ok" \ + "pre_kernel_ok=\qualifier pre-kernel-ok" \ + "async=\qualifier async" \ "atomic_api=As for all atomic APIs, includes a full/sequentially-consistent memory barrier (where applicable)." \ - "supervisor=\htmlonly supervisor \endhtmlonly \xmlonly embed:rst:inline :ref:`api_term_supervisor` \endxmlonly" + "supervisor=\qualifier supervisor" # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources # only. Doxygen will then generate output that is more tailored for C. For diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index acf20d2867c0..05be8c3fd01c 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -24,6 +24,7 @@ add_subdirectory_ifdef(CONFIG_CACHE_MANAGEMENT cache) add_subdirectory_ifdef(CONFIG_CAN can) add_subdirectory_ifdef(CONFIG_CHARGER charger) add_subdirectory_ifdef(CONFIG_CLOCK_CONTROL clock_control) +add_subdirectory_ifdef(CONFIG_COMPARATOR comparator) add_subdirectory_ifdef(CONFIG_CONSOLE console) add_subdirectory_ifdef(CONFIG_COREDUMP_DEVICE coredump) add_subdirectory_ifdef(CONFIG_COUNTER counter) diff --git a/drivers/Kconfig b/drivers/Kconfig index ec9e0c77b6d4..db80ba39a66f 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -15,6 +15,7 @@ source "drivers/cache/Kconfig" source "drivers/can/Kconfig" source "drivers/charger/Kconfig" source "drivers/clock_control/Kconfig" +source "drivers/comparator/Kconfig" source "drivers/console/Kconfig" source "drivers/coredump/Kconfig" source "drivers/counter/Kconfig" diff --git a/drivers/adc/adc_gd32.c b/drivers/adc/adc_gd32.c index 75760de6713f..46fbfc783b75 100644 --- a/drivers/adc/adc_gd32.c +++ b/drivers/adc/adc_gd32.c @@ -41,9 +41,9 @@ LOG_MODULE_REGISTER(adc_gd32, CONFIG_ADC_LOG_LEVEL); #define ADC1_NODE DT_NODELABEL(adc1) #define ADC2_NODE DT_NODELABEL(adc2) -#define ADC0_ENABLE DT_NODE_HAS_STATUS(ADC0_NODE, okay) -#define ADC1_ENABLE DT_NODE_HAS_STATUS(ADC1_NODE, okay) -#define ADC2_ENABLE DT_NODE_HAS_STATUS(ADC2_NODE, okay) +#define ADC0_ENABLE DT_NODE_HAS_STATUS_OKAY(ADC0_NODE) +#define ADC1_ENABLE DT_NODE_HAS_STATUS_OKAY(ADC1_NODE) +#define ADC2_ENABLE DT_NODE_HAS_STATUS_OKAY(ADC2_NODE) #ifndef ADC0 /** diff --git a/drivers/adc/adc_nrfx_saadc.c b/drivers/adc/adc_nrfx_saadc.c index e4c37a1f7360..b8782d024548 100644 --- a/drivers/adc/adc_nrfx_saadc.c +++ b/drivers/adc/adc_nrfx_saadc.c @@ -66,9 +66,9 @@ BUILD_ASSERT((NRF_SAADC_AIN0 == NRF_SAADC_INPUT_AIN0) && "Definitions from nrf-adc.h do not match those from nrf_saadc.h"); #endif -#if defined(CONFIG_SOC_NRF54H20) || defined(CONFIG_SOC_NRF9280) +#if defined(CONFIG_NRF_PLATFORM_HALTIUM) -/* nRF54H20 and nRF9280 always use bounce buffers in RAM */ +/* Haltium devices always use bounce buffers in RAM */ #define SAADC_MEMORY_SECTION \ COND_CODE_1(DT_NODE_HAS_PROP(DT_NODELABEL(adc), memory_regions), \ @@ -80,7 +80,7 @@ static uint16_t adc_samples_buffer[SAADC_CH_NUM] SAADC_MEMORY_SECTION; #define ADC_BUFFER_IN_RAM -#endif /* defined(CONFIG_SOC_NRF54H20) || defined(CONFIG_SOC_NRF9280) */ +#endif /* defined(CONFIG_NRF_PLATFORM_HALTIUM) */ struct driver_data { struct adc_context ctx; @@ -669,7 +669,7 @@ static const struct adc_driver_api adc_nrfx_driver_api = { #endif #if defined(CONFIG_SOC_NRF54L15) .ref_internal = 900, -#elif defined(CONFIG_SOC_NRF54H20) || defined(CONFIG_SOC_NRF9280) +#elif defined(CONFIG_NRF_PLATFORM_HALTIUM) .ref_internal = 1024, #else .ref_internal = 600, diff --git a/drivers/audio/dmic_mcux.c b/drivers/audio/dmic_mcux.c index ff357fda9bbb..0f032e8368cc 100644 --- a/drivers/audio/dmic_mcux.c +++ b/drivers/audio/dmic_mcux.c @@ -686,7 +686,7 @@ static const struct _dmic_ops dmic_ops = { /* Gets pointer for a given PDM channel node */ #define PDM_DMIC_CHAN_GET(pdm_node) \ - COND_CODE_1(DT_NODE_HAS_STATUS(pdm_node, okay), \ + COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(pdm_node), \ (&pdm_channel_##pdm_node), (NULL)), /* Gets array of pointers to PDM channels */ diff --git a/drivers/cache/Kconfig.nrf b/drivers/cache/Kconfig.nrf index c1cfc2c8c582..ffcbfe66d195 100644 --- a/drivers/cache/Kconfig.nrf +++ b/drivers/cache/Kconfig.nrf @@ -10,6 +10,6 @@ config CACHE_NRF_CACHE config CACHE_NRF_PATCH_LINEADDR bool "Patch lineaddr" - default y if SOC_NRF54H20 + default y if SOC_NRF54H20 || SOC_NRF54H20_ENGB help Manually set 28th bit in the LINEADDR in Trustzone Secure build. diff --git a/drivers/clock_control/Kconfig.nrf b/drivers/clock_control/Kconfig.nrf index 8c806119fd6c..f7b0de3db090 100644 --- a/drivers/clock_control/Kconfig.nrf +++ b/drivers/clock_control/Kconfig.nrf @@ -175,6 +175,7 @@ endif # CLOCK_CONTROL_NRF config CLOCK_CONTROL_NRF2 bool "nRF clock control support" + default y depends on SOC_SERIES_NRF54HX && !RISCV_CORE_NORDIC_VPR select ONOFF select NRFS if HAS_NRFS diff --git a/drivers/clock_control/clock_control_gd32.c b/drivers/clock_control/clock_control_gd32.c index 1a20d5e4ab21..52b197e2029f 100644 --- a/drivers/clock_control/clock_control_gd32.c +++ b/drivers/clock_control/clock_control_gd32.c @@ -43,7 +43,7 @@ struct clock_control_gd32_config { #if DT_HAS_COMPAT_STATUS_OKAY(gd_gd32_timer) /* timer identifiers */ #define TIMER_ID_OR_NONE(nodelabel) \ - COND_CODE_1(DT_NODE_HAS_STATUS(DT_NODELABEL(nodelabel), okay), \ + COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(nodelabel)), \ (DT_CLOCKS_CELL(DT_NODELABEL(nodelabel), id),), ()) static const uint16_t timer_ids[] = { diff --git a/drivers/clock_control/clock_control_ifx_cat1.c b/drivers/clock_control/clock_control_ifx_cat1.c index 1d89ed0fbe0c..606e06c4e467 100644 --- a/drivers/clock_control/clock_control_ifx_cat1.c +++ b/drivers/clock_control/clock_control_ifx_cat1.c @@ -18,111 +18,111 @@ /* Enumeration of enabled in device tree Clock, uses for indexing clock info table */ enum { -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_imo), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_imo)) INFINEON_CAT1_CLOCK_IMO, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_iho), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_iho)) INFINEON_CAT1_CLOCK_IHO, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(path_mux0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(path_mux0)) INFINEON_CAT1_CLOCK_PATHMUX0, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(path_mux1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(path_mux1)) INFINEON_CAT1_CLOCK_PATHMUX1, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(path_mux2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(path_mux2)) INFINEON_CAT1_CLOCK_PATHMUX2, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(path_mux3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(path_mux3)) INFINEON_CAT1_CLOCK_PATHMUX3, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(path_mux4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(path_mux4)) INFINEON_CAT1_CLOCK_PATHMUX4, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf0)) INFINEON_CAT1_CLOCK_HF0, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf1)) INFINEON_CAT1_CLOCK_HF1, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf2)) INFINEON_CAT1_CLOCK_HF2, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf3)) INFINEON_CAT1_CLOCK_HF3, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf4)) INFINEON_CAT1_CLOCK_HF4, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf5), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf5)) INFINEON_CAT1_CLOCK_HF5, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf6), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf6)) INFINEON_CAT1_CLOCK_HF6, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf7), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf7)) INFINEON_CAT1_CLOCK_HF7, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf8), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf8)) INFINEON_CAT1_CLOCK_HF8, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf9), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf9)) INFINEON_CAT1_CLOCK_HF9, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf10), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf10)) INFINEON_CAT1_CLOCK_HF10, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf11), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf11)) INFINEON_CAT1_CLOCK_HF11, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf12), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf12)) INFINEON_CAT1_CLOCK_HF12, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf13), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf13)) INFINEON_CAT1_CLOCK_HF13, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_fast), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_fast)) INFINEON_CAT1_CLOCK_FAST, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_slow), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_slow)) INFINEON_CAT1_CLOCK_SLOW, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_peri), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_peri)) INFINEON_CAT1_CLOCK_PERI, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pll0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pll0)) INFINEON_CAT1_CLOCK_PLL0, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pll1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pll1)) INFINEON_CAT1_CLOCK_PLL1, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(fll0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(fll0)) INFINEON_CAT1_CLOCK_FLL0, #endif @@ -142,111 +142,111 @@ struct infineon_cat1_clock_info_t { static struct infineon_cat1_clock_info_t clock_info_table[INFINEON_CAT1_ENABLED_CLOCK_COUNT] = { /* We always have IMO */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_imo), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_imo)) [INFINEON_CAT1_CLOCK_IMO] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_imo)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_iho), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_iho)) [INFINEON_CAT1_CLOCK_IHO] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_iho)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(path_mux0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(path_mux0)) [INFINEON_CAT1_CLOCK_PATHMUX0] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(path_mux0)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(path_mux1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(path_mux1)) [INFINEON_CAT1_CLOCK_PATHMUX1] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(path_mux1)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(path_mux2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(path_mux2)) [INFINEON_CAT1_CLOCK_PATHMUX2] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(path_mux2)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(path_mux3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(path_mux3)) [INFINEON_CAT1_CLOCK_PATHMUX3] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(path_mux3)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(path_mux4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(path_mux4)) [INFINEON_CAT1_CLOCK_PATHMUX4] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(path_mux4)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf0)) [INFINEON_CAT1_CLOCK_HF0] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_hf0)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf1)) [INFINEON_CAT1_CLOCK_HF1] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_hf1)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf2)) [INFINEON_CAT1_CLOCK_HF2] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_hf2)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf3)) [INFINEON_CAT1_CLOCK_HF3] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_hf3)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf4)) [INFINEON_CAT1_CLOCK_HF4] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_hf4)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf5), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf5)) [INFINEON_CAT1_CLOCK_HF5] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_hf5)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf6), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf6)) [INFINEON_CAT1_CLOCK_HF6] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_hf6)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf7), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf7)) [INFINEON_CAT1_CLOCK_HF7] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_hf7)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf8), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf8)) [INFINEON_CAT1_CLOCK_HF8] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_hf8)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf9), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf9)) [INFINEON_CAT1_CLOCK_HF9] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_hf9)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf10), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf10)) [INFINEON_CAT1_CLOCK_HF10] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_hf10)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf11), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf11)) [INFINEON_CAT1_CLOCK_HF11] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_hf11)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf12), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf12)) [INFINEON_CAT1_CLOCK_HF12] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_hf12)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf13), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf13)) [INFINEON_CAT1_CLOCK_HF13] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_hf13)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_fast), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_fast)) [INFINEON_CAT1_CLOCK_FAST] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_fast)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_slow), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_slow)) [INFINEON_CAT1_CLOCK_SLOW] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_slow)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_peri), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_peri)) [INFINEON_CAT1_CLOCK_PERI] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(clk_peri)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pll0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pll0)) [INFINEON_CAT1_CLOCK_PLL0] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(pll0)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pll1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pll1)) [INFINEON_CAT1_CLOCK_PLL1] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(pll1)) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(fll0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(fll0)) [INFINEON_CAT1_CLOCK_FLL0] = { .dt_ord = DT_DEP_ORD(DT_NODELABEL(fll0)) }, #endif }; @@ -326,7 +326,7 @@ static cyhal_clock_t *_get_hal_obj_from_ord(uint32_t dt_ord) return ret_obj; } -#if DT_NODE_HAS_STATUS(DT_NODELABEL(dpll_hp), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dpll_hp)) __WEAK void cycfg_ClockStartupError(uint32_t error) { (void)error; /* Suppress the compiler warning */ @@ -390,25 +390,25 @@ static int clock_control_infineon_cat1_init(const struct device *dev) uint32 clock_div; /* Configure IMO */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_imo), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_imo)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_IMO].obj; if (cyhal_clock_get(clock_obj, &CYHAL_CLOCK_RSC_IMO)) { return -EIO; } #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_iho), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_iho)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_IHO].obj; if (cyhal_clock_get(clock_obj, &CYHAL_CLOCK_RSC_IHO)) { return -EIO; } #endif -#if !DT_NODE_HAS_STATUS(DT_NODELABEL(clk_imo), okay) && \ - !DT_NODE_HAS_STATUS(DT_NODELABEL(clk_iho), okay) +#if !DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_imo)) && \ + !DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_iho)) #error "IMO clock or IHO clock must be enabled" #endif /* Configure the PathMux[0] to source defined in tree device 'path_mux0' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(path_mux0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(path_mux0)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_PATHMUX0].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(path_mux0)); @@ -418,7 +418,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the PathMux[1] to source defined in tree device 'path_mux1' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(path_mux1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(path_mux1)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_PATHMUX1].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(path_mux1)); @@ -428,7 +428,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the PathMux[2] to source defined in tree device 'path_mux2' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(path_mux2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(path_mux2)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_PATHMUX2].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(path_mux2)); @@ -438,7 +438,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the PathMux[3] to source defined in tree device 'path_mux3' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(path_mux3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(path_mux3)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_PATHMUX3].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(path_mux3)); @@ -448,7 +448,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the PathMux[4] to source defined in tree device 'path_mux4' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(path_mux4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(path_mux4)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_PATHMUX4].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(path_mux4)); @@ -458,7 +458,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure FLL0 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(fll0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(fll0)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_FLL0].obj; frequency = DT_PROP(DT_NODELABEL(fll0), clock_frequency); @@ -470,7 +470,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure PLL0 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pll0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pll0)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_PLL0].obj; frequency = DT_PROP(DT_NODELABEL(pll0), clock_frequency); @@ -483,7 +483,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure PLL1 */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pll1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pll1)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_PLL1].obj; frequency = DT_PROP(DT_NODELABEL(pll1), clock_frequency); @@ -495,7 +495,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the HF[0] to source defined in tree device 'clk_hf0' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf0)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_HF0].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(clk_hf0)); clock_div = DT_PROP(DT_NODELABEL(clk_hf0), clock_div); @@ -506,7 +506,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the HF[1] to source defined in tree device 'clk_hf1' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf1)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_HF1].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(clk_hf1)); clock_div = DT_PROP(DT_NODELABEL(clk_hf1), clock_div); @@ -517,7 +517,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the HF[2] to source defined in tree device 'clk_hf2' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf2)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_HF2].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(clk_hf2)); clock_div = DT_PROP(DT_NODELABEL(clk_hf2), clock_div); @@ -528,7 +528,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the HF[3] to source defined in tree device 'clk_hf3' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf3)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_HF3].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(clk_hf3)); clock_div = DT_PROP(DT_NODELABEL(clk_hf3), clock_div); @@ -539,7 +539,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the HF[4] to source defined in tree device 'clk_hf4' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf4)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_HF4].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(clk_hf4)); clock_div = DT_PROP(DT_NODELABEL(clk_hf4), clock_div); @@ -550,7 +550,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the HF[5] to source defined in tree device 'clk_hf5' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf5), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf5)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_HF5].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(clk_hf5)); clock_div = DT_PROP(DT_NODELABEL(clk_hf5), clock_div); @@ -561,7 +561,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the HF[6] to source defined in tree device 'clk_hf6' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf6), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf6)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_HF6].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(clk_hf6)); clock_div = DT_PROP(DT_NODELABEL(clk_hf6), clock_div); @@ -572,7 +572,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the HF[7] to source defined in tree device 'clk_hf7' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf7), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf7)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_HF7].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(clk_hf7)); clock_div = DT_PROP(DT_NODELABEL(clk_hf7), clock_div); @@ -583,7 +583,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the HF[8] to source defined in tree device 'clk_hf8' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf8), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf8)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_HF8].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(clk_hf8)); clock_div = DT_PROP(DT_NODELABEL(clk_hf8), clock_div); @@ -594,7 +594,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the HF[9] to source defined in tree device 'clk_hf9' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf9), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf9)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_HF9].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(clk_hf9)); clock_div = DT_PROP(DT_NODELABEL(clk_hf9), clock_div); @@ -605,7 +605,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the HF[10] to source defined in tree device 'clk_hf10' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf10), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf10)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_HF10].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(clk_hf10)); clock_div = DT_PROP(DT_NODELABEL(clk_hf10), clock_div); @@ -616,7 +616,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the HF[11] to source defined in tree device 'clk_hf11' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf11), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf11)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_HF11].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(clk_hf11)); clock_div = DT_PROP(DT_NODELABEL(clk_hf11), clock_div); @@ -627,7 +627,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the HF[12] to source defined in tree device 'clk_hf12' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf12), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf12)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_HF12].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(clk_hf12)); clock_div = DT_PROP(DT_NODELABEL(clk_hf12), clock_div); @@ -638,7 +638,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the HF[13] to source defined in tree device 'clk_hf13' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_hf13), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_hf13)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_HF13].obj; clock_source_obj = _get_hal_obj_from_ord(GET_CLK_SOURCE_ORD(clk_hf13)); clock_div = DT_PROP(DT_NODELABEL(clk_hf13), clock_div); @@ -649,7 +649,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the clock fast to source defined in tree device 'clk_fast' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_fast), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_fast)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_FAST].obj; clock_div = DT_PROP(DT_NODELABEL(clk_fast), clock_div); @@ -663,7 +663,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the clock peri to source defined in tree device 'clk_peri' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_peri), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_peri)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_PERI].obj; clock_div = DT_PROP(DT_NODELABEL(clk_peri), clock_div); @@ -677,7 +677,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) #endif /* Configure the clock slow to source defined in tree device 'clk_slow' node */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_slow), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_slow)) clock_obj = &clock_info_table[INFINEON_CAT1_CLOCK_SLOW].obj; clock_div = DT_PROP(DT_NODELABEL(clk_slow), clock_div); @@ -690,7 +690,7 @@ static int clock_control_infineon_cat1_init(const struct device *dev) } #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(dpll_hp), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dpll_hp)) Cy_SysClk_Dpll_Hp0_Init(); SystemCoreClockUpdate(); #endif @@ -713,7 +713,7 @@ static const struct clock_control_driver_api clock_control_infineon_cat1_api = { .off = clock_control_infineon_cat_on_off }; -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_imo), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_imo)) DEVICE_DT_DEFINE(DT_NODELABEL(clk_imo), clock_control_infineon_cat1_init, NULL, @@ -723,7 +723,7 @@ DEVICE_DT_DEFINE(DT_NODELABEL(clk_imo), CONFIG_CLOCK_CONTROL_INIT_PRIORITY, &clock_control_infineon_cat1_api); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_iho), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_iho)) DEVICE_DT_DEFINE(DT_NODELABEL(clk_iho), clock_control_infineon_cat1_init, NULL, diff --git a/drivers/clock_control/clock_control_litex.h b/drivers/clock_control/clock_control_litex.h index 14d371c077c6..8a1b25de4007 100644 --- a/drivers/clock_control/clock_control_litex.h +++ b/drivers/clock_control/clock_control_litex.h @@ -73,7 +73,7 @@ lcko->margin.exp = CLKOUT_MARGIN_EXP(N); /* Devicetree clkout defines */ -#define CLKOUT_EXIST(N) DT_NODE_HAS_STATUS(DT_NODELABEL(clk##N), okay) +#define CLKOUT_EXIST(N) DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk##N)) #define CLKOUT_ID(N) DT_REG_ADDR(DT_NODELABEL(clk##N)) #define CLKOUT_FREQ(N) DT_PROP(DT_NODELABEL(clk##N), \ litex_clock_frequency) diff --git a/drivers/clock_control/clock_control_max32.c b/drivers/clock_control/clock_control_max32.c index 2cbed41bd23a..29d7cc2fef42 100644 --- a/drivers/clock_control/clock_control_max32.c +++ b/drivers/clock_control/clock_control_max32.c @@ -106,27 +106,27 @@ static void setup_fixed_clocks(void) MXC_SYS_ClockSourceDisable(ADI_MAX32_CLK_EXTCLK); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_ipo), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_ipo)) MXC_SYS_ClockSourceEnable(ADI_MAX32_CLK_IPO); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_erfo), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_erfo)) MXC_SYS_ClockSourceEnable(ADI_MAX32_CLK_ERFO); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_ibro), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_ibro)) MXC_SYS_ClockSourceEnable(ADI_MAX32_CLK_IBRO); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_iso), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_iso)) MXC_SYS_ClockSourceEnable(ADI_MAX32_CLK_ISO); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_inro), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_inro)) MXC_SYS_ClockSourceEnable(ADI_MAX32_CLK_INRO); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(clk_ertco), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_ertco)) MXC_SYS_ClockSourceEnable(ADI_MAX32_CLK_ERTCO); #endif diff --git a/drivers/clock_control/clock_control_mcux_ccm.c b/drivers/clock_control/clock_control_mcux_ccm.c index 8ff096723521..c3b7f2416c47 100644 --- a/drivers/clock_control/clock_control_mcux_ccm.c +++ b/drivers/clock_control/clock_control_mcux_ccm.c @@ -216,14 +216,14 @@ static int mcux_ccm_get_subsys_rate(const struct device *dev, #endif #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usdhc1), okay) && CONFIG_IMX_USDHC +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usdhc1)) && CONFIG_IMX_USDHC case IMX_CCM_USDHC1_CLK: *rate = CLOCK_GetSysPfdFreq(kCLOCK_Pfd0) / (CLOCK_GetDiv(kCLOCK_Usdhc1Div) + 1U); break; #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usdhc2), okay) && CONFIG_IMX_USDHC +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usdhc2)) && CONFIG_IMX_USDHC case IMX_CCM_USDHC2_CLK: *rate = CLOCK_GetSysPfdFreq(kCLOCK_Pfd0) / (CLOCK_GetDiv(kCLOCK_Usdhc2Div) + 1U); @@ -339,12 +339,12 @@ static int mcux_ccm_get_subsys_rate(const struct device *dev, / (CLOCK_GetDiv(kCLOCK_Sai3Div) + 1); break; #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexspi), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexspi)) case IMX_CCM_FLEXSPI_CLK: *rate = CLOCK_GetClockRootFreq(kCLOCK_FlexspiClkRoot); break; #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexspi2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexspi2)) case IMX_CCM_FLEXSPI2_CLK: *rate = CLOCK_GetClockRootFreq(kCLOCK_Flexspi2ClkRoot); break; @@ -354,7 +354,7 @@ static int mcux_ccm_get_subsys_rate(const struct device *dev, *rate = CLOCK_GetFreq(kCLOCK_PerClk); break; #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexio1), okay) && CONFIG_MCUX_FLEXIO +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexio1)) && CONFIG_MCUX_FLEXIO case IMX_CCM_FLEXIO1_CLK: { uint32_t flexio_mux = CLOCK_GetMux(kCLOCK_Flexio1Mux); @@ -376,8 +376,8 @@ static int mcux_ccm_get_subsys_rate(const struct device *dev, / (CLOCK_GetDiv(kCLOCK_Flexio1Div) + 1); } break; #endif -#if (DT_NODE_HAS_STATUS(DT_NODELABEL(flexio2), okay) \ - || DT_NODE_HAS_STATUS(DT_NODELABEL(flexio3), okay)) && CONFIG_MCUX_FLEXIO +#if (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexio2)) \ + || DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexio3))) && CONFIG_MCUX_FLEXIO case IMX_CCM_FLEXIO2_3_CLK: { uint32_t flexio_mux = CLOCK_GetMux(kCLOCK_Flexio2Mux); diff --git a/drivers/clock_control/clock_control_mcux_scg.c b/drivers/clock_control/clock_control_mcux_scg.c index 5642aabe8dd7..684cb8f2aa21 100644 --- a/drivers/clock_control/clock_control_mcux_scg.c +++ b/drivers/clock_control/clock_control_mcux_scg.c @@ -125,7 +125,7 @@ static int mcux_scg_get_rate(const struct device *dev, static int mcux_scg_init(const struct device *dev) { -#if DT_NODE_HAS_STATUS(MCUX_SCG_CLOCK_NODE(clkout_clk), okay) +#if DT_NODE_HAS_STATUS_OKAY(MCUX_SCG_CLOCK_NODE(clkout_clk)) #if DT_SAME_NODE(DT_CLOCKS_CTLR(MCUX_SCG_CLOCK_NODE(clkout_clk)), MCUX_SCG_CLOCK_NODE(slow_clk)) CLOCK_SetClkOutSel(kClockClkoutSelScgSlow); #elif DT_SAME_NODE(DT_CLOCKS_CTLR(MCUX_SCG_CLOCK_NODE(clkout_clk)), MCUX_SCG_CLOCK_NODE(sosc_clk)) @@ -139,7 +139,7 @@ static int mcux_scg_init(const struct device *dev) #else #error Unsupported SCG clkout clock source #endif -#endif /* DT_NODE_HAS_STATUS(MCUX_SCG_CLOCK_NODE(clkout_clk), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(MCUX_SCG_CLOCK_NODE(clkout_clk)) */ return 0; } diff --git a/drivers/clock_control/clock_control_mcux_sim.c b/drivers/clock_control/clock_control_mcux_sim.c index 26c9a3c1c2a6..2b16e5d6361b 100644 --- a/drivers/clock_control/clock_control_mcux_sim.c +++ b/drivers/clock_control/clock_control_mcux_sim.c @@ -67,7 +67,7 @@ static int mcux_sim_get_subsys_rate(const struct device *dev, return 0; } -#if DT_NODE_HAS_STATUS(DT_INST(0, nxp_kinetis_ke1xf_sim), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nxp_kinetis_ke1xf_sim)) #define NXP_KINETIS_SIM_NODE DT_INST(0, nxp_kinetis_ke1xf_sim) #if DT_NODE_HAS_PROP(DT_INST(0, nxp_kinetis_ke1xf_sim), clkout_source) #define NXP_KINETIS_SIM_CLKOUT_SOURCE \ diff --git a/drivers/clock_control/clock_control_nrf2_fll16m.c b/drivers/clock_control/clock_control_nrf2_fll16m.c index 7f3bf0aaceeb..613e433e5274 100644 --- a/drivers/clock_control/clock_control_nrf2_fll16m.c +++ b/drivers/clock_control/clock_control_nrf2_fll16m.c @@ -26,7 +26,7 @@ BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 1, #define FLL16M_LFXO_NODE DT_INST_PHANDLE_BY_NAME(0, clocks, lfxo) #define FLL16M_HFXO_NODE DT_INST_PHANDLE_BY_NAME(0, clocks, hfxo) -#define FLL16M_HAS_LFXO DT_NODE_HAS_STATUS(FLL16M_LFXO_NODE, okay) +#define FLL16M_HAS_LFXO DT_NODE_HAS_STATUS_OKAY(FLL16M_LFXO_NODE) #define FLL16M_LFXO_ACCURACY DT_PROP(FLL16M_LFXO_NODE, accuracy_ppm) #define FLL16M_HFXO_ACCURACY DT_PROP(FLL16M_HFXO_NODE, accuracy_ppm) diff --git a/drivers/clock_control/clock_control_nrf2_hsfll.c b/drivers/clock_control/clock_control_nrf2_hsfll.c index 90cd56318dd7..026edf9abbd5 100644 --- a/drivers/clock_control/clock_control_nrf2_hsfll.c +++ b/drivers/clock_control/clock_control_nrf2_hsfll.c @@ -17,7 +17,7 @@ LOG_MODULE_DECLARE(clock_control_nrf2, CONFIG_CLOCK_CONTROL_LOG_LEVEL); BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 1, "multiple instances not supported"); -#ifdef CONFIG_NRFS_HAS_DVFS_SERVICE +#ifdef CONFIG_NRFS_DVFS_LOCAL_DOMAIN #include #define FLAG_FREQ_CHANGE_CB_EXPECTED BIT(FLAGS_COMMON_BITS) @@ -131,13 +131,13 @@ static struct onoff_manager *hsfll_find_mgr(const struct device *dev, LOG_ERR("invalid frequency"); return NULL; } -#endif /* CONFIG_NRFS_HAS_DVFS_SERVICE */ +#endif /* CONFIG_NRFS_DVFS_LOCAL_DOMAIN */ static int api_request_hsfll(const struct device *dev, const struct nrf_clock_spec *spec, struct onoff_client *cli) { -#ifdef CONFIG_NRFS_HAS_DVFS_SERVICE +#ifdef CONFIG_NRFS_DVFS_LOCAL_DOMAIN struct onoff_manager *mgr = hsfll_find_mgr(dev, spec); if (mgr) { @@ -153,7 +153,7 @@ static int api_request_hsfll(const struct device *dev, static int api_release_hsfll(const struct device *dev, const struct nrf_clock_spec *spec) { -#ifdef CONFIG_NRFS_HAS_DVFS_SERVICE +#ifdef CONFIG_NRFS_DVFS_LOCAL_DOMAIN struct onoff_manager *mgr = hsfll_find_mgr(dev, spec); if (mgr) { @@ -170,7 +170,7 @@ static int api_cancel_or_release_hsfll(const struct device *dev, const struct nrf_clock_spec *spec, struct onoff_client *cli) { -#ifdef CONFIG_NRFS_HAS_DVFS_SERVICE +#ifdef CONFIG_NRFS_DVFS_LOCAL_DOMAIN struct onoff_manager *mgr = hsfll_find_mgr(dev, spec); if (mgr) { @@ -197,7 +197,7 @@ static int api_get_rate_hsfll(const struct device *dev, static int hsfll_init(const struct device *dev) { -#ifdef CONFIG_NRFS_HAS_DVFS_SERVICE +#ifdef CONFIG_NRFS_DVFS_LOCAL_DOMAIN struct hsfll_dev_data *dev_data = dev->data; int rc; @@ -228,12 +228,12 @@ static struct nrf_clock_control_driver_api hsfll_drv_api = { .cancel_or_release = api_cancel_or_release_hsfll, }; -#ifdef CONFIG_NRFS_HAS_DVFS_SERVICE +#ifdef CONFIG_NRFS_DVFS_LOCAL_DOMAIN static struct hsfll_dev_data hsfll_data; #endif DEVICE_DT_INST_DEFINE(0, hsfll_init, NULL, - COND_CODE_1(CONFIG_NRFS_HAS_DVFS_SERVICE, + COND_CODE_1(CONFIG_NRFS_DVFS_LOCAL_DOMAIN, (&hsfll_data), (NULL)), NULL, diff --git a/drivers/clock_control/clock_control_nrf2_lfclk.c b/drivers/clock_control/clock_control_nrf2_lfclk.c index 9ce7974570e6..36b8e2472977 100644 --- a/drivers/clock_control/clock_control_nrf2_lfclk.c +++ b/drivers/clock_control/clock_control_nrf2_lfclk.c @@ -19,7 +19,7 @@ BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 1, #define LFCLK_LFXO_NODE DT_INST_PHANDLE_BY_NAME(0, clocks, lfxo) #define LFCLK_HFXO_NODE DT_INST_PHANDLE_BY_NAME(0, clocks, hfxo) -#define LFCLK_HAS_LFXO DT_NODE_HAS_STATUS(LFCLK_LFXO_NODE, okay) +#define LFCLK_HAS_LFXO DT_NODE_HAS_STATUS_OKAY(LFCLK_LFXO_NODE) #define LFCLK_LFLPRC_ACCURACY DT_INST_PROP(0, lflprc_accuracy_ppm) #define LFCLK_LFRC_ACCURACY DT_INST_PROP(0, lfrc_accuracy_ppm) diff --git a/drivers/clock_control/clock_control_renesas_ra.c b/drivers/clock_control/clock_control_renesas_ra.c index 0b058633151c..3065c94e785a 100644 --- a/drivers/clock_control/clock_control_renesas_ra.c +++ b/drivers/clock_control/clock_control_renesas_ra.c @@ -38,7 +38,7 @@ #define CLKSRC_FREQ(clk) DT_PROP(DT_PATH(clocks, clk), clock_frequency) -#define IS_CLKSRC_ENABLED(clk) DT_NODE_HAS_STATUS(DT_PATH(clocks, clk), okay) +#define IS_CLKSRC_ENABLED(clk) DT_NODE_HAS_STATUS_OKAY(DT_PATH(clocks, clk)) #define SCKSCR_INIT_VALUE _CONCAT(CLKSRC_, SYSCLK_SRC) diff --git a/drivers/clock_control/clock_control_renesas_ra_cgc.c b/drivers/clock_control/clock_control_renesas_ra_cgc.c index b03852fc86e1..70512905be7a 100644 --- a/drivers/clock_control/clock_control_renesas_ra_cgc.c +++ b/drivers/clock_control/clock_control_renesas_ra_cgc.c @@ -12,7 +12,7 @@ #include #include -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pclkblock), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pclkblock)) #define MSTP_REGS_ELEM(node_id, prop, idx) \ [DT_STRING_TOKEN_BY_IDX(node_id, prop, idx)] = \ (volatile uint32_t *)DT_REG_ADDR_BY_IDX(node_id, idx), diff --git a/drivers/clock_control/clock_control_smartbond.c b/drivers/clock_control/clock_control_smartbond.c index ed0cc2052642..3d866fb4c582 100644 --- a/drivers/clock_control/clock_control_smartbond.c +++ b/drivers/clock_control/clock_control_smartbond.c @@ -265,7 +265,7 @@ static inline int smartbond_clock_control_off(const struct device *dev, switch (clk) { case SMARTBOND_CLK_RC32K: /* RC32K is used by POWERUP and WAKEUP HW FSM */ - BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(rc32k), okay), + BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(rc32k)), "RC32K is not allowed to be turned off"); ret = -EPERM; break; @@ -472,12 +472,12 @@ static void smartbond_clock_control_update_memory_settings(uint32_t sys_clock_fr { if (sys_clock_freq > 32000000) { da1469x_qspi_set_read_pipe_delay(QSPIC_ID, 7); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(memc), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(memc)) da1469x_qspi_set_read_pipe_delay(QSPIC2_ID, 7); #endif } else { da1469x_qspi_set_read_pipe_delay(QSPIC_ID, 2); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(memc), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(memc)) da1469x_qspi_set_read_pipe_delay(QSPIC2_ID, 2); #endif } @@ -485,7 +485,7 @@ static void smartbond_clock_control_update_memory_settings(uint32_t sys_clock_fr da1469x_qspi_set_cs_delay(QSPIC_ID, SystemCoreClock, DT_PROP(DT_NODELABEL(flash_controller), read_cs_idle_delay), DT_PROP(DT_NODELABEL(flash_controller), erase_cs_idle_delay)); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(memc), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(memc)) da1469x_qspi_set_cs_delay(QSPIC2_ID, SystemCoreClock, DT_PROP(DT_NODELABEL(memc), read_cs_idle_min_ns), DT_PROP_OR(DT_NODELABEL(memc), erase_cs_idle_min_ns, 0)); @@ -565,7 +565,7 @@ int smartbond_clocks_init(const struct device *dev) ARG_UNUSED(dev); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(memc), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(memc)) /* Make sure QSPIC2 is enabled */ da1469x_clock_amba_enable(CRG_TOP_CLK_AMBA_REG_QSPI2_ENABLE_Msk); #endif @@ -579,12 +579,12 @@ int smartbond_clocks_init(const struct device *dev) DT_FOREACH_CHILD_STATUS_OKAY_SEP(DT_PATH(crg, osc), ENABLE_OSC, (;)); /* Make sure that selected sysclock is enabled */ - BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_PROP(DT_NODELABEL(sys_clk), clock_src), okay), + BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(DT_PROP(DT_NODELABEL(sys_clk), clock_src)), "Clock selected as system clock no enabled in DT"); - BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_PROP(DT_NODELABEL(lp_clk), clock_src), okay), + BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(DT_PROP(DT_NODELABEL(lp_clk), clock_src)), "Clock selected as LP clock no enabled in DT"); BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(pll), disabled) || - DT_NODE_HAS_STATUS(DT_NODELABEL(xtal32m), okay), + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(xtal32m)), "PLL enabled in DT but XTAL32M is disabled"); clk_id = DT_DEP_ORD(DT_PROP(DT_NODELABEL(lp_clk), clock_src)); @@ -616,7 +616,7 @@ static int smartbond_clocks_pm_action(const struct device *dev, enum pm_device_a case PM_DEVICE_ACTION_SUSPEND: break; case PM_DEVICE_ACTION_RESUME: -#if DT_NODE_HAS_STATUS(DT_NODELABEL(memc), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(memc)) /* Make sure QSPIC2 is enabled */ da1469x_clock_amba_enable(CRG_TOP_CLK_AMBA_REG_QSPI2_ENABLE_Msk); #endif diff --git a/drivers/clock_control/clock_stm32_ll_wb0.c b/drivers/clock_control/clock_stm32_ll_wb0.c index 6654867e01e7..3a08cf64067b 100644 --- a/drivers/clock_control/clock_stm32_ll_wb0.c +++ b/drivers/clock_control/clock_stm32_ll_wb0.c @@ -39,7 +39,7 @@ #if DT_NODE_HAS_PROP(STM32_CLOCK_CONTROL_NODE, slow_clock) -# if !DT_NODE_HAS_STATUS(DT_RCC_SLOWCLK_NODE, okay) +# if !DT_NODE_HAS_STATUS_OKAY(DT_RCC_SLOWCLK_NODE) # error slow-clock source is not enabled # endif diff --git a/drivers/comparator/CMakeLists.txt b/drivers/comparator/CMakeLists.txt new file mode 100644 index 000000000000..43462d64288a --- /dev/null +++ b/drivers/comparator/CMakeLists.txt @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +zephyr_syscall_header(${ZEPHYR_BASE}/include/zephyr/drivers/comparator.h) + +zephyr_library() + +zephyr_library_sources_ifdef(CONFIG_USERSPACE comparator_handlers.c) +zephyr_library_sources_ifdef(CONFIG_COMPARATOR_FAKE_COMP comparator_fake_comp.c) +zephyr_library_sources_ifdef(CONFIG_COMPARATOR_MCUX_ACMP comparator_mcux_acmp.c) +zephyr_library_sources_ifdef(CONFIG_COMPARATOR_NRF_COMP comparator_nrf_comp.c) +zephyr_library_sources_ifdef(CONFIG_COMPARATOR_NRF_LPCOMP comparator_nrf_lpcomp.c) +zephyr_library_sources_ifdef(CONFIG_COMPARATOR_SHELL comparator_shell.c) diff --git a/drivers/comparator/Kconfig b/drivers/comparator/Kconfig new file mode 100644 index 000000000000..978adc032517 --- /dev/null +++ b/drivers/comparator/Kconfig @@ -0,0 +1,27 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +menuconfig COMPARATOR + bool "Comparator drivers" + help + Enable comparator driver configuration. + +if COMPARATOR + +module = COMPARATOR +module-str = comparator +source "subsys/logging/Kconfig.template.log_config" + +config COMPARATOR_INIT_PRIORITY + int "COMPARATOR init priority" + default KERNEL_INIT_PRIORITY_DEVICE + help + Comparator device driver initialization priority. + +rsource "Kconfig.fake_comp" +rsource "Kconfig.mcux_acmp" +rsource "Kconfig.nrf_comp" +rsource "Kconfig.nrf_lpcomp" +rsource "Kconfig.shell" + +endif # COMPARATOR diff --git a/drivers/comparator/Kconfig.fake_comp b/drivers/comparator/Kconfig.fake_comp new file mode 100644 index 000000000000..5fca8db18780 --- /dev/null +++ b/drivers/comparator/Kconfig.fake_comp @@ -0,0 +1,8 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config COMPARATOR_FAKE_COMP + bool "Fake comparator driver" + default y + depends on DT_HAS_ZEPHYR_FAKE_COMP_ENABLED + depends on ZTEST diff --git a/drivers/comparator/Kconfig.mcux_acmp b/drivers/comparator/Kconfig.mcux_acmp new file mode 100644 index 000000000000..8109cb1cdd2d --- /dev/null +++ b/drivers/comparator/Kconfig.mcux_acmp @@ -0,0 +1,9 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config COMPARATOR_MCUX_ACMP + bool "NXP MCUX ACMP comparator driver" + default y + depends on DT_HAS_NXP_KINETIS_ACMP_ENABLED + select PINCTRL + select MCUX_ACMP diff --git a/drivers/comparator/Kconfig.nrf_comp b/drivers/comparator/Kconfig.nrf_comp new file mode 100644 index 000000000000..0e0c889f3ee0 --- /dev/null +++ b/drivers/comparator/Kconfig.nrf_comp @@ -0,0 +1,8 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config COMPARATOR_NRF_COMP + bool "Nordic COMP comparator driver" + default y + depends on DT_HAS_NORDIC_NRF_COMP_ENABLED + select NRFX_COMP diff --git a/drivers/comparator/Kconfig.nrf_lpcomp b/drivers/comparator/Kconfig.nrf_lpcomp new file mode 100644 index 000000000000..f33de46f15d9 --- /dev/null +++ b/drivers/comparator/Kconfig.nrf_lpcomp @@ -0,0 +1,8 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config COMPARATOR_NRF_LPCOMP + bool "Nordic LPCOMP comparator driver" + default y + depends on DT_HAS_NORDIC_NRF_LPCOMP_ENABLED + select NRFX_LPCOMP diff --git a/drivers/comparator/Kconfig.shell b/drivers/comparator/Kconfig.shell new file mode 100644 index 000000000000..de244619be33 --- /dev/null +++ b/drivers/comparator/Kconfig.shell @@ -0,0 +1,21 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config COMPARATOR_SHELL + bool "Comparator shell" + default y + depends on SHELL + help + Comparator device driver shell. + +if COMPARATOR_SHELL + +config COMPARATOR_SHELL_AWAIT_TRIGGER_DEFAULT_TIMEOUT + int "Default timeout for await_trigger command in seconds" + default 10 + +config COMPARATOR_SHELL_AWAIT_TRIGGER_MAX_TIMEOUT + int "Max timeout for await_trigger command in seconds" + default 60 + +endif # COMPARATOR_SHELL diff --git a/drivers/comparator/comparator_fake_comp.c b/drivers/comparator/comparator_fake_comp.c new file mode 100644 index 000000000000..85abbad21743 --- /dev/null +++ b/drivers/comparator/comparator_fake_comp.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#ifdef CONFIG_ZTEST +#include +#endif + +#define DT_DRV_COMPAT zephyr_fake_comp + +DEFINE_FAKE_VALUE_FUNC(int, + comp_fake_comp_get_output, + const struct device *); + +DEFINE_FAKE_VALUE_FUNC(int, + comp_fake_comp_set_trigger, + const struct device *, + enum comparator_trigger); + +DEFINE_FAKE_VALUE_FUNC(int, + comp_fake_comp_set_trigger_callback, + const struct device *, + comparator_callback_t, + void *); + +DEFINE_FAKE_VALUE_FUNC(int, + comp_fake_comp_trigger_is_pending, + const struct device *); + +static const struct comparator_driver_api fake_comp_api = { + .get_output = comp_fake_comp_get_output, + .set_trigger = comp_fake_comp_set_trigger, + .set_trigger_callback = comp_fake_comp_set_trigger_callback, + .trigger_is_pending = comp_fake_comp_trigger_is_pending, +}; + +#ifdef CONFIG_ZTEST +static void fake_comp_reset_rule_before(const struct ztest_unit_test *test, void *fixture) +{ + ARG_UNUSED(test); + ARG_UNUSED(fixture); + + RESET_FAKE(comp_fake_comp_get_output); + RESET_FAKE(comp_fake_comp_set_trigger); + RESET_FAKE(comp_fake_comp_set_trigger_callback); + RESET_FAKE(comp_fake_comp_trigger_is_pending); +} + +ZTEST_RULE(comp_fake_comp_reset_rule, fake_comp_reset_rule_before, NULL); +#endif + +DEVICE_DT_INST_DEFINE( + 0, + NULL, + NULL, + NULL, + NULL, + POST_KERNEL, + CONFIG_COMPARATOR_INIT_PRIORITY, + &fake_comp_api +); diff --git a/drivers/comparator/comparator_handlers.c b/drivers/comparator/comparator_handlers.c new file mode 100644 index 000000000000..fba43a9ce8e1 --- /dev/null +++ b/drivers/comparator/comparator_handlers.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +static inline int z_vrfy_comparator_get_output(const struct device *dev) +{ + K_OOPS(K_SYSCALL_DRIVER_COMPARATOR(dev, get_output)); + return z_impl_comparator_get_output(dev); +} +#include + +static inline int z_vrfy_comparator_set_trigger(const struct device *dev, + enum comparator_trigger trigger) +{ + K_OOPS(K_SYSCALL_DRIVER_COMPARATOR(dev, set_trigger)); + return z_impl_comparator_set_trigger(dev, trigger); +} +#include + +static inline int z_vrfy_comparator_trigger_is_pending(const struct device *dev) +{ + K_OOPS(K_SYSCALL_DRIVER_COMPARATOR(dev, trigger_is_pending)); + return z_impl_comparator_trigger_is_pending(dev); +} +#include diff --git a/drivers/comparator/comparator_mcux_acmp.c b/drivers/comparator/comparator_mcux_acmp.c new file mode 100644 index 000000000000..4d76f105e341 --- /dev/null +++ b/drivers/comparator/comparator_mcux_acmp.c @@ -0,0 +1,651 @@ +/* + * Copyright (c) 2020 Vestas Wind Systems A/S + * Copyright (c) 2022 NXP + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include +LOG_MODULE_REGISTER(nxp_kinetis_acmp, CONFIG_COMPARATOR_LOG_LEVEL); + +#define DT_DRV_COMPAT nxp_kinetis_acmp + +/* + * DAC is a register defined in the MCUX HAL. We don't need it here and it conflicts + * with the COMP_MCUX_ACMP_PORT_INPUT_DAC definition so undef it here. + */ +#ifdef DAC +#undef DAC +#endif + +#if defined(FSL_FEATURE_ACMP_HAS_C0_OFFSET_BIT) && (FSL_FEATURE_ACMP_HAS_C0_OFFSET_BIT == 1U) +#define COMP_MCUX_ACMP_HAS_OFFSET 1 +#else +#define COMP_MCUX_ACMP_HAS_OFFSET 0 +#endif + +#if defined(FSL_FEATURE_ACMP_HAS_C0_HYSTCTR_BIT) && (FSL_FEATURE_ACMP_HAS_C0_HYSTCTR_BIT == 1U) +#define COMP_MCUX_ACMP_HAS_HYSTERESIS 1 +#else +#define COMP_MCUX_ACMP_HAS_HYSTERESIS 0 +#endif + +#if defined(FSL_FEATURE_ACMP_HAS_C1_INPSEL_BIT) && (FSL_FEATURE_ACMP_HAS_C1_INPSEL_BIT == 1U) +#define COMP_MCUX_ACMP_HAS_INPSEL 1 +#else +#define COMP_MCUX_ACMP_HAS_INPSEL 0 +#endif + +#if defined(FSL_FEATURE_ACMP_HAS_C1_INNSEL_BIT) && (FSL_FEATURE_ACMP_HAS_C1_INNSEL_BIT == 1U) +#define COMP_MCUX_ACMP_HAS_INNSEL 1 +#else +#define COMP_MCUX_ACMP_HAS_INNSEL 0 +#endif + +#if defined(FSL_FEATURE_ACMP_HAS_C1_DACOE_BIT) && (FSL_FEATURE_ACMP_HAS_C1_DACOE_BIT == 1U) +#define COMP_MCUX_ACMP_HAS_DAC_OUT_ENABLE 1 +#else +#define COMP_MCUX_ACMP_HAS_DAC_OUT_ENABLE 0 +#endif + +#if defined(FSL_FEATURE_ACMP_HAS_C1_DMODE_BIT) && (FSL_FEATURE_ACMP_HAS_C1_DMODE_BIT == 1U) +#define COMP_MCUX_ACMP_HAS_DAC_WORK_MODE 1 +#else +#define COMP_MCUX_ACMP_HAS_DAC_WORK_MODE 0 +#endif + +#if defined(FSL_FEATURE_ACMP_HAS_C3_REG) && (FSL_FEATURE_ACMP_HAS_C3_REG != 0U) +#define COMP_MCUX_ACMP_HAS_DISCRETE_MODE 1 +#else +#define COMP_MCUX_ACMP_HAS_DISCRETE_MODE 0 +#endif + +#if !(defined(FSL_FEATURE_ACMP_HAS_NO_WINDOW_MODE) && (FSL_FEATURE_ACMP_HAS_NO_WINDOW_MODE == 1U)) +#define COMP_MCUX_ACMP_HAS_WINDOW_MODE 1 +#else +#define COMP_MCUX_ACMP_HAS_WINDOW_MODE 0 +#endif + +#define MCUX_ACMP_ENUM(name, value) \ + _CONCAT_4(COMP_MCUX_ACMP_, name, _, value) + +#define MCUX_ACMP_DT_INST_ENUM(inst, name, prop) \ + MCUX_ACMP_ENUM(name, DT_INST_STRING_TOKEN(inst, prop)) + +#define MCUX_ACMP_DT_INST_ENUM_OR(inst, name, prop, or) \ + COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, prop), \ + (MCUX_ACMP_DT_INST_ENUM(inst, name, prop)), \ + (MCUX_ACMP_ENUM(name, or))) + +#define MCUX_ACMP_DT_INST_OFFSET_MODE(inst) \ + MCUX_ACMP_DT_INST_ENUM_OR(inst, OFFSET_MODE, offset_mode, LEVEL0) + +#define MCUX_ACMP_DT_INST_HYST_MODE(inst) \ + MCUX_ACMP_DT_INST_ENUM_OR(inst, HYSTERESIS_MODE, hysteresis_mode, LEVEL0) + +#define MCUX_ACMP_DT_INST_EN_HS_MODE(inst) \ + DT_INST_PROP(inst, enable_high_speed_mode) + +#define MCUX_ACMP_DT_INST_INV_OUT(inst) \ + DT_INST_PROP(inst, invert_output) + +#define MCUX_ACMP_DT_INST_USE_UNFILTERED_OUT(inst) \ + DT_INST_PROP(inst, use_unfiltered_output) + +#define MCUX_ACMP_DT_INST_EN_PIN_OUT(inst) \ + DT_INST_PROP(inst, enable_pin_out) + +#define MCUX_ACMP_DT_INST_MODE_CONFIG_INIT(inst) \ + { \ + .offset_mode = MCUX_ACMP_DT_INST_OFFSET_MODE(inst), \ + .hysteresis_mode = MCUX_ACMP_DT_INST_HYST_MODE(inst), \ + .enable_high_speed_mode = MCUX_ACMP_DT_INST_EN_HS_MODE(inst), \ + .invert_output = MCUX_ACMP_DT_INST_INV_OUT(inst), \ + .use_unfiltered_output = MCUX_ACMP_DT_INST_USE_UNFILTERED_OUT(inst), \ + .enable_pin_output = MCUX_ACMP_DT_INST_EN_PIN_OUT(inst), \ + } + +#define MCUX_ACMP_DT_INST_P_MUX_IN(inst) \ + MCUX_ACMP_DT_INST_ENUM(inst, MUX_INPUT, positive_mux_input) + +#define MCUX_ACMP_DT_INST_N_MUX_IN(inst) \ + MCUX_ACMP_DT_INST_ENUM(inst, MUX_INPUT, negative_mux_input) + +#define MCUX_ACMP_DT_INST_P_PORT_IN(inst) \ + MCUX_ACMP_DT_INST_ENUM_OR(inst, PORT_INPUT, positive_port_input, MUX) + +#define MCUX_ACMP_DT_INST_N_PORT_IN(inst) \ + MCUX_ACMP_DT_INST_ENUM_OR(inst, PORT_INPUT, negative_port_input, MUX) + +#define MCUX_ACMP_DT_INST_INPUT_CONFIG_INIT(inst) \ + { \ + .positive_mux_input = MCUX_ACMP_DT_INST_P_MUX_IN(inst), \ + .negative_mux_input = MCUX_ACMP_DT_INST_N_MUX_IN(inst), \ + .positive_port_input = MCUX_ACMP_DT_INST_P_PORT_IN(inst), \ + .negative_port_input = MCUX_ACMP_DT_INST_N_PORT_IN(inst), \ + } + +#define MCUX_ACMP_DT_INST_FILTER_EN_SAMPLE(inst) \ + DT_INST_PROP(inst, filter_enable_sample) + +#define MCUX_ACMP_DT_INST_FILTER_COUNT(inst) \ + DT_INST_PROP_OR(inst, filter_count, 0) + +#define MCUX_ACMP_DT_INST_FILTER_PERIOD(inst) \ + DT_INST_PROP_OR(inst, filter_period, 0) + +#define MCUX_ACMP_DT_INST_FILTER_CONFIG_INIT(inst) \ + { \ + .enable_sample = MCUX_ACMP_DT_INST_FILTER_EN_SAMPLE(inst), \ + .filter_count = MCUX_ACMP_DT_INST_FILTER_COUNT(inst), \ + .filter_period = MCUX_ACMP_DT_INST_FILTER_PERIOD(inst), \ + } + +#define MCUX_ACMP_DT_INST_DAC_VREF_SOURCE(inst) \ + MCUX_ACMP_DT_INST_ENUM_OR(inst, DAC_VREF_SOURCE, dac_vref_source, VIN1) + +#define MCUX_ACMP_DT_INST_DAC_VALUE(inst) \ + DT_INST_PROP_OR(inst, dac_value, 0) + +#define MCUX_ACMP_DT_INST_DAC_EN(inst) \ + DT_INST_PROP(inst, dac_enable) + +#define MCUX_ACMP_DT_INST_DAC_EN_HS(inst) \ + DT_INST_PROP(inst, dac_enable_high_speed) + +#define MCUX_ACMP_DT_INST_DAC_CONFIG_INIT(inst) \ + { \ + .vref_source = MCUX_ACMP_DT_INST_DAC_VREF_SOURCE(inst), \ + .value = MCUX_ACMP_DT_INST_DAC_VALUE(inst), \ + .enable_output = MCUX_ACMP_DT_INST_DAC_EN(inst), \ + .enable_high_speed_mode = MCUX_ACMP_DT_INST_DAC_EN_HS(inst), \ + } + +#define MCUX_ACMP_DT_INST_DM_EN_P_CH(inst) \ + DT_INST_PROP(inst, discrete_mode_enable_positive_channel) + +#define MCUX_ACMP_DT_INST_DM_EN_N_CH(inst) \ + DT_INST_PROP(inst, discrete_mode_enable_negative_channel) + +#define MCUX_ACMP_DT_INST_DM_EN_RES_DIV(inst) \ + DT_INST_PROP(inst, discrete_mode_enable_resistor_divider) + +#define MCUX_ACMP_DT_INST_DM_CLOCK_SOURCE(inst) \ + MCUX_ACMP_DT_INST_ENUM_OR(inst, DM_CLOCK, discrete_mode_clock_source, SLOW) + +#define MCUX_ACMP_DT_INST_DM_SAMPLE_TIME(inst) \ + MCUX_ACMP_DT_INST_ENUM_OR(inst, DM_SAMPLE_TIME, discrete_mode_sample_time, T1) + +#define MCUX_ACMP_DT_INST_DM_PHASE1_TIME(inst) \ + MCUX_ACMP_DT_INST_ENUM_OR(inst, DM_PHASE_TIME, discrete_mode_phase1_time, ALT0) + +#define MCUX_ACMP_DT_INST_DM_PHASE2_TIME(inst) \ + MCUX_ACMP_DT_INST_ENUM_OR(inst, DM_PHASE_TIME, discrete_mode_phase2_time, ALT0) + +#define MCUX_ACMP_DT_INST_DM_CONFIG_INIT(inst) \ + { \ + .enable_positive_channel = MCUX_ACMP_DT_INST_DM_EN_P_CH(inst), \ + .enable_negative_channel = MCUX_ACMP_DT_INST_DM_EN_N_CH(inst), \ + .enable_resistor_divider = MCUX_ACMP_DT_INST_DM_EN_RES_DIV(inst), \ + .clock_source = MCUX_ACMP_DT_INST_DM_CLOCK_SOURCE(inst), \ + .sample_time = MCUX_ACMP_DT_INST_DM_SAMPLE_TIME(inst), \ + .phase1_time = MCUX_ACMP_DT_INST_DM_PHASE1_TIME(inst), \ + .phase2_time = MCUX_ACMP_DT_INST_DM_PHASE2_TIME(inst), \ + } + +#define MCUX_ACMP_DT_INST_EN_WINDOW_MODE(inst) \ + DT_INST_PROP(inst, enable_window_mode) + +struct mcux_acmp_config { + CMP_Type *base; + const struct pinctrl_dev_config *pincfg; + void (*irq_init)(void); + const struct comp_mcux_acmp_mode_config mode_config; + const struct comp_mcux_acmp_input_config input_config; + const struct comp_mcux_acmp_filter_config filter_config; + const struct comp_mcux_acmp_dac_config dac_config; +#if COMP_MCUX_ACMP_HAS_DISCRETE_MODE + const struct comp_mcux_acmp_dm_config dm_config; +#endif +#if COMP_MCUX_ACMP_HAS_WINDOW_MODE + bool enable_window_mode; +#endif +}; + +#if MCUX_ACMP_HAS_OFFSET +BUILD_ASSERT((int)kACMP_OffsetLevel0 == (int)COMP_MCUX_ACMP_OFFSET_MODE_LEVEL0); +BUILD_ASSERT((int)kACMP_OffsetLevel1 == (int)COMP_MCUX_ACMP_OFFSET_MODE_LEVEL1); +#endif + +#if COMP_MCUX_ACMP_HAS_HYSTERESIS +BUILD_ASSERT((int)kACMP_HysteresisLevel0 == (int)COMP_MCUX_ACMP_HYSTERESIS_MODE_LEVEL0); +BUILD_ASSERT((int)kACMP_HysteresisLevel1 == (int)COMP_MCUX_ACMP_HYSTERESIS_MODE_LEVEL1); +BUILD_ASSERT((int)kACMP_HysteresisLevel2 == (int)COMP_MCUX_ACMP_HYSTERESIS_MODE_LEVEL2); +BUILD_ASSERT((int)kACMP_HysteresisLevel3 == (int)COMP_MCUX_ACMP_HYSTERESIS_MODE_LEVEL3); +#endif + +BUILD_ASSERT((int)kACMP_VrefSourceVin1 == (int)COMP_MCUX_ACMP_DAC_VREF_SOURCE_VIN1); +BUILD_ASSERT((int)kACMP_VrefSourceVin2 == (int)COMP_MCUX_ACMP_DAC_VREF_SOURCE_VIN2); + +#if MCUX_ACMP_HAS_INPSEL || MCUX_ACMP_HAS_INNSEL +BUILD_ASSERT((int)kACMP_PortInputFromDAC == (int)COMP_MCUX_ACMP_PORT_INPUT_DAC); +BUILD_ASSERT((int)kACMP_PortInputFromMux == (int)COMP_MCUX_ACMP_PORT_INPUT_MUX); +#endif + +#if COMP_MCUX_ACMP_HAS_DISCRETE_MODE +BUILD_ASSERT((int)kACMP_DiscreteClockSlow == (int)COMP_MCUX_ACMP_DM_CLOCK_SLOW); +BUILD_ASSERT((int)kACMP_DiscreteClockFast == (int)COMP_MCUX_ACMP_DM_CLOCK_FAST); + +BUILD_ASSERT((int)kACMP_DiscreteSampleTimeAs1T == (int)COMP_MCUX_ACMP_DM_SAMPLE_TIME_T1); +BUILD_ASSERT((int)kACMP_DiscreteSampleTimeAs2T == (int)COMP_MCUX_ACMP_DM_SAMPLE_TIME_T2); +BUILD_ASSERT((int)kACMP_DiscreteSampleTimeAs4T == (int)COMP_MCUX_ACMP_DM_SAMPLE_TIME_T4); +BUILD_ASSERT((int)kACMP_DiscreteSampleTimeAs8T == (int)COMP_MCUX_ACMP_DM_SAMPLE_TIME_T8); +BUILD_ASSERT((int)kACMP_DiscreteSampleTimeAs16T == (int)COMP_MCUX_ACMP_DM_SAMPLE_TIME_T16); +BUILD_ASSERT((int)kACMP_DiscreteSampleTimeAs32T == (int)COMP_MCUX_ACMP_DM_SAMPLE_TIME_T32); +BUILD_ASSERT((int)kACMP_DiscreteSampleTimeAs64T == (int)COMP_MCUX_ACMP_DM_SAMPLE_TIME_T64); +BUILD_ASSERT((int)kACMP_DiscreteSampleTimeAs256T == (int)COMP_MCUX_ACMP_DM_SAMPLE_TIME_T256); + +BUILD_ASSERT((int)kACMP_DiscretePhaseTimeAlt0 == (int)COMP_MCUX_ACMP_DM_PHASE_TIME_ALT0); +BUILD_ASSERT((int)kACMP_DiscretePhaseTimeAlt1 == (int)COMP_MCUX_ACMP_DM_PHASE_TIME_ALT1); +BUILD_ASSERT((int)kACMP_DiscretePhaseTimeAlt2 == (int)COMP_MCUX_ACMP_DM_PHASE_TIME_ALT2); +BUILD_ASSERT((int)kACMP_DiscretePhaseTimeAlt3 == (int)COMP_MCUX_ACMP_DM_PHASE_TIME_ALT3); +BUILD_ASSERT((int)kACMP_DiscretePhaseTimeAlt4 == (int)COMP_MCUX_ACMP_DM_PHASE_TIME_ALT4); +BUILD_ASSERT((int)kACMP_DiscretePhaseTimeAlt5 == (int)COMP_MCUX_ACMP_DM_PHASE_TIME_ALT5); +BUILD_ASSERT((int)kACMP_DiscretePhaseTimeAlt6 == (int)COMP_MCUX_ACMP_DM_PHASE_TIME_ALT6); +BUILD_ASSERT((int)kACMP_DiscretePhaseTimeAlt7 == (int)COMP_MCUX_ACMP_DM_PHASE_TIME_ALT7); +#endif + +struct mcux_acmp_data { + uint32_t interrupt_mask; + comparator_callback_t callback; + void *user_data; +}; + +#if CONFIG_PM_DEVICE +static bool mcux_acmp_is_resumed(const struct device *dev) +{ + enum pm_device_state state; + + (void)pm_device_state_get(dev, &state); + return state == PM_DEVICE_STATE_ACTIVE; +} +#else +static bool mcux_acmp_is_resumed(const struct device *dev) +{ + ARG_UNUSED(dev); + return true; +} +#endif + +static int mcux_acmp_get_output(const struct device *dev) +{ + const struct mcux_acmp_config *config = dev->config; + uint32_t status; + + status = ACMP_GetStatusFlags(config->base); + return (status & kACMP_OutputAssertEventFlag) ? 1 : 0; +} + +static int mcux_acmp_set_trigger(const struct device *dev, + enum comparator_trigger trigger) +{ + const struct mcux_acmp_config *config = dev->config; + struct mcux_acmp_data *data = dev->data; + + ACMP_DisableInterrupts(config->base, UINT32_MAX); + + switch (trigger) { + case COMPARATOR_TRIGGER_NONE: + data->interrupt_mask = 0; + break; + + case COMPARATOR_TRIGGER_RISING_EDGE: + data->interrupt_mask = kACMP_OutputRisingInterruptEnable; + break; + + case COMPARATOR_TRIGGER_FALLING_EDGE: + data->interrupt_mask = kACMP_OutputFallingInterruptEnable; + break; + + case COMPARATOR_TRIGGER_BOTH_EDGES: + data->interrupt_mask = kACMP_OutputFallingInterruptEnable | + kACMP_OutputRisingInterruptEnable; + break; + } + + if (data->interrupt_mask && data->callback != NULL) { + ACMP_EnableInterrupts(config->base, data->interrupt_mask); + } + + return 0; +} + +static int mcux_acmp_set_trigger_callback(const struct device *dev, + comparator_callback_t callback, + void *user_data) +{ + const struct mcux_acmp_config *config = dev->config; + struct mcux_acmp_data *data = dev->data; + + ACMP_DisableInterrupts(config->base, UINT32_MAX); + + data->callback = callback; + data->user_data = user_data; + + if (data->callback == NULL) { + return 0; + } + + if (data->interrupt_mask) { + ACMP_EnableInterrupts(config->base, data->interrupt_mask); + } + + return 0; +} + +static int mcux_acmp_trigger_is_pending(const struct device *dev) +{ + const struct mcux_acmp_config *config = dev->config; + struct mcux_acmp_data *data = dev->data; + uint32_t status_flags; + + status_flags = ACMP_GetStatusFlags(config->base); + ACMP_ClearStatusFlags(config->base, UINT32_MAX); + + if ((data->interrupt_mask & kACMP_OutputRisingInterruptEnable) && + (status_flags & kACMP_OutputRisingEventFlag)) { + return 1; + } + + if ((data->interrupt_mask & kACMP_OutputFallingInterruptEnable) && + (status_flags & kACMP_OutputFallingEventFlag)) { + return 1; + } + + return 0; +} + +static const struct comparator_driver_api mcux_acmp_comp_api = { + .get_output = mcux_acmp_get_output, + .set_trigger = mcux_acmp_set_trigger, + .set_trigger_callback = mcux_acmp_set_trigger_callback, + .trigger_is_pending = mcux_acmp_trigger_is_pending, +}; + +static void comp_mcux_acmp_init_mode_config(const struct device *dev, + const struct comp_mcux_acmp_mode_config *config) +{ + const struct mcux_acmp_config *dev_config = dev->config; + acmp_config_t acmp_config; + +#if COMP_MCUX_ACMP_HAS_OFFSET + acmp_config.offsetMode = (acmp_offset_mode_t)config->offset_mode; +#endif + +#if COMP_MCUX_ACMP_HAS_HYSTERESIS + acmp_config.hysteresisMode = (acmp_hysteresis_mode_t)config->hysteresis_mode; +#endif + + acmp_config.enableHighSpeed = config->enable_high_speed_mode; + acmp_config.enableInvertOutput = config->invert_output; + acmp_config.useUnfilteredOutput = config->use_unfiltered_output; + acmp_config.enablePinOut = config->enable_pin_output; + + ACMP_Init(dev_config->base, &acmp_config); +} + +int comp_mcux_acmp_set_mode_config(const struct device *dev, + const struct comp_mcux_acmp_mode_config *config) +{ + const struct mcux_acmp_config *dev_config = dev->config; + + comp_mcux_acmp_init_mode_config(dev, config); + + if (mcux_acmp_is_resumed(dev)) { + ACMP_Enable(dev_config->base, true); + } + + return 0; +} + +int comp_mcux_acmp_set_input_config(const struct device *dev, + const struct comp_mcux_acmp_input_config *config) +{ + const struct mcux_acmp_config *dev_config = dev->config; + acmp_channel_config_t acmp_channel_config; + +#if COMP_MCUX_ACMP_HAS_INPSEL + acmp_channel_config.positivePortInput = (acmp_port_input_t)config->positive_port_input; +#endif + + acmp_channel_config.plusMuxInput = (uint32_t)config->positive_mux_input; + +#if COMP_MCUX_ACMP_HAS_INNSEL + acmp_channel_config.negativePortInput = (acmp_port_input_t)config->negative_port_input; +#endif + + acmp_channel_config.minusMuxInput = (uint32_t)config->negative_mux_input; + + ACMP_SetChannelConfig(dev_config->base, &acmp_channel_config); + return 0; +} + +int comp_mcux_acmp_set_filter_config(const struct device *dev, + const struct comp_mcux_acmp_filter_config *config) +{ + const struct mcux_acmp_config *dev_config = dev->config; + acmp_filter_config_t acmp_filter_config; + + if (config->enable_sample && config->filter_count == 0) { + return -EINVAL; + } + + if (config->filter_count > 7) { + return -EINVAL; + } + + acmp_filter_config.enableSample = config->enable_sample; + acmp_filter_config.filterCount = config->filter_count; + acmp_filter_config.filterPeriod = config->filter_period; + + ACMP_SetFilterConfig(dev_config->base, &acmp_filter_config); + return 0; +} + +int comp_mcux_acmp_set_dac_config(const struct device *dev, + const struct comp_mcux_acmp_dac_config *config) +{ + const struct mcux_acmp_config *dev_config = dev->config; + acmp_dac_config_t acmp_dac_config; + + acmp_dac_config.referenceVoltageSource = + (acmp_reference_voltage_source_t)config->vref_source; + + acmp_dac_config.DACValue = config->value; + +#if COMP_MCUX_ACMP_HAS_DAC_OUT_ENABLE + acmp_dac_config.enableOutput = config->enable_output; +#endif + +#if COMP_MCUX_ACMP_HAS_DAC_WORK_MODE + acmp_dac_config.workMode = config->enable_high_speed_mode + ? kACMP_DACWorkHighSpeedMode + : kACMP_DACWorkLowSpeedMode; +#endif + + ACMP_SetDACConfig(dev_config->base, &acmp_dac_config); + return 0; +} + +#if COMP_MCUX_ACMP_HAS_DISCRETE_MODE +int comp_mcux_acmp_set_dm_config(const struct device *dev, + const struct comp_mcux_acmp_dm_config *config) +{ + const struct mcux_acmp_config *dev_config = dev->config; + acmp_discrete_mode_config_t acmp_dm_config; + + acmp_dm_config.enablePositiveChannelDiscreteMode = config->enable_positive_channel; + acmp_dm_config.enableNegativeChannelDiscreteMode = config->enable_negative_channel; + acmp_dm_config.enableResistorDivider = config->enable_resistor_divider; + acmp_dm_config.clockSource = (acmp_discrete_clock_source_t)config->clock_source; + acmp_dm_config.sampleTime = (acmp_discrete_sample_time_t)config->sample_time; + acmp_dm_config.phase1Time = (acmp_discrete_phase_time_t)config->phase1_time; + acmp_dm_config.phase2Time = (acmp_discrete_phase_time_t)config->phase2_time; + + ACMP_SetDiscreteModeConfig(dev_config->base, &acmp_dm_config); + return 0; +} +#endif + +#if COMP_MCUX_ACMP_HAS_WINDOW_MODE +int comp_mcux_acmp_set_window_mode(const struct device *dev, bool enable) +{ + const struct mcux_acmp_config *config = dev->config; + + ACMP_EnableWindowMode(config->base, enable); + return 0; +} +#endif + +static int mcux_acmp_pm_callback(const struct device *dev, enum pm_device_action action) +{ + const struct mcux_acmp_config *config = dev->config; + + if (action == PM_DEVICE_ACTION_RESUME) { + ACMP_Enable(config->base, true); + } + +#if CONFIG_PM_DEVICE + if (action == PM_DEVICE_ACTION_SUSPEND) { + ACMP_Enable(config->base, false); + } +#endif + + return 0; +} + +static void mcux_acmp_irq_handler(const struct device *dev) +{ + const struct mcux_acmp_config *config = dev->config; + struct mcux_acmp_data *data = dev->data; + + ACMP_ClearStatusFlags(config->base, UINT32_MAX); + + if (data->callback == NULL) { + return; + } + + data->callback(dev, data->user_data); +} + +static int mcux_acmp_init(const struct device *dev) +{ + const struct mcux_acmp_config *config = dev->config; + int ret; + + ret = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); + if (ret) { + LOG_ERR("failed to set %s", "pincfg"); + return ret; + } + + comp_mcux_acmp_init_mode_config(dev, &config->mode_config); + + ret = comp_mcux_acmp_set_input_config(dev, &config->input_config); + if (ret) { + LOG_ERR("failed to set %s", "input config"); + return ret; + } + + ret = comp_mcux_acmp_set_filter_config(dev, &config->filter_config); + if (ret) { + LOG_ERR("failed to set %s", "filter config"); + return ret; + } + + ret = comp_mcux_acmp_set_dac_config(dev, &config->dac_config); + if (ret) { + LOG_ERR("failed to set %s", "dac config"); + return ret; + } + +#if COMP_MCUX_ACMP_HAS_DISCRETE_MODE + ret = comp_mcux_acmp_set_dm_config(dev, &config->dm_config); + if (ret) { + LOG_ERR("failed to set %s", "discrete mode config"); + return ret; + } +#endif + +#if COMP_MCUX_ACMP_HAS_WINDOW_MODE + ret = comp_mcux_acmp_set_window_mode(dev, config->enable_window_mode); + if (ret) { + LOG_ERR("failed to set %s", "window mode"); + return ret; + } +#endif + + ACMP_DisableInterrupts(config->base, UINT32_MAX); + config->irq_init(); + + return pm_device_driver_init(dev, mcux_acmp_pm_callback); +} + +#define MCUX_ACMP_IRQ_HANDLER_SYM(inst) \ + _CONCAT(mcux_acmp_irq_init, inst) + +#define MCUX_ACMP_IRQ_HANDLER_DEFINE(inst) \ + static void MCUX_ACMP_IRQ_HANDLER_SYM(inst)(void) \ + { \ + IRQ_CONNECT(DT_INST_IRQN(inst), \ + DT_INST_IRQ(inst, priority), \ + mcux_acmp_irq_handler, \ + DEVICE_DT_INST_GET(inst), \ + 0); \ + \ + irq_enable(DT_INST_IRQN(inst)); \ + } + +#define MCUX_ACMP_DEVICE(inst) \ + PINCTRL_DT_INST_DEFINE(inst); \ + \ + static struct mcux_acmp_data _CONCAT(data, inst); \ + \ + MCUX_ACMP_IRQ_HANDLER_DEFINE(inst) \ + \ + static const struct mcux_acmp_config _CONCAT(config, inst) = { \ + .base = (CMP_Type *)DT_INST_REG_ADDR(inst), \ + .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ + .irq_init = MCUX_ACMP_IRQ_HANDLER_SYM(inst), \ + .mode_config = MCUX_ACMP_DT_INST_MODE_CONFIG_INIT(inst), \ + .input_config = MCUX_ACMP_DT_INST_INPUT_CONFIG_INIT(inst), \ + .filter_config = MCUX_ACMP_DT_INST_FILTER_CONFIG_INIT(inst), \ + .dac_config = MCUX_ACMP_DT_INST_DAC_CONFIG_INIT(inst), \ + IF_ENABLED(COMP_MCUX_ACMP_HAS_DISCRETE_MODE, \ + (.dm_config = MCUX_ACMP_DT_INST_DM_CONFIG_INIT(inst),)) \ + IF_ENABLED(COMP_MCUX_ACMP_HAS_WINDOW_MODE, \ + (.enable_window_mode = MCUX_ACMP_DT_INST_EN_WINDOW_MODE(inst),)) \ + }; \ + \ + PM_DEVICE_DT_INST_DEFINE(inst, mcux_acmp_pm_callback); \ + \ + DEVICE_DT_INST_DEFINE(inst, \ + mcux_acmp_init, \ + PM_DEVICE_DT_INST_GET(inst), \ + &_CONCAT(data, inst), \ + &_CONCAT(config, inst), \ + POST_KERNEL, \ + CONFIG_COMPARATOR_INIT_PRIORITY, \ + &mcux_acmp_comp_api); + +DT_INST_FOREACH_STATUS_OKAY(MCUX_ACMP_DEVICE) diff --git a/drivers/comparator/comparator_nrf_comp.c b/drivers/comparator/comparator_nrf_comp.c new file mode 100644 index 000000000000..339d24f8dcda --- /dev/null +++ b/drivers/comparator/comparator_nrf_comp.c @@ -0,0 +1,764 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include +#include + +#define DT_DRV_COMPAT nordic_nrf_comp + +#define SHIM_NRF_COMP_DT_INST_REFSEL(inst) \ + _CONCAT(COMP_NRF_COMP_REFSEL_, DT_INST_STRING_TOKEN(inst, refsel)) + +#define SHIM_NRF_COMP_DT_INST_REFSEL_IS_AREF(inst) \ + DT_INST_ENUM_HAS_VALUE(inst, refsel, AREF) + +#define SHIM_NRF_COMP_DT_INST_EXTREFSEL(inst) \ + _CONCAT(COMP_NRF_COMP_EXTREFSEL_, DT_INST_STRING_TOKEN(inst, extrefsel)) + +#define SHIM_NRF_COMP_DT_INST_MAIN_MODE_IS_SE(inst) \ + DT_INST_ENUM_HAS_VALUE(inst, main_mode, SE) + +#define SHIM_NRF_COMP_DT_INST_MAIN_MODE_IS_DIFF(inst) \ + DT_INST_ENUM_HAS_VALUE(inst, main_mode, DIFF) + +#define SHIM_NRF_COMP_DT_INST_TH_DOWN(inst) \ + DT_INST_PROP(inst, th_down) + +#define SHIM_NRF_COMP_DT_INST_TH_UP(inst) \ + DT_INST_PROP(inst, th_up) + +#define SHIM_NRF_COMP_DT_INST_SP_MODE(inst) \ + _CONCAT(COMP_NRF_COMP_SP_MODE_, DT_INST_STRING_TOKEN(inst, sp_mode)) + +#define SHIM_NRF_COMP_DT_INST_ENABLE_HYST(inst) \ + DT_INST_PROP(inst, enable_hyst) + +#define SHIM_NRF_COMP_DT_INST_ISOURCE(inst) \ + _CONCAT(COMP_NRF_COMP_ISOURCE_, DT_INST_STRING_TOKEN(inst, isource)) + +#define SHIM_NRF_COMP_DT_INST_PSEL(inst) \ + _CONCAT(COMP_NRF_COMP_PSEL_, DT_INST_STRING_TOKEN(inst, psel)) + +#if defined(COMP_HYST_HYST_Hyst40mV) +#define NRF_COMP_HYST_ENABLED NRF_COMP_HYST_40MV +#elif defined(COMP_HYST_HYST_Hyst50mV) +#define NRF_COMP_HYST_ENABLED NRF_COMP_HYST_50MV +#endif + +#define NRF_COMP_HYST_DISABLED NRF_COMP_HYST_NO_HYST + +#if defined(NRF_COMP_HYST_ENABLED) +#define NRF_COMP_HAS_HYST 1 +#else +#define NRF_COMP_HAS_HYST 0 +#endif + +struct shim_nrf_comp_data { + uint32_t event_mask; + bool started; + atomic_t triggered; + comparator_callback_t callback; + void *user_data; +}; + +#if (NRF_COMP_HAS_AIN_AS_PIN) +static const uint32_t shim_nrf_comp_ain_map[] = { +#if defined(CONFIG_SOC_NRF54H20) || defined(CONFIG_SOC_NRF9280) + NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(1U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(2U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), +#elif defined(CONFIG_SOC_NRF54L15) + NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(11U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(13U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(14U, 1), +#endif +}; +#endif + +#if SHIM_NRF_COMP_DT_INST_MAIN_MODE_IS_SE(0) +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_DOWN(0) < 64); +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_UP(0) < 64); +#endif + +#if NRF_COMP_HAS_AIN_AS_PIN +BUILD_ASSERT((COMP_NRF_COMP_PSEL_AIN0 == 0)); +BUILD_ASSERT((COMP_NRF_COMP_PSEL_AIN7 == 7)); +BUILD_ASSERT((COMP_NRF_COMP_EXTREFSEL_AIN0 == 0)); +BUILD_ASSERT((COMP_NRF_COMP_EXTREFSEL_AIN7 == 7)); +#else +#ifndef COMP_PSEL_PSEL_AnalogInput4 +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_AIN4); +#endif + +#ifndef COMP_PSEL_PSEL_AnalogInput5 +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_AIN5); +#endif + +#ifndef COMP_PSEL_PSEL_AnalogInput6 +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_AIN6); +#endif + +#ifndef COMP_PSEL_PSEL_AnalogInput7 +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_AIN7); +#endif +#endif + +#ifndef COMP_PSEL_PSEL_VddDiv2 +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_VDD_DIV2); +#endif + +#ifndef COMP_PSEL_PSEL_VddhDiv5 +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_VDDH_DIV5); +#endif + +#ifndef COMP_MODE_SP_Normal +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_SP_MODE(0) != COMP_NRF_COMP_SP_MODE_NORMAL); +#endif + +#if NRF_COMP_HAS_ISOURCE +#ifndef COMP_ISOURCE_ISOURCE_Ien2uA5 +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_ISOURCE(0) != COMP_NRF_COMP_ISOURCE_2UA5); +#endif + +#ifndef COMP_ISOURCE_ISOURCE_Ien5uA +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_ISOURCE(0) != COMP_NRF_COMP_ISOURCE_5UA); +#endif + +#ifndef COMP_ISOURCE_ISOURCE_Ien10uA +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_ISOURCE(0) != COMP_NRF_COMP_ISOURCE_10UA); +#endif +#endif + +#if SHIM_NRF_COMP_DT_INST_REFSEL_IS_AREF(0) +#ifndef COMP_EXTREFSEL_EXTREFSEL_AnalogReference4 +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_EXTREFSEL(0) != COMP_NRF_COMP_EXTREFSEL_AIN4); +#endif + +#ifndef COMP_EXTREFSEL_EXTREFSEL_AnalogReference5 +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_EXTREFSEL(0) != COMP_NRF_COMP_EXTREFSEL_AIN5); +#endif + +#ifndef COMP_EXTREFSEL_EXTREFSEL_AnalogReference6 +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_EXTREFSEL(0) != COMP_NRF_COMP_EXTREFSEL_AIN6); +#endif + +#ifndef COMP_EXTREFSEL_EXTREFSEL_AnalogReference7 +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_EXTREFSEL(0) != COMP_NRF_COMP_EXTREFSEL_AIN7); +#endif +#endif + +#if SHIM_NRF_COMP_DT_INST_MAIN_MODE_IS_SE(0) +#ifndef COMP_REFSEL_REFSEL_Int1V8 +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_REFSEL(0) != COMP_NRF_COMP_REFSEL_INT_1V8); +#endif + +#ifndef COMP_REFSEL_REFSEL_Int2V4 +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_REFSEL(0) != COMP_NRF_COMP_REFSEL_INT_2V4); +#endif + +#ifndef COMP_REFSEL_REFSEL_AVDDAO1V8 +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_REFSEL(0) != COMP_NRF_COMP_REFSEL_AVDDAO1V8); +#endif + +#ifndef COMP_REFSEL_REFSEL_VDD +BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_REFSEL(0) != COMP_NRF_COMP_REFSEL_VDD); +#endif +#endif + +#if SHIM_NRF_COMP_DT_INST_MAIN_MODE_IS_DIFF(0) +#if SHIM_NRF_COMP_DT_INST_ENABLE_HYST(0) +BUILD_ASSERT(NRF_COMP_HAS_HYST); +#endif +#endif + +#if SHIM_NRF_COMP_DT_INST_MAIN_MODE_IS_SE(0) +static const struct comp_nrf_comp_se_config shim_nrf_comp_config0 = { + .psel = SHIM_NRF_COMP_DT_INST_PSEL(0), + .sp_mode = SHIM_NRF_COMP_DT_INST_SP_MODE(0), + .isource = SHIM_NRF_COMP_DT_INST_ISOURCE(0), +#if SHIM_NRF_COMP_DT_INST_REFSEL_IS_AREF(0) + .extrefsel = SHIM_NRF_COMP_DT_INST_EXTREFSEL(0), +#endif + .refsel = SHIM_NRF_COMP_DT_INST_REFSEL(0), + .th_down = SHIM_NRF_COMP_DT_INST_TH_DOWN(0), + .th_up = SHIM_NRF_COMP_DT_INST_TH_UP(0), +}; +#else +static const struct comp_nrf_comp_diff_config shim_nrf_comp_config0 = { + .psel = SHIM_NRF_COMP_DT_INST_PSEL(0), + .sp_mode = SHIM_NRF_COMP_DT_INST_SP_MODE(0), + .isource = SHIM_NRF_COMP_DT_INST_ISOURCE(0), + .extrefsel = SHIM_NRF_COMP_DT_INST_EXTREFSEL(0), + .enable_hyst = SHIM_NRF_COMP_DT_INST_ENABLE_HYST(0), +}; +#endif + +static struct shim_nrf_comp_data shim_nrf_comp_data0; + +#if CONFIG_PM_DEVICE +static bool shim_nrf_comp_is_resumed(void) +{ + enum pm_device_state state; + + (void)pm_device_state_get(DEVICE_DT_INST_GET(0), &state); + return state == PM_DEVICE_STATE_ACTIVE; +} +#else +static bool shim_nrf_comp_is_resumed(void) +{ + return true; +} +#endif + +static void shim_nrf_comp_start(void) +{ + if (shim_nrf_comp_data0.started) { + return; + } + + nrfx_comp_start(shim_nrf_comp_data0.event_mask, 0); + shim_nrf_comp_data0.started = true; +} + +static void shim_nrf_comp_stop(void) +{ + if (!shim_nrf_comp_data0.started) { + return; + } + + nrfx_comp_stop(); + shim_nrf_comp_data0.started = false; +} + +static int shim_nrf_comp_pm_callback(const struct device *dev, enum pm_device_action action) +{ + ARG_UNUSED(dev); + + switch (action) { + case PM_DEVICE_ACTION_RESUME: + shim_nrf_comp_start(); + break; + +#if CONFIG_PM_DEVICE + case PM_DEVICE_ACTION_SUSPEND: + shim_nrf_comp_stop(); + break; +#endif + + default: + return -ENOTSUP; + } + + return 0; +} + +#if (NRF_COMP_HAS_AIN_AS_PIN) +static int shim_nrf_comp_psel_to_nrf(enum comp_nrf_comp_psel shim, + nrf_comp_input_t *nrf) +{ + if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { + return -EINVAL; + } + + *nrf = shim_nrf_comp_ain_map[(uint32_t)shim]; + return 0; +} +#else +static int shim_nrf_comp_psel_to_nrf(enum comp_nrf_comp_psel shim, + nrf_comp_input_t *nrf) +{ + switch (shim) { + case COMP_NRF_COMP_PSEL_AIN0: + *nrf = NRF_COMP_INPUT_0; + break; + + case COMP_NRF_COMP_PSEL_AIN1: + *nrf = NRF_COMP_INPUT_1; + break; + + case COMP_NRF_COMP_PSEL_AIN2: + *nrf = NRF_COMP_INPUT_2; + break; + + case COMP_NRF_COMP_PSEL_AIN3: + *nrf = NRF_COMP_INPUT_3; + break; + +#if defined(COMP_PSEL_PSEL_AnalogInput4) + case COMP_NRF_COMP_PSEL_AIN4: + *nrf = NRF_COMP_INPUT_4; + break; +#endif + +#if defined(COMP_PSEL_PSEL_AnalogInput5) + case COMP_NRF_COMP_PSEL_AIN5: + *nrf = NRF_COMP_INPUT_5; + break; +#endif + +#if defined(COMP_PSEL_PSEL_AnalogInput6) + case COMP_NRF_COMP_PSEL_AIN6: + *nrf = NRF_COMP_INPUT_6; + break; +#endif + +#if defined(COMP_PSEL_PSEL_AnalogInput7) + case COMP_NRF_COMP_PSEL_AIN7: + *nrf = NRF_COMP_INPUT_7; + break; +#endif + +#if defined(COMP_PSEL_PSEL_VddDiv2) + case COMP_NRF_COMP_PSEL_VDD_DIV2: + *nrf = NRF_COMP_VDD_DIV2; + break; +#endif + +#if defined(COMP_PSEL_PSEL_VddhDiv5) + case COMP_NRF_COMP_PSEL_VDDH_DIV5: + *nrf = NRF_COMP_VDDH_DIV5; + break; +#endif + + default: + return -EINVAL; + } + + return 0; +} +#endif + +static int shim_nrf_comp_sp_mode_to_nrf(enum comp_nrf_comp_sp_mode shim, + nrf_comp_sp_mode_t *nrf) +{ + switch (shim) { + case COMP_NRF_COMP_SP_MODE_LOW: + *nrf = NRF_COMP_SP_MODE_LOW; + break; + +#if defined(COMP_MODE_SP_Normal) + case COMP_NRF_COMP_SP_MODE_NORMAL: + *nrf = NRF_COMP_SP_MODE_NORMAL; + break; +#endif + + case COMP_NRF_COMP_SP_MODE_HIGH: + *nrf = NRF_COMP_SP_MODE_HIGH; + break; + + default: + return -EINVAL; + } + + return 0; +} + +#if NRF_COMP_HAS_ISOURCE +static int shim_nrf_comp_isource_to_nrf(enum comp_nrf_comp_isource shim, + nrf_isource_t *nrf) +{ + switch (shim) { + case COMP_NRF_COMP_ISOURCE_DISABLED: + *nrf = NRF_COMP_ISOURCE_OFF; + break; + +#if defined(COMP_ISOURCE_ISOURCE_Ien2uA5) + case COMP_NRF_COMP_ISOURCE_2UA5: + *nrf = NRF_COMP_ISOURCE_IEN_2UA5; + break; +#endif + +#if defined(COMP_ISOURCE_ISOURCE_Ien5uA) + case COMP_NRF_COMP_ISOURCE_5UA: + *nrf = NRF_COMP_ISOURCE_IEN_5UA; + break; +#endif + +#if defined(COMP_ISOURCE_ISOURCE_Ien10uA) + case COMP_NRF_COMP_ISOURCE_10UA: + *nrf = NRF_COMP_ISOURCE_IEN_10UA; + break; +#endif + + default: + return -EINVAL; + } + + return 0; +} +#endif + +#if (NRF_COMP_HAS_AIN_AS_PIN) +static int shim_nrf_comp_extrefsel_to_nrf(enum comp_nrf_comp_extrefsel shim, + nrf_comp_ext_ref_t *nrf) +{ + if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { + return -EINVAL; + } + + *nrf = shim_nrf_comp_ain_map[(uint32_t)shim]; + return 0; +} +#else +static int shim_nrf_comp_extrefsel_to_nrf(enum comp_nrf_comp_extrefsel shim, + nrf_comp_ext_ref_t *nrf) +{ + switch (shim) { + case COMP_NRF_COMP_EXTREFSEL_AIN0: + *nrf = NRF_COMP_EXT_REF_0; + break; + + case COMP_NRF_COMP_EXTREFSEL_AIN1: + *nrf = NRF_COMP_EXT_REF_1; + break; + + case COMP_NRF_COMP_EXTREFSEL_AIN2: + *nrf = NRF_COMP_EXT_REF_2; + break; + + case COMP_NRF_COMP_EXTREFSEL_AIN3: + *nrf = NRF_COMP_EXT_REF_3; + break; + +#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference4) + case COMP_NRF_COMP_EXTREFSEL_AIN4: + *nrf = NRF_COMP_EXT_REF_4; + break; +#endif + +#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference5) + case COMP_NRF_COMP_EXTREFSEL_AIN5: + *nrf = NRF_COMP_EXT_REF_5; + break; +#endif + +#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference6) + case COMP_NRF_COMP_EXTREFSEL_AIN6: + *nrf = NRF_COMP_EXT_REF_6; + break; +#endif + +#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference7) + case COMP_NRF_COMP_EXTREFSEL_AIN7: + *nrf = NRF_COMP_EXT_REF_7; + break; +#endif + + default: + return -EINVAL; + } + + return 0; +} +#endif + +static int shim_nrf_comp_refsel_to_nrf(enum comp_nrf_comp_refsel shim, + nrf_comp_ref_t *nrf) +{ + switch (shim) { + case COMP_NRF_COMP_REFSEL_INT_1V2: + *nrf = NRF_COMP_REF_INT_1V2; + break; + +#if defined(COMP_REFSEL_REFSEL_Int1V8) + case COMP_NRF_COMP_REFSEL_INT_1V8: + *nrf = NRF_COMP_REF_INT_1V8; + break; +#endif + +#if defined(COMP_REFSEL_REFSEL_Int2V4) + case COMP_NRF_COMP_REFSEL_INT_2V4: + *nrf = NRF_COMP_REF_INT_2V4; + break; +#endif + +#if defined(COMP_REFSEL_REFSEL_AVDDAO1V8) + case COMP_NRF_COMP_REFSEL_AVDDAO1V8: + *nrf = NRF_COMP_REF_AVDDAO1V8; + break; +#endif + +#if defined(COMP_REFSEL_REFSEL_VDD) + case COMP_NRF_COMP_REFSEL_VDD: + *nrf = NRF_COMP_REF_VDD; + break; +#endif + + case COMP_NRF_COMP_REFSEL_AREF: + *nrf = NRF_COMP_REF_AREF; + break; + + default: + return -EINVAL; + } + + return 0; +} + +static int shim_nrf_comp_se_config_to_nrf(const struct comp_nrf_comp_se_config *shim, + nrfx_comp_config_t *nrf) +{ + if (shim_nrf_comp_refsel_to_nrf(shim->refsel, &nrf->reference)) { + return -EINVAL; + } + + if (shim_nrf_comp_extrefsel_to_nrf(shim->extrefsel, &nrf->ext_ref)) { + return -EINVAL; + } + + nrf->main_mode = NRF_COMP_MAIN_MODE_SE; + + if (shim->th_down > 63 || shim->th_up > 63) { + return -EINVAL; + } + + nrf->threshold.th_down = shim->th_down; + nrf->threshold.th_up = shim->th_up; + + if (shim_nrf_comp_sp_mode_to_nrf(shim->sp_mode, &nrf->speed_mode)) { + return -EINVAL; + } + + nrf->hyst = NRF_COMP_HYST_NO_HYST; + +#if NRF_COMP_HAS_ISOURCE + if (shim_nrf_comp_isource_to_nrf(shim->isource, &nrf->isource)) { + return -EINVAL; + } +#else + if (shim->isource != COMP_NRF_COMP_ISOURCE_DISABLED) { + return -EINVAL; + } +#endif + + if (shim_nrf_comp_psel_to_nrf(shim->psel, &nrf->input)) { + return -EINVAL; + } + + nrf->interrupt_priority = 0; + return 0; +} + +static int shim_nrf_comp_diff_config_to_nrf(const struct comp_nrf_comp_diff_config *shim, + nrfx_comp_config_t *nrf) +{ + nrf->reference = NRF_COMP_REF_AREF; + + if (shim_nrf_comp_extrefsel_to_nrf(shim->extrefsel, &nrf->ext_ref)) { + return -EINVAL; + } + + nrf->main_mode = NRF_COMP_MAIN_MODE_DIFF; + nrf->threshold.th_down = 0; + nrf->threshold.th_up = 0; + + if (shim_nrf_comp_sp_mode_to_nrf(shim->sp_mode, &nrf->speed_mode)) { + return -EINVAL; + } + +#if NRF_COMP_HAS_HYST + if (shim->enable_hyst) { + nrf->hyst = NRF_COMP_HYST_ENABLED; + } else { + nrf->hyst = NRF_COMP_HYST_DISABLED; + } +#else + if (shim->enable_hyst) { + return -EINVAL; + } +#endif + +#if NRF_COMP_HAS_ISOURCE + if (shim_nrf_comp_isource_to_nrf(shim->isource, &nrf->isource)) { + return -EINVAL; + } +#else + if (shim->isource != COMP_NRF_COMP_ISOURCE_DISABLED) { + return -EINVAL; + } +#endif + + if (shim_nrf_comp_psel_to_nrf(shim->psel, &nrf->input)) { + return -EINVAL; + } + + nrf->interrupt_priority = 0; + return 0; +} + +static int shim_nrf_comp_get_output(const struct device *dev) +{ + ARG_UNUSED(dev); + + return nrfx_comp_sample(); +} + +static int shim_nrf_comp_set_trigger(const struct device *dev, + enum comparator_trigger trigger) +{ + shim_nrf_comp_stop(); + + switch (trigger) { + case COMPARATOR_TRIGGER_NONE: + shim_nrf_comp_data0.event_mask = 0; + break; + + case COMPARATOR_TRIGGER_RISING_EDGE: + shim_nrf_comp_data0.event_mask = NRF_COMP_INT_UP_MASK; + break; + + case COMPARATOR_TRIGGER_FALLING_EDGE: + shim_nrf_comp_data0.event_mask = NRF_COMP_INT_DOWN_MASK; + break; + + case COMPARATOR_TRIGGER_BOTH_EDGES: + shim_nrf_comp_data0.event_mask = NRF_COMP_INT_CROSS_MASK; + break; + } + + if (shim_nrf_comp_is_resumed()) { + shim_nrf_comp_start(); + } + + return 0; +} + +static int shim_nrf_comp_set_trigger_callback(const struct device *dev, + comparator_callback_t callback, + void *user_data) +{ + shim_nrf_comp_stop(); + + shim_nrf_comp_data0.callback = callback; + shim_nrf_comp_data0.user_data = user_data; + + if (callback != NULL && atomic_test_and_clear_bit(&shim_nrf_comp_data0.triggered, 0)) { + callback(dev, user_data); + } + + if (shim_nrf_comp_is_resumed()) { + shim_nrf_comp_start(); + } + + return 0; +} + +static int shim_nrf_comp_trigger_is_pending(const struct device *dev) +{ + ARG_UNUSED(dev); + + return atomic_test_and_clear_bit(&shim_nrf_comp_data0.triggered, 0); +} + +static const struct comparator_driver_api shim_nrf_comp_api = { + .get_output = shim_nrf_comp_get_output, + .set_trigger = shim_nrf_comp_set_trigger, + .set_trigger_callback = shim_nrf_comp_set_trigger_callback, + .trigger_is_pending = shim_nrf_comp_trigger_is_pending, +}; + +static int shim_nrf_comp_reconfigure(const nrfx_comp_config_t *nrf) +{ + shim_nrf_comp_stop(); + + (void)nrfx_comp_reconfigure(nrf); + + if (shim_nrf_comp_is_resumed()) { + shim_nrf_comp_start(); + } + + return 0; +} + +int comp_nrf_comp_configure_se(const struct device *dev, + const struct comp_nrf_comp_se_config *config) +{ + nrfx_comp_config_t nrf = {}; + + ARG_UNUSED(dev); + + if (shim_nrf_comp_se_config_to_nrf(config, &nrf)) { + return -EINVAL; + } + + return shim_nrf_comp_reconfigure(&nrf); +} + +int comp_nrf_comp_configure_diff(const struct device *dev, + const struct comp_nrf_comp_diff_config *config) +{ + nrfx_comp_config_t nrf = {}; + + ARG_UNUSED(dev); + + if (shim_nrf_comp_diff_config_to_nrf(config, &nrf)) { + return -EINVAL; + } + + return shim_nrf_comp_reconfigure(&nrf); +} + +static void shim_nrf_comp_event_handler(nrf_comp_event_t event) +{ + ARG_UNUSED(event); + + if (shim_nrf_comp_data0.callback == NULL) { + atomic_set_bit(&shim_nrf_comp_data0.triggered, 0); + return; + } + + shim_nrf_comp_data0.callback(DEVICE_DT_INST_GET(0), shim_nrf_comp_data0.user_data); + atomic_clear_bit(&shim_nrf_comp_data0.triggered, 0); +} + +static int shim_nrf_comp_init(const struct device *dev) +{ + nrfx_comp_config_t nrf = {}; + + IRQ_CONNECT(DT_INST_IRQN(0), + DT_INST_IRQ(0, priority), + nrfx_isr, + nrfx_comp_irq_handler, + 0); + + irq_enable(DT_INST_IRQN(0)); + +#if SHIM_NRF_COMP_DT_INST_MAIN_MODE_IS_SE(0) + (void)shim_nrf_comp_se_config_to_nrf(&shim_nrf_comp_config0, &nrf); +#else + (void)shim_nrf_comp_diff_config_to_nrf(&shim_nrf_comp_config0, &nrf); +#endif + + if (nrfx_comp_init(&nrf, shim_nrf_comp_event_handler) != NRFX_SUCCESS) { + return -ENODEV; + } + + return pm_device_driver_init(dev, shim_nrf_comp_pm_callback); +} + +PM_DEVICE_DT_INST_DEFINE(0, shim_nrf_comp_pm_callback); + +DEVICE_DT_INST_DEFINE(0, + shim_nrf_comp_init, + PM_DEVICE_DT_INST_GET(0), + NULL, + NULL, + POST_KERNEL, + CONFIG_COMPARATOR_INIT_PRIORITY, + &shim_nrf_comp_api); diff --git a/drivers/comparator/comparator_nrf_lpcomp.c b/drivers/comparator/comparator_nrf_lpcomp.c new file mode 100644 index 000000000000..6c6710d337d8 --- /dev/null +++ b/drivers/comparator/comparator_nrf_lpcomp.c @@ -0,0 +1,491 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include +#include + +#include + +#define DT_DRV_COMPAT nordic_nrf_lpcomp + +#define SHIM_NRF_LPCOMP_DT_INST_REFSEL(inst) \ + _CONCAT(COMP_NRF_LPCOMP_REFSEL_, DT_INST_STRING_TOKEN(inst, refsel)) + +#define SHIM_NRF_LPCOMP_DT_INST_REFSEL_IS_AREF(inst) \ + DT_INST_ENUM_HAS_VALUE(inst, refsel, AREF) + +#define SHIM_NRF_LPCOMP_DT_INST_EXTREFSEL(inst) \ + _CONCAT(COMP_NRF_LPCOMP_EXTREFSEL_, DT_INST_STRING_TOKEN(inst, extrefsel)) + +#define SHIM_NRF_LPCOMP_DT_INST_ENABLE_HYST(inst) \ + DT_INST_PROP(inst, enable_hyst) + +#define SHIM_NRF_LPCOMP_DT_INST_PSEL(inst) \ + _CONCAT(COMP_NRF_LPCOMP_PSEL_, DT_INST_STRING_TOKEN(inst, psel)) + +struct shim_nrf_lpcomp_data { + nrfx_lpcomp_config_t config; + uint32_t event_mask; + bool started; + atomic_t triggered; + comparator_callback_t callback; + void *user_data; +}; + +#if (NRF_LPCOMP_HAS_AIN_AS_PIN) +static const uint32_t shim_nrf_lpcomp_ain_map[] = { +#if defined(CONFIG_SOC_NRF54H20) || defined(CONFIG_SOC_NRF9280) + NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(1U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(2U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), +#elif defined(CONFIG_SOC_NRF54L15) + NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(11U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(13U, 1), + NRF_PIN_PORT_TO_PIN_NUMBER(14U, 1), +#endif +}; +#endif + +#if (NRF_LPCOMP_HAS_AIN_AS_PIN) +BUILD_ASSERT(COMP_NRF_LPCOMP_PSEL_AIN0 == 0); +BUILD_ASSERT(COMP_NRF_LPCOMP_PSEL_AIN7 == 7); +BUILD_ASSERT(COMP_NRF_LPCOMP_EXTREFSEL_AIN0 == 0); +BUILD_ASSERT(COMP_NRF_LPCOMP_EXTREFSEL_AIN1 == 1); +#endif + +#if (LPCOMP_REFSEL_RESOLUTION == 8) +BUILD_ASSERT((SHIM_NRF_LPCOMP_DT_INST_REFSEL(0) < COMP_NRF_LPCOMP_REFSEL_VDD_1_16) || + (SHIM_NRF_LPCOMP_DT_INST_REFSEL(0) > COMP_NRF_LPCOMP_REFSEL_VDD_15_16)); +#endif + +#if SHIM_NRF_LPCOMP_DT_INST_ENABLE_HYST(0) +BUILD_ASSERT(NRF_LPCOMP_HAS_HYST); +#endif + +static struct shim_nrf_lpcomp_data shim_nrf_lpcomp_data0; + +static const struct comp_nrf_lpcomp_config shim_nrf_lpcomp_config0 = { + .psel = SHIM_NRF_LPCOMP_DT_INST_PSEL(0), +#if SHIM_NRF_LPCOMP_DT_INST_REFSEL_IS_AREF(0) + .extrefsel = SHIM_NRF_LPCOMP_DT_INST_EXTREFSEL(0), +#endif + .refsel = SHIM_NRF_LPCOMP_DT_INST_REFSEL(0), + .enable_hyst = SHIM_NRF_LPCOMP_DT_INST_ENABLE_HYST(0), +}; + +#if CONFIG_PM_DEVICE +static bool shim_nrf_lpcomp_is_resumed(void) +{ + enum pm_device_state state; + + (void)pm_device_state_get(DEVICE_DT_INST_GET(0), &state); + return state == PM_DEVICE_STATE_ACTIVE; +} +#else +static bool shim_nrf_lpcomp_is_resumed(void) +{ + return true; +} +#endif + +static void shim_nrf_lpcomp_start(void) +{ + if (shim_nrf_lpcomp_data0.started) { + return; + } + + nrfx_lpcomp_start(shim_nrf_lpcomp_data0.event_mask, 0); + shim_nrf_lpcomp_data0.started = true; +} + +static void shim_nrf_lpcomp_stop(void) +{ + if (!shim_nrf_lpcomp_data0.started) { + return; + } + + nrfx_lpcomp_stop(); + shim_nrf_lpcomp_data0.started = false; +} + +static int shim_nrf_lpcomp_pm_callback(const struct device *dev, enum pm_device_action action) +{ + ARG_UNUSED(dev); + + ARG_UNUSED(dev); + + switch (action) { + case PM_DEVICE_ACTION_RESUME: + shim_nrf_lpcomp_start(); + break; + +#if CONFIG_PM_DEVICE + case PM_DEVICE_ACTION_SUSPEND: + shim_nrf_lpcomp_stop(); + break; +#endif + + default: + return -ENOTSUP; + } + + return 0; +} + +#if (NRF_LPCOMP_HAS_AIN_AS_PIN) +static int shim_nrf_lpcomp_psel_to_nrf(enum comp_nrf_lpcomp_psel shim, + nrf_lpcomp_input_t *nrf) +{ + if (shim >= ARRAY_SIZE(shim_nrf_lpcomp_ain_map)) { + return -EINVAL; + } + + *nrf = shim_nrf_lpcomp_ain_map[(uint32_t)shim]; + return 0; +} +#else +static int shim_nrf_lpcomp_psel_to_nrf(enum comp_nrf_lpcomp_psel shim, + nrf_lpcomp_input_t *nrf) +{ + switch (shim) { + case COMP_NRF_LPCOMP_PSEL_AIN0: + *nrf = NRF_LPCOMP_INPUT_0; + break; + + case COMP_NRF_LPCOMP_PSEL_AIN1: + *nrf = NRF_LPCOMP_INPUT_1; + break; + + case COMP_NRF_LPCOMP_PSEL_AIN2: + *nrf = NRF_LPCOMP_INPUT_2; + break; + + case COMP_NRF_LPCOMP_PSEL_AIN3: + *nrf = NRF_LPCOMP_INPUT_3; + break; + + case COMP_NRF_LPCOMP_PSEL_AIN4: + *nrf = NRF_LPCOMP_INPUT_4; + break; + + case COMP_NRF_LPCOMP_PSEL_AIN5: + *nrf = NRF_LPCOMP_INPUT_5; + break; + + case COMP_NRF_LPCOMP_PSEL_AIN6: + *nrf = NRF_LPCOMP_INPUT_6; + break; + + case COMP_NRF_LPCOMP_PSEL_AIN7: + *nrf = NRF_LPCOMP_INPUT_7; + break; + + default: + return -EINVAL; + } + + return 0; +} +#endif + +#if (NRF_LPCOMP_HAS_AIN_AS_PIN) +static int shim_nrf_lpcomp_extrefsel_to_nrf(enum comp_nrf_lpcomp_extrefsel shim, + nrf_lpcomp_ext_ref_t *nrf) +{ + if (shim >= ARRAY_SIZE(shim_nrf_lpcomp_ain_map)) { + return -EINVAL; + } + + *nrf = shim_nrf_lpcomp_ain_map[shim]; + return 0; +} +#else +static int shim_nrf_lpcomp_extrefsel_to_nrf(enum comp_nrf_lpcomp_extrefsel shim, + nrf_lpcomp_ext_ref_t *nrf) +{ + switch (shim) { + case COMP_NRF_LPCOMP_EXTREFSEL_AIN0: + *nrf = NRF_LPCOMP_EXT_REF_REF0; + break; + + case COMP_NRF_LPCOMP_EXTREFSEL_AIN1: + *nrf = NRF_LPCOMP_EXT_REF_REF1; + break; + + default: + return -EINVAL; + } + + return 0; +} +#endif + +static int shim_nrf_lpcomp_refsel_to_nrf(enum comp_nrf_lpcomp_refsel shim, + nrf_lpcomp_ref_t *nrf) +{ + switch (shim) { + case COMP_NRF_LPCOMP_REFSEL_VDD_1_8: + *nrf = NRF_LPCOMP_REF_SUPPLY_1_8; + break; + + case COMP_NRF_LPCOMP_REFSEL_VDD_2_8: + *nrf = NRF_LPCOMP_REF_SUPPLY_2_8; + break; + + case COMP_NRF_LPCOMP_REFSEL_VDD_3_8: + *nrf = NRF_LPCOMP_REF_SUPPLY_3_8; + break; + + case COMP_NRF_LPCOMP_REFSEL_VDD_4_8: + *nrf = NRF_LPCOMP_REF_SUPPLY_4_8; + break; + + case COMP_NRF_LPCOMP_REFSEL_VDD_5_8: + *nrf = NRF_LPCOMP_REF_SUPPLY_5_8; + break; + + case COMP_NRF_LPCOMP_REFSEL_VDD_6_8: + *nrf = NRF_LPCOMP_REF_SUPPLY_6_8; + break; + + case COMP_NRF_LPCOMP_REFSEL_VDD_7_8: + *nrf = NRF_LPCOMP_REF_SUPPLY_7_8; + break; + +#if (LPCOMP_REFSEL_RESOLUTION == 16) + case COMP_NRF_LPCOMP_REFSEL_VDD_1_16: + *nrf = NRF_LPCOMP_REF_SUPPLY_1_16; + break; + + case COMP_NRF_LPCOMP_REFSEL_VDD_3_16: + *nrf = NRF_LPCOMP_REF_SUPPLY_3_16; + break; + + case COMP_NRF_LPCOMP_REFSEL_VDD_5_16: + *nrf = NRF_LPCOMP_REF_SUPPLY_5_16; + break; + + case COMP_NRF_LPCOMP_REFSEL_VDD_7_16: + *nrf = NRF_LPCOMP_REF_SUPPLY_7_16; + break; + + case COMP_NRF_LPCOMP_REFSEL_VDD_9_16: + *nrf = NRF_LPCOMP_REF_SUPPLY_9_16; + break; + + case COMP_NRF_LPCOMP_REFSEL_VDD_11_16: + *nrf = NRF_LPCOMP_REF_SUPPLY_11_16; + break; + + case COMP_NRF_LPCOMP_REFSEL_VDD_13_16: + *nrf = NRF_LPCOMP_REF_SUPPLY_13_16; + break; + + case COMP_NRF_LPCOMP_REFSEL_VDD_15_16: + *nrf = NRF_LPCOMP_REF_SUPPLY_15_16; + break; +#endif + + case COMP_NRF_LPCOMP_REFSEL_AREF: + *nrf = NRF_LPCOMP_REF_EXT_REF; + break; + + default: + return -EINVAL; + } + + return 0; +} + +static int shim_nrf_lpcomp_config_to_nrf(const struct comp_nrf_lpcomp_config *shim, + nrfx_lpcomp_config_t *nrf) +{ + if (shim_nrf_lpcomp_refsel_to_nrf(shim->refsel, &nrf->reference)) { + return -EINVAL; + } + + if (shim_nrf_lpcomp_extrefsel_to_nrf(shim->extrefsel, &nrf->ext_ref)) { + return -EINVAL; + } + +#if NRF_LPCOMP_HAS_HYST + if (shim->enable_hyst) { + nrf->hyst = NRF_LPCOMP_HYST_ENABLED; + } else { + nrf->hyst = NRF_LPCOMP_HYST_NOHYST; + } +#else + if (shim->enable_hyst) { + return -EINVAL; + } +#endif + + if (shim_nrf_lpcomp_psel_to_nrf(shim->psel, &nrf->input)) { + return -EINVAL; + } + + return 0; +} + +static void shim_nrf_lpcomp_reconfigure(void) +{ + (void)nrfx_lpcomp_reconfigure(&shim_nrf_lpcomp_data0.config); +} + +static int shim_nrf_lpcomp_get_output(const struct device *dev) +{ + ARG_UNUSED(dev); + + return nrfx_lpcomp_sample(); +} + +static int shim_nrf_lpcomp_set_trigger(const struct device *dev, + enum comparator_trigger trigger) +{ + shim_nrf_lpcomp_stop(); + + switch (trigger) { + case COMPARATOR_TRIGGER_NONE: + shim_nrf_lpcomp_data0.event_mask = 0; + shim_nrf_lpcomp_data0.config.detection = NRF_LPCOMP_DETECT_CROSS; + break; + + case COMPARATOR_TRIGGER_RISING_EDGE: + shim_nrf_lpcomp_data0.event_mask = NRF_LPCOMP_INT_UP_MASK; + shim_nrf_lpcomp_data0.config.detection = NRF_LPCOMP_DETECT_UP; + break; + + case COMPARATOR_TRIGGER_FALLING_EDGE: + shim_nrf_lpcomp_data0.event_mask = NRF_LPCOMP_INT_DOWN_MASK; + shim_nrf_lpcomp_data0.config.detection = NRF_LPCOMP_DETECT_DOWN; + break; + + case COMPARATOR_TRIGGER_BOTH_EDGES: + shim_nrf_lpcomp_data0.event_mask = NRF_LPCOMP_INT_CROSS_MASK; + shim_nrf_lpcomp_data0.config.detection = NRF_LPCOMP_DETECT_CROSS; + break; + } + + shim_nrf_lpcomp_reconfigure(); + + if (shim_nrf_lpcomp_is_resumed()) { + shim_nrf_lpcomp_start(); + } + + return 0; +} + +static int shim_nrf_lpcomp_set_trigger_callback(const struct device *dev, + comparator_callback_t callback, + void *user_data) +{ + shim_nrf_lpcomp_stop(); + + shim_nrf_lpcomp_data0.callback = callback; + shim_nrf_lpcomp_data0.user_data = user_data; + + if (callback != NULL && atomic_test_and_clear_bit(&shim_nrf_lpcomp_data0.triggered, 0)) { + callback(dev, user_data); + } + + if (shim_nrf_lpcomp_is_resumed()) { + shim_nrf_lpcomp_start(); + } + + return 0; +} + +static int shim_nrf_lpcomp_trigger_is_pending(const struct device *dev) +{ + ARG_UNUSED(dev); + + return atomic_test_and_clear_bit(&shim_nrf_lpcomp_data0.triggered, 0); +} + +static const struct comparator_driver_api shim_nrf_lpcomp_api = { + .get_output = shim_nrf_lpcomp_get_output, + .set_trigger = shim_nrf_lpcomp_set_trigger, + .set_trigger_callback = shim_nrf_lpcomp_set_trigger_callback, + .trigger_is_pending = shim_nrf_lpcomp_trigger_is_pending, +}; + +int comp_nrf_lpcomp_configure(const struct device *dev, + const struct comp_nrf_lpcomp_config *config) +{ + nrfx_lpcomp_config_t nrf = {}; + + if (shim_nrf_lpcomp_config_to_nrf(config, &nrf)) { + return -EINVAL; + } + + memcpy(&shim_nrf_lpcomp_data0.config, &nrf, sizeof(shim_nrf_lpcomp_data0.config)); + + shim_nrf_lpcomp_stop(); + shim_nrf_lpcomp_reconfigure(); + if (shim_nrf_lpcomp_is_resumed()) { + shim_nrf_lpcomp_start(); + } + + return 0; +} + +static void shim_nrf_lpcomp_event_handler(nrf_lpcomp_event_t event) +{ + ARG_UNUSED(event); + + if (shim_nrf_lpcomp_data0.callback == NULL) { + atomic_set_bit(&shim_nrf_lpcomp_data0.triggered, 0); + return; + } + + shim_nrf_lpcomp_data0.callback(DEVICE_DT_INST_GET(0), shim_nrf_lpcomp_data0.user_data); + atomic_clear_bit(&shim_nrf_lpcomp_data0.triggered, 0); +} + +static int shim_nrf_lpcomp_init(const struct device *dev) +{ + IRQ_CONNECT(DT_INST_IRQN(0), + DT_INST_IRQ(0, priority), + nrfx_isr, + nrfx_lpcomp_irq_handler, + 0); + + irq_enable(DT_INST_IRQN(0)); + + (void)shim_nrf_lpcomp_config_to_nrf(&shim_nrf_lpcomp_config0, + &shim_nrf_lpcomp_data0.config); + + if (nrfx_lpcomp_init(&shim_nrf_lpcomp_data0.config, + shim_nrf_lpcomp_event_handler) != NRFX_SUCCESS) { + return -ENODEV; + } + + return pm_device_driver_init(dev, shim_nrf_lpcomp_pm_callback); +} + +PM_DEVICE_DT_INST_DEFINE(0, shim_nrf_lpcomp_pm_callback); + +DEVICE_DT_INST_DEFINE(0, + shim_nrf_lpcomp_init, + PM_DEVICE_DT_INST_GET(0), + NULL, + NULL, + POST_KERNEL, + CONFIG_COMPARATOR_INIT_PRIORITY, + &shim_nrf_lpcomp_api); diff --git a/drivers/comparator/comparator_shell.c b/drivers/comparator/comparator_shell.c new file mode 100644 index 000000000000..2d7475308716 --- /dev/null +++ b/drivers/comparator/comparator_shell.c @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include + +#define AWAIT_TRIGGER_DEFAULT_TIMEOUT \ + CONFIG_COMPARATOR_SHELL_AWAIT_TRIGGER_DEFAULT_TIMEOUT + +#define AWAIT_TRIGGER_MAX_TIMEOUT \ + CONFIG_COMPARATOR_SHELL_AWAIT_TRIGGER_MAX_TIMEOUT + +/* Mapped 1-1 to enum comparator_trigger */ +static const char *const trigger_lookup[] = { + "NONE", + "RISING_EDGE", + "FALLING_EDGE", + "BOTH_EDGES", +}; + +static K_SEM_DEFINE(triggered_sem, 0, 1); + +static int get_device_from_str(const struct shell *sh, + const char *dev_str, + const struct device **dev) +{ + *dev = device_get_binding(dev_str); + + if (*dev == NULL) { + shell_error(sh, "%s not %s", dev_str, "found"); + return -ENODEV; + } + + if (!device_is_ready(*dev)) { + shell_error(sh, "%s not %s", dev_str, "ready"); + return -ENODEV; + } + + return 0; +} + +static int cmd_get_output(const struct shell *sh, size_t argc, char **argv) +{ + int ret; + const char *dev_str; + const struct device *dev; + + ARG_UNUSED(argc); + + dev_str = argv[1]; + ret = get_device_from_str(sh, dev_str, &dev); + if (ret < 0) { + return ret; + } + + ret = comparator_get_output(dev); + if (ret < 0) { + shell_error(sh, "failed to %s %s", "get", "output"); + return -EIO; + } + + shell_print(sh, "%i", ret); + return 0; +} + +static int get_trigger_from_str(const struct shell *sh, + const char *trigger_str, + enum comparator_trigger *trigger) +{ + ARRAY_FOR_EACH(trigger_lookup, i) { + if (strcmp(trigger_lookup[i], trigger_str) == 0) { + *trigger = (enum comparator_trigger)i; + return 0; + } + } + + shell_error(sh, "%s not %s", trigger_str, "valid"); + return -EINVAL; +} + +static int cmd_set_trigger(const struct shell *sh, size_t argc, char **argv) +{ + const char *dev_str; + const char *trigger_str; + int ret; + const struct device *dev; + enum comparator_trigger trigger; + + ARG_UNUSED(argc); + + dev_str = argv[1]; + ret = get_device_from_str(sh, dev_str, &dev); + if (ret < 0) { + return ret; + } + + trigger_str = argv[2]; + ret = get_trigger_from_str(sh, trigger_str, &trigger); + if (ret < 0) { + return ret; + } + + ret = comparator_set_trigger(dev, trigger); + if (ret < 0) { + shell_error(sh, "failed to %s %s", "set", "trigger"); + return -EIO; + } + + return 0; +} + +static int get_timeout_from_str(const struct shell *sh, + const char *timeout_str, + k_timeout_t *timeout) +{ + long seconds; + char *end; + + seconds = strtol(timeout_str, &end, 10); + if ((*end != '\0') || + (seconds < 1) || + (seconds > AWAIT_TRIGGER_MAX_TIMEOUT)) { + shell_error(sh, "%s not %s", timeout_str, "valid"); + return -EINVAL; + } + + *timeout = K_SECONDS(seconds); + return 0; +} + +static void trigger_cb(const struct device *dev, void *user_data) +{ + ARG_UNUSED(dev); + ARG_UNUSED(user_data); + + k_sem_give(&triggered_sem); +} + +static int cmd_await_trigger(const struct shell *sh, size_t argc, char **argv) +{ + const char *dev_str; + const char *timeout_str; + int ret; + const struct device *dev; + k_timeout_t timeout; + + dev_str = argv[1]; + ret = get_device_from_str(sh, dev_str, &dev); + if (ret < 0) { + return ret; + } + + if (argc == 3) { + timeout_str = argv[2]; + ret = get_timeout_from_str(sh, timeout_str, &timeout); + if (ret < 0) { + return ret; + } + } else { + timeout = K_SECONDS(AWAIT_TRIGGER_DEFAULT_TIMEOUT); + } + + k_sem_reset(&triggered_sem); + + ret = comparator_set_trigger_callback(dev, trigger_cb, NULL); + if (ret < 0) { + shell_error(sh, "failed to %s %s", "set", "trigger callback"); + return -EIO; + } + + ret = k_sem_take(&triggered_sem, timeout); + if (ret == 0) { + shell_print(sh, "triggered"); + } else if (ret == -EAGAIN) { + shell_print(sh, "timed out"); + } else { + shell_error(sh, "internal error"); + } + + ret = comparator_set_trigger_callback(dev, NULL, NULL); + if (ret < 0) { + shell_error(sh, "failed to %s %s", "clear", "trigger callback"); + return -EIO; + } + + return 0; +} + +static int cmd_trigger_is_pending(const struct shell *sh, size_t argc, char **argv) +{ + int ret; + const char *dev_str; + const struct device *dev; + + ARG_UNUSED(argc); + + dev_str = argv[1]; + ret = get_device_from_str(sh, dev_str, &dev); + if (ret < 0) { + return ret; + } + + ret = comparator_trigger_is_pending(dev); + if (ret < 0) { + shell_error(sh, "failed to %s %s", "get", "trigger status"); + return -EIO; + } + + shell_print(sh, "%i", ret); + return 0; +} + +static void dsub_set_trigger_lookup_1(size_t idx, struct shell_static_entry *entry) +{ + entry->syntax = (idx < ARRAY_SIZE(trigger_lookup)) ? trigger_lookup[idx] : NULL; + entry->handler = NULL; + entry->help = NULL; + entry->subcmd = NULL; +} + +SHELL_DYNAMIC_CMD_CREATE(dsub_set_trigger_1, dsub_set_trigger_lookup_1); + +static void dsub_set_trigger_lookup_0(size_t idx, struct shell_static_entry *entry) +{ + const struct device *dev = shell_device_lookup(idx, NULL); + + entry->syntax = dev != NULL ? dev->name : NULL; + entry->handler = NULL; + entry->help = NULL; + entry->subcmd = &dsub_set_trigger_1; +} + +SHELL_DYNAMIC_CMD_CREATE(dsub_set_trigger_0, dsub_set_trigger_lookup_0); + +static void dsub_device_lookup_0(size_t idx, struct shell_static_entry *entry) +{ + const struct device *dev = shell_device_lookup(idx, NULL); + + entry->syntax = (dev != NULL) ? dev->name : NULL; + entry->handler = NULL; + entry->help = NULL; + entry->subcmd = NULL; +} + +SHELL_DYNAMIC_CMD_CREATE(dsub_device_0, dsub_device_lookup_0); + +#define GET_OUTPUT_HELP \ + ("comp get_output ") + +#define SET_TRIGGER_HELP \ + ("comp set_trigger ") + +#define AWAIT_TRIGGER_HELP \ + ("comp await_trigger [timeout] (default " \ + STRINGIFY(AWAIT_TRIGGER_DEFAULT_TIMEOUT) \ + "s, max " \ + STRINGIFY(AWAIT_TRIGGER_MAX_TIMEOUT) \ + "s)") + +#define TRIGGER_PENDING_HELP \ + ("comp trigger_is_pending ") + +SHELL_STATIC_SUBCMD_SET_CREATE( + sub_comp, + SHELL_CMD_ARG(get_output, &dsub_device_0, GET_OUTPUT_HELP, cmd_get_output, 2, 0), + SHELL_CMD_ARG(set_trigger, &dsub_set_trigger_0, SET_TRIGGER_HELP, cmd_set_trigger, 3, 0), + SHELL_CMD_ARG(await_trigger, &dsub_device_0, AWAIT_TRIGGER_HELP, cmd_await_trigger, 2, 1), + SHELL_CMD_ARG(trigger_is_pending, &dsub_device_0, TRIGGER_PENDING_HELP, + cmd_trigger_is_pending, 2, 1), + SHELL_SUBCMD_SET_END +); + +SHELL_CMD_REGISTER(comp, &sub_comp, "Comparator device commands", NULL); diff --git a/drivers/counter/counter_mcux_snvs.c b/drivers/counter/counter_mcux_snvs.c index 3346cc21e75e..172b4b894a30 100644 --- a/drivers/counter/counter_mcux_snvs.c +++ b/drivers/counter/counter_mcux_snvs.c @@ -311,7 +311,7 @@ static const struct counter_driver_api mcux_snvs_driver_api = { BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) <= 1, "unsupported snvs instance"); -#if DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) static struct mcux_snvs_data mcux_snvs_data_0; static void mcux_snvs_irq_config_0(const struct device *dev); @@ -339,4 +339,4 @@ static void mcux_snvs_irq_config_0(const struct device *dev) mcux_snvs_isr, DEVICE_DT_INST_GET(0), 0); irq_enable(DT_INST_IRQN(0)); } -#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) */ diff --git a/drivers/counter/counter_smartbond_timer.c b/drivers/counter/counter_smartbond_timer.c index 8dc3baba045f..8ee8f006dae6 100644 --- a/drivers/counter/counter_smartbond_timer.c +++ b/drivers/counter/counter_smartbond_timer.c @@ -27,7 +27,7 @@ LOG_MODULE_REGISTER(counter_timer, CONFIG_COUNTER_LOG_LEVEL); #define COUNTER_DT_DEVICE(_idx) DEVICE_DT_GET_OR_NULL(DT_NODELABEL(timer##_idx)) -#define PDC_XTAL_EN (DT_NODE_HAS_STATUS(DT_NODELABEL(xtal32m), okay) ? \ +#define PDC_XTAL_EN (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(xtal32m)) ? \ MCU_PDC_EN_XTAL : MCU_PDC_EN_NONE) struct counter_smartbond_data { diff --git a/drivers/disk/sdmmc_stm32.c b/drivers/disk/sdmmc_stm32.c index a344bb9d1923..393950fb6643 100644 --- a/drivers/disk/sdmmc_stm32.c +++ b/drivers/disk/sdmmc_stm32.c @@ -710,7 +710,7 @@ static int disk_stm32_sdmmc_init(const struct device *dev) return err; } -#if DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) #if STM32_SDMMC_USE_DMA diff --git a/drivers/dma/dma_mcux_edma.c b/drivers/dma/dma_mcux_edma.c index 26c7cf58c34b..7da8bf79b06d 100644 --- a/drivers/dma/dma_mcux_edma.c +++ b/drivers/dma/dma_mcux_edma.c @@ -55,11 +55,11 @@ struct dma_mcux_edma_config { #ifdef CONFIG_DMA_MCUX_USE_DTCM_FOR_DMA_DESCRIPTORS -#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)) #define EDMA_TCDPOOL_CACHE_ATTR __dtcm_noinit_section -#else /* DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay) */ +#else /* DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)) */ #error Selected DTCM for MCUX DMA descriptors but no DTCM section. -#endif /* DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)) */ #elif defined(CONFIG_NOCACHE_MEMORY) #define EDMA_TCDPOOL_CACHE_ATTR __nocache diff --git a/drivers/dma/dma_stm32.c b/drivers/dma/dma_stm32.c index 178d83665b4c..e2941a77cdcc 100644 --- a/drivers/dma/dma_stm32.c +++ b/drivers/dma/dma_stm32.c @@ -29,7 +29,7 @@ LOG_MODULE_REGISTER(dma_stm32, CONFIG_DMA_LOG_LEVEL); #define DT_DRV_COMPAT st_stm32_dma_v2bis #endif -#if DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) #if DT_INST_IRQ_HAS_IDX(0, 7) #define DMA_STM32_0_STREAM_COUNT 8 #elif DT_INST_IRQ_HAS_IDX(0, 6) @@ -41,9 +41,9 @@ LOG_MODULE_REGISTER(dma_stm32, CONFIG_DMA_LOG_LEVEL); #else #define DMA_STM32_0_STREAM_COUNT 3 #endif -#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) */ -#if DT_NODE_HAS_STATUS(DT_DRV_INST(1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(1)) #if DT_INST_IRQ_HAS_IDX(1, 7) #define DMA_STM32_1_STREAM_COUNT 8 #elif DT_INST_IRQ_HAS_IDX(1, 6) @@ -53,7 +53,7 @@ LOG_MODULE_REGISTER(dma_stm32, CONFIG_DMA_LOG_LEVEL); #else #define DMA_STM32_1_STREAM_COUNT 5 #endif -#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(1), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(1)) */ static const uint32_t table_m_size[] = { LL_DMA_MDATAALIGN_BYTE, @@ -755,7 +755,7 @@ static void dma_stm32_irq_##dma##_##chan(const struct device *dev) \ #endif /* CONFIG_DMA_STM32_SHARED_IRQS */ -#if DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) DMA_STM32_DEFINE_IRQ_HANDLER(0, 0); DMA_STM32_DEFINE_IRQ_HANDLER(0, 1); @@ -803,10 +803,10 @@ static void dma_stm32_config_irq_0(const struct device *dev) DMA_STM32_INIT_DEV(0); -#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) */ -#if DT_NODE_HAS_STATUS(DT_DRV_INST(1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(1)) DMA_STM32_DEFINE_IRQ_HANDLER(1, 0); DMA_STM32_DEFINE_IRQ_HANDLER(1, 1); @@ -855,4 +855,4 @@ static void dma_stm32_config_irq_1(const struct device *dev) DMA_STM32_INIT_DEV(1); -#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(1), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(1)) */ diff --git a/drivers/dma/dma_stm32_bdma.c b/drivers/dma/dma_stm32_bdma.c index 1df5746facbf..7f769f47ac4a 100644 --- a/drivers/dma/dma_stm32_bdma.c +++ b/drivers/dma/dma_stm32_bdma.c @@ -901,7 +901,7 @@ static void bdma_stm32_irq_##bdma##_##chan(const struct device *dev) \ } while (false) -#if DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) #define BDMA_STM32_DEFINE_IRQ_HANDLER_GEN(i, _) \ BDMA_STM32_DEFINE_IRQ_HANDLER(0, i) @@ -918,4 +918,4 @@ static void bdma_stm32_config_irq_0(const struct device *dev) BDMA_STM32_INIT_DEV(0); -#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) */ diff --git a/drivers/dma/dmamux_stm32.c b/drivers/dma/dmamux_stm32.c index d12a294eb7ff..27e02b1c1880 100644 --- a/drivers/dma/dmamux_stm32.c +++ b/drivers/dma/dmamux_stm32.c @@ -108,7 +108,7 @@ struct dmamux_stm32_dma_fops { }; #if (defined(CONFIG_DMA_STM32_V1) || defined(CONFIG_DMA_STM32_V2)) && \ - DT_NODE_HAS_STATUS(DT_NODELABEL(dmamux1), okay) + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dmamux1)) static const struct dmamux_stm32_dma_fops dmamux1 = { dma_stm32_configure, dma_stm32_start, @@ -118,7 +118,7 @@ static const struct dmamux_stm32_dma_fops dmamux1 = { }; #endif -#if defined(CONFIG_DMA_STM32_BDMA) && DT_NODE_HAS_STATUS(DT_NODELABEL(dmamux2), okay) +#if defined(CONFIG_DMA_STM32_BDMA) && DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dmamux2)) static const struct dmamux_stm32_dma_fops dmamux2 = { bdma_stm32_configure, bdma_stm32_start, @@ -130,17 +130,17 @@ static const struct dmamux_stm32_dma_fops dmamux2 = { const struct dmamux_stm32_dma_fops *get_dma_fops(const struct dmamux_stm32_config *dev_config) { -#if DT_NODE_HAS_STATUS(DT_NODELABEL(dmamux1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dmamux1)) if (dev_config->base == DT_REG_ADDR(DT_NODELABEL(dmamux1))) { return &dmamux1; } -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(dmamux1), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dmamux1)) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(dmamux2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dmamux2)) if (dev_config->base == DT_REG_ADDR(DT_NODELABEL(dmamux2))) { return &dmamux2; } -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(dmamux2), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dmamux2)) */ __ASSERT(false, "Unknown dma base address %x", dev_config->base); return (void *)0; @@ -298,24 +298,24 @@ static int dmamux_stm32_init(const struct device *dev) } #endif /* DT_INST_NODE_HAS_PROP(0, clocks) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(dmamux1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dmamux1)) /* DMA 1 and DMA2 for DMAMUX1, BDMA for DMAMUX2 */ if (config->base == DT_REG_ADDR(DT_NODELABEL(dmamux1))) { /* DMAs assigned to DMAMUX channels at build time might not be ready. */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(dma1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dma1)) if (device_is_ready(DEVICE_DT_GET(DT_NODELABEL(dma1))) == false) { return -ENODEV; } #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(dma2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dma2)) if (device_is_ready(DEVICE_DT_GET(DT_NODELABEL(dma2))) == false) { return -ENODEV; } #endif } -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(dmamux1), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dmamux1)) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(dmamux2), okay) && DT_NODE_HAS_STATUS(DT_NODELABEL(bdma1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dmamux2)) && DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(bdma1)) if (config->base == DT_REG_ADDR(DT_NODELABEL(dmamux2))) { if (device_is_ready(DEVICE_DT_GET(DT_NODELABEL(bdma1))) == false) { return -ENODEV; @@ -346,19 +346,19 @@ static const struct dma_driver_api dma_funcs = { #define DMA_1_BEGIN_DMAMUX_CHANNEL DT_PROP_OR(DT_NODELABEL(dma1), dma_offset, 0) #define DMA_1_END_DMAMUX_CHANNEL (DMA_1_BEGIN_DMAMUX_CHANNEL + \ DT_PROP_OR(DT_NODELABEL(dma1), dma_requests, 0)) -#define DEV_DMA1 COND_CODE_1(DT_NODE_HAS_STATUS(DT_NODELABEL(dma1), okay), \ +#define DEV_DMA1 COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dma1)), \ DEVICE_DT_GET(DT_NODELABEL(dma1)), NULL) #define DMA_2_BEGIN_DMAMUX_CHANNEL DT_PROP_OR(DT_NODELABEL(dma2), dma_offset, 0) #define DMA_2_END_DMAMUX_CHANNEL (DMA_2_BEGIN_DMAMUX_CHANNEL + \ DT_PROP_OR(DT_NODELABEL(dma2), dma_requests, 0)) -#define DEV_DMA2 COND_CODE_1(DT_NODE_HAS_STATUS(DT_NODELABEL(dma2), okay), \ +#define DEV_DMA2 COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dma2)), \ DEVICE_DT_GET(DT_NODELABEL(dma2)), NULL) #define BDMA_1_BEGIN_DMAMUX_CHANNEL DT_PROP_OR(DT_NODELABEL(bdma1), dma_offset, 0) #define BDMA_1_END_DMAMUX_CHANNEL (BDMA_1_BEGIN_DMAMUX_CHANNEL + \ DT_PROP_OR(DT_NODELABEL(bdma1), dma_requests, 0)) -#define DEV_BDMA COND_CODE_1(DT_NODE_HAS_STATUS(DT_NODELABEL(bdma1), okay), \ +#define DEV_BDMA COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(bdma1)), \ DEVICE_DT_GET(DT_NODELABEL(bdma1)), NULL) #define DEV_DMA_BINDING(mux_channel) \ diff --git a/drivers/espi/espi_mchp_xec_host_v2.c b/drivers/espi/espi_mchp_xec_host_v2.c index 8cf4e085ed5f..12d32007e84b 100644 --- a/drivers/espi/espi_mchp_xec_host_v2.c +++ b/drivers/espi/espi_mchp_xec_host_v2.c @@ -108,7 +108,7 @@ static uint8_t ec_host_cmd_sram[CONFIG_ESPI_XEC_PERIPHERAL_HOST_CMD_PARAM_SIZE] #ifdef CONFIG_ESPI_PERIPHERAL_XEC_MAILBOX -BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(mbox0), okay), +BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(mbox0)), "XEC mbox0 DT node is disabled!"); static struct xec_mbox_config { @@ -171,7 +171,7 @@ static int init_mbox0(const struct device *dev) #ifdef CONFIG_ESPI_PERIPHERAL_8042_KBC -BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(kbc0), okay), +BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(kbc0)), "XEC kbc0 DT node is disabled!"); struct xec_kbc0_config { @@ -665,7 +665,7 @@ static int init_acpi_ec1(const struct device *dev) #ifdef CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD -BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(emi0), okay), +BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(emi0)), "XEC EMI0 DT node is disabled!"); struct xec_emi_config { diff --git a/drivers/ethernet/eth_stm32_hal.c b/drivers/ethernet/eth_stm32_hal.c index 02ae6830f605..4186039a1be6 100644 --- a/drivers/ethernet/eth_stm32_hal.c +++ b/drivers/ethernet/eth_stm32_hal.c @@ -50,7 +50,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #endif #if defined(CONFIG_ETH_STM32_HAL_USE_DTCM_FOR_DMA_BUFFER) && \ - !DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay) + !DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)) #error DTCM for DMA buffer is activated but zephyr,dtcm is not present in dts #endif @@ -91,7 +91,7 @@ static const struct device *eth_stm32_phy_dev = DEVICE_PHY_BY_NAME(0); #define ETH_DMA_TX_TIMEOUT_MS 20U /* transmit timeout in milliseconds */ #if defined(CONFIG_ETH_STM32_HAL_USE_DTCM_FOR_DMA_BUFFER) && \ - DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay) + DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)) #define __eth_stm32_desc __dtcm_noinit_section #define __eth_stm32_buf __dtcm_noinit_section #elif defined(CONFIG_SOC_SERIES_STM32H7X) diff --git a/drivers/ethernet/nxp_enet/eth_mcux.c b/drivers/ethernet/nxp_enet/eth_mcux.c index 2ac0296d6b28..397fa58bae14 100644 --- a/drivers/ethernet/nxp_enet/eth_mcux.c +++ b/drivers/ethernet/nxp_enet/eth_mcux.c @@ -149,7 +149,7 @@ static const char *eth_name(ENET_Type *base) switch ((int)base) { case DT_INST_REG_ADDR(0): return "ETH_0"; -#if DT_NODE_HAS_STATUS(DT_DRV_INST(1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(1)) case DT_INST_REG_ADDR(1): return "ETH_1"; #endif @@ -964,10 +964,10 @@ static void eth_mcux_init(const struct device *dev) context->phy_handle->ops = &phyksz8081_ops; #if defined(CONFIG_SOC_SERIES_IMXRT10XX) -#if DT_NODE_HAS_STATUS(DT_NODELABEL(enet), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(enet)) sys_clock = CLOCK_GetFreq(kCLOCK_IpgClk); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(enet2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(enet2)) sys_clock = CLOCK_GetFreq(kCLOCK_EnetPll1Clk); #endif #elif defined(CONFIG_SOC_SERIES_IMXRT11XX) @@ -1350,7 +1350,7 @@ static void eth_mcux_err_isr(const struct device *dev) } while (false) #define ETH_MCUX_IRQ_PTP(n) \ - COND_CODE_1(DT_NODE_HAS_STATUS(PTP_INST_NODEID(n), okay), \ + COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(PTP_INST_NODEID(n)), \ (ETH_MCUX_IRQ_PTP_INIT(n)), \ (ETH_MCUX_NONE)) @@ -1454,7 +1454,7 @@ static void eth_mcux_err_isr(const struct device *dev) #define ETH_MCUX_PINCTRL_INIT(n) #endif -#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay) && \ +#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)) && \ CONFIG_ETH_MCUX_USE_DTCM_FOR_DMA_BUFFER /* Use DTCM for hardware DMA buffers */ #define _mcux_dma_desc __dtcm_bss_section diff --git a/drivers/ethernet/nxp_enet/eth_nxp_enet.c b/drivers/ethernet/nxp_enet/eth_nxp_enet.c index a92b13f8da91..b80e0cc34bd6 100644 --- a/drivers/ethernet/nxp_enet/eth_nxp_enet.c +++ b/drivers/ethernet/nxp_enet/eth_nxp_enet.c @@ -854,7 +854,7 @@ static const struct ethernet_api api_funcs = { #define NXP_ENET_DT_PHY_DEV(node_id, phy_phandle, idx) \ DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, phy_phandle, idx)) -#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay) && \ +#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)) && \ CONFIG_ETH_NXP_ENET_USE_DTCM_FOR_DMA_BUFFER #define _nxp_enet_dma_desc_section __dtcm_bss_section #define _nxp_enet_dma_buffer_section __dtcm_noinit_section diff --git a/drivers/ethernet/phy/phy_adin2111.c b/drivers/ethernet/phy/phy_adin2111.c index 380def0ebe74..902838bd08d2 100644 --- a/drivers/ethernet/phy/phy_adin2111.c +++ b/drivers/ethernet/phy/phy_adin2111.c @@ -7,7 +7,7 @@ #include -#if DT_NODE_HAS_STATUS(DT_INST(0, adi_adin2111_phy), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_INST(0, adi_adin2111_phy)) #define DT_DRV_COMPAT adi_adin2111_phy #else #define DT_DRV_COMPAT adi_adin1100_phy diff --git a/drivers/flash/soc_flash_lpc.c b/drivers/flash/soc_flash_lpc.c index ae457fe926b7..5f931a1bf734 100644 --- a/drivers/flash/soc_flash_lpc.c +++ b/drivers/flash/soc_flash_lpc.c @@ -17,9 +17,9 @@ #include "fsl_flashiap.h" -#if DT_NODE_HAS_STATUS(DT_INST(0, nxp_iap_fmc11), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nxp_iap_fmc11)) #define DT_DRV_COMPAT nxp_iap_fmc11 -#elif DT_NODE_HAS_STATUS(DT_INST(0, nxp_iap_fmc54), okay) +#elif DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nxp_iap_fmc54)) #define DT_DRV_COMPAT nxp_iap_fmc54 #else #error No matching compatible for soc_flash_lpc.c diff --git a/drivers/flash/soc_flash_mcux.c b/drivers/flash/soc_flash_mcux.c index 6eaf90cd010c..cc743371baa8 100644 --- a/drivers/flash/soc_flash_mcux.c +++ b/drivers/flash/soc_flash_mcux.c @@ -22,19 +22,19 @@ LOG_MODULE_REGISTER(flash_mcux); -#if DT_NODE_HAS_STATUS(DT_INST(0, nxp_kinetis_ftfa), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nxp_kinetis_ftfa)) #define DT_DRV_COMPAT nxp_kinetis_ftfa -#elif DT_NODE_HAS_STATUS(DT_INST(0, nxp_kinetis_ftfe), okay) +#elif DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nxp_kinetis_ftfe)) #define DT_DRV_COMPAT nxp_kinetis_ftfe -#elif DT_NODE_HAS_STATUS(DT_INST(0, nxp_kinetis_ftfl), okay) +#elif DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nxp_kinetis_ftfl)) #define DT_DRV_COMPAT nxp_kinetis_ftfl -#elif DT_NODE_HAS_STATUS(DT_INST(0, nxp_iap_fmc55), okay) +#elif DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nxp_iap_fmc55)) #define DT_DRV_COMPAT nxp_iap_fmc55 #define SOC_HAS_IAP 1 -#elif DT_NODE_HAS_STATUS(DT_INST(0, nxp_iap_fmc553), okay) +#elif DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nxp_iap_fmc553)) #define DT_DRV_COMPAT nxp_iap_fmc553 #define SOC_HAS_IAP 1 -#elif DT_NODE_HAS_STATUS(DT_INST(0, nxp_iap_msf1), okay) +#elif DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nxp_iap_msf1)) #define DT_DRV_COMPAT nxp_iap_msf1 #define SOC_HAS_IAP_MSF1 1 #else diff --git a/drivers/flash/soc_flash_nrf.c b/drivers/flash/soc_flash_nrf.c index 16ab00b9660a..a960656f5d29 100644 --- a/drivers/flash/soc_flash_nrf.c +++ b/drivers/flash/soc_flash_nrf.c @@ -23,13 +23,13 @@ #include LOG_MODULE_REGISTER(flash_nrf); -#if DT_NODE_HAS_STATUS(DT_INST(0, nordic_nrf51_flash_controller), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nordic_nrf51_flash_controller)) #define DT_DRV_COMPAT nordic_nrf51_flash_controller -#elif DT_NODE_HAS_STATUS(DT_INST(0, nordic_nrf52_flash_controller), okay) +#elif DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nordic_nrf52_flash_controller)) #define DT_DRV_COMPAT nordic_nrf52_flash_controller -#elif DT_NODE_HAS_STATUS(DT_INST(0, nordic_nrf53_flash_controller), okay) +#elif DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nordic_nrf53_flash_controller)) #define DT_DRV_COMPAT nordic_nrf53_flash_controller -#elif DT_NODE_HAS_STATUS(DT_INST(0, nordic_nrf91_flash_controller), okay) +#elif DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nordic_nrf91_flash_controller)) #define DT_DRV_COMPAT nordic_nrf91_flash_controller #else #error No matching compatible for soc_flash_nrf.c diff --git a/drivers/gpio/gpio_esp32.c b/drivers/gpio/gpio_esp32.c index ea12070235e9..d0c933ca37df 100644 --- a/drivers/gpio/gpio_esp32.c +++ b/drivers/gpio/gpio_esp32.c @@ -284,7 +284,7 @@ static int gpio_esp32_port_get_raw(const struct device *port, uint32_t *value) if (cfg->gpio_port == 0) { *value = cfg->gpio_dev->in; -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) } else { *value = cfg->gpio_dev->in1.data; #endif @@ -302,7 +302,7 @@ static int gpio_esp32_port_set_masked_raw(const struct device *port, if (cfg->gpio_port == 0) { cfg->gpio_dev->out = (cfg->gpio_dev->out & ~mask) | (mask & value); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) } else { cfg->gpio_dev->out1.data = (cfg->gpio_dev->out1.data & ~mask) | (mask & value); #endif @@ -320,7 +320,7 @@ static int gpio_esp32_port_set_bits_raw(const struct device *port, if (cfg->gpio_port == 0) { cfg->gpio_dev->out_w1ts = pins; -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) } else { cfg->gpio_dev->out1_w1ts.data = pins; #endif @@ -336,7 +336,7 @@ static int gpio_esp32_port_clear_bits_raw(const struct device *port, if (cfg->gpio_port == 0) { cfg->gpio_dev->out_w1tc = pins; -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) } else { cfg->gpio_dev->out1_w1tc.data = pins; #endif @@ -353,7 +353,7 @@ static int gpio_esp32_port_toggle_bits(const struct device *port, if (cfg->gpio_port == 0) { cfg->gpio_dev->out ^= pins; -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) } else { cfg->gpio_dev->out1.data ^= pins; #endif @@ -531,11 +531,11 @@ static void IRAM_ATTR gpio_esp32_isr(void *param) { ARG_UNUSED(param); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio0)) gpio_esp32_fire_callbacks(DEVICE_DT_INST_GET(0)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) gpio_esp32_fire_callbacks(DEVICE_DT_INST_GET(1)); #endif } diff --git a/drivers/gpio/gpio_gd32.c b/drivers/gpio/gpio_gd32.c index 744f5e4a7768..1c40be4de4c5 100644 --- a/drivers/gpio/gpio_gd32.c +++ b/drivers/gpio/gpio_gd32.c @@ -365,7 +365,7 @@ static int gpio_gd32_init(const struct device *port) }, \ .reg = DT_INST_REG_ADDR(n), \ .clkid = DT_INST_CLOCKS_CELL(n, id), \ - COND_CODE_1(DT_NODE_HAS_STATUS(SYSCFG_NODE, okay), \ + COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(SYSCFG_NODE), \ (.clkid_exti = DT_CLOCKS_CELL(SYSCFG_NODE, id),), \ (.clkid_exti = DT_CLOCKS_CELL(AFIO_NODE, id),)) \ .reset = RESET_DT_SPEC_INST_GET(n), \ diff --git a/drivers/gpio/gpio_lpc11u6x.c b/drivers/gpio/gpio_lpc11u6x.c index a44deceed9bb..102d8c3e8b61 100644 --- a/drivers/gpio/gpio_lpc11u6x.c +++ b/drivers/gpio/gpio_lpc11u6x.c @@ -459,21 +459,21 @@ static void gpio_lpc11u6x_isr(const void *arg) } } /* For each port with active pins, fire the GPIO interrupt callbacks. */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio0)) if (pins[0]) { port = DEVICE_DT_GET(DT_NODELABEL(gpio0)); data = port->data; gpio_fire_callbacks(&data->cb_list, port, pins[0]); } #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) if (pins[1]) { port = DEVICE_DT_GET(DT_NODELABEL(gpio1)); data = port->data; gpio_fire_callbacks(&data->cb_list, port, pins[1]); } #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio2)) if (pins[2]) { port = DEVICE_DT_GET(DT_NODELABEL(gpio2)); data = port->data; @@ -589,14 +589,14 @@ DEVICE_DT_DEFINE(DT_NODELABEL(gpio##id), \ PRE_KERNEL_2, CONFIG_GPIO_INIT_PRIORITY, \ &gpio_lpc11u6x_driver_api) -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio0)) GPIO_LPC11U6X_INIT(0); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) GPIO_LPC11U6X_INIT(1); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio2)) GPIO_LPC11U6X_INIT(2); #endif diff --git a/drivers/gpio/gpio_mchp_xec.c b/drivers/gpio/gpio_mchp_xec.c index 86d9f2a5d7a5..e96130a09416 100644 --- a/drivers/gpio/gpio_mchp_xec.c +++ b/drivers/gpio/gpio_mchp_xec.c @@ -341,7 +341,7 @@ static const struct gpio_driver_api gpio_xec_driver_api = { .manage_callback = gpio_xec_manage_callback, }; -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio_000_036), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio_000_036)) static int gpio_xec_port000_036_init(const struct device *dev); static const struct gpio_xec_config gpio_xec_port000_036_config = { @@ -385,9 +385,9 @@ static int gpio_xec_port000_036_init(const struct device *dev) #endif return 0; } -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio_000_036), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio_000_036)) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio_040_076), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio_040_076)) static int gpio_xec_port040_076_init(const struct device *dev); static const struct gpio_xec_config gpio_xec_port040_076_config = { @@ -431,9 +431,9 @@ static int gpio_xec_port040_076_init(const struct device *dev) #endif return 0; } -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio_040_076), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio_040_076)) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio_100_136), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio_100_136)) static int gpio_xec_port100_136_init(const struct device *dev); static const struct gpio_xec_config gpio_xec_port100_136_config = { @@ -477,9 +477,9 @@ static int gpio_xec_port100_136_init(const struct device *dev) #endif return 0; } -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio_100_136), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio_100_136)) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio_140_176), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio_140_176)) static int gpio_xec_port140_176_init(const struct device *dev); static const struct gpio_xec_config gpio_xec_port140_176_config = { @@ -523,9 +523,9 @@ static int gpio_xec_port140_176_init(const struct device *dev) #endif return 0; } -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio_140_176), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio_140_176)) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio_200_236), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio_200_236)) static int gpio_xec_port200_236_init(const struct device *dev); static const struct gpio_xec_config gpio_xec_port200_236_config = { @@ -569,9 +569,9 @@ static int gpio_xec_port200_236_init(const struct device *dev) #endif return 0; } -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio_200_236), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio_200_236)) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio_240_276), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio_240_276)) static int gpio_xec_port240_276_init(const struct device *dev); static const struct gpio_xec_config gpio_xec_port240_276_config = { @@ -615,4 +615,4 @@ static int gpio_xec_port240_276_init(const struct device *dev) #endif return 0; } -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio_240_276), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio_240_276)) */ diff --git a/drivers/gpio/gpio_nrfx.c b/drivers/gpio/gpio_nrfx.c index d89c964cc90a..151cf1a830c5 100644 --- a/drivers/gpio/gpio_nrfx.c +++ b/drivers/gpio/gpio_nrfx.c @@ -446,7 +446,7 @@ static const struct gpio_driver_api gpio_nrfx_drv_api_funcs = { #define GPIOTE_CHECK(id) \ COND_CODE_1(DT_INST_NODE_HAS_PROP(id, gpiote_instance), \ - (BUILD_ASSERT(DT_NODE_HAS_STATUS(GPIOTE_PHANDLE(id), okay), \ + (BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(GPIOTE_PHANDLE(id)), \ "Please enable GPIOTE instance for used GPIO port!")), \ ()) diff --git a/drivers/gpio/gpio_nxp_s32.c b/drivers/gpio/gpio_nxp_s32.c index e9bcc29c907c..5e9e7a554712 100644 --- a/drivers/gpio/gpio_nxp_s32.c +++ b/drivers/gpio/gpio_nxp_s32.c @@ -519,7 +519,7 @@ static const struct gpio_driver_api gpio_nxp_s32_driver_api = { DT_NODE_HAS_PROP(DT_DRV_INST(n), interrupts)), \ "interrupts and interrupt-parent must be set when " \ "using external interrupts"); \ - IF_ENABLED(DT_NODE_HAS_STATUS(GPIO_NXP_S32_EIRQ_NODE(n), okay), ( \ + IF_ENABLED(DT_NODE_HAS_STATUS_OKAY(GPIO_NXP_S32_EIRQ_NODE(n)), ( \ static uint8_t gpio_nxp_s32_eirq_data_##n[] = { \ LISTIFY(DT_NUM_IRQS(DT_DRV_INST(n)), \ GPIO_NXP_S32_EIRQ_PIN_LINE, (,), n) \ @@ -533,7 +533,7 @@ static const struct gpio_driver_api gpio_nxp_s32_driver_api = { )) #define GPIO_NXP_S32_GET_EIRQ_INFO(n) \ - .eirq_info = UTIL_AND(DT_NODE_HAS_STATUS(GPIO_NXP_S32_EIRQ_NODE(n), okay),\ + .eirq_info = UTIL_AND(DT_NODE_HAS_STATUS_OKAY(GPIO_NXP_S32_EIRQ_NODE(n)),\ &gpio_nxp_s32_eirq_##n), #else #define GPIO_NXP_S32_SET_EIRQ_INFO(n) @@ -547,7 +547,7 @@ static const struct gpio_driver_api gpio_nxp_s32_driver_api = { BUILD_ASSERT((DT_INST_NODE_HAS_PROP(n, nxp_wkpu) == \ DT_INST_NODE_HAS_PROP(n, nxp_wkpu_interrupts)), \ "nxp,wkpu and nxp,wkpu-interrupts must be provided"); \ - IF_ENABLED(DT_NODE_HAS_STATUS(GPIO_NXP_S32_WKPU_NODE(n), okay), ( \ + IF_ENABLED(DT_NODE_HAS_STATUS_OKAY(GPIO_NXP_S32_WKPU_NODE(n)), ( \ static uint8_t gpio_nxp_s32_wkpu_data_##n[] = \ DT_INST_PROP(n, nxp_wkpu_interrupts); \ static struct gpio_nxp_s32_irq_config gpio_nxp_s32_wkpu_##n = { \ @@ -560,7 +560,7 @@ static const struct gpio_driver_api gpio_nxp_s32_driver_api = { )) #define GPIO_NXP_S32_GET_WKPU_INFO(n) \ - .wkpu_info = UTIL_AND(DT_NODE_HAS_STATUS(GPIO_NXP_S32_WKPU_NODE(n), okay),\ + .wkpu_info = UTIL_AND(DT_NODE_HAS_STATUS_OKAY(GPIO_NXP_S32_WKPU_NODE(n)),\ &gpio_nxp_s32_wkpu_##n) #else #define GPIO_NXP_S32_SET_WKPU_INFO(n) diff --git a/drivers/gpio/gpio_renesas_ra_ioport.c b/drivers/gpio/gpio_renesas_ra_ioport.c index 8005acab3607..65fc946438a2 100644 --- a/drivers/gpio/gpio_renesas_ra_ioport.c +++ b/drivers/gpio/gpio_renesas_ra_ioport.c @@ -176,7 +176,7 @@ static const struct gpio_driver_api gpio_ra_drv_api_funcs = { DT_REG_ADDR(DT_NODELABEL(ioport##suffix))) #define GPIO_DEVICE_INIT_RA_IF_OKAY(suffix) \ - COND_CODE_1(DT_NODE_HAS_STATUS(DT_NODELABEL(ioport##suffix), okay), \ + COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ioport##suffix)), \ (GPIO_DEVICE_INIT_RA(suffix)), \ ()) diff --git a/drivers/gpio/gpio_sam0.c b/drivers/gpio/gpio_sam0.c index 03cfab48e600..98234d3319d8 100644 --- a/drivers/gpio/gpio_sam0.c +++ b/drivers/gpio/gpio_sam0.c @@ -286,7 +286,7 @@ static const struct gpio_driver_api gpio_sam0_api = { static int gpio_sam0_init(const struct device *dev) { return 0; } /* Port A */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(porta), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(porta)) static const struct gpio_sam0_config gpio_sam0_config_0 = { .common = { @@ -308,7 +308,7 @@ DEVICE_DT_DEFINE(DT_NODELABEL(porta), #endif /* Port B */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(portb), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(portb)) static const struct gpio_sam0_config gpio_sam0_config_1 = { .common = { @@ -330,7 +330,7 @@ DEVICE_DT_DEFINE(DT_NODELABEL(portb), #endif /* Port C */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(portc), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(portc)) static const struct gpio_sam0_config gpio_sam0_config_2 = { .common = { @@ -352,7 +352,7 @@ DEVICE_DT_DEFINE(DT_NODELABEL(portc), #endif /* Port D */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(portd), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(portd)) static const struct gpio_sam0_config gpio_sam0_config_3 = { .common = { diff --git a/drivers/gpio/gpio_stm32.c b/drivers/gpio/gpio_stm32.c index 407c1a414e6a..23edb977755b 100644 --- a/drivers/gpio/gpio_stm32.c +++ b/drivers/gpio/gpio_stm32.c @@ -697,7 +697,7 @@ static int gpio_stm32_init(const struct device *dev) } #if (defined(PWR_CR2_IOSV) || defined(PWR_SVMCR_IO2SV)) && \ - DT_NODE_HAS_STATUS(DT_NODELABEL(gpiog), okay) + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpiog)) z_stm32_hsem_lock(CFG_HW_RCC_SEMID, HSEM_LOCK_DEFAULT_RETRY); /* Port G[15:2] requires external power supply */ /* Cf: L4/L5 RM, Chapter "Independent I/O supply rail" */ @@ -747,7 +747,7 @@ static int gpio_stm32_init(const struct device *dev) DT_CLOCKS_CELL(DT_NODELABEL(gpio##__suffix), bus)) #define GPIO_DEVICE_INIT_STM32_IF_OKAY(__suffix, __SUFFIX) \ - COND_CODE_1(DT_NODE_HAS_STATUS(DT_NODELABEL(gpio##__suffix), okay), \ + COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio##__suffix)), \ (GPIO_DEVICE_INIT_STM32(__suffix, __SUFFIX)), \ ()) diff --git a/drivers/gpio/gpio_xlnx_axi.c b/drivers/gpio/gpio_xlnx_axi.c index 4b50bf85cd6e..3b1238310f99 100644 --- a/drivers/gpio/gpio_xlnx_axi.c +++ b/drivers/gpio/gpio_xlnx_axi.c @@ -382,7 +382,7 @@ static const struct gpio_driver_api gpio_xlnx_axi_driver_api = { #define GPIO_XLNX_AXI_GPIO2_HAS_COMPAT_STATUS_OKAY(n) \ UTIL_AND(DT_NODE_HAS_COMPAT(DT_INST_CHILD(n, gpio2), xlnx_xps_gpio_1_00_a_gpio2), \ - DT_NODE_HAS_STATUS(DT_INST_CHILD(n, gpio2), okay)) + DT_NODE_HAS_STATUS_OKAY(DT_INST_CHILD(n, gpio2))) #define GPIO_XLNX_AXI_GPIO2_COND_INIT(n) \ IF_ENABLED(UTIL_AND(DT_INST_PROP_OR(n, xlnx_is_dual, 1), \ diff --git a/drivers/i2c/i2c_esp32.c b/drivers/i2c/i2c_esp32.c index 3c1381722090..07c8ea536caf 100644 --- a/drivers/i2c/i2c_esp32.c +++ b/drivers/i2c/i2c_esp32.c @@ -843,7 +843,7 @@ static int IRAM_ATTR i2c_esp32_init(const struct device *dev) &i2c_esp32_config_##idx, POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \ &i2c_esp32_driver_api); -#if DT_NODE_HAS_STATUS(I2C(0), okay) +#if DT_NODE_HAS_STATUS_OKAY(I2C(0)) #ifndef SOC_I2C_SUPPORT_HW_CLR_BUS #if !DT_NODE_HAS_PROP(I2C(0), sda_gpios) || !DT_NODE_HAS_PROP(I2C(0), scl_gpios) #error "Missing and properties to build for this target." @@ -854,9 +854,9 @@ static int IRAM_ATTR i2c_esp32_init(const struct device *dev) #endif #endif /* !SOC_I2C_SUPPORT_HW_CLR_BUS */ ESP32_I2C_INIT(0); -#endif /* DT_NODE_HAS_STATUS(I2C(0), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(I2C(0)) */ -#if DT_NODE_HAS_STATUS(I2C(1), okay) +#if DT_NODE_HAS_STATUS_OKAY(I2C(1)) #ifndef SOC_I2C_SUPPORT_HW_CLR_BUS #if !DT_NODE_HAS_PROP(I2C(1), sda_gpios) || !DT_NODE_HAS_PROP(I2C(1), scl_gpios) #error "Missing and properties to build for this target." @@ -867,4 +867,4 @@ ESP32_I2C_INIT(0); #endif #endif /* !SOC_I2C_SUPPORT_HW_CLR_BUS */ ESP32_I2C_INIT(1); -#endif /* DT_NODE_HAS_STATUS(I2C(1), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(I2C(1)) */ diff --git a/drivers/i2s/i2s_litex.c b/drivers/i2s/i2s_litex.c index e66eaed7972c..6105804d8cee 100644 --- a/drivers/i2s/i2s_litex.c +++ b/drivers/i2s/i2s_litex.c @@ -634,9 +634,9 @@ static const struct i2s_driver_api i2s_litex_driver_api = { irq_enable(DT_IRQN(DT_NODELABEL(i2s_##dir))); \ } -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2s_rx), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2s_rx)) I2S_INIT(rx); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2s_tx), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2s_tx)) I2S_INIT(tx); #endif diff --git a/drivers/interrupt_controller/intc_mchp_ecia_xec.c b/drivers/interrupt_controller/intc_mchp_ecia_xec.c index f1fc0f8c28b7..c4844643ccbf 100644 --- a/drivers/interrupt_controller/intc_mchp_ecia_xec.c +++ b/drivers/interrupt_controller/intc_mchp_ecia_xec.c @@ -445,7 +445,7 @@ int mchp_ecia_info_unset_callback(int ecia_info) * Leaving a node disabled also allows another driver/application to take over * aggregation by managing the GIRQ itself. */ -#define XEC_CHK_REQ_AGGR(n) DT_NODE_HAS_STATUS(n, okay) | +#define XEC_CHK_REQ_AGGR(n) DT_NODE_HAS_STATUS_OKAY(n) | #define XEC_ECIA_REQUIRE_AGGR_ISR \ ( \ diff --git a/drivers/led_strip/lpd880x.c b/drivers/led_strip/lpd880x.c index 991e2e3fb57e..d4b56509db1b 100644 --- a/drivers/led_strip/lpd880x.c +++ b/drivers/led_strip/lpd880x.c @@ -9,7 +9,7 @@ #include #include -#if DT_NODE_HAS_STATUS(DT_INST(0, greeled_lpd8806), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_INST(0, greeled_lpd8806)) #define DT_DRV_COMPAT greeled_lpd8806 #else #define DT_DRV_COMPAT greeled_lpd8803 diff --git a/drivers/lora/shell.c b/drivers/lora/shell.c index 692446b06cf6..7d3775c9d5c3 100644 --- a/drivers/lora/shell.c +++ b/drivers/lora/shell.c @@ -13,7 +13,7 @@ LOG_MODULE_REGISTER(lora_shell, CONFIG_LORA_LOG_LEVEL); #define DEFAULT_RADIO_NODE DT_ALIAS(lora0) -BUILD_ASSERT(DT_NODE_HAS_STATUS(DEFAULT_RADIO_NODE, okay), +BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(DEFAULT_RADIO_NODE), "No default LoRa radio specified in DT"); static struct lora_modem_config modem_config = { diff --git a/drivers/memc/memc_nxp_s32_qspi.c b/drivers/memc/memc_nxp_s32_qspi.c index f588a0bd9af7..e1d5c60bd67d 100644 --- a/drivers/memc/memc_nxp_s32_qspi.c +++ b/drivers/memc/memc_nxp_s32_qspi.c @@ -139,7 +139,7 @@ uint8_t memc_nxp_s32_qspi_get_instance(const struct device *dev) #define QSPI_PORT_SIZE_FN(node_id, side_upper, port) \ COND_CODE_1(IS_EQ(DT_REG_ADDR(node_id), QSPI_PCSF##side_upper##port), \ - (COND_CODE_1(DT_NODE_HAS_STATUS(node_id, okay), \ + (COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(node_id), \ (.memSize##side_upper##port = DT_PROP(node_id, size) / 8,), \ (.memSize##side_upper##port = 0,))), \ (EMPTY)) diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index 65f03cba43d5..eb59319ac24b 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -454,10 +454,15 @@ static void modem_cellular_chat_on_cxreg(struct modem_chat *chat, char **argv, u struct modem_cellular_data *data = (struct modem_cellular_data *)user_data; enum cellular_registration_status registration_status = 0; - if (argc == 2) { - registration_status = atoi(argv[1]); - } else if (argc == 3 || argc == 6) { + /* This receives both +C*REG? read command answers and unsolicited notifications. + * Their syntax differs in that the former has one more parameter, , which is first. + */ + if (argc >= 3 && argv[2][0] != '"') { + /* +CEREG: ,[,[...]] */ registration_status = atoi(argv[2]); + } else if (argc >= 2) { + /* +CEREG: [,[...]] */ + registration_status = atoi(argv[1]); } else { return; } @@ -466,7 +471,7 @@ static void modem_cellular_chat_on_cxreg(struct modem_chat *chat, char **argv, u data->registration_status_gsm = registration_status; } else if (strcmp(argv[0], "+CGREG: ") == 0) { data->registration_status_gprs = registration_status; - } else { + } else { /* CEREG */ data->registration_status_lte = registration_status; } diff --git a/drivers/pinctrl/pinctrl_esp32.c b/drivers/pinctrl/pinctrl_esp32.c index 89c1ba43b414..4ed39229d562 100644 --- a/drivers/pinctrl/pinctrl_esp32.c +++ b/drivers/pinctrl/pinctrl_esp32.c @@ -254,7 +254,7 @@ static int esp32_pin_configure(const uint32_t pin_mux, const uint32_t pin_cfg) gpio_dev_t *const gpio_dev = (gpio_dev_t *)DT_REG_ADDR(DT_NODELABEL(gpio0)); gpio_dev->out_w1ts = BIT(pin_num); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) } else { gpio_dev_t *const gpio_dev = (gpio_dev_t *)DT_REG_ADDR(DT_NODELABEL(gpio1)); @@ -268,7 +268,7 @@ static int esp32_pin_configure(const uint32_t pin_mux, const uint32_t pin_cfg) gpio_dev_t *const gpio_dev = (gpio_dev_t *)DT_REG_ADDR(DT_NODELABEL(gpio0)); gpio_dev->out_w1tc = BIT(pin_num); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) } else { gpio_dev_t *const gpio_dev = (gpio_dev_t *)DT_REG_ADDR(DT_NODELABEL(gpio1)); diff --git a/drivers/pinctrl/pinctrl_ite_it8xxx2.c b/drivers/pinctrl/pinctrl_ite_it8xxx2.c index 91ca93ea293e..422f8c6c67ff 100644 --- a/drivers/pinctrl/pinctrl_ite_it8xxx2.c +++ b/drivers/pinctrl/pinctrl_ite_it8xxx2.c @@ -366,7 +366,7 @@ static int pinctrl_it8xxx2_init(const struct device *dev) gpio_base->GPIO_GCR &= ~IT8XXX2_GPIO_LPCRSTEN; #ifdef CONFIG_SOC_IT8XXX2_REG_SET_V2 -#if defined(CONFIG_I2C_ITE_ENHANCE) && DT_NODE_HAS_STATUS(DT_NODELABEL(i2c5), okay) +#if defined(CONFIG_I2C_ITE_ENHANCE) && DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2c5)) const struct gpio_dt_spec scl_gpios = GPIO_DT_SPEC_GET(DT_NODELABEL(i2c5), scl_gpios); const struct gpio_dt_spec sda_gpios = GPIO_DT_SPEC_GET(DT_NODELABEL(i2c5), sda_gpios); diff --git a/drivers/pinctrl/pinctrl_kinetis.c b/drivers/pinctrl/pinctrl_kinetis.c index 13b0c8ac7204..bc250d742cf3 100644 --- a/drivers/pinctrl/pinctrl_kinetis.c +++ b/drivers/pinctrl/pinctrl_kinetis.c @@ -75,10 +75,14 @@ static int pinctrl_mcux_init(const struct device *dev) return 0; } -#if DT_NODE_HAS_STATUS(DT_INST(0, nxp_kinetis_sim), okay) -#define PINCTRL_MCUX_DT_INST_CLOCK_SUBSYS(n) \ - CLK_GATE_DEFINE(DT_INST_CLOCKS_CELL(n, offset), \ - DT_INST_CLOCKS_CELL(n, bits)) +#if DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nxp_kinetis_sim)) +#define PINCTRL_MCUX_DT_INST_CLOCK_SUBSYS(n) \ + CLK_GATE_DEFINE(DT_INST_CLOCKS_CELL(n, offset), DT_INST_CLOCKS_CELL(n, bits)) +#elif DT_HAS_COMPAT_STATUS_OKAY(nxp_scg_k4) +#define PINCTRL_MCUX_DT_INST_CLOCK_SUBSYS(n) \ + (DT_INST_CLOCKS_CELL(n, mrcc_offset) == 0 \ + ? 0 \ + : MAKE_MRCC_REGADDR(MRCC_BASE, DT_INST_CLOCKS_CELL(n, mrcc_offset))) #else #define PINCTRL_MCUX_DT_INST_CLOCK_SUBSYS(n) \ DT_INST_CLOCKS_CELL(n, name) diff --git a/drivers/rtc/rtc_smartbond.c b/drivers/rtc/rtc_smartbond.c index 7aa0d461d273..3d171e58f694 100644 --- a/drivers/rtc/rtc_smartbond.c +++ b/drivers/rtc/rtc_smartbond.c @@ -626,7 +626,7 @@ static int rtc_smartbond_init(const struct device *dev) /* Wakeup device from RTC events (alarm/roll over) */ #if CONFIG_PM - bool is_xtal32m_enabled = DT_NODE_HAS_STATUS(DT_NODELABEL(xtal32m), okay); + bool is_xtal32m_enabled = DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(xtal32m)); int pdc_idx = da1469x_pdc_add(MCU_PDC_TRIGGER_RTC_ALARM, MCU_PDC_MASTER_M33, is_xtal32m_enabled ? MCU_PDC_EN_XTAL : 0); diff --git a/drivers/sensor/bosch/bmi08x/bmi08x.h b/drivers/sensor/bosch/bmi08x/bmi08x.h index 6b8b33f8ec72..83926126e484 100644 --- a/drivers/sensor/bosch/bmi08x/bmi08x.h +++ b/drivers/sensor/bosch/bmi08x/bmi08x.h @@ -427,7 +427,7 @@ enum bmi08x_odr { #define BMI08X_GYR_SCALE(range_dps) ((2 * range_dps * SENSOR_PI) / 180LL / 65536LL) /* report of data sync is selected */ -#define BMI08X_ACCEL_DATA_SYNC_EN(inst) DT_NODE_HAS_STATUS(DT_INST_PHANDLE(inst, data_sync), okay) +#define BMI08X_ACCEL_DATA_SYNC_EN(inst) DT_NODE_HAS_STATUS_OKAY(DT_INST_PHANDLE(inst, data_sync)) /* Macro used for compile time optimization to compile in/out code used for data-sync * if at least 1 bmi08x has data-sync enabled */ diff --git a/drivers/sensor/nxp/CMakeLists.txt b/drivers/sensor/nxp/CMakeLists.txt index 73dc2cb274b3..36e39e002bf9 100644 --- a/drivers/sensor/nxp/CMakeLists.txt +++ b/drivers/sensor/nxp/CMakeLists.txt @@ -5,10 +5,10 @@ add_subdirectory_ifdef(CONFIG_FXAS21002 fxas21002) add_subdirectory_ifdef(CONFIG_FXLS8974 fxls8974) add_subdirectory_ifdef(CONFIG_FXOS8700 fxos8700) -add_subdirectory_ifdef(CONFIG_MCUX_ACMP mcux_acmp) add_subdirectory_ifdef(CONFIG_MCUX_LPCMP mcux_lpcmp) add_subdirectory_ifdef(CONFIG_NXP_TEMPMON nxp_tempmon) add_subdirectory_ifdef(CONFIG_QDEC_MCUX qdec_mcux) add_subdirectory_ifdef(CONFIG_QDEC_NXP_S32 qdec_nxp_s32) +add_subdirectory_ifdef(CONFIG_SENSOR_MCUX_ACMP mcux_acmp) add_subdirectory_ifdef(CONFIG_TEMP_KINETIS nxp_kinetis_temp) # zephyr-keep-sorted-stop diff --git a/drivers/sensor/nxp/mcux_acmp/Kconfig b/drivers/sensor/nxp/mcux_acmp/Kconfig index 0f976c65e215..1934e4d93f7a 100644 --- a/drivers/sensor/nxp/mcux_acmp/Kconfig +++ b/drivers/sensor/nxp/mcux_acmp/Kconfig @@ -4,17 +4,18 @@ # Copyright 2024 NXP # SPDX-License-Identifier: Apache-2.0 -config MCUX_ACMP +config SENSOR_MCUX_ACMP bool "NXP MCUX Analog Comparator (ACMP)" default y depends on DT_HAS_NXP_KINETIS_ACMP_ENABLED select PINCTRL + select MCUX_ACMP help Enable driver for the NXP MCUX Analog Comparator (ACMP). -config MCUX_ACMP_TRIGGER +config SENSOR_MCUX_ACMP_TRIGGER bool "Trigger support" - depends on MCUX_ACMP + depends on SENSOR_MCUX_ACMP help Enable trigger support for the NXP MCUX Analog Comparator (ACMP). diff --git a/drivers/sensor/nxp/mcux_acmp/mcux_acmp.c b/drivers/sensor/nxp/mcux_acmp/mcux_acmp.c index 30339f3e48dd..90dde17e83c3 100644 --- a/drivers/sensor/nxp/mcux_acmp/mcux_acmp.c +++ b/drivers/sensor/nxp/mcux_acmp/mcux_acmp.c @@ -41,13 +41,56 @@ BUILD_ASSERT(kACMP_PortInputFromDAC == 0); BUILD_ASSERT(kACMP_PortInputFromMux == 1); #endif /* MCUX_ACMP_HAS_INPSEL || MCUX_ACMP_HAS_INNSEL */ +/* + * prop New property name + * depr Deprecated property name + */ +#define MCUX_ACMP_DT_INST_PROP(inst, prop, depr) \ + COND_CODE_1( \ + DT_INST_NODE_HAS_PROP(inst, prop), \ + (DT_INST_PROP(inst, prop)), \ + (DT_INST_PROP(inst, depr)) \ + ) + +/* + * prop New property name + * depr Deprecated property name + */ +#define MCUX_ACMP_DT_INST_PROP_OR(inst, prop, depr, default_value) \ + COND_CODE_1( \ + DT_INST_NODE_HAS_PROP(inst, prop) || DT_INST_NODE_HAS_PROP(inst, depr), \ + (MCUX_ACMP_DT_INST_PROP(inst, prop, depr)), \ + (default_value) \ + ) + +#define MCUX_ACMP_DT_INST_ENABLE_SAMPLE(inst) \ + MCUX_ACMP_DT_INST_PROP(inst, filter_enable_sample, nxp_enable_sample) + +#define MCUX_ACMP_DT_INST_FILTER_COUNT(inst) \ + MCUX_ACMP_DT_INST_PROP_OR(inst, filter_count, nxp_filter_count, 0) + +#define MCUX_ACMP_DT_INST_FILTER_PERIOD(inst) \ + MCUX_ACMP_DT_INST_PROP_OR(inst, filter_period, nxp_filter_period, 0) + +#define MCUX_ACMP_DT_INST_HIGH_SPEED(inst) \ + MCUX_ACMP_DT_INST_PROP(inst, enable_high_speed_mode, nxp_high_speed_mode) + +#define MCUX_ACMP_DT_INST_USE_UNFILTERED_MODE(inst) \ + MCUX_ACMP_DT_INST_PROP(inst, use_unfiltered_output, nxp_use_unfiltered_output) + +#define MCUX_ACMP_DT_INST_USE_ENABLE_PIN_OUT(inst) \ + MCUX_ACMP_DT_INST_PROP(inst, enable_pin_out, nxp_enable_output_pin) + +#define MCUX_ACMP_DT_INST_ENABLE_WINDOW_MODE(inst) \ + MCUX_ACMP_DT_INST_PROP(inst, enable_window_mode, nxp_window_mode) + struct mcux_acmp_config { CMP_Type *base; acmp_filter_config_t filter; const struct pinctrl_dev_config *pincfg; -#ifdef CONFIG_MCUX_ACMP_TRIGGER +#ifdef CONFIG_SENSOR_MCUX_ACMP_TRIGGER void (*irq_config_func)(const struct device *dev); -#endif /* CONFIG_MCUX_ACMP_TRIGGER */ +#endif /* CONFIG_SENSOR_MCUX_ACMP_TRIGGER */ bool high_speed : 1; bool unfiltered : 1; bool output : 1; @@ -61,7 +104,7 @@ struct mcux_acmp_data { #if MCUX_ACMP_HAS_DISCRETE_MODE acmp_discrete_mode_config_t discrete_config; #endif -#ifdef CONFIG_MCUX_ACMP_TRIGGER +#ifdef CONFIG_SENSOR_MCUX_ACMP_TRIGGER const struct device *dev; sensor_trigger_handler_t rising_handler; const struct sensor_trigger *rising_trigger; @@ -69,7 +112,7 @@ struct mcux_acmp_data { const struct sensor_trigger *falling_trigger; struct k_work work; volatile uint32_t status; -#endif /* CONFIG_MCUX_ACMP_TRIGGER */ +#endif /* CONFIG_SENSOR_MCUX_ACMP_TRIGGER */ bool cout; }; @@ -370,7 +413,7 @@ static int mcux_acmp_channel_get(const struct device *dev, return 0; } -#ifdef CONFIG_MCUX_ACMP_TRIGGER +#ifdef CONFIG_SENSOR_MCUX_ACMP_TRIGGER static int mcux_acmp_trigger_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) @@ -431,7 +474,7 @@ static void mcux_acmp_isr(const struct device *dev) k_work_submit(&data->work); } -#endif /* CONFIG_MCUX_ACMP_TRIGGER */ +#endif /* CONFIG_SENSOR_MCUX_ACMP_TRIGGER */ static int mcux_acmp_init(const struct device *dev) { @@ -462,7 +505,7 @@ static int mcux_acmp_init(const struct device *dev) /* Disable DAC */ ACMP_SetDACConfig(config->base, NULL); -#ifdef CONFIG_MCUX_ACMP_TRIGGER +#ifdef CONFIG_SENSOR_MCUX_ACMP_TRIGGER data->dev = dev; k_work_init(&data->work, mcux_acmp_trigger_work_handler); @@ -470,7 +513,7 @@ static int mcux_acmp_init(const struct device *dev) ACMP_EnableInterrupts(config->base, kACMP_OutputRisingInterruptEnable | kACMP_OutputFallingInterruptEnable); -#endif /* CONFIG_MCUX_ACMP_TRIGGER */ +#endif /* CONFIG_SENSOR_MCUX_ACMP_TRIGGER */ ACMP_Enable(config->base, true); @@ -480,30 +523,30 @@ static int mcux_acmp_init(const struct device *dev) static const struct sensor_driver_api mcux_acmp_driver_api = { .attr_set = mcux_acmp_attr_set, .attr_get = mcux_acmp_attr_get, -#ifdef CONFIG_MCUX_ACMP_TRIGGER +#ifdef CONFIG_SENSOR_MCUX_ACMP_TRIGGER .trigger_set = mcux_acmp_trigger_set, -#endif /* CONFIG_MCUX_ACMP_TRIGGER */ +#endif /* CONFIG_SENSOR_MCUX_ACMP_TRIGGER */ .sample_fetch = mcux_acmp_sample_fetch, .channel_get = mcux_acmp_channel_get, }; -#define MCUX_ACMP_DECLARE_CONFIG(n, config_func_init) \ +#define MCUX_ACMP_DECLARE_CONFIG(n, config_func_init) \ static const struct mcux_acmp_config mcux_acmp_config_##n = { \ .base = (CMP_Type *)DT_INST_REG_ADDR(n), \ .filter = { \ - .enableSample = DT_INST_PROP(n, nxp_enable_sample), \ - .filterCount = DT_INST_PROP_OR(n, nxp_filter_count, 0), \ - .filterPeriod = DT_INST_PROP_OR(n, nxp_filter_period, 0), \ + .enableSample = MCUX_ACMP_DT_INST_ENABLE_SAMPLE(n), \ + .filterCount = MCUX_ACMP_DT_INST_FILTER_COUNT(n), \ + .filterPeriod = MCUX_ACMP_DT_INST_FILTER_PERIOD(n), \ }, \ - .high_speed = DT_INST_PROP(n, nxp_high_speed_mode), \ - .unfiltered = DT_INST_PROP(n, nxp_use_unfiltered_output), \ - .output = DT_INST_PROP(n, nxp_enable_output_pin), \ - .window = DT_INST_PROP(n, nxp_window_mode), \ + .high_speed = MCUX_ACMP_DT_INST_HIGH_SPEED(n), \ + .unfiltered = MCUX_ACMP_DT_INST_USE_UNFILTERED_MODE(n), \ + .output = MCUX_ACMP_DT_INST_USE_ENABLE_PIN_OUT(n), \ + .window = MCUX_ACMP_DT_INST_ENABLE_WINDOW_MODE(n), \ .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ config_func_init \ } -#ifdef CONFIG_MCUX_ACMP_TRIGGER +#ifdef CONFIG_SENSOR_MCUX_ACMP_TRIGGER #define MCUX_ACMP_CONFIG_FUNC(n) \ static void mcux_acmp_config_func_##n(const struct device *dev) \ { \ @@ -517,12 +560,12 @@ static const struct mcux_acmp_config mcux_acmp_config_##n = { \ .irq_config_func = mcux_acmp_config_func_##n #define MCUX_ACMP_INIT_CONFIG(n) \ MCUX_ACMP_DECLARE_CONFIG(n, MCUX_ACMP_CONFIG_FUNC_INIT(n)) -#else /* !CONFIG_MCUX_ACMP_TRIGGER */ +#else /* !CONFIG_SENSOR_MCUX_ACMP_TRIGGER */ #define MCUX_ACMP_CONFIG_FUNC(n) #define MCUX_ACMP_CONFIG_FUNC_INIT #define MCUX_ACMP_INIT_CONFIG(n) \ MCUX_ACMP_DECLARE_CONFIG(n, MCUX_ACMP_CONFIG_FUNC_INIT) -#endif /* !CONFIG_MCUX_ACMP_TRIGGER */ +#endif /* !CONFIG_SENSOR_MCUX_ACMP_TRIGGER */ #define MCUX_ACMP_INIT(n) \ static struct mcux_acmp_data mcux_acmp_data_##n; \ diff --git a/drivers/sensor/st/stm32_temp/stm32_temp.c b/drivers/sensor/st/stm32_temp/stm32_temp.c index aa746e0c6999..787eb4c99e6d 100644 --- a/drivers/sensor/st/stm32_temp/stm32_temp.c +++ b/drivers/sensor/st/stm32_temp/stm32_temp.c @@ -188,7 +188,7 @@ static int stm32_temp_init(const struct device *dev) * this driver even if the ADC used for measurement is disabled. In such cases, * fail build with an explicit error message. */ -#if !DT_NODE_HAS_STATUS(DT_INST_IO_CHANNELS_CTLR(0), okay) +#if !DT_NODE_HAS_STATUS_OKAY(DT_INST_IO_CHANNELS_CTLR(0)) /* Use BUILD_ASSERT to get preprocessing on the message */ BUILD_ASSERT(0, "ADC '" DT_NODE_FULL_NAME(DT_INST_IO_CHANNELS_CTLR(0)) "' needed by " @@ -235,4 +235,4 @@ SENSOR_DEVICE_DT_INST_DEFINE(0, stm32_temp_init, NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &stm32_temp_driver_api); -#endif /* !DT_NODE_HAS_STATUS(DT_INST_IO_CHANNELS_CTLR(0), okay) */ +#endif /* !DT_NODE_HAS_STATUS_OKAY(DT_INST_IO_CHANNELS_CTLR(0)) */ diff --git a/drivers/sensor/st/stm32_vbat/stm32_vbat.c b/drivers/sensor/st/stm32_vbat/stm32_vbat.c index b74e0cf8b7f6..98bebad37fae 100644 --- a/drivers/sensor/st/stm32_vbat/stm32_vbat.c +++ b/drivers/sensor/st/stm32_vbat/stm32_vbat.c @@ -125,7 +125,7 @@ static int stm32_vbat_init(const struct device *dev) } #define ASSERT_VBAT_ADC_ENABLED(inst) \ - BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_INST_IO_CHANNELS_CTLR(inst), okay), \ + BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(DT_INST_IO_CHANNELS_CTLR(inst)), \ "ADC instance '" DT_NODE_FULL_NAME(DT_INST_IO_CHANNELS_CTLR(inst)) "' needed " \ "by Vbat sensor '" DT_NODE_FULL_NAME(DT_DRV_INST(inst)) "' is not enabled") diff --git a/drivers/sensor/st/stm32_vref/stm32_vref.c b/drivers/sensor/st/stm32_vref/stm32_vref.c index b2cf7222fadb..b76c2ea0e6ec 100644 --- a/drivers/sensor/st/stm32_vref/stm32_vref.c +++ b/drivers/sensor/st/stm32_vref/stm32_vref.c @@ -154,7 +154,7 @@ static int stm32_vref_init(const struct device *dev) * possible to compile this driver even if the ADC used for measurement is * disabled. In such cases, fail build with an explicit error message. */ -#if !DT_NODE_HAS_STATUS(DT_INST_IO_CHANNELS_CTLR(0), okay) +#if !DT_NODE_HAS_STATUS_OKAY(DT_INST_IO_CHANNELS_CTLR(0)) /* Use BUILD_ASSERT to get preprocessing on the message */ BUILD_ASSERT(0, "ADC '" DT_NODE_FULL_NAME(DT_INST_IO_CHANNELS_CTLR(0)) "' needed by " @@ -183,4 +183,4 @@ static const struct stm32_vref_config stm32_vref_dev_config = { SENSOR_DEVICE_DT_INST_DEFINE(0, stm32_vref_init, NULL, &stm32_vref_dev_data, &stm32_vref_dev_config, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &stm32_vref_driver_api); -#endif /* !DT_NODE_HAS_STATUS(DT_INST_IO_CHANNELS_CTLR(0), okay) */ +#endif /* !DT_NODE_HAS_STATUS_OKAY(DT_INST_IO_CHANNELS_CTLR(0)) */ diff --git a/drivers/serial/Kconfig.nrfx b/drivers/serial/Kconfig.nrfx index daf185cd7e86..650404fceecb 100644 --- a/drivers/serial/Kconfig.nrfx +++ b/drivers/serial/Kconfig.nrfx @@ -31,12 +31,20 @@ config UART_NRFX_UARTE config UART_NRFX_UARTE_LEGACY_SHIM bool "Legacy UARTE shim" depends on UART_NRFX_UARTE - depends on !SOC_SERIES_NRF54LX - depends on !SOC_SERIES_NRF54HX || RISCV - depends on !SOC_SERIES_NRF92X || RISCV - # New shim takes more ROM. Until it is fixed use legacy shim. default y +config UART_NRFX_UARTE_ENHANCED_RX + bool "Enhanced RX handling" + depends on UART_ASYNC_API + depends on UART_NRFX_UARTE_LEGACY_SHIM + default y if !(UART_0_NRF_HW_ASYNC || UART_1_NRF_HW_ASYNC || UART_2_NRF_HW_ASYNC) + help + Enable RX handling mode which is switching buffers on timeout. This is an + enhancement compared to other two modes (default and hardware assisted). + Default mode could miscount bytes when interrupt was not handled on time + and hardware assisted required TIMER peripheral instance and PPI channel + for accurate byte counting. + config UART_ASYNC_TX_CACHE_SIZE int "TX cache buffer size" depends on UART_ASYNC_API diff --git a/drivers/serial/Kconfig.nrfx_uart_instance b/drivers/serial/Kconfig.nrfx_uart_instance index 0840cad7760c..d44c1ab7e026 100644 --- a/drivers/serial/Kconfig.nrfx_uart_instance +++ b/drivers/serial/Kconfig.nrfx_uart_instance @@ -68,10 +68,14 @@ config UART_$(nrfx_uart_num)_NRF_ASYNC_LOW_POWER depends on HAS_HW_NRF_UARTE$(nrfx_uart_num) depends on UART_ASYNC_API depends on UART_NRFX_UARTE_LEGACY_SHIM + default y if !PM_DEVICE help When enabled, UARTE is enabled before each TX or RX usage and disabled when not used. Disabling UARTE while in idle allows to achieve lowest power consumption. It is only feasible if receiver is not always on. + This option is irrelevant when device power management (PM) is enabled + because then device state is controlled by the PM actions. + config UART_$(nrfx_uart_num)_NRF_HW_ASYNC_TIMER int "Timer instance" @@ -119,12 +123,3 @@ config UART_$(nrfx_uart_num)_A2I_RX_BUF_COUNT default 0 help Number of chunks into RX space is divided. - -config UART_$(nrfx_uart_num)_GPIO_MANAGEMENT - bool "GPIO management on port $(nrfx_uart_num)" - depends on PM_DEVICE - default y - help - If enabled, the driver will configure the GPIOs used by the uart to - their default configuration when device is powered down. The GPIOs - will be configured back to correct state when UART is powered up. diff --git a/drivers/serial/leuart_gecko.c b/drivers/serial/leuart_gecko.c index daaff59069c7..9eec982802c1 100644 --- a/drivers/serial/leuart_gecko.c +++ b/drivers/serial/leuart_gecko.c @@ -317,7 +317,7 @@ static const struct uart_driver_api leuart_gecko_driver_api = { #endif }; -#if DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) #define PIN_LEUART_0_RXD {DT_INST_PROP_BY_IDX(0, location_rx, 1), \ DT_INST_PROP_BY_IDX(0, location_rx, 2), gpioModeInput, 1} @@ -368,9 +368,9 @@ static void leuart_gecko_config_func_0(const struct device *dev) } #endif -#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) */ -#if DT_NODE_HAS_STATUS(DT_DRV_INST(1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(1)) #define PIN_LEUART_1_RXD {DT_INST_PROP_BY_IDX(1, location_rx, 1), \ DT_INST_PROP_BY_IDX(1, location_rx, 2), gpioModeInput, 1} @@ -421,4 +421,4 @@ static void leuart_gecko_config_func_1(const struct device *dev) } #endif -#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(1), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(1)) */ diff --git a/drivers/serial/uart_cmsdk_apb.c b/drivers/serial/uart_cmsdk_apb.c index a6568133b724..e4ceb883bd62 100644 --- a/drivers/serial/uart_cmsdk_apb.c +++ b/drivers/serial/uart_cmsdk_apb.c @@ -475,7 +475,7 @@ static const struct uart_driver_api uart_cmsdk_apb_driver_api = { #endif /* CONFIG_UART_INTERRUPT_DRIVEN */ }; -#if DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) #ifdef CONFIG_UART_INTERRUPT_DRIVEN static void uart_cmsdk_apb_irq_config_func_0(const struct device *dev); @@ -538,9 +538,9 @@ static void uart_cmsdk_apb_irq_config_func_0(const struct device *dev) #endif #endif -#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) */ -#if DT_NODE_HAS_STATUS(DT_DRV_INST(1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(1)) #ifdef CONFIG_UART_INTERRUPT_DRIVEN static void uart_cmsdk_apb_irq_config_func_1(const struct device *dev); @@ -603,9 +603,9 @@ static void uart_cmsdk_apb_irq_config_func_1(const struct device *dev) #endif #endif -#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(1), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(1)) */ -#if DT_NODE_HAS_STATUS(DT_DRV_INST(2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(2)) #ifdef CONFIG_UART_INTERRUPT_DRIVEN static void uart_cmsdk_apb_irq_config_func_2(const struct device *dev); @@ -668,9 +668,9 @@ static void uart_cmsdk_apb_irq_config_func_2(const struct device *dev) #endif #endif -#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(2), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(2)) */ -#if DT_NODE_HAS_STATUS(DT_DRV_INST(3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(3)) #ifdef CONFIG_UART_INTERRUPT_DRIVEN static void uart_cmsdk_apb_irq_config_func_3(const struct device *dev); @@ -733,9 +733,9 @@ static void uart_cmsdk_apb_irq_config_func_3(const struct device *dev) #endif #endif -#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(3), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(3)) */ -#if DT_NODE_HAS_STATUS(DT_DRV_INST(4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(4)) #ifdef CONFIG_UART_INTERRUPT_DRIVEN static void uart_cmsdk_apb_irq_config_func_4(const struct device *dev); @@ -798,4 +798,4 @@ static void uart_cmsdk_apb_irq_config_func_4(const struct device *dev) #endif #endif -#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(4), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(4)) */ diff --git a/drivers/serial/uart_lpc11u6x.c b/drivers/serial/uart_lpc11u6x.c index 5645fb7910b4..3a13850429fd 100644 --- a/drivers/serial/uart_lpc11u6x.c +++ b/drivers/serial/uart_lpc11u6x.c @@ -13,7 +13,7 @@ #include "uart_lpc11u6x.h" -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart0)) static int lpc11u6x_uart0_poll_in(const struct device *dev, unsigned char *c) { const struct lpc11u6x_uart0_config *cfg = dev->config; @@ -443,12 +443,12 @@ static void lpc11u6x_uart0_isr_config(const struct device *dev) } #endif /* CONFIG_UART_INTERRUPT_DRIVEN */ -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart0), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart0)) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) || \ - DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) || \ - DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay) || \ - DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) || \ + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) || \ + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3)) || \ + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart4)) static int lpc11u6x_uartx_poll_in(const struct device *dev, unsigned char *c) { @@ -810,18 +810,18 @@ static int lpc11u6x_uartx_init(const struct device *dev) LPC11U6X_UARTX_CFG_ENABLE; #ifdef CONFIG_UART_INTERRUPT_DRIVEN -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) || \ - DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) || \ + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart4)) lpc11u6x_uartx_isr_config_1(dev); -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) || - * DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) || + * DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart4)) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) || \ - DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) || \ + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3)) lpc11u6x_uartx_isr_config_2(dev); -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) || - * DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay) +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) || + * DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3)) */ #endif /* CONFIG_UART_INTERRUPT_DRIVEN */ return 0; @@ -876,44 +876,44 @@ DEVICE_DT_DEFINE(DT_NODELABEL(uart##idx), \ PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY, \ &uartx_api) -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) LPC11U6X_UARTX_INIT(1); -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) LPC11U6X_UARTX_INIT(2); -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3)) LPC11U6X_UARTX_INIT(3); -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3)) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart4)) LPC11U6X_UARTX_INIT(4); -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart4)) */ #if CONFIG_UART_INTERRUPT_DRIVEN && \ - (DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) || \ - DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay)) + (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) || \ + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart4))) struct lpc11u6x_uartx_shared_irq lpc11u6x_uartx_shared_irq_info_1 = { .devices = { -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) DEVICE_DT_GET(DT_NODELABEL(uart1)), #else NULL, -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) */ +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart4)) DEVICE_DT_GET(DT_NODELABEL(uart4)), #else NULL, -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart4)) */ }, }; static void lpc11u6x_uartx_isr_config_1(const struct device *dev) { -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) IRQ_CONNECT(DT_IRQN(DT_NODELABEL(uart1)), DT_IRQ(DT_NODELABEL(uart1), priority), lpc11u6x_uartx_shared_isr, @@ -927,34 +927,34 @@ static void lpc11u6x_uartx_isr_config_1(const struct device *dev) &lpc11u6x_uartx_shared_irq_info_1, 0); irq_enable(DT_IRQN(DT_NODELABEL(uart4))); -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) */ } #endif /* CONFIG_UART_INTERRUPT_DRIVEN && - * (DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) || - * DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay)) + * (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) || + * DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart4))) */ #if CONFIG_UART_INTERRUPT_DRIVEN && \ - (DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) || \ - DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay)) + (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) || \ + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3))) struct lpc11u6x_uartx_shared_irq lpc11u6x_uartx_shared_irq_info_2 = { .devices = { -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) DEVICE_DT_GET(DT_NODELABEL(uart2)), #else NULL, -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay) +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) */ +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3)) DEVICE_DT_GET(DT_NODELABEL(uart3)), #else NULL, -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3)) */ }, }; static void lpc11u6x_uartx_isr_config_2(const struct device *dev) { -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) IRQ_CONNECT(DT_IRQN(DT_NODELABEL(uart2)), DT_IRQ(DT_NODELABEL(uart2), priority), lpc11u6x_uartx_shared_isr, @@ -968,11 +968,11 @@ static void lpc11u6x_uartx_isr_config_2(const struct device *dev) &lpc11u6x_uartx_shared_irq_info_2, 0); irq_enable(DT_IRQN(DT_NODELABEL(uart3))); -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) */ } #endif /* CONFIG_UART_INTERRUPT_DRIVEN && - * (DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) || - * DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay)) + * (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) || + * DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3))) */ #endif /* DT_NODE_EXISTS(DT_NODELABEL(uart1) || * DT_NODE_EXISTS(DT_NODELABEL(uart2) || diff --git a/drivers/serial/uart_lpc11u6x.h b/drivers/serial/uart_lpc11u6x.h index 8951945e65ab..257846cbdd49 100644 --- a/drivers/serial/uart_lpc11u6x.h +++ b/drivers/serial/uart_lpc11u6x.h @@ -199,20 +199,20 @@ struct lpc11u6x_uartx_shared_irq { }; #if CONFIG_UART_INTERRUPT_DRIVEN && \ - (DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) || \ - DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay)) + (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) || \ + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart4))) static void lpc11u6x_uartx_isr_config_1(const struct device *dev); #endif /* CONFIG_UART_INTERRUPT_DRIVEN && - * (DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) || - * DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay)) + * (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) || + * DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3))) */ #if CONFIG_UART_INTERRUPT_DRIVEN && \ - (DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) || \ - DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay)) + (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) || \ + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3))) static void lpc11u6x_uartx_isr_config_2(const struct device *dev); #endif /* CONFIG_UART_INTERRUPT_DRIVEN && - * (DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) || - * DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay)) + * (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) || + * DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3))) */ #endif /* ZEPHYR_DRIVERS_SERIAL_UART_LPC11U6X_H_ */ diff --git a/drivers/serial/uart_miv.c b/drivers/serial/uart_miv.c index bf35b4cf6563..d1b5cfb0e266 100644 --- a/drivers/serial/uart_miv.c +++ b/drivers/serial/uart_miv.c @@ -387,7 +387,7 @@ static const struct uart_driver_api uart_miv_driver_api = { BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) <= 1, "unsupported uart_miv instance"); -#if DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) static struct uart_miv_data uart_miv_data_0; @@ -424,4 +424,4 @@ static void uart_miv_irq_cfg_func_0(const struct device *dev) } #endif -#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) */ diff --git a/drivers/serial/uart_nrfx_uart.c b/drivers/serial/uart_nrfx_uart.c index 9fa634fe01fa..1e0da0f882f0 100644 --- a/drivers/serial/uart_nrfx_uart.c +++ b/drivers/serial/uart_nrfx_uart.c @@ -1087,12 +1087,9 @@ static int uart_nrfx_pm_action(const struct device *dev, switch (action) { case PM_DEVICE_ACTION_RESUME: - if (IS_ENABLED(CONFIG_UART_0_GPIO_MANAGEMENT)) { - ret = pinctrl_apply_state(config->pcfg, - PINCTRL_STATE_DEFAULT); - if (ret < 0) { - return ret; - } + ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); + if (ret < 0) { + return ret; } nrf_uart_enable(uart0_addr); @@ -1103,13 +1100,9 @@ static int uart_nrfx_pm_action(const struct device *dev, break; case PM_DEVICE_ACTION_SUSPEND: nrf_uart_disable(uart0_addr); - - if (IS_ENABLED(CONFIG_UART_0_GPIO_MANAGEMENT)) { - ret = pinctrl_apply_state(config->pcfg, - PINCTRL_STATE_SLEEP); - if (ret < 0) { - return ret; - } + ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_SLEEP); + if (ret < 0) { + return ret; } break; default: diff --git a/drivers/serial/uart_nrfx_uarte.c b/drivers/serial/uart_nrfx_uarte.c index 00225464f37f..2fb2ab3537e2 100644 --- a/drivers/serial/uart_nrfx_uarte.c +++ b/drivers/serial/uart_nrfx_uarte.c @@ -9,40 +9,32 @@ */ #include +#include #include +#include #include #include #include #include +#include #include +#include #include #include #include - #include LOG_MODULE_REGISTER(uart_nrfx_uarte, CONFIG_UART_LOG_LEVEL); -#include - -/* Generalize PPI or DPPI channel management */ -#if defined(PPI_PRESENT) -#include -#define gppi_channel_t nrf_ppi_channel_t -#define gppi_channel_alloc nrfx_ppi_channel_alloc -#define gppi_channel_enable nrfx_ppi_channel_enable -#elif defined(DPPI_PRESENT) -#include -#define gppi_channel_t uint8_t -#define gppi_channel_alloc nrfx_dppi_channel_alloc -#define gppi_channel_enable nrfx_dppi_channel_enable -#else -#error "No PPI or DPPI" +#if !defined(CONFIG_ARCH_POSIX) +#define RX_FLUSH_WORKAROUND 1 #endif #define UARTE(idx) DT_NODELABEL(uart##idx) #define UARTE_HAS_PROP(idx, prop) DT_NODE_HAS_PROP(UARTE(idx), prop) #define UARTE_PROP(idx, prop) DT_PROP(UARTE(idx), prop) +#define UARTE_IS_CACHEABLE(idx) DMM_IS_REG_CACHEABLE(DT_PHANDLE(UARTE(idx), memory_regions)) + /* Execute macro f(x) for all instances. */ #define UARTE_FOR_EACH_INSTANCE(f, sep, off_code, ...) \ NRFX_FOREACH_PRESENT(UARTE, f, sep, off_code, __VA_ARGS__) @@ -78,7 +70,7 @@ LOG_MODULE_REGISTER(uart_nrfx_uarte, CONFIG_UART_LOG_LEVEL); #define IS_HW_ASYNC(unused, prefix, i, _) IS_ENABLED(CONFIG_UART_##prefix##i##_NRF_HW_ASYNC) #if UARTE_FOR_EACH_INSTANCE(IS_HW_ASYNC, (||), (0)) -#define UARTE_HW_ASYNC 1 +#define UARTE_ANY_HW_ASYNC 1 #endif /* Determine if any instance is using enhanced poll_out feature. */ @@ -98,6 +90,33 @@ LOG_MODULE_REGISTER(uart_nrfx_uarte, CONFIG_UART_LOG_LEVEL); #define UARTE_HAS_ENDTX_STOPTX_SHORT 1 #endif +#if (UARTE_FOR_EACH_INSTANCE(INSTANCE_PROP, (+), (0), frame_timeout_supported)) == \ + (UARTE_FOR_EACH_INSTANCE(INSTANCE_PRESENT, (+), (0), frame_timeout_supported)) +#define UARTE_HAS_FRAME_TIMEOUT 1 +#endif + +#define INSTANCE_NEEDS_CACHE_MGMT(unused, prefix, i, prop) UARTE_IS_CACHEABLE(prefix##i) + +#if UARTE_FOR_EACH_INSTANCE(INSTANCE_NEEDS_CACHE_MGMT, (+), (0), _) +#define UARTE_ANY_CACHE 1 +#endif + +#define IS_LOW_POWER(unused, prefix, i, _) IS_ENABLED(CONFIG_UART_##prefix##i##_NRF_ASYNC_LOW_POWER) + +#if UARTE_FOR_EACH_INSTANCE(IS_LOW_POWER, (||), (0)) +#define UARTE_ANY_LOW_POWER 1 +#endif + +#ifdef UARTE_ANY_CACHE +/* uart120 instance does not retain BAUDRATE register when ENABLE=0. When this instance + * is used then baudrate must be set after enabling the peripheral and not before. + * This approach works for all instances so can be generally applied when uart120 is used. + * It is not default for all because it costs some resources. Since currently only uart120 + * needs cache, that is used to determine if workaround shall be applied. + */ +#define UARTE_BAUDRATE_RETENTION_WORKAROUND 1 +#endif + /* * RX timeout is divided into time slabs, this define tells how many divisions * should be made. More divisions - higher timeout accuracy and processor usage. @@ -108,44 +127,57 @@ LOG_MODULE_REGISTER(uart_nrfx_uarte, CONFIG_UART_LOG_LEVEL); #define UARTE_HW_RX_FIFO_SIZE 5 #ifdef UARTE_ANY_ASYNC -struct uarte_async_cb { - uart_callback_t user_callback; - void *user_data; - const uint8_t *tx_buf; - volatile size_t tx_size; +struct uarte_async_tx { + struct k_timer timer; + const uint8_t *buf; + volatile size_t len; const uint8_t *xfer_buf; size_t xfer_len; + size_t cache_offset; + volatile int amount; + bool pending; +}; - size_t tx_cache_offset; - - struct k_timer tx_timeout_timer; - - uint8_t *rx_buf; - size_t rx_buf_len; - size_t rx_offset; - uint8_t *rx_next_buf; - size_t rx_next_buf_len; - uint32_t rx_total_byte_cnt; /* Total number of bytes received */ - uint32_t rx_total_user_byte_cnt; /* Total number of bytes passed to user */ - int32_t rx_timeout; /* Timeout set by user */ - int32_t rx_timeout_slab; /* rx_timeout divided by RX_TIMEOUT_DIV */ - int32_t rx_timeout_left; /* Current time left until user callback */ - struct k_timer rx_timeout_timer; +struct uarte_async_rx { + struct k_timer timer; +#ifdef CONFIG_HAS_NORDIC_DMM + uint8_t *usr_buf; + uint8_t *next_usr_buf; +#endif + uint8_t *buf; + size_t buf_len; + size_t offset; + uint8_t *next_buf; + size_t next_buf_len; +#ifdef CONFIG_UART_NRFX_UARTE_ENHANCED_RX +#if !defined(UARTE_HAS_FRAME_TIMEOUT) + uint32_t idle_cnt; +#endif + k_timeout_t timeout; +#else + uint32_t total_byte_cnt; /* Total number of bytes received */ + uint32_t total_user_byte_cnt; /* Total number of bytes passed to user */ + int32_t timeout_us; /* Timeout set by user */ + int32_t timeout_slab; /* rx_timeout divided by RX_TIMEOUT_DIV */ + int32_t timeout_left; /* Current time left until user callback */ union { - gppi_channel_t ppi; + uint8_t ppi; uint32_t cnt; - } rx_cnt; - volatile int tx_amount; - - atomic_t low_power_mask; - uint8_t rx_flush_buffer[UARTE_HW_RX_FIFO_SIZE]; - uint8_t rx_flush_cnt; - volatile bool rx_enabled; - volatile bool discard_rx_fifo; - bool pending_tx; + } cnt; /* Flag to ensure that RX timeout won't be executed during ENDRX ISR */ volatile bool is_in_irq; +#endif /* CONFIG_UART_NRFX_UARTE_ENHANCED_RX */ + uint8_t flush_cnt; + volatile bool enabled; + volatile bool discard_fifo; +}; + +struct uarte_async_cb { + uart_callback_t user_callback; + void *user_data; + struct uarte_async_rx rx; + struct uarte_async_tx tx; }; #endif /* UARTE_ANY_ASYNC */ @@ -166,9 +198,11 @@ struct uarte_nrfx_int_driven { /* Device data structure */ struct uarte_nrfx_data { - const struct device *dev; #ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE struct uart_config uart_config; +#ifdef UARTE_BAUDRATE_RETENTION_WORKAROUND + nrf_uarte_baudrate_t nrf_baudrate; +#endif #endif #ifdef UARTE_INTERRUPT_DRIVEN struct uarte_nrfx_int_driven *int_driven; @@ -177,27 +211,31 @@ struct uarte_nrfx_data { struct uarte_async_cb *async; #endif atomic_val_t poll_out_lock; - uint8_t *char_out; - uint8_t *rx_data; - gppi_channel_t ppi_ch_endtx; + atomic_t flags; +#ifdef UARTE_ENHANCED_POLL_OUT + uint8_t ppi_ch_endtx; +#endif }; -#define UARTE_LOW_POWER_TX BIT(0) -#define UARTE_LOW_POWER_RX BIT(1) - -/* If enabled, pins are managed when going to low power mode. */ -#define UARTE_CFG_FLAG_GPIO_MGMT BIT(0) +#define UARTE_FLAG_LOW_POWER_TX BIT(0) +#define UARTE_FLAG_LOW_POWER_RX BIT(1) +#define UARTE_FLAG_LOW_POWER (UARTE_FLAG_LOW_POWER_TX | UARTE_FLAG_LOW_POWER_RX) +#define UARTE_FLAG_TRIG_RXTO BIT(2) +#define UARTE_FLAG_POLL_OUT BIT(3) /* If enabled then ENDTX is PPI'ed to TXSTOP */ -#define UARTE_CFG_FLAG_PPI_ENDTX BIT(1) +#define UARTE_CFG_FLAG_PPI_ENDTX BIT(0) /* If enabled then TIMER and PPI is used for byte counting. */ -#define UARTE_CFG_FLAG_HW_BYTE_COUNTING BIT(2) +#define UARTE_CFG_FLAG_HW_BYTE_COUNTING BIT(1) /* If enabled then UARTE peripheral is disabled when not used. This allows * to achieve lowest power consumption in idle. */ -#define UARTE_CFG_FLAG_LOW_POWER BIT(4) +#define UARTE_CFG_FLAG_LOW_POWER BIT(2) + +/* If enabled then UARTE peripheral is using memory which is cacheable. */ +#define UARTE_CFG_FLAG_CACHEABLE BIT(3) /* Macro for converting numerical baudrate to register value. It is convenient * to use this approach because for constant input it can calculate nrf setting @@ -224,23 +262,39 @@ struct uarte_nrfx_data { (baudrate) == 921600 ? NRF_UARTE_BAUDRATE_921600 : \ (baudrate) == 1000000 ? NRF_UARTE_BAUDRATE_1000000 : 0) +#define LOW_POWER_ENABLED(_config) \ + (IS_ENABLED(UARTE_ANY_LOW_POWER) && \ + !IS_ENABLED(CONFIG_PM_DEVICE) && \ + (_config->flags & UARTE_CFG_FLAG_LOW_POWER)) /** * @brief Structure for UARTE configuration. */ struct uarte_nrfx_config { NRF_UARTE_Type *uarte_regs; /* Instance address */ - uint32_t clock_freq; uint32_t flags; bool disable_rx; const struct pinctrl_dev_config *pcfg; -#ifndef CONFIG_UART_USE_RUNTIME_CONFIGURE - nrf_uarte_baudrate_t baudrate; - nrf_uarte_config_t hw_config; +#ifdef CONFIG_HAS_NORDIC_DMM + void *mem_reg; +#endif +#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE + /* None-zero in case of high speed instances. Baudrate is adjusted by that ratio. */ + uint32_t clock_freq; +#else +#ifdef UARTE_HAS_FRAME_TIMEOUT + uint32_t baudrate; #endif + nrf_uarte_baudrate_t nrf_baudrate; + nrf_uarte_config_t hw_config; +#endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */ + #ifdef UARTE_ANY_ASYNC nrfx_timer_t timer; uint8_t *tx_cache; + uint8_t *rx_flush_buf; #endif + uint8_t *poll_out_byte; + uint8_t *poll_in_byte; }; static inline NRF_UARTE_Type *get_uarte_instance(const struct device *dev) @@ -277,6 +331,7 @@ static void uarte_nrfx_isr_int(const void *arg) { const struct device *dev = arg; const struct uarte_nrfx_config *config = dev->config; + struct uarte_nrfx_data *data = dev->data; NRF_UARTE_Type *uarte = get_uarte_instance(dev); /* If interrupt driven and asynchronous APIs are disabled then UART @@ -288,34 +343,35 @@ static void uarte_nrfx_isr_int(const void *arg) endtx_isr(dev); } - if (config->flags & UARTE_CFG_FLAG_LOW_POWER) { + bool txstopped = nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED); + + if (txstopped && (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) || LOW_POWER_ENABLED(config))) { unsigned int key = irq_lock(); - if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED)) { + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) && + (data->flags & UARTE_FLAG_POLL_OUT)) { + data->flags &= ~UARTE_FLAG_POLL_OUT; + pm_device_runtime_put(dev); + } else { nrf_uarte_disable(uarte); } #ifdef UARTE_INTERRUPT_DRIVEN - struct uarte_nrfx_data *data = dev->data; - if (!data->int_driven || data->int_driven->fifo_fill_lock == 0) #endif { - nrf_uarte_int_disable(uarte, - NRF_UARTE_INT_TXSTOPPED_MASK); + nrf_uarte_int_disable(uarte, NRF_UARTE_INT_TXSTOPPED_MASK); } irq_unlock(key); } #ifdef UARTE_INTERRUPT_DRIVEN - struct uarte_nrfx_data *data = dev->data; - if (!data->int_driven) { return; } - if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED)) { + if (txstopped) { data->int_driven->fifo_fill_lock = 0; if (data->int_driven->disable_tx_irq) { nrf_uarte_int_disable(uarte, @@ -354,7 +410,6 @@ static int baudrate_set(const struct device *dev, uint32_t baudrate) const struct uarte_nrfx_config *config = dev->config; /* calculated baudrate divisor */ nrf_uarte_baudrate_t nrf_baudrate = NRF_BAUDRATE(baudrate); - NRF_UARTE_Type *uarte = get_uarte_instance(dev); if (nrf_baudrate == 0) { return -EINVAL; @@ -365,7 +420,13 @@ static int baudrate_set(const struct device *dev, uint32_t baudrate) nrf_baudrate /= config->clock_freq / NRF_UARTE_BASE_FREQUENCY_16MHZ; } - nrf_uarte_baudrate_set(uarte, nrf_baudrate); +#ifdef UARTE_BAUDRATE_RETENTION_WORKAROUND + struct uarte_nrfx_data *data = dev->data; + + data->nrf_baudrate = nrf_baudrate; +#else + nrf_uarte_baudrate_set(get_uarte_instance(dev), nrf_baudrate); +#endif return 0; } @@ -376,10 +437,6 @@ static int uarte_nrfx_configure(const struct device *dev, struct uarte_nrfx_data *data = dev->data; nrf_uarte_config_t uarte_cfg; -#if NRF_UARTE_HAS_FRAME_TIMEOUT - uarte_cfg.frame_timeout = NRF_UARTE_FRAME_TIMEOUT_DIS; -#endif - #if defined(UARTE_CONFIG_STOP_Msk) switch (cfg->stop_bits) { case UART_CFG_STOP_BITS_1: @@ -436,6 +493,9 @@ static int uarte_nrfx_configure(const struct device *dev, return -ENOTSUP; } +#ifdef UARTE_HAS_FRAME_TIMEOUT + uarte_cfg.frame_timeout = NRF_UARTE_FRAME_TIMEOUT_EN; +#endif nrf_uarte_configure(get_uarte_instance(dev), &uarte_cfg); data->uart_config = *cfg; @@ -510,60 +570,66 @@ static int wait_tx_ready(const struct device *dev) return key; } -#if defined(UARTE_ANY_ASYNC) || defined(CONFIG_PM_DEVICE) -static int pins_state_change(const struct device *dev, bool on) -{ - const struct uarte_nrfx_config *config = dev->config; - - if (config->flags & UARTE_CFG_FLAG_GPIO_MGMT) { - return pinctrl_apply_state(config->pcfg, - on ? PINCTRL_STATE_DEFAULT : PINCTRL_STATE_SLEEP); - } - - return 0; -} -#endif - -#ifdef UARTE_ANY_ASYNC - /* Using Macro instead of static inline function to handle NO_OPTIMIZATIONS case * where static inline fails on linking. */ -#define HW_RX_COUNTING_ENABLED(config) \ - (IS_ENABLED(UARTE_HW_ASYNC) ? (config->flags & UARTE_CFG_FLAG_HW_BYTE_COUNTING) : false) - -#endif /* UARTE_ANY_ASYNC */ +#define HW_RX_COUNTING_ENABLED(config) \ + (IS_ENABLED(UARTE_ANY_HW_ASYNC) ? \ + (config->flags & UARTE_CFG_FLAG_HW_BYTE_COUNTING) : false) -static int uarte_enable(const struct device *dev, uint32_t mask) +static void uarte_periph_enable(const struct device *dev) { -#ifdef UARTE_ANY_ASYNC + NRF_UARTE_Type *uarte = get_uarte_instance(dev); const struct uarte_nrfx_config *config = dev->config; struct uarte_nrfx_data *data = dev->data; - if (data->async) { - bool disabled = data->async->low_power_mask == 0; - int ret; - - data->async->low_power_mask |= mask; - ret = pins_state_change(dev, true); - if (ret < 0) { - return ret; - } + (void)data; + nrf_uarte_enable(uarte); +#if UARTE_BAUDRATE_RETENTION_WORKAROUND + nrf_uarte_baudrate_set(uarte, + COND_CODE_1(CONFIG_UART_USE_RUNTIME_CONFIGURE, + (data->nrf_baudrate), (config->nrf_baudrate))); +#endif - if (HW_RX_COUNTING_ENABLED(config) && disabled) { +#ifdef UARTE_ANY_ASYNC + if (data->async) { + if (HW_RX_COUNTING_ENABLED(config)) { const nrfx_timer_t *timer = &config->timer; nrfx_timer_enable(timer); - for (int i = 0; i < data->async->rx_flush_cnt; i++) { + for (int i = 0; i < data->async->rx.flush_cnt; i++) { nrfx_timer_increment(timer); } } + return; } #endif - nrf_uarte_enable(get_uarte_instance(dev)); - return 0; + if (IS_ENABLED(UARTE_ANY_NONE_ASYNC) && !config->disable_rx) { + nrf_uarte_rx_buffer_set(uarte, config->poll_in_byte, 1); + nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDRX); + nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STARTRX); +#if defined(UARTE_INTERRUPT_DRIVEN) && defined(CONFIG_PM_DEVICE) + if (data->int_driven && data->int_driven->rx_irq_enabled) { + nrf_uarte_int_enable(uarte, NRF_UARTE_INT_ENDRX_MASK); + } +#endif + } +} + +static void uarte_enable_locked(const struct device *dev, uint32_t act_mask) +{ + struct uarte_nrfx_data *data = dev->data; + bool already_active = (data->flags & UARTE_FLAG_LOW_POWER) != 0; + + data->flags |= act_mask; + if (already_active) { + /* Second direction already enabled so UARTE is enabled. */ + return; + } + + uarte_periph_enable(dev); } /* At this point we should have irq locked and any previous transfer completed. @@ -574,7 +640,7 @@ static void tx_start(const struct device *dev, const uint8_t *buf, size_t len) const struct uarte_nrfx_config *config = dev->config; NRF_UARTE_Type *uarte = get_uarte_instance(dev); -#ifdef CONFIG_PM_DEVICE +#if defined(CONFIG_PM_DEVICE) && !defined(CONFIG_PM_DEVICE_RUNTIME) enum pm_device_state state; (void)pm_device_state_get(dev, &state); @@ -582,43 +648,64 @@ static void tx_start(const struct device *dev, const uint8_t *buf, size_t len) return; } #endif + + if (IS_ENABLED(UARTE_ANY_CACHE) && (config->flags & UARTE_CFG_FLAG_CACHEABLE)) { + sys_cache_data_flush_range((void *)buf, len); + } + nrf_uarte_tx_buffer_set(uarte, buf, len); - nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDTX); + if (!IS_ENABLED(UARTE_HAS_ENDTX_STOPTX_SHORT)) { + nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDTX); + } nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_TXSTOPPED); - if (config->flags & UARTE_CFG_FLAG_LOW_POWER) { - (void)uarte_enable(dev, UARTE_LOW_POWER_TX); - nrf_uarte_int_enable(uarte, NRF_UARTE_INT_TXSTOPPED_MASK); + if (LOW_POWER_ENABLED(config)) { + uarte_enable_locked(dev, UARTE_FLAG_LOW_POWER_TX); } nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STARTTX); } -#if defined(UARTE_ANY_ASYNC) || defined(CONFIG_PM_DEVICE) -static void uart_disable(const struct device *dev) +#if defined(UARTE_ANY_ASYNC) +/** @brief Disable UARTE peripheral is not used by RX or TX. + * + * It must be called with interrupts locked so that deciding if no direction is + * using the UARTE is atomically performed with UARTE peripheral disabling. Otherwise + * it would be possible that after clearing flags we get preempted and UARTE is + * enabled from the higher priority context and when we come back UARTE is disabled + * here. + * @param dev Device. + * @param dis_mask Mask of direction (RX or TX) which now longer uses the UARTE instance. + */ +static void uarte_disable_locked(const struct device *dev, uint32_t dis_mask) { -#ifdef UARTE_ANY_ASYNC - const struct uarte_nrfx_config *config = dev->config; struct uarte_nrfx_data *data = dev->data; + data->flags &= ~dis_mask; + if (data->flags & UARTE_FLAG_LOW_POWER) { + return; + } + +#if !defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX) + const struct uarte_nrfx_config *config = dev->config; + if (data->async && HW_RX_COUNTING_ENABLED(config)) { nrfx_timer_disable(&config->timer); /* Timer/counter value is reset when disabled. */ - data->async->rx_total_byte_cnt = 0; - data->async->rx_total_user_byte_cnt = 0; + data->async->rx.total_byte_cnt = 0; + data->async->rx.total_user_byte_cnt = 0; } #endif nrf_uarte_disable(get_uarte_instance(dev)); } -#endif - -#ifdef UARTE_ANY_ASYNC -static void timer_handler(nrf_timer_event_t event_type, void *p_context) { } static void rx_timeout(struct k_timer *timer); static void tx_timeout(struct k_timer *timer); +#if !defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX) +static void timer_handler(nrf_timer_event_t event_type, void *p_context) { } + static int uarte_nrfx_rx_counting_init(const struct device *dev) { struct uarte_nrfx_data *data = dev->data; @@ -629,6 +716,8 @@ static int uarte_nrfx_rx_counting_init(const struct device *dev) if (HW_RX_COUNTING_ENABLED(cfg)) { nrfx_timer_config_t tmr_config = NRFX_TIMER_DEFAULT_CONFIG( NRF_TIMER_BASE_FREQUENCY_GET(cfg->timer.p_reg)); + uint32_t evt_addr = nrf_uarte_event_address_get(uarte, NRF_UARTE_EVENT_RXDRDY); + uint32_t tsk_addr = nrfx_timer_task_address_get(&cfg->timer, NRF_TIMER_TASK_COUNT); tmr_config.mode = NRF_TIMER_MODE_COUNTER; tmr_config.bit_width = NRF_TIMER_BIT_WIDTH_32; @@ -639,71 +728,52 @@ static int uarte_nrfx_rx_counting_init(const struct device *dev) LOG_ERR("Timer already initialized"); return -EINVAL; } else { - nrfx_timer_enable(&cfg->timer); nrfx_timer_clear(&cfg->timer); } - ret = gppi_channel_alloc(&data->async->rx_cnt.ppi); + ret = nrfx_gppi_channel_alloc(&data->async->rx.cnt.ppi); if (ret != NRFX_SUCCESS) { LOG_ERR("Failed to allocate PPI Channel"); nrfx_timer_uninit(&cfg->timer); return -EINVAL; } -#if CONFIG_HAS_HW_NRF_PPI - ret = nrfx_ppi_channel_assign( - data->async->rx_cnt.ppi, - nrf_uarte_event_address_get(uarte, - NRF_UARTE_EVENT_RXDRDY), - nrfx_timer_task_address_get(&cfg->timer, - NRF_TIMER_TASK_COUNT)); - - if (ret != NRFX_SUCCESS) { - return -EIO; - } -#else - nrf_uarte_publish_set(uarte, - NRF_UARTE_EVENT_RXDRDY, - data->async->rx_cnt.ppi); - nrf_timer_subscribe_set(cfg->timer.p_reg, - NRF_TIMER_TASK_COUNT, - data->async->rx_cnt.ppi); - -#endif - ret = gppi_channel_enable(data->async->rx_cnt.ppi); - if (ret != NRFX_SUCCESS) { - return -EIO; - } + nrfx_gppi_channel_endpoints_setup(data->async->rx.cnt.ppi, evt_addr, tsk_addr); + nrfx_gppi_channels_enable(BIT(data->async->rx.cnt.ppi)); } else { nrf_uarte_int_enable(uarte, NRF_UARTE_INT_RXDRDY_MASK); } return 0; } +#endif /* !defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX) */ -static int uarte_nrfx_init(const struct device *dev) +static int uarte_async_init(const struct device *dev) { struct uarte_nrfx_data *data = dev->data; NRF_UARTE_Type *uarte = get_uarte_instance(dev); - + static const uint32_t rx_int_mask = + NRF_UARTE_INT_ENDRX_MASK | + NRF_UARTE_INT_RXSTARTED_MASK | + NRF_UARTE_INT_ERROR_MASK | + NRF_UARTE_INT_RXTO_MASK | + ((IS_ENABLED(CONFIG_UART_NRFX_UARTE_ENHANCED_RX) && + !IS_ENABLED(UARTE_HAS_FRAME_TIMEOUT)) ? NRF_UARTE_INT_RXDRDY_MASK : 0); + +#if !defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX) int ret = uarte_nrfx_rx_counting_init(dev); if (ret != 0) { return ret; } +#endif - data->async->low_power_mask = UARTE_LOW_POWER_TX; - nrf_uarte_int_enable(uarte, - NRF_UARTE_INT_ENDRX_MASK | - NRF_UARTE_INT_RXSTARTED_MASK | - NRF_UARTE_INT_ERROR_MASK | - NRF_UARTE_INT_RXTO_MASK); - nrf_uarte_enable(uarte); + nrf_uarte_int_enable(uarte, rx_int_mask); - k_timer_init(&data->async->rx_timeout_timer, rx_timeout, NULL); - k_timer_user_data_set(&data->async->rx_timeout_timer, data); - k_timer_init(&data->async->tx_timeout_timer, tx_timeout, NULL); - k_timer_user_data_set(&data->async->tx_timeout_timer, data); + k_timer_init(&data->async->rx.timer, rx_timeout, NULL); + k_timer_user_data_set(&data->async->rx.timer, (void *)dev); + k_timer_init(&data->async->tx.timer, tx_timeout, NULL); + k_timer_user_data_set(&data->async->tx.timer, (void *)dev); return 0; } @@ -714,13 +784,14 @@ static int uarte_nrfx_init(const struct device *dev) */ static void start_tx_locked(const struct device *dev, struct uarte_nrfx_data *data) { + nrf_uarte_int_enable(get_uarte_instance(dev), NRF_UARTE_INT_TXSTOPPED_MASK); if (!is_tx_ready(dev)) { /* Active poll out, postpone until it is completed. */ - data->async->pending_tx = true; + data->async->tx.pending = true; } else { - data->async->pending_tx = false; - data->async->tx_amount = -1; - tx_start(dev, data->async->xfer_buf, data->async->xfer_len); + data->async->tx.pending = false; + data->async->tx.amount = -1; + tx_start(dev, data->async->tx.xfer_buf, data->async->tx.xfer_len); } } @@ -733,7 +804,7 @@ static bool setup_tx_cache(const struct device *dev) { struct uarte_nrfx_data *data = dev->data; const struct uarte_nrfx_config *config = dev->config; - size_t remaining = data->async->tx_size - data->async->tx_cache_offset; + size_t remaining = data->async->tx.len - data->async->tx.cache_offset; if (!remaining) { return false; @@ -741,9 +812,9 @@ static bool setup_tx_cache(const struct device *dev) size_t len = MIN(remaining, CONFIG_UART_ASYNC_TX_CACHE_SIZE); - data->async->xfer_len = len; - data->async->xfer_buf = config->tx_cache; - memcpy(config->tx_cache, &data->async->tx_buf[data->async->tx_cache_offset], len); + data->async->tx.xfer_len = len; + data->async->tx.xfer_buf = config->tx_cache; + memcpy(config->tx_cache, &data->async->tx.buf[data->async->tx.cache_offset], len); return true; } @@ -770,29 +841,32 @@ static int uarte_nrfx_tx(const struct device *dev, const uint8_t *buf, unsigned int key = irq_lock(); - if (data->async->tx_size) { + if (data->async->tx.len) { irq_unlock(key); return -EBUSY; } - data->async->tx_size = len; - data->async->tx_buf = buf; - nrf_uarte_int_enable(uarte, NRF_UARTE_INT_TXSTOPPED_MASK); + data->async->tx.len = len; + data->async->tx.buf = buf; - if (nrfx_is_in_ram(buf)) { - data->async->xfer_buf = buf; - data->async->xfer_len = len; + if (nrf_dma_accessible_check(uarte, buf)) { + data->async->tx.xfer_buf = buf; + data->async->tx.xfer_len = len; } else { - data->async->tx_cache_offset = 0; + data->async->tx.cache_offset = 0; (void)setup_tx_cache(dev); } + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_get(dev); + } + start_tx_locked(dev, data); irq_unlock(key); if (has_hwfc(dev) && timeout != SYS_FOREVER_US) { - k_timer_start(&data->async->tx_timeout_timer, K_USEC(timeout), K_NO_WAIT); + k_timer_start(&data->async->tx.timer, K_USEC(timeout), K_NO_WAIT); } return 0; } @@ -802,12 +876,12 @@ static int uarte_nrfx_tx_abort(const struct device *dev) struct uarte_nrfx_data *data = dev->data; NRF_UARTE_Type *uarte = get_uarte_instance(dev); - if (data->async->tx_buf == NULL) { + if (data->async->tx.buf == NULL) { return -EFAULT; } - data->async->pending_tx = false; - k_timer_stop(&data->async->tx_timeout_timer); + data->async->tx.pending = false; + k_timer_stop(&data->async->tx.timer); nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STOPTX); return 0; @@ -827,25 +901,22 @@ static void notify_uart_rx_rdy(const struct device *dev, size_t len) struct uarte_nrfx_data *data = dev->data; struct uart_event evt = { .type = UART_RX_RDY, - .data.rx.buf = data->async->rx_buf, + .data.rx.buf = data->async->rx.buf, .data.rx.len = len, - .data.rx.offset = data->async->rx_offset + .data.rx.offset = data->async->rx.offset }; user_callback(dev, &evt); } -static void rx_buf_release(const struct device *dev, uint8_t **buf) +static void rx_buf_release(const struct device *dev, uint8_t *buf) { - if (*buf) { - struct uart_event evt = { - .type = UART_RX_BUF_RELEASED, - .data.rx_buf.buf = *buf, - }; + struct uart_event evt = { + .type = UART_RX_BUF_RELEASED, + .data.rx_buf.buf = buf, + }; - user_callback(dev, &evt); - *buf = NULL; - } + user_callback(dev, &evt); } static void notify_rx_disable(const struct device *dev) @@ -857,14 +928,23 @@ static void notify_rx_disable(const struct device *dev) user_callback(dev, (struct uart_event *)&evt); } +#ifdef UARTE_HAS_FRAME_TIMEOUT +static uint32_t us_to_bauds(uint32_t baudrate, int32_t timeout) +{ + uint64_t bauds = (uint64_t)baudrate * timeout / 1000000; + + return MIN((uint32_t)bauds, UARTE_FRAMETIMEOUT_COUNTERTOP_Msk); +} +#endif + static int uarte_nrfx_rx_enable(const struct device *dev, uint8_t *buf, size_t len, int32_t timeout) { struct uarte_nrfx_data *data = dev->data; + struct uarte_async_rx *async_rx = &data->async->rx; const struct uarte_nrfx_config *cfg = dev->config; NRF_UARTE_Type *uarte = get_uarte_instance(dev); - int ret = 0; if (cfg->disable_rx) { __ASSERT(false, "TX only UARTE instance"); @@ -875,36 +955,93 @@ static int uarte_nrfx_rx_enable(const struct device *dev, uint8_t *buf, * for the RXTO event after a call to uart_rx_disable() to discard * data from the UARTE internal RX FIFO. */ - if (data->async->rx_enabled || data->async->discard_rx_fifo) { + if (async_rx->enabled || async_rx->discard_fifo) { return -EBUSY; } - data->async->rx_timeout = timeout; - data->async->rx_timeout_slab = timeout / RX_TIMEOUT_DIV; +#ifdef CONFIG_HAS_NORDIC_DMM + uint8_t *dma_buf; + int ret = 0; + + ret = dmm_buffer_in_prepare(cfg->mem_reg, buf, len, (void **)&dma_buf); + if (ret < 0) { + return ret; + } + + async_rx->usr_buf = buf; + buf = dma_buf; +#endif + +#ifdef CONFIG_UART_NRFX_UARTE_ENHANCED_RX +#ifdef UARTE_HAS_FRAME_TIMEOUT + if (timeout != SYS_FOREVER_US) { + uint32_t baudrate = COND_CODE_1(CONFIG_UART_USE_RUNTIME_CONFIGURE, + (data->uart_config.baudrate), (cfg->baudrate)); + + async_rx->timeout = K_USEC(timeout); + nrf_uarte_frame_timeout_set(uarte, us_to_bauds(baudrate, timeout)); + nrf_uarte_shorts_enable(uarte, NRF_UARTE_SHORT_FRAME_TIMEOUT_STOPRX); + } else { + async_rx->timeout = K_NO_WAIT; + } +#else + async_rx->timeout = (timeout == SYS_FOREVER_US) ? + K_NO_WAIT : K_USEC(timeout / RX_TIMEOUT_DIV); + async_rx->idle_cnt = 0; +#endif /* UARTE_HAS_FRAME_TIMEOUT */ +#else + async_rx->timeout_us = timeout; + async_rx->timeout_slab = timeout / RX_TIMEOUT_DIV; +#endif + + async_rx->buf = buf; + async_rx->buf_len = len; + async_rx->offset = 0; + async_rx->next_buf = NULL; + async_rx->next_buf_len = 0; - data->async->rx_buf = buf; - data->async->rx_buf_len = len; - data->async->rx_offset = 0; - data->async->rx_next_buf = NULL; - data->async->rx_next_buf_len = 0; + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) || LOW_POWER_ENABLED(cfg)) { + if (async_rx->flush_cnt) { + int cpy_len = MIN(len, async_rx->flush_cnt); - if (cfg->flags & UARTE_CFG_FLAG_LOW_POWER) { - if (data->async->rx_flush_cnt) { - int cpy_len = MIN(len, data->async->rx_flush_cnt); + if (IS_ENABLED(UARTE_ANY_CACHE) && + (cfg->flags & UARTE_CFG_FLAG_CACHEABLE)) { + sys_cache_data_invd_range(cfg->rx_flush_buf, cpy_len); + } + + memcpy(buf, cfg->rx_flush_buf, cpy_len); + + if (IS_ENABLED(UARTE_ANY_CACHE) && + (cfg->flags & UARTE_CFG_FLAG_CACHEABLE)) { + sys_cache_data_flush_range(buf, cpy_len); + } - memcpy(buf, data->async->rx_flush_buffer, cpy_len); buf += cpy_len; len -= cpy_len; - /* If flush content filled whole new buffer complete the - * request and indicate rx being disabled. + /* If flush content filled whole new buffer trigger interrupt + * to notify about received data and disabled RX from there. */ if (!len) { - data->async->rx_flush_cnt -= cpy_len; - notify_uart_rx_rdy(dev, cpy_len); - rx_buf_release(dev, &data->async->rx_buf); - notify_rx_disable(dev); + async_rx->flush_cnt -= cpy_len; + memmove(cfg->rx_flush_buf, &cfg->rx_flush_buf[cpy_len], + async_rx->flush_cnt); + if (IS_ENABLED(UARTE_ANY_CACHE) && + (cfg->flags & UARTE_CFG_FLAG_CACHEABLE)) { + sys_cache_data_flush_range(cfg->rx_flush_buf, + async_rx->flush_cnt); + } + atomic_or(&data->flags, UARTE_FLAG_TRIG_RXTO); + NRFX_IRQ_PENDING_SET(nrfx_get_irq_number(uarte)); return 0; + } else { +#ifdef CONFIG_UART_NRFX_UARTE_ENHANCED_RX + if (!K_TIMEOUT_EQ(async_rx->timeout, K_NO_WAIT)) { + nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXDRDY); + k_timer_start(&async_rx->timer, async_rx->timeout, + K_NO_WAIT); + } +#endif } } } @@ -914,11 +1051,14 @@ static int uarte_nrfx_rx_enable(const struct device *dev, uint8_t *buf, nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDRX); nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXSTARTED); - data->async->rx_enabled = true; - if (cfg->flags & UARTE_CFG_FLAG_LOW_POWER) { + async_rx->enabled = true; + + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_get(dev); + } else if (LOW_POWER_ENABLED(cfg)) { unsigned int key = irq_lock(); - ret = uarte_enable(dev, UARTE_LOW_POWER_RX); + uarte_enable_locked(dev, UARTE_FLAG_LOW_POWER_RX); irq_unlock(key); } @@ -931,17 +1071,39 @@ static int uarte_nrfx_rx_buf_rsp(const struct device *dev, uint8_t *buf, size_t len) { struct uarte_nrfx_data *data = dev->data; + struct uarte_async_rx *async_rx = &data->async->rx; int err; NRF_UARTE_Type *uarte = get_uarte_instance(dev); unsigned int key = irq_lock(); - if (data->async->rx_buf == NULL) { + if (async_rx->buf == NULL) { err = -EACCES; - } else if (data->async->rx_next_buf == NULL) { - data->async->rx_next_buf = buf; - data->async->rx_next_buf_len = len; + } else if (async_rx->next_buf == NULL) { +#ifdef CONFIG_HAS_NORDIC_DMM + uint8_t *dma_buf; + const struct uarte_nrfx_config *config = dev->config; + + err = dmm_buffer_in_prepare(config->mem_reg, buf, len, (void **)&dma_buf); + if (err < 0) { + return err; + } + async_rx->next_usr_buf = buf; + buf = dma_buf; +#endif + async_rx->next_buf = buf; + async_rx->next_buf_len = len; nrf_uarte_rx_buffer_set(uarte, buf, len); - nrf_uarte_shorts_enable(uarte, NRF_UARTE_SHORT_ENDRX_STARTRX); + /* If buffer is shorter than RX FIFO then there is a risk that due + * to interrupt handling latency ENDRX event is not handled on time + * and due to ENDRX_STARTRX short data will start to be overwritten. + * In that case short is not enabled and ENDRX event handler will + * manually start RX for that buffer. Thanks to RX FIFO there is + * 5 byte time for doing that. If interrupt latency is higher and + * there is no HWFC in both cases data will be lost or corrupted. + */ + if (len >= UARTE_HW_RX_FIFO_SIZE) { + nrf_uarte_shorts_enable(uarte, NRF_UARTE_SHORT_ENDRX_STARTRX); + } err = 0; } else { err = -EBUSY; @@ -971,29 +1133,36 @@ static int uarte_nrfx_callback_set(const struct device *dev, static int uarte_nrfx_rx_disable(const struct device *dev) { struct uarte_nrfx_data *data = dev->data; + struct uarte_async_rx *async_rx = &data->async->rx; NRF_UARTE_Type *uarte = get_uarte_instance(dev); + int key; - if (data->async->rx_buf == NULL) { + if (async_rx->buf == NULL) { return -EFAULT; } - if (data->async->rx_next_buf != NULL) { + + k_timer_stop(&async_rx->timer); + + key = irq_lock(); + + if (async_rx->next_buf != NULL) { nrf_uarte_shorts_disable(uarte, NRF_UARTE_SHORT_ENDRX_STARTRX); nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXSTARTED); } - k_timer_stop(&data->async->rx_timeout_timer); - data->async->rx_enabled = false; - data->async->discard_rx_fifo = true; + async_rx->enabled = false; + async_rx->discard_fifo = true; nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STOPRX); + irq_unlock(key); return 0; } static void tx_timeout(struct k_timer *timer) { - struct uarte_nrfx_data *data = k_timer_user_data_get(timer); - (void) uarte_nrfx_tx_abort(data->dev); + const struct device *dev = k_timer_user_data_get(timer); + (void) uarte_nrfx_tx_abort(dev); } /** @@ -1006,12 +1175,48 @@ static void tx_timeout(struct k_timer *timer) */ static void rx_timeout(struct k_timer *timer) { - struct uarte_nrfx_data *data = k_timer_user_data_get(timer); - const struct device *dev = data->dev; + const struct device *dev = k_timer_user_data_get(timer); + +#if CONFIG_UART_NRFX_UARTE_ENHANCED_RX + NRF_UARTE_Type *uarte = get_uarte_instance(dev); + +#ifdef UARTE_HAS_FRAME_TIMEOUT + if (!nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_RXDRDY)) { + nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STOPRX); + } + return; +#else /* UARTE_HAS_FRAME_TIMEOUT */ + struct uarte_nrfx_data *data = dev->data; + struct uarte_async_rx *async_rx = &data->async->rx; + + if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_RXDRDY)) { + nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXDRDY); + async_rx->idle_cnt = 0; + } else { + async_rx->idle_cnt++; + /* We compare against RX_TIMEOUT_DIV - 1 to get rather earlier timeout + * than late. idle_cnt is reset when last RX activity (RXDRDY event) is + * detected. It may happen that it happens when RX is inactive for whole + * RX timeout period (and it is the case when transmission is short compared + * to the timeout, for example timeout is 50 ms and transmission of few bytes + * takes less than 1ms). In that case if we compare against RX_TIMEOUT_DIV + * then RX notification would come after (RX_TIMEOUT_DIV + 1) * timeout. + */ + if (async_rx->idle_cnt == (RX_TIMEOUT_DIV - 1)) { + nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STOPRX); + return; + } + } + + k_timer_start(&async_rx->timer, async_rx->timeout, K_NO_WAIT); +#endif /* UARTE_HAS_FRAME_TIMEOUT */ +#else /* CONFIG_UART_NRFX_UARTE_ENHANCED_RX */ const struct uarte_nrfx_config *cfg = dev->config; + struct uarte_nrfx_data *data = dev->data; + struct uarte_async_rx *async_rx = &data->async->rx; uint32_t read; - if (data->async->is_in_irq) { + if (async_rx->is_in_irq) { return; } @@ -1024,21 +1229,20 @@ static void rx_timeout(struct k_timer *timer) if (HW_RX_COUNTING_ENABLED(cfg)) { read = nrfx_timer_capture(&cfg->timer, 0); } else { - read = data->async->rx_cnt.cnt; + read = async_rx->cnt.cnt; } /* Check if data was received since last function call */ - if (read != data->async->rx_total_byte_cnt) { - data->async->rx_total_byte_cnt = read; - data->async->rx_timeout_left = data->async->rx_timeout; + if (read != async_rx->total_byte_cnt) { + async_rx->total_byte_cnt = read; + async_rx->timeout_left = async_rx->timeout_us; } /* Check if there is data that was not sent to user yet * Note though that 'len' is a count of data bytes received, but not * necessarily the amount available in the current buffer */ - int32_t len = data->async->rx_total_byte_cnt - - data->async->rx_total_user_byte_cnt; + int32_t len = async_rx->total_byte_cnt - async_rx->total_user_byte_cnt; if (!HW_RX_COUNTING_ENABLED(cfg) && (len < 0)) { @@ -1047,7 +1251,7 @@ static void rx_timeout(struct k_timer *timer) * At this point, the number of received bytes is at least * equal to what was reported to the user. */ - data->async->rx_cnt.cnt = data->async->rx_total_user_byte_cnt; + async_rx->cnt.cnt = async_rx->total_user_byte_cnt; len = 0; } @@ -1059,37 +1263,34 @@ static void rx_timeout(struct k_timer *timer) */ bool clipped = false; - if (len + data->async->rx_offset > data->async->rx_buf_len) { - len = data->async->rx_buf_len - data->async->rx_offset; + if (len + async_rx->offset > async_rx->buf_len) { + len = async_rx->buf_len - async_rx->offset; clipped = true; } if (len > 0) { - if (clipped || - (data->async->rx_timeout_left - < data->async->rx_timeout_slab)) { + if (clipped || (async_rx->timeout_left < async_rx->timeout_slab)) { /* rx_timeout us elapsed since last receiving */ - if (data->async->rx_buf != NULL) { + if (async_rx->buf != NULL) { notify_uart_rx_rdy(dev, len); - data->async->rx_offset += len; - data->async->rx_total_user_byte_cnt += len; + async_rx->offset += len; + async_rx->total_user_byte_cnt += len; } } else { - data->async->rx_timeout_left -= - data->async->rx_timeout_slab; + async_rx->timeout_left -= async_rx->timeout_slab; } /* If there's nothing left to report until the buffers are * switched then the timer can be stopped */ if (clipped) { - k_timer_stop(&data->async->rx_timeout_timer); + k_timer_stop(&async_rx->timer); } } nrf_uarte_int_enable(get_uarte_instance(dev), NRF_UARTE_INT_ENDRX_MASK); - +#endif /* CONFIG_UART_NRFX_UARTE_ENHANCED_RX */ } #define UARTE_ERROR_FROM_MASK(mask) \ @@ -1102,49 +1303,78 @@ static void rx_timeout(struct k_timer *timer) static void error_isr(const struct device *dev) { NRF_UARTE_Type *uarte = get_uarte_instance(dev); - uint32_t err = nrf_uarte_errorsrc_get_and_clear(uarte); + uint32_t err = nrf_uarte_errorsrc_get(uarte); struct uart_event evt = { .type = UART_RX_STOPPED, .data.rx_stop.reason = UARTE_ERROR_FROM_MASK(err), }; + + /* For VPR cores read and write may be reordered - barrier needed. */ + nrf_barrier_r(); + nrf_uarte_errorsrc_clear(uarte, err); + user_callback(dev, &evt); (void) uarte_nrfx_rx_disable(dev); } static void rxstarted_isr(const struct device *dev) { - struct uarte_nrfx_data *data = dev->data; struct uart_event evt = { .type = UART_RX_BUF_REQUEST, }; - user_callback(dev, &evt); - if (data->async->rx_timeout != SYS_FOREVER_US) { - data->async->rx_timeout_left = data->async->rx_timeout; - k_timer_start(&data->async->rx_timeout_timer, - K_USEC(data->async->rx_timeout_slab), - K_USEC(data->async->rx_timeout_slab)); + +#ifndef UARTE_HAS_FRAME_TIMEOUT + struct uarte_nrfx_data *data = dev->data; + struct uarte_async_rx *async_rx = &data->async->rx; + +#ifdef CONFIG_UART_NRFX_UARTE_ENHANCED_RX + NRF_UARTE_Type *uarte = get_uarte_instance(dev); + + if (!K_TIMEOUT_EQ(async_rx->timeout, K_NO_WAIT)) { + nrf_uarte_int_enable(uarte, NRF_UARTE_INT_RXDRDY_MASK); + } +#else + if (async_rx->timeout_us != SYS_FOREVER_US) { + k_timeout_t timeout = K_USEC(async_rx->timeout_slab); + + async_rx->timeout_left = async_rx->timeout_us; + k_timer_start(&async_rx->timer, timeout, timeout); } +#endif /* CONFIG_UART_NRFX_UARTE_ENHANCED_RX */ +#endif /* !UARTE_HAS_FRAME_TIMEOUT */ + user_callback(dev, &evt); } static void endrx_isr(const struct device *dev) { struct uarte_nrfx_data *data = dev->data; + struct uarte_async_rx *async_rx = &data->async->rx; NRF_UARTE_Type *uarte = get_uarte_instance(dev); - data->async->is_in_irq = true; +#if !defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX) + async_rx->is_in_irq = true; +#endif /* ensure rx timer is stopped - it will be restarted in RXSTARTED * handler if needed */ - k_timer_stop(&data->async->rx_timeout_timer); + k_timer_stop(&async_rx->timer); /* this is the amount that the EasyDMA controller has copied into the * buffer */ - const int rx_amount = nrf_uarte_rx_amount_get(uarte) + - data->async->rx_flush_cnt; + const int rx_amount = nrf_uarte_rx_amount_get(uarte) + async_rx->flush_cnt; - data->async->rx_flush_cnt = 0; +#ifdef CONFIG_HAS_NORDIC_DMM + const struct uarte_nrfx_config *config = dev->config; + int err = + dmm_buffer_in_release(config->mem_reg, async_rx->usr_buf, rx_amount, async_rx->buf); + + (void)err; + __ASSERT_NO_MSG(err == 0); + async_rx->buf = async_rx->usr_buf; +#endif + async_rx->flush_cnt = 0; /* The 'rx_offset' can be bigger than 'rx_amount', so it the length * of data we report back the user may need to be clipped. @@ -1153,147 +1383,100 @@ static void endrx_isr(const struct device *dev) * here to handle this buffer. (The next buffer is now already active * because of the ENDRX_STARTRX shortcut) */ - int rx_len = rx_amount - data->async->rx_offset; + int rx_len = rx_amount - async_rx->offset; if (rx_len < 0) { rx_len = 0; } - data->async->rx_total_user_byte_cnt += rx_len; +#if !defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX) + async_rx->total_user_byte_cnt += rx_len; +#endif /* Only send the RX_RDY event if there is something to send */ if (rx_len > 0) { notify_uart_rx_rdy(dev, rx_len); } - if (!data->async->rx_enabled) { - data->async->is_in_irq = false; - return; - } - - rx_buf_release(dev, &data->async->rx_buf); - - /* If there is a next buffer, then STARTRX will have already been - * invoked by the short (the next buffer will be filling up already) - * and here we just do the swap of which buffer the driver is following, - * the next rx_timeout() will update the rx_offset. - */ - unsigned int key = irq_lock(); - - if (data->async->rx_next_buf) { - data->async->rx_buf = data->async->rx_next_buf; - data->async->rx_buf_len = data->async->rx_next_buf_len; - data->async->rx_next_buf = NULL; - data->async->rx_next_buf_len = 0; - - data->async->rx_offset = 0; - /* Check is based on assumption that ISR handler handles - * ENDRX before RXSTARTED so if short was set on time, RXSTARTED - * event will be set. + rx_buf_release(dev, async_rx->buf); + async_rx->buf = async_rx->next_buf; + async_rx->buf_len = async_rx->next_buf_len; +#ifdef CONFIG_HAS_NORDIC_DMM + async_rx->usr_buf = async_rx->next_usr_buf; +#endif + async_rx->next_buf = NULL; + async_rx->next_buf_len = 0; + async_rx->offset = 0; + + if (async_rx->enabled) { + /* If there is a next buffer, then STARTRX will have already been + * invoked by the short (the next buffer will be filling up already) + * and here we just do the swap of which buffer the driver is following, + * the next rx_timeout() will update the rx_offset. */ - if (!nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_RXSTARTED)) { - nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STARTRX); + unsigned int key = irq_lock(); + + if (async_rx->buf) { + /* Check is based on assumption that ISR handler handles + * ENDRX before RXSTARTED so if short was set on time, RXSTARTED + * event will be set. + */ + if (!nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_RXSTARTED)) { + nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STARTRX); + } + /* Remove the short until the subsequent next buffer is setup */ + nrf_uarte_shorts_disable(uarte, NRF_UARTE_SHORT_ENDRX_STARTRX); + } else { + nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STOPRX); } - /* Remove the short until the subsequent next buffer is setup */ - nrf_uarte_shorts_disable(uarte, NRF_UARTE_SHORT_ENDRX_STARTRX); - } else { - nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STOPRX); - } - irq_unlock(key); + irq_unlock(key); + } - data->async->is_in_irq = false; +#if !defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX) + async_rx->is_in_irq = false; +#endif } -/* Function for flushing internal RX fifo. Function can be called in case - * flushed data is discarded or when data is valid and needs to be retrieved. - * - * However, UARTE does not update RXAMOUNT register if fifo is empty. Old value - * remains. In certain cases it makes it impossible to distinguish between - * case when fifo was empty and not. Function is trying to minimize chances of - * error with following measures: - * - RXAMOUNT is read before flushing and compared against value after flushing - * if they differ it indicates that data was flushed - * - user buffer is dirtied and if RXAMOUNT did not changed it is checked if - * it is still dirty. If not then it indicates that data was flushed +/** @brief RX FIFO flushing * - * In other cases function indicates that fifo was empty. It means that if - * number of bytes in the fifo equal last rx transfer length and data is equal - * to dirty marker it will be discarded. + * Due to the HW bug which does not update RX.AMOUNT register when FIFO was empty + * a workaround is applied which checks RXSTARTED event. If that event is set it + * means that FIFO was not empty. * * @param dev Device. - * @param buf Buffer for flushed data, null indicates that flushed data can be - * dropped but we still want to get amount of data flushed. - * @param len Buffer size, not used if @p buf is null. * * @return number of bytes flushed from the fifo. */ -static uint8_t rx_flush(const struct device *dev, uint8_t *buf, uint32_t len) +static uint8_t rx_flush(const struct device *dev) { - /* Flushing RX fifo requires buffer bigger than 4 bytes to empty fifo*/ - static const uint8_t dirty; NRF_UARTE_Type *uarte = get_uarte_instance(dev); - uint32_t prev_rx_amount = nrf_uarte_rx_amount_get(uarte); - uint8_t tmp_buf[UARTE_HW_RX_FIFO_SIZE]; - uint8_t *flush_buf = buf ? buf : tmp_buf; - size_t flush_len = buf ? len : sizeof(tmp_buf); - - if (buf) { - flush_buf = buf; - flush_len = len; - } else { - flush_buf = tmp_buf; - flush_len = sizeof(tmp_buf); - } + const struct uarte_nrfx_config *config = dev->config; + uint32_t rx_amount; - memset(flush_buf, dirty, flush_len); - nrf_uarte_rx_buffer_set(uarte, flush_buf, flush_len); - /* Final part of handling RXTO event is in ENDRX interrupt - * handler. ENDRX is generated as a result of FLUSHRX task. - */ - nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDRX); + nrf_uarte_rx_buffer_set(uarte, config->rx_flush_buf, UARTE_HW_RX_FIFO_SIZE); nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_FLUSHRX); while (!nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ENDRX)) { /* empty */ } nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDRX); - uint32_t rx_amount = nrf_uarte_rx_amount_get(uarte); - - if (rx_amount != prev_rx_amount) { - return rx_amount; + if (!IS_ENABLED(RX_FLUSH_WORKAROUND)) { + nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXSTARTED); + rx_amount = nrf_uarte_rx_amount_get(uarte); + } else if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_RXSTARTED)) { + nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXSTARTED); + rx_amount = nrf_uarte_rx_amount_get(uarte); + } else { + rx_amount = 0; } - for (int i = 0; i < flush_len; i++) { - if (flush_buf[i] != dirty) { - return rx_amount; - } + if (IS_ENABLED(UARTE_ANY_CACHE) && (config->flags & UARTE_CFG_FLAG_CACHEABLE) && + rx_amount) { + sys_cache_data_invd_range(config->rx_flush_buf, rx_amount); } - return 0; -} - -static void async_uart_release(const struct device *dev, uint32_t dir_mask) -{ - struct uarte_nrfx_data *data = dev->data; - unsigned int key = irq_lock(); - - data->async->low_power_mask &= ~dir_mask; - if (!data->async->low_power_mask) { - if (dir_mask == UARTE_LOW_POWER_RX) { - data->async->rx_flush_cnt = - rx_flush(dev, data->async->rx_flush_buffer, - sizeof(data->async->rx_flush_buffer)); - } - - uart_disable(dev); - int err = pins_state_change(dev, false); - - (void)err; - __ASSERT_NO_MSG(err == 0); - } - - irq_unlock(key); + return rx_amount; } /* This handler is called when the receiver is stopped. If rx was aborted @@ -1303,9 +1486,16 @@ static void rxto_isr(const struct device *dev) { const struct uarte_nrfx_config *config = dev->config; struct uarte_nrfx_data *data = dev->data; + struct uarte_async_rx *async_rx = &data->async->rx; - rx_buf_release(dev, &data->async->rx_buf); - rx_buf_release(dev, &data->async->rx_next_buf); + if (async_rx->buf) { +#ifdef CONFIG_HAS_NORDIC_DMM + (void)dmm_buffer_in_release(config->mem_reg, async_rx->usr_buf, 0, async_rx->buf); + async_rx->buf = async_rx->usr_buf; +#endif + rx_buf_release(dev, async_rx->buf); + async_rx->buf = NULL; + } /* This point can be reached in two cases: * 1. RX is disabled because all provided RX buffers have been filled. @@ -1315,22 +1505,36 @@ static void rxto_isr(const struct device *dev) * In the second case, additionally, data from the UARTE internal RX * FIFO need to be discarded. */ - data->async->rx_enabled = false; - if (data->async->discard_rx_fifo) { - uint8_t flushed; - - data->async->discard_rx_fifo = false; - flushed = rx_flush(dev, NULL, 0); + async_rx->enabled = false; + if (async_rx->discard_fifo) { + async_rx->discard_fifo = false; +#if !defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX) if (HW_RX_COUNTING_ENABLED(config)) { /* It need to be included because TIMER+PPI got RXDRDY events * and counted those flushed bytes. */ - data->async->rx_total_user_byte_cnt += flushed; + async_rx->total_user_byte_cnt += rx_flush(dev); } +#endif + } else if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) || LOW_POWER_ENABLED(config)) { + async_rx->flush_cnt = rx_flush(dev); } - if (config->flags & UARTE_CFG_FLAG_LOW_POWER) { - async_uart_release(dev, UARTE_LOW_POWER_RX); +#ifdef CONFIG_UART_NRFX_UARTE_ENHANCED_RX + NRF_UARTE_Type *uarte = get_uarte_instance(dev); +#ifdef UARTE_HAS_FRAME_TIMEOUT + nrf_uarte_shorts_disable(uarte, NRF_UARTE_SHORT_FRAME_TIMEOUT_STOPRX); +#endif + nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXDRDY); +#endif + + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_put(dev); + } else if (LOW_POWER_ENABLED(config)) { + uint32_t key = irq_lock(); + + uarte_disable_locked(dev, UARTE_FLAG_LOW_POWER_RX); + irq_unlock(key); } notify_rx_disable(dev); @@ -1343,30 +1547,33 @@ static void txstopped_isr(const struct device *dev) NRF_UARTE_Type *uarte = get_uarte_instance(dev); unsigned int key; - if (config->flags & UARTE_CFG_FLAG_LOW_POWER) { - nrf_uarte_int_disable(uarte, NRF_UARTE_INT_TXSTOPPED_MASK); - async_uart_release(dev, UARTE_LOW_POWER_TX); + key = irq_lock(); - if (!data->async->tx_size) { - return; + size_t amount = (data->async->tx.amount >= 0) ? + data->async->tx.amount : nrf_uarte_tx_amount_get(uarte); + + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + nrf_uarte_int_disable(uarte, NRF_UARTE_INT_TXSTOPPED_MASK); + if (data->flags & UARTE_FLAG_POLL_OUT) { + pm_device_runtime_put(dev); + data->flags &= ~UARTE_FLAG_POLL_OUT; } + } else if (LOW_POWER_ENABLED(config)) { + nrf_uarte_int_disable(uarte, NRF_UARTE_INT_TXSTOPPED_MASK); + uarte_disable_locked(dev, UARTE_FLAG_LOW_POWER_TX); } - if (!data->async->tx_buf) { + irq_unlock(key); + + if (!data->async->tx.buf) { return; } - key = irq_lock(); - size_t amount = (data->async->tx_amount >= 0) ? - data->async->tx_amount : nrf_uarte_tx_amount_get(uarte); - - irq_unlock(key); - /* If there is a pending tx request, it means that uart_tx() * was called when there was ongoing uart_poll_out. Handling * TXSTOPPED interrupt means that uart_poll_out has completed. */ - if (data->async->pending_tx) { + if (data->async->tx.pending) { key = irq_lock(); start_tx_locked(dev, data); irq_unlock(key); @@ -1374,12 +1581,12 @@ static void txstopped_isr(const struct device *dev) } /* Cache buffer is used because tx_buf wasn't in RAM. */ - if (data->async->tx_buf != data->async->xfer_buf) { + if (data->async->tx.buf != data->async->tx.xfer_buf) { /* In that case setup next chunk. If that was the last chunk * fall back to reporting TX_DONE. */ - if (amount == data->async->xfer_len) { - data->async->tx_cache_offset += amount; + if (amount == data->async->tx.xfer_len) { + data->async->tx.cache_offset += amount; if (setup_tx_cache(dev)) { key = irq_lock(); start_tx_locked(dev, data); @@ -1387,55 +1594,85 @@ static void txstopped_isr(const struct device *dev) return; } - /* Amount is already included in tx_cache_offset. */ - amount = data->async->tx_cache_offset; + /* Amount is already included in cache_offset. */ + amount = data->async->tx.cache_offset; } else { - /* TX was aborted, include tx_cache_offset in amount. */ - amount += data->async->tx_cache_offset; + /* TX was aborted, include cache_offset in amount. */ + amount += data->async->tx.cache_offset; } } - k_timer_stop(&data->async->tx_timeout_timer); + k_timer_stop(&data->async->tx.timer); struct uart_event evt = { - .data.tx.buf = data->async->tx_buf, + .data.tx.buf = data->async->tx.buf, .data.tx.len = amount, }; - if (amount == data->async->tx_size) { + if (amount == data->async->tx.len) { evt.type = UART_TX_DONE; } else { evt.type = UART_TX_ABORTED; } nrf_uarte_int_disable(uarte, NRF_UARTE_INT_TXSTOPPED_MASK); - data->async->tx_buf = NULL; - data->async->tx_size = 0; + data->async->tx.buf = NULL; + data->async->tx.len = 0; + + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_put(dev); + } user_callback(dev, &evt); } +static void rxdrdy_isr(const struct device *dev) +{ +#if !defined(UARTE_HAS_FRAME_TIMEOUT) + struct uarte_nrfx_data *data = dev->data; + +#if defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX) + NRF_UARTE_Type *uarte = get_uarte_instance(dev); + + data->async->rx.idle_cnt = 0; + k_timer_start(&data->async->rx.timer, data->async->rx.timeout, K_NO_WAIT); + nrf_uarte_int_disable(uarte, NRF_UARTE_INT_RXDRDY_MASK); +#else + data->async->rx.cnt.cnt++; +#endif +#endif /* !UARTE_HAS_FRAME_TIMEOUT */ +} + +static bool event_check_clear(NRF_UARTE_Type *uarte, nrf_uarte_event_t event, + uint32_t int_mask, uint32_t int_en_mask) +{ + if (nrf_uarte_event_check(uarte, event) && (int_mask & int_en_mask)) { + nrf_uarte_event_clear(uarte, event); + return true; + } + + return false; +} + static void uarte_nrfx_isr_async(const void *arg) { const struct device *dev = arg; NRF_UARTE_Type *uarte = get_uarte_instance(dev); const struct uarte_nrfx_config *config = dev->config; + struct uarte_nrfx_data *data = dev->data; + struct uarte_async_rx *async_rx = &data->async->rx; + uint32_t imask = nrf_uarte_int_enable_check(uarte, UINT32_MAX); - if (!HW_RX_COUNTING_ENABLED(config) - && nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_RXDRDY)) { - struct uarte_nrfx_data *data = dev->data; + if (!(HW_RX_COUNTING_ENABLED(config) || IS_ENABLED(UARTE_HAS_FRAME_TIMEOUT)) + && event_check_clear(uarte, NRF_UARTE_EVENT_RXDRDY, NRF_UARTE_INT_RXDRDY_MASK, imask)) { + rxdrdy_isr(dev); - nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXDRDY); - data->async->rx_cnt.cnt++; - return; } - if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ERROR)) { - nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ERROR); + if (event_check_clear(uarte, NRF_UARTE_EVENT_ERROR, NRF_UARTE_INT_ERROR_MASK, imask)) { error_isr(dev); } - if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ENDRX) - && nrf_uarte_int_enable_check(uarte, NRF_UARTE_INT_ENDRX_MASK)) { + if (event_check_clear(uarte, NRF_UARTE_EVENT_ENDRX, NRF_UARTE_INT_ENDRX_MASK, imask)) { nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDRX); endrx_isr(dev); } @@ -1447,7 +1684,8 @@ static void uarte_nrfx_isr_async(const void *arg) * UARTE interrupt got preempted. Events are not cleared * and isr will be called again. ENDRX will be handled first. */ - if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_RXSTARTED) && + if ((imask & NRF_UARTE_INT_RXSTARTED_MASK) && + nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_RXSTARTED) && !nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ENDRX)) { nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXSTARTED); rxstarted_isr(dev); @@ -1459,22 +1697,41 @@ static void uarte_nrfx_isr_async(const void *arg) * UARTE interrupt got preempted. Events are not cleared * and isr will be called again. ENDRX will be handled first. */ - if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_RXTO) && + if ((imask & NRF_UARTE_INT_RXTO_MASK) && + nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_RXTO) && !nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ENDRX)) { nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXTO); rxto_isr(dev); } if (!IS_ENABLED(UARTE_HAS_ENDTX_STOPTX_SHORT) && - (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ENDTX) && - nrf_uarte_int_enable_check(uarte, NRF_UARTE_INT_ENDTX_MASK))) { + (imask & NRF_UARTE_INT_ENDTX_MASK) && + nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ENDTX)) { endtx_isr(dev); } - if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED) && - nrf_uarte_int_enable_check(uarte, NRF_UARTE_INT_TXSTOPPED_MASK)) { + if ((imask & NRF_UARTE_INT_TXSTOPPED_MASK) && + nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED)) { txstopped_isr(dev); } + + if (atomic_and(&data->flags, ~UARTE_FLAG_TRIG_RXTO) & UARTE_FLAG_TRIG_RXTO) { +#ifdef CONFIG_HAS_NORDIC_DMM + int ret; + + ret = dmm_buffer_in_release(config->mem_reg, async_rx->usr_buf, async_rx->buf_len, + async_rx->buf); + + (void)ret; + __ASSERT_NO_MSG(ret == 0); + async_rx->buf = async_rx->usr_buf; +#endif + notify_uart_rx_rdy(dev, async_rx->buf_len); + rx_buf_release(dev, async_rx->buf); + async_rx->buf_len = 0; + async_rx->buf = NULL; + notify_rx_disable(dev); + } } #endif /* UARTE_ANY_ASYNC */ @@ -1489,11 +1746,12 @@ static void uarte_nrfx_isr_async(const void *arg) */ static int uarte_nrfx_poll_in(const struct device *dev, unsigned char *c) { - - const struct uarte_nrfx_data *data = dev->data; + const struct uarte_nrfx_config *config = dev->config; NRF_UARTE_Type *uarte = get_uarte_instance(dev); #ifdef UARTE_ANY_ASYNC + struct uarte_nrfx_data *data = dev->data; + if (data->async) { return -ENOTSUP; } @@ -1503,7 +1761,11 @@ static int uarte_nrfx_poll_in(const struct device *dev, unsigned char *c) return -1; } - *c = *data->rx_data; + if (IS_ENABLED(UARTE_ANY_CACHE) && (config->flags & UARTE_CFG_FLAG_CACHEABLE)) { + sys_cache_data_invd_range(config->poll_in_byte, 1); + } + + *c = *config->poll_in_byte; /* clear the interrupt */ nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDRX); @@ -1520,8 +1782,10 @@ static int uarte_nrfx_poll_in(const struct device *dev, unsigned char *c) */ static void uarte_nrfx_poll_out(const struct device *dev, unsigned char c) { - struct uarte_nrfx_data *data = dev->data; + const struct uarte_nrfx_config *config = dev->config; bool isr_mode = k_is_in_isr() || k_is_pre_kernel(); + struct uarte_nrfx_data *data = dev->data; + NRF_UARTE_Type *uarte = get_uarte_instance(dev); unsigned int key; if (isr_mode) { @@ -1529,11 +1793,9 @@ static void uarte_nrfx_poll_out(const struct device *dev, unsigned char c) key = irq_lock(); if (is_tx_ready(dev)) { #if UARTE_ANY_ASYNC - if (data->async && data->async->tx_size && - data->async->tx_amount < 0) { - data->async->tx_amount = - nrf_uarte_tx_amount_get( - get_uarte_instance(dev)); + if (data->async && data->async->tx.len && + data->async->tx.amount < 0) { + data->async->tx.amount = nrf_uarte_tx_amount_get(uarte); } #endif break; @@ -1546,8 +1808,19 @@ static void uarte_nrfx_poll_out(const struct device *dev, unsigned char c) key = wait_tx_ready(dev); } - *data->char_out = c; - tx_start(dev, data->char_out, 1); + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + if (!(data->flags & UARTE_FLAG_POLL_OUT)) { + data->flags |= UARTE_FLAG_POLL_OUT; + pm_device_runtime_get(dev); + } + } + + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) || LOW_POWER_ENABLED(config)) { + nrf_uarte_int_enable(uarte, NRF_UARTE_INT_TXSTOPPED_MASK); + } + + *config->poll_out_byte = c; + tx_start(dev, config->poll_out_byte, 1); irq_unlock(key); } @@ -1590,14 +1863,18 @@ static int uarte_nrfx_fifo_read(const struct device *dev, { int num_rx = 0; NRF_UARTE_Type *uarte = get_uarte_instance(dev); - const struct uarte_nrfx_data *data = dev->data; + const struct uarte_nrfx_config *config = dev->config; if (size > 0 && nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ENDRX)) { /* Clear the interrupt */ nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDRX); + if (IS_ENABLED(UARTE_ANY_CACHE) && (config->flags & UARTE_CFG_FLAG_CACHEABLE)) { + sys_cache_data_invd_range(config->poll_in_byte, 1); + } + /* Receive a character */ - rx_data[num_rx++] = *data->rx_data; + rx_data[num_rx++] = *config->poll_in_byte; nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STARTRX); } @@ -1760,7 +2037,7 @@ static int endtx_stoptx_ppi_init(NRF_UARTE_Type *uarte, { nrfx_err_t ret; - ret = gppi_channel_alloc(&data->ppi_ch_endtx); + ret = nrfx_gppi_channel_alloc(&data->ppi_ch_endtx); if (ret != NRFX_SUCCESS) { LOG_ERR("Failed to allocate PPI Channel"); return -EIO; @@ -1775,91 +2052,6 @@ static int endtx_stoptx_ppi_init(NRF_UARTE_Type *uarte, } #endif /* UARTE_ENHANCED_POLL_OUT */ -static int uarte_instance_init(const struct device *dev, - uint8_t interrupts_active) -{ - int err; - NRF_UARTE_Type *uarte = get_uarte_instance(dev); - struct uarte_nrfx_data *data = dev->data; - const struct uarte_nrfx_config *cfg = dev->config; - - nrf_uarte_disable(uarte); - - data->dev = dev; - -#ifdef CONFIG_ARCH_POSIX - /* For simulation the DT provided peripheral address needs to be corrected */ - ((struct pinctrl_dev_config *)cfg->pcfg)->reg = (uintptr_t)cfg->uarte_regs; -#endif - - err = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); - if (err < 0) { - return err; - } - -#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE - err = uarte_nrfx_configure(dev, &data->uart_config); - if (err) { - return err; - } -#else - nrf_uarte_baudrate_set(uarte, cfg->baudrate); - nrf_uarte_configure(uarte, &cfg->hw_config); -#endif - -#ifdef UARTE_HAS_ENDTX_STOPTX_SHORT - nrf_uarte_shorts_enable(uarte, NRF_UARTE_SHORT_ENDTX_STOPTX); -#elif defined(UARTE_ENHANCED_POLL_OUT) - if (cfg->flags & UARTE_CFG_FLAG_PPI_ENDTX) { - err = endtx_stoptx_ppi_init(uarte, data); - if (err < 0) { - return err; - } - } -#endif - -#ifdef UARTE_ANY_ASYNC - if (data->async) { - err = uarte_nrfx_init(dev); - if (err < 0) { - return err; - } - } else -#endif - { - /* Enable receiver and transmitter */ - nrf_uarte_enable(uarte); - - if (!cfg->disable_rx) { - nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDRX); - - nrf_uarte_rx_buffer_set(uarte, data->rx_data, 1); - nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STARTRX); - } - } - - if (!IS_ENABLED(UARTE_HAS_ENDTX_STOPTX_SHORT) && !(cfg->flags & UARTE_CFG_FLAG_PPI_ENDTX)) { - nrf_uarte_int_enable(uarte, NRF_UARTE_INT_ENDTX_MASK); - } - - if (cfg->flags & UARTE_CFG_FLAG_LOW_POWER) { - nrf_uarte_int_enable(uarte, NRF_UARTE_INT_TXSTOPPED_MASK); - } - - /* Set TXSTOPPED event by requesting fake (zero-length) transfer. - * Pointer to RAM variable (data->tx_buffer) is set because otherwise - * such operation may result in HardFault or RAM corruption. - */ - nrf_uarte_tx_buffer_set(uarte, data->char_out, 0); - nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STARTTX); - - /* switch off transmitter to save an energy */ - nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STOPTX); - - return 0; -} - -#ifdef CONFIG_PM_DEVICE /** @brief Pend until TX is stopped. * * There are 2 configurations that must be handled: @@ -1883,7 +2075,9 @@ static void wait_for_tx_stopped(const struct device *dev) nrf_uarte_int_disable(uarte, NRF_UARTE_INT_ENDTX_MASK); NRFX_WAIT_FOR(is_tx_ready(dev), 1000, 1, res); if (!nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED)) { - nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDTX); + if (!IS_ENABLED(UARTE_HAS_ENDTX_STOPTX_SHORT)) { + nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDTX); + } nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STOPTX); } } @@ -1896,81 +2090,59 @@ static void wait_for_tx_stopped(const struct device *dev) } } - -static int uarte_nrfx_pm_action(const struct device *dev, - enum pm_device_action action) +static void uarte_pm_resume(const struct device *dev) { - NRF_UARTE_Type *uarte = get_uarte_instance(dev); -#if defined(UARTE_ANY_ASYNC) || defined(UARTE_INTERRUPT_DRIVEN) - struct uarte_nrfx_data *data = dev->data; -#endif const struct uarte_nrfx_config *cfg = dev->config; - int ret; - -#ifdef UARTE_ANY_ASYNC - /* If low power mode for asynchronous mode is used then there is nothing to do here. - * In low power mode UARTE is turned off whenever there is no activity. - */ - if (data->async && (cfg->flags & UARTE_CFG_FLAG_LOW_POWER)) { - return 0; - } -#endif - switch (action) { - case PM_DEVICE_ACTION_RESUME: + (void)pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); - ret = pins_state_change(dev, true); - if (ret < 0) { - return ret; - } + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) || !LOW_POWER_ENABLED(cfg)) { + uarte_periph_enable(dev); + } +} - nrf_uarte_enable(uarte); +static void uarte_pm_suspend(const struct device *dev) +{ + NRF_UARTE_Type *uarte = get_uarte_instance(dev); + const struct uarte_nrfx_config *cfg = dev->config; + struct uarte_nrfx_data *data = dev->data; + (void)data; #ifdef UARTE_ANY_ASYNC - if (data->async) { - if (HW_RX_COUNTING_ENABLED(cfg)) { - nrfx_timer_enable(&cfg->timer); - } - - return 0; - } -#endif - if (!cfg->disable_rx) { - - nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDRX); - nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STARTRX); -#ifdef UARTE_INTERRUPT_DRIVEN - if (data->int_driven && - data->int_driven->rx_irq_enabled) { - nrf_uarte_int_enable(uarte, - NRF_UARTE_INT_ENDRX_MASK); - } -#endif - } - break; - case PM_DEVICE_ACTION_SUSPEND: - /* Disabling UART requires stopping RX, but stop RX event is - * only sent after each RX if async UART API is used. + if (data->async) { + /* Entering inactive state requires device to be no + * active asynchronous calls. */ -#ifdef UARTE_ANY_ASYNC - if (data->async) { - /* Entering inactive state requires device to be no - * active asynchronous calls. + __ASSERT_NO_MSG(!data->async->rx.enabled); + __ASSERT_NO_MSG(!data->async->tx.len); + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + /* If runtime PM is enabled then reference counting ensures that + * suspend will not occur when TX is active. */ - __ASSERT_NO_MSG(!data->async->rx_enabled); - __ASSERT_NO_MSG(!data->async->tx_size); + __ASSERT_NO_MSG(nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED)); + } else { + wait_for_tx_stopped(dev); + } +#if !defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX) + if (data->async && HW_RX_COUNTING_ENABLED(cfg)) { + nrfx_timer_disable(&cfg->timer); + /* Timer/counter value is reset when disabled. */ + data->async->rx.total_byte_cnt = 0; + data->async->rx.total_user_byte_cnt = 0; } #endif + } else if (IS_ENABLED(UARTE_ANY_NONE_ASYNC)) +#endif + { if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_RXSTARTED)) { -#ifdef UARTE_INTERRUPT_DRIVEN +#if defined(UARTE_INTERRUPT_DRIVEN) && defined(CONFIG_PM_DEVICE) if (data->int_driven) { data->int_driven->rx_irq_enabled = - nrf_uarte_int_enable_check(uarte, - NRF_UARTE_INT_ENDRX_MASK); + nrf_uarte_int_enable_check(uarte, + NRF_UARTE_INT_ENDRX_MASK); if (data->int_driven->rx_irq_enabled) { - nrf_uarte_int_disable(uarte, - NRF_UARTE_INT_ENDRX_MASK); + nrf_uarte_int_disable(uarte, NRF_UARTE_INT_ENDRX_MASK); } } #endif @@ -1986,21 +2158,114 @@ static int uarte_nrfx_pm_action(const struct device *dev, } wait_for_tx_stopped(dev); - uart_disable(dev); + } - ret = pins_state_change(dev, false); - if (ret < 0) { - return ret; - } + nrf_uarte_disable(uarte); - break; - default: + (void)pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_SLEEP); +} + +static int uarte_nrfx_pm_action(const struct device *dev, enum pm_device_action action) +{ + if (action == PM_DEVICE_ACTION_RESUME) { + uarte_pm_resume(dev); + } else if (IS_ENABLED(CONFIG_PM_DEVICE) && (action == PM_DEVICE_ACTION_SUSPEND)) { + uarte_pm_suspend(dev); + } else { return -ENOTSUP; } return 0; } -#endif /* CONFIG_PM_DEVICE */ + +static int uarte_tx_path_init(const struct device *dev) +{ + NRF_UARTE_Type *uarte = get_uarte_instance(dev); + const struct uarte_nrfx_config *cfg = dev->config; + bool auto_endtx = false; + +#ifdef UARTE_HAS_ENDTX_STOPTX_SHORT + nrf_uarte_shorts_enable(uarte, NRF_UARTE_SHORT_ENDTX_STOPTX); + auto_endtx = true; +#elif defined(UARTE_ENHANCED_POLL_OUT) + if (cfg->flags & UARTE_CFG_FLAG_PPI_ENDTX) { + struct uarte_nrfx_data *data = dev->data; + int err; + + err = endtx_stoptx_ppi_init(uarte, data); + if (err < 0) { + return err; + } + auto_endtx = true; + } +#endif + + /* Get to the point where TXSTOPPED event is set but TXSTOPPED interrupt is + * disabled. This trick is later on used to handle TX path and determine + * using HW if TX is active (TXSTOPPED event set means TX is inactive). + * + * Set TXSTOPPED event by requesting fake (zero-length) transfer. + * Pointer to RAM variable is set because otherwise such operation may + * result in HardFault or RAM corruption. + */ + nrf_uarte_enable(uarte); + nrf_uarte_tx_buffer_set(uarte, cfg->poll_out_byte, 0); + nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STARTTX); + if (!auto_endtx) { + while (!nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ENDTX)) { + } + nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDTX); + nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STOPTX); + nrf_uarte_int_enable(uarte, NRF_UARTE_INT_ENDTX_MASK); + } + while (!nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED)) { + } + nrf_uarte_disable(uarte); + + return 0; +} + +static int uarte_instance_init(const struct device *dev, + uint8_t interrupts_active) +{ + int err; + const struct uarte_nrfx_config *cfg = dev->config; + + if (IS_ENABLED(CONFIG_ARCH_POSIX)) { + /* For simulation the DT provided peripheral address needs to be corrected */ + ((struct pinctrl_dev_config *)cfg->pcfg)->reg = (uintptr_t)cfg->uarte_regs; + } + +#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE + err = uarte_nrfx_configure(dev, &((struct uarte_nrfx_data *)dev->data)->uart_config); + if (err) { + return err; + } +#else + NRF_UARTE_Type *uarte = get_uarte_instance(dev); + + nrf_uarte_baudrate_set(uarte, cfg->nrf_baudrate); + nrf_uarte_configure(uarte, &cfg->hw_config); +#endif + +#ifdef UARTE_ANY_ASYNC + struct uarte_nrfx_data *data = dev->data; + + if (data->async) { + err = uarte_async_init(dev); + if (err < 0) { + return err; + } + } +#endif + + err = uarte_tx_path_init(dev); + if (err) { + return err; + } + + return pm_device_driver_init(dev, uarte_nrfx_pm_action); +} #define UARTE_IRQ_CONFIGURE(idx, isr_handler) \ do { \ @@ -2012,11 +2277,12 @@ static int uarte_nrfx_pm_action(const struct device *dev, /* Low power mode is used when disable_rx is not defined or in async mode if * kconfig option is enabled. */ -#define USE_LOW_POWER(idx) \ - ((!UARTE_PROP(idx, disable_rx) && \ - COND_CODE_1(CONFIG_UART_##idx##_ASYNC, \ - (!IS_ENABLED(CONFIG_UART_##idx##_NRF_ASYNC_LOW_POWER)), \ - (1))) ? 0 : UARTE_CFG_FLAG_LOW_POWER) +#define USE_LOW_POWER(idx) \ + COND_CODE_1(CONFIG_PM_DEVICE, (0), \ + (((!UARTE_PROP(idx, disable_rx) && \ + COND_CODE_1(CONFIG_UART_##idx##_ASYNC, \ + (!IS_ENABLED(CONFIG_UART_##idx##_NRF_ASYNC_LOW_POWER)),\ + (1))) ? 0 : UARTE_CFG_FLAG_LOW_POWER))) #define UARTE_DISABLE_RX_INIT(node_id) \ .disable_rx = DT_PROP(node_id, disable_rx) @@ -2027,12 +2293,13 @@ static int uarte_nrfx_pm_action(const struct device *dev, COND_CODE_1(DT_CLOCKS_HAS_IDX(UARTE(idx), 0), \ ((UARTE_GET_FREQ(idx) / NRF_UARTE_BASE_FREQUENCY_16MHZ)), (1)) -/* When calculating baudrate we need to take into account that some instances - * must have baudrate adjusted to the ratio between UARTE clocking frequency and 16 MHz. +/* When calculating baudrate we need to take into account that high speed instances + * must have baudrate adjust to the ratio between UARTE clocking frequency and 16 MHz. */ #define UARTE_GET_BAUDRATE(idx) \ (NRF_BAUDRATE(UARTE_PROP(idx, current_speed)) / UARTE_GET_BAUDRATE_DIV(idx)) + /* Macro for setting nRF specific configuration structures. */ #define UARTE_NRF_CONFIG(idx) { \ .hwfc = (UARTE_PROP(idx, hw_flow_control) == \ @@ -2043,6 +2310,8 @@ static int uarte_nrfx_pm_action(const struct device *dev, IF_ENABLED(UARTE_HAS_STOP_CONFIG, (.stop = NRF_UARTE_STOP_ONE,))\ IF_ENABLED(UARTE_ODD_PARITY_ALLOWED, \ (.paritytype = NRF_UARTE_PARITYTYPE_EVEN,)) \ + IF_ENABLED(UARTE_HAS_FRAME_TIMEOUT, \ + (.frame_timeout = NRF_UARTE_FRAME_TIMEOUT_EN,)) \ } /* Macro for setting zephyr specific configuration structures. */ @@ -2065,13 +2334,13 @@ static int uarte_nrfx_pm_action(const struct device *dev, IF_ENABLED(CONFIG_UART_##idx##_ASYNC, ( \ static uint8_t \ uarte##idx##_tx_cache[CONFIG_UART_ASYNC_TX_CACHE_SIZE] \ - UARTE_MEMORY_SECTION(idx); \ + DMM_MEMORY_SECTION(UARTE(idx)); \ + static uint8_t uarte##idx##_flush_buf[UARTE_HW_RX_FIFO_SIZE] \ + DMM_MEMORY_SECTION(UARTE(idx)); \ struct uarte_async_cb uarte##idx##_async;)) \ - static uint8_t uarte##idx##_char_out UARTE_MEMORY_SECTION(idx); \ - static uint8_t uarte##idx##_rx_data UARTE_MEMORY_SECTION(idx); \ + static uint8_t uarte##idx##_poll_out_byte DMM_MEMORY_SECTION(UARTE(idx));\ + static uint8_t uarte##idx##_poll_in_byte DMM_MEMORY_SECTION(UARTE(idx)); \ static struct uarte_nrfx_data uarte_##idx##_data = { \ - .char_out = &uarte##idx##_char_out, \ - .rx_data = &uarte##idx##_rx_data, \ IF_ENABLED(CONFIG_UART_USE_RUNTIME_CONFIGURE, \ (.uart_config = UARTE_CONFIG(idx),)) \ IF_ENABLED(CONFIG_UART_##idx##_ASYNC, \ @@ -2083,28 +2352,35 @@ static int uarte_nrfx_pm_action(const struct device *dev, (BUILD_ASSERT(NRF_BAUDRATE(UARTE_PROP(idx, current_speed)) > 0,\ "Unsupported baudrate");)) \ static const struct uarte_nrfx_config uarte_##idx##z_config = { \ - COND_CODE_1(CONFIG_UART_USE_RUNTIME_CONFIGURE, (), \ - (.baudrate = UARTE_GET_BAUDRATE(idx), \ + COND_CODE_1(CONFIG_UART_USE_RUNTIME_CONFIGURE, \ + (IF_ENABLED(DT_CLOCKS_HAS_IDX(UARTE(idx), 0), \ + (.clock_freq = UARTE_GET_FREQ(idx),))), \ + (IF_ENABLED(UARTE_HAS_FRAME_TIMEOUT, \ + (.baudrate = UARTE_PROP(idx, current_speed),)) \ + .nrf_baudrate = UARTE_GET_BAUDRATE(idx), \ .hw_config = UARTE_NRF_CONFIG(idx),)) \ .pcfg = PINCTRL_DT_DEV_CONFIG_GET(UARTE(idx)), \ .uarte_regs = _CONCAT(NRF_UARTE, idx), \ + IF_ENABLED(CONFIG_HAS_NORDIC_DMM, \ + (.mem_reg = DMM_DEV_TO_REG(UARTE(idx)),)) \ .flags = \ - (IS_ENABLED(CONFIG_UART_##idx##_GPIO_MANAGEMENT) ? \ - UARTE_CFG_FLAG_GPIO_MGMT : 0) | \ (IS_ENABLED(CONFIG_UART_##idx##_ENHANCED_POLL_OUT) ? \ UARTE_CFG_FLAG_PPI_ENDTX : 0) | \ (IS_ENABLED(CONFIG_UART_##idx##_NRF_HW_ASYNC) ? \ UARTE_CFG_FLAG_HW_BYTE_COUNTING : 0) | \ + (!IS_ENABLED(CONFIG_HAS_NORDIC_DMM) ? 0 : \ + (UARTE_IS_CACHEABLE(idx) ? \ + UARTE_CFG_FLAG_CACHEABLE : 0)) | \ USE_LOW_POWER(idx), \ UARTE_DISABLE_RX_INIT(UARTE(idx)), \ + .poll_out_byte = &uarte##idx##_poll_out_byte, \ + .poll_in_byte = &uarte##idx##_poll_in_byte, \ IF_ENABLED(CONFIG_UART_##idx##_ASYNC, \ - (.tx_cache = uarte##idx##_tx_cache,)) \ + (.tx_cache = uarte##idx##_tx_cache, \ + .rx_flush_buf = uarte##idx##_flush_buf,)) \ IF_ENABLED(CONFIG_UART_##idx##_NRF_HW_ASYNC, \ (.timer = NRFX_TIMER_INSTANCE( \ CONFIG_UART_##idx##_NRF_HW_ASYNC_TIMER),)) \ - IF_ENABLED(DT_CLOCKS_HAS_IDX(UARTE(idx), 0), \ - (.clock_freq = DT_PROP(DT_CLOCKS_CTLR(UARTE(idx)), \ - clock_frequency),)) \ }; \ static int uarte_##idx##_init(const struct device *dev) \ { \ @@ -2116,7 +2392,8 @@ static int uarte_nrfx_pm_action(const struct device *dev, IS_ENABLED(CONFIG_UART_##idx##_INTERRUPT_DRIVEN)); \ } \ \ - PM_DEVICE_DT_DEFINE(UARTE(idx), uarte_nrfx_pm_action); \ + PM_DEVICE_DT_DEFINE(UARTE(idx), uarte_nrfx_pm_action, \ + PM_DEVICE_ISR_SAFE); \ \ DEVICE_DT_DEFINE(UARTE(idx), \ uarte_##idx##_init, \ @@ -2132,19 +2409,13 @@ static int uarte_nrfx_pm_action(const struct device *dev, (static uint8_t uarte##idx##_tx_buffer \ [MIN(CONFIG_UART_##idx##_NRF_TX_BUFFER_SIZE, \ BIT_MASK(UARTE##idx##_EASYDMA_MAXCNT_SIZE))] \ - UARTE_MEMORY_SECTION(idx); \ + DMM_MEMORY_SECTION(UARTE(idx)); \ static struct uarte_nrfx_int_driven \ uarte##idx##_int_driven = { \ .tx_buffer = uarte##idx##_tx_buffer, \ .tx_buff_size = sizeof(uarte##idx##_tx_buffer),\ };)) -#define UARTE_MEMORY_SECTION(idx) \ - COND_CODE_1(UARTE_HAS_PROP(idx, memory_regions), \ - (__attribute__((__section__(LINKER_DT_NODE_REGION_NAME( \ - DT_PHANDLE(UARTE(idx), memory_regions)))))), \ - ()) - #define COND_UART_NRF_UARTE_DEVICE(unused, prefix, i, _) \ IF_ENABLED(CONFIG_HAS_HW_NRF_UARTE##prefix##i, (UART_NRF_UARTE_DEVICE(prefix##i);)) diff --git a/drivers/serial/uart_nrfx_uarte2.c b/drivers/serial/uart_nrfx_uarte2.c index 594f5a79b554..ae25334f03fe 100644 --- a/drivers/serial/uart_nrfx_uarte2.c +++ b/drivers/serial/uart_nrfx_uarte2.c @@ -141,14 +141,11 @@ struct uarte_nrfx_data { }; BUILD_ASSERT(offsetof(struct uarte_nrfx_data, a2i_data) == 0); -/* If set then pins are managed when going to low power mode. */ -#define UARTE_CFG_FLAG_GPIO_MGMT BIT(0) - /* If set then receiver is not used. */ -#define UARTE_CFG_FLAG_NO_RX BIT(1) +#define UARTE_CFG_FLAG_NO_RX BIT(0) /* If set then instance is using interrupt driven API. */ -#define UARTE_CFG_FLAG_INTERRUPT_DRIVEN_API BIT(2) +#define UARTE_CFG_FLAG_INTERRUPT_DRIVEN_API BIT(1) /** * @brief Structure for UARTE configuration. @@ -917,11 +914,9 @@ static int uarte_nrfx_pm_action(const struct device *dev, switch (action) { case PM_DEVICE_ACTION_RESUME: - if (cfg->flags & UARTE_CFG_FLAG_GPIO_MGMT) { - ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); - if (ret < 0) { - return ret; - } + ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); + if (ret < 0) { + return ret; } if (!IS_ASYNC_API(dev) && !(cfg->flags & UARTE_CFG_FLAG_NO_RX)) { return start_rx(dev); @@ -933,11 +928,9 @@ static int uarte_nrfx_pm_action(const struct device *dev, stop_rx(dev); } - if (cfg->flags & UARTE_CFG_FLAG_GPIO_MGMT) { - ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_SLEEP); - if (ret < 0) { - return ret; - } + ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_SLEEP); + if (ret < 0) { + return ret; } break; @@ -1032,8 +1025,6 @@ static int uarte_nrfx_pm_action(const struct device *dev, }, \ .pcfg = PINCTRL_DT_DEV_CONFIG_GET(UARTE(idx)), \ .flags = (UARTE_PROP(idx, disable_rx) ? UARTE_CFG_FLAG_NO_RX : 0) | \ - (IS_ENABLED(CONFIG_UART_##idx##_GPIO_MANAGEMENT) ? \ - UARTE_CFG_FLAG_GPIO_MGMT : 0) | \ (IS_ENABLED(CONFIG_UART_##idx##_INTERRUPT_DRIVEN) ? \ UARTE_CFG_FLAG_INTERRUPT_DRIVEN_API : 0), \ LOG_INSTANCE_PTR_INIT(log, LOG_MODULE_NAME, idx) \ diff --git a/drivers/spi/spi_smartbond.c b/drivers/spi/spi_smartbond.c index 324273bc12e3..7a2be279e986 100644 --- a/drivers/spi/spi_smartbond.c +++ b/drivers/spi/spi_smartbond.c @@ -1227,11 +1227,11 @@ static int spi_smartbond_isr_connect(const struct device *dev) switch ((uint32_t)cfg->regs) { case (uint32_t)SPI: - COND_CODE_1(DT_NODE_HAS_STATUS(DT_NODELABEL(spi), okay), + COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(spi)), (SPI_SMARTBOND_ISR_CONNECT), (NULL)); break; case (uint32_t)SPI2: - COND_CODE_1(DT_NODE_HAS_STATUS(DT_NODELABEL(spi2), okay), + COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(spi2)), (SPI2_SMARTBOND_ISR_CONNECT), (NULL)); break; default: diff --git a/drivers/spi/spi_xec_qmspi.c b/drivers/spi/spi_xec_qmspi.c index f606f3145c37..02cd34d259f9 100644 --- a/drivers/spi/spi_xec_qmspi.c +++ b/drivers/spi/spi_xec_qmspi.c @@ -681,7 +681,7 @@ static const struct spi_driver_api spi_qmspi_driver_api = { DT_INST_PROP(0, dldh), \ DT_INST_PROP(0, dcsda)) -#if DT_NODE_HAS_STATUS(DT_INST(0, microchip_xec_qmspi), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_INST(0, microchip_xec_qmspi)) PINCTRL_DT_INST_DEFINE(0); @@ -708,4 +708,4 @@ DEVICE_DT_INST_DEFINE(0, &spi_qmspi_0_config, POST_KERNEL, CONFIG_SPI_INIT_PRIORITY, &spi_qmspi_driver_api); -#endif /* DT_NODE_HAS_STATUS(DT_INST(0, microchip_xec_qmspi), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_INST(0, microchip_xec_qmspi)) */ diff --git a/drivers/timer/mcux_os_timer.c b/drivers/timer/mcux_os_timer.c index 74580e684b02..c6eb776e43ab 100644 --- a/drivers/timer/mcux_os_timer.c +++ b/drivers/timer/mcux_os_timer.c @@ -36,7 +36,7 @@ static OSTIMER_Type *base; * certain deep sleep modes and the time elapsed when it is powered off. */ static uint64_t cyc_sys_compensated; -#if DT_NODE_HAS_STATUS(DT_NODELABEL(standby), okay) && CONFIG_PM +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(standby)) && CONFIG_PM static const struct device *counter_dev; #endif @@ -71,7 +71,7 @@ void mcux_lpc_ostick_isr(const void *arg) sys_clock_announce(IS_ENABLED(CONFIG_TICKLESS_KERNEL) ? dticks : 1); } -#if DT_NODE_HAS_STATUS(DT_NODELABEL(standby), okay) && CONFIG_PM +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(standby)) && CONFIG_PM /* The OS Timer is disabled in certain low power modes and cannot wakeup the system * on timeout. This function will be called by the low power code to allow the @@ -178,7 +178,7 @@ void sys_clock_set_timeout(int32_t ticks, bool idle) return; } -#if DT_NODE_HAS_STATUS(DT_NODELABEL(standby), okay) && CONFIG_PM +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(standby)) && CONFIG_PM if (idle) { /* OS Timer may not be able to wakeup in certain low power modes. * For these cases, we start a counter that can wakeup @@ -247,7 +247,7 @@ uint64_t sys_clock_cycle_get_64(void) void sys_clock_idle_exit(void) { -#if DT_NODE_HAS_STATUS(DT_NODELABEL(standby), okay) && CONFIG_PM +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(standby)) && CONFIG_PM /* The tick should be compensated for states where the * OS Timer is disabled */ @@ -280,7 +280,7 @@ static int sys_clock_driver_init(void) irq_enable(DT_INST_IRQN(0)); /* On some SoC's, OS Timer cannot wakeup from low power mode in standby modes */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(standby), okay) && CONFIG_PM +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(standby)) && CONFIG_PM counter_dev = DEVICE_DT_GET_OR_NULL(DT_INST_PHANDLE(0, deep_sleep_counter)); #endif diff --git a/drivers/timer/nrf_grtc_timer.c b/drivers/timer/nrf_grtc_timer.c index 07d58e402c97..ee3f35e09d0c 100644 --- a/drivers/timer/nrf_grtc_timer.c +++ b/drivers/timer/nrf_grtc_timer.c @@ -426,8 +426,12 @@ int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us) nrfy_grtc_timeout_get(NRF_GRTC) * CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / 32768 + MAX_CC_LATCH_WAIT_TIME_US; k_busy_wait(wait_time); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lfxo), okay) && NRF_GRTC_HAS_CLKSEL +#if NRF_GRTC_HAS_CLKSEL +#if defined(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC) + nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFLPRC); +#elif DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lfxo)) nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFXO); +#endif #endif k_spin_unlock(&lock, key); return 0; @@ -501,11 +505,15 @@ static int sys_clock_driver_init(void) z_nrf_clock_control_lf_on(mode); #endif -#if defined(CONFIG_NRF_GRTC_TIMER_CLOCK_MANAGEMENT) && \ - DT_NODE_HAS_STATUS(DT_NODELABEL(lfxo), okay) && NRF_GRTC_HAS_CLKSEL +#if defined(CONFIG_NRF_GRTC_TIMER_CLOCK_MANAGEMENT) && NRF_GRTC_HAS_CLKSEL +#if defined(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC) + /* Switch to LFPRC as the low-frequency clock source. */ + nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFLPRC); +#elif DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lfxo)) /* Switch to LFXO as the low-frequency clock source. */ nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFXO); #endif +#endif #if defined(CONFIG_NRF_GRTC_ALWAYS_ON) nrfx_grtc_active_request_set(true); diff --git a/drivers/timer/smartbond_timer.c b/drivers/timer/smartbond_timer.c index ceef22ce5fa2..afa86617e0e5 100644 --- a/drivers/timer/smartbond_timer.c +++ b/drivers/timer/smartbond_timer.c @@ -199,7 +199,7 @@ static int sys_clock_driver_init(void) uint8_t pdc_idx; uint8_t en_xtal; - en_xtal = DT_NODE_HAS_STATUS(DT_NODELABEL(xtal32m), okay) ? MCU_PDC_EN_XTAL : 0; + en_xtal = DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(xtal32m)) ? MCU_PDC_EN_XTAL : 0; /* Enable wakeup by TIMER2 */ pdc_idx = da1469x_pdc_add(MCU_PDC_TRIGGER_TIMER2, MCU_PDC_MASTER_M33, en_xtal); diff --git a/drivers/usb/device/usb_dc_mcux.c b/drivers/usb/device/usb_dc_mcux.c index b28499db1d6f..14a8918d1067 100644 --- a/drivers/usb/device/usb_dc_mcux.c +++ b/drivers/usb/device/usb_dc_mcux.c @@ -84,17 +84,17 @@ BUILD_ASSERT(NUM_INSTS <= 1, "Only one USB device supported"); #elif defined(CONFIG_SOC_LPC55S36) #define CONTROLLER_ID kUSB_ControllerLpcIp3511Fs0 #elif defined(CONFIG_SOC_LPC55S69_CPU0) || defined(CONFIG_SOC_LPC55S69_CPU1) -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usbhs), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usbhs)) #define CONTROLLER_ID kUSB_ControllerLpcIp3511Hs0 -#elif DT_NODE_HAS_STATUS(DT_NODELABEL(usbfs), okay) +#elif DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usbfs)) #define CONTROLLER_ID kUSB_ControllerLpcIp3511Fs0 #endif /* LPC55s69 */ #elif defined(CONFIG_SOC_SERIES_IMXRT11XX) || \ defined(CONFIG_SOC_SERIES_IMXRT10XX) || \ defined(CONFIG_SOC_SERIES_MCXN) -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usb1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usb1)) #define CONTROLLER_ID kUSB_ControllerEhci0 -#elif DT_NODE_HAS_STATUS(DT_NODELABEL(usb2), okay) +#elif DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usb2)) #define CONTROLLER_ID kUSB_ControllerEhci1 #endif /* IMX RT */ #elif defined(CONFIG_SOC_SERIES_RW6XX) diff --git a/drivers/usb/device/usb_dc_nrfx.c b/drivers/usb/device/usb_dc_nrfx.c index a165c24f7891..c8442cb8f649 100644 --- a/drivers/usb/device/usb_dc_nrfx.c +++ b/drivers/usb/device/usb_dc_nrfx.c @@ -1900,8 +1900,8 @@ static int usb_init(void) == NRF5X_REG_MODE_DCDC), #if NRFX_POWER_SUPPORTS_DCDCEN_VDDH .dcdcenhv = COND_CODE_1(CONFIG_SOC_SERIES_NRF52X, - (DT_NODE_HAS_STATUS(DT_INST(0, nordic_nrf52x_regulator_hv), okay)), - (DT_NODE_HAS_STATUS(DT_INST(0, nordic_nrf53x_regulator_hv), okay))), + (DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nordic_nrf52x_regulator_hv))), + (DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nordic_nrf53x_regulator_hv)))), #endif }; diff --git a/drivers/usb/udc/udc_nrf.c b/drivers/usb/udc/udc_nrf.c index c6951074c854..c024d2a6a184 100644 --- a/drivers/usb/udc/udc_nrf.c +++ b/drivers/usb/udc/udc_nrf.c @@ -824,8 +824,8 @@ static const struct udc_nrf_config udc_nrf_cfg = { == NRF5X_REG_MODE_DCDC), #if NRFX_POWER_SUPPORTS_DCDCEN_VDDH .dcdcenhv = COND_CODE_1(CONFIG_SOC_SERIES_NRF52X, - (DT_NODE_HAS_STATUS(DT_INST(0, nordic_nrf52x_regulator_hv), okay)), - (DT_NODE_HAS_STATUS(DT_INST(0, nordic_nrf53x_regulator_hv), okay))), + (DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nordic_nrf52x_regulator_hv))), + (DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nordic_nrf53x_regulator_hv)))), #endif }, diff --git a/drivers/watchdog/wdt_esp32.c b/drivers/watchdog/wdt_esp32.c index 8fe4c877fd0a..1c7ee61ee64c 100644 --- a/drivers/watchdog/wdt_esp32.c +++ b/drivers/watchdog/wdt_esp32.c @@ -226,10 +226,10 @@ static void wdt_esp32_isr(void *arg) } -#if DT_NODE_HAS_STATUS(DT_NODELABEL(wdt0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(wdt0)) ESP32_WDT_INIT(0); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(wdt1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(wdt1)) ESP32_WDT_INIT(1); #endif diff --git a/drivers/wifi/nrfwifi/CMakeLists.txt b/drivers/wifi/nrfwifi/CMakeLists.txt index e8eba37ca01a..57fcfc8b31db 100644 --- a/drivers/wifi/nrfwifi/CMakeLists.txt +++ b/drivers/wifi/nrfwifi/CMakeLists.txt @@ -29,10 +29,15 @@ zephyr_include_directories_ifdef(CONFIG_NRF70_RADIO_TEST ${OS_AGNOSTIC_BASE}/fw_if/umac_if/inc/radio_test ) -zephyr_include_directories_ifndef(CONFIG_NRF70_RADIO_TEST - ${OS_AGNOSTIC_BASE}/fw_if/umac_if/inc/default +zephyr_include_directories_ifdef(CONFIG_NRF70_OFFLOADED_RAW_TX + ${OS_AGNOSTIC_BASE}/fw_if/umac_if/inc/offload_raw_tx + off_raw_tx/inc ) +if(NOT CONFIG_NRF70_RADIO_TEST AND NOT CONFIG_NRF70_OFFLOADED_RAW_TX) + zephyr_include_directories(${OS_AGNOSTIC_BASE}/fw_if/umac_if/inc/default) +endif() + zephyr_library_sources_ifdef(CONFIG_NRF70_SR_COEX src/coex.c ) @@ -57,23 +62,28 @@ zephyr_library_sources( src/shim.c src/work.c src/timer.c - src/fmac_main.c src/qspi/src/device.c src/qspi/src/rpu_hw_if.c src/qspi/src/ficr_prog.c ) +zephyr_library_sources_ifndef(CONFIG_NRF70_OFFLOADED_RAW_TX + src/fmac_main.c +) + zephyr_library_sources_ifdef(CONFIG_NRF_WIFI_PATCHES_BUILTIN src/fw_load.c ) -zephyr_library_sources_ifndef(CONFIG_NRF70_RADIO_TEST +if(NOT CONFIG_NRF70_RADIO_TEST AND NOT CONFIG_NRF70_OFFLOADED_RAW_TX) + zephyr_library_sources( ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/rx.c ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/fmac_vif.c ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/fmac_util.c src/net_if.c ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/default/fmac_api.c ) +endif() zephyr_library_sources_ifdef(CONFIG_NET_L2_WIFI_MGMT src/wifi_mgmt_scan.c @@ -88,6 +98,12 @@ zephyr_library_sources_ifdef(CONFIG_NRF70_RADIO_TEST ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/fmac_util.c ) +zephyr_library_sources_ifdef(CONFIG_NRF70_OFFLOADED_RAW_TX + ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/offload_raw_tx/fmac_api.c + ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/fmac_util.c + off_raw_tx/src/off_raw_tx_api.c +) + zephyr_library_sources_ifdef(CONFIG_NRF70_DATA_TX ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/tx.c ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/fmac_peer.c @@ -112,6 +128,10 @@ zephyr_library_sources_ifdef(CONFIG_NRF70_STA_MODE ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/fmac_util.c ) +zephyr_library_sources_ifdef(CONFIG_NRF70_PROMISC_DATA_RX + ${OS_AGNOSTIC_BASE}/fw_if/umac_if/src/fmac_promisc.c +) + zephyr_library_sources_ifdef(CONFIG_NRF70_ON_QSPI src/qspi/src/qspi_if.c ) @@ -152,6 +172,8 @@ elseif(CONFIG_NRF_WIFI_PATCHES_BUILTIN) set(NRF70_PATCH ${FW_BINS_BASE}/scan_only/nrf70.bin) elseif (CONFIG_NRF70_SYSTEM_WITH_RAW_MODES) set(NRF70_PATCH ${FW_BINS_BASE}/system_with_raw/nrf70.bin) + elseif(CONFIG_NRF70_OFFLOADED_RAW_TX) + set(NRF70_PATCH ${FW_BINS_BASE}/offloaded_raw_tx/nrf70.bin) else() # Error message(FATAL_ERROR "Unsupported nRF70 patch configuration") @@ -231,6 +253,10 @@ zephyr_compile_definitions_ifdef(CONFIG_NRF70_RADIO_TEST -DNRF70_RADIO_TEST ) +zephyr_compile_definitions_ifdef(CONFIG_NRF70_OFFLOADED_RAW_TX + -DNRF70_OFFLOADED_RAW_TX +) + zephyr_compile_definitions_ifdef(CONFIG_NRF70_TCP_IP_CHECKSUM_OFFLOAD -DNRF70_TCP_IP_CHECKSUM_OFFLOAD ) @@ -263,13 +289,36 @@ zephyr_compile_definitions_ifdef(CONFIG_NRF70_AP_MODE -DNRF70_AP_MODE ) +zephyr_compile_definitions_ifdef(CONFIG_NRF_WIFI_MGMT_BUFF_OFFLOAD + -DNRF_WIFI_MGMT_BUFF_OFFLOAD +) + +zephyr_compile_definitions_ifdef(CONFIG_NRF_WIFI_FEAT_KEEPALIVE + -DNRF_WIFI_FEAT_KEEPALIVE +) + +zephyr_compile_definitions_ifdef(CONFIG_NRF_WIFI_FEAT_KEEPALIVE + -DNRF_WIFI_KEEPALIVE_PERIOD_S=${CONFIG_NRF_WIFI_KEEPALIVE_PERIOD_S} +) + +zephyr_compile_definitions_ifdef(CONFIG_NRF70_OFFLOADED_RAW_TX + -DNRF_NRF70_OFFLOADED_RAW_TX +) + +zephyr_compile_definitions_ifdef(CONFIG_NRF70_PASSIVE_SCAN_ONLY + -DNRF70_PASSIVE_SCAN_ONLY +) + +zephyr_compile_definitions_ifdef(CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS + -DWIFI_MGMT_RAW_SCAN_RESULTS +) + zephyr_compile_definitions( -DNRF70_RX_NUM_BUFS=${CONFIG_NRF70_RX_NUM_BUFS} -DNRF70_MAX_TX_TOKENS=${CONFIG_NRF70_MAX_TX_TOKENS} -DNRF70_RX_MAX_DATA_SIZE=${CONFIG_NRF70_RX_MAX_DATA_SIZE} -DNRF70_MAX_TX_PENDING_QLEN=${CONFIG_NRF70_MAX_TX_PENDING_QLEN} -DNRF70_RPU_PS_IDLE_TIMEOUT_MS=${CONFIG_NRF70_RPU_PS_IDLE_TIMEOUT_MS} - -DNRF70_REG_DOMAIN=${CONFIG_NRF70_REG_DOMAIN} -DNRF70_BAND_2G_LOWER_EDGE_BACKOFF_DSSS=${CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_DSSS} -DNRF70_BAND_2G_LOWER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HT} -DNRF70_BAND_2G_LOWER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HE} @@ -304,4 +353,6 @@ zephyr_compile_definitions( -DNRF70_ANT_GAIN_5G_BAND1=${CONFIG_NRF70_ANT_GAIN_5G_BAND1} -DNRF70_ANT_GAIN_5G_BAND2=${CONFIG_NRF70_ANT_GAIN_5G_BAND2} -DNRF70_ANT_GAIN_5G_BAND3=${CONFIG_NRF70_ANT_GAIN_5G_BAND3} + -DNRF_WIFI_PS_INT_PS=${CONFIG_NRF_WIFI_PS_INT_PS} + -DNRF_WIFI_RPU_RECOVERY_PS_ACTIVE_TIMEOUT_MS=${CONFIG_NRF_WIFI_RPU_RECOVERY_PS_ACTIVE_TIMEOUT_MS} ) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index bccb48b8576e..7087e20beb66 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -62,13 +62,15 @@ config NRF70_SYSTEM_MODE config NRF70_SCAN_ONLY bool "nRF70 scan only mode" - depends on WIFI_NRF7000 help Select this option to enable scan only mode of the nRF70 driver config NRF70_RADIO_TEST bool "Radio test mode of the nRF70 driver" +config NRF70_OFFLOADED_RAW_TX + bool "Offloaded raw Tx mode of the nRF70 driver" + config NRF70_SYSTEM_WITH_RAW_MODES bool "nRF70 system mode with raw modes" depends on WIFI_NRF7002 || WIFI_NRF7001 @@ -83,7 +85,7 @@ config NRF70_SYSTEM_MODE_COMMON default y if NRF70_SYSTEM_MODE || NRF70_SYSTEM_WITH_RAW_MODES config NET_L2_ETHERNET - default y if !NRF70_RADIO_TEST + default y if (!NRF70_RADIO_TEST && !NRF70_OFFLOADED_RAW_TX) config HEAP_MEM_POOL_ADD_SIZE_NRF70 # Use a maximum that works for typical usecases and boards, each sample/app can override @@ -511,8 +513,8 @@ config WIFI_FIXED_MAC_ADDRESS choice prompt "Wi-Fi MAC address type" - default WIFI_OTP_MAC_ADDRESS if WIFI_FIXED_MAC_ADDRESS = "" default WIFI_FIXED_MAC_ADDRESS_ENABLED if WIFI_FIXED_MAC_ADDRESS != "" + default WIFI_OTP_MAC_ADDRESS help Select the type of MAC address to be used by the Wi-Fi driver @@ -567,6 +569,12 @@ config NET_TC_TX_COUNT endif # NETWORKING +# nRF70 now uses variable buffers as default to optimize RAM usage. Default pool sizes are used, samples/apps can override +# for higher performance. +choice NET_PKT_DATA_ALLOC_TYPE + default NET_BUF_VARIABLE_DATA_SIZE +endchoice + config MAIN_STACK_SIZE default 4096 @@ -652,6 +660,8 @@ config NRF_WIFI_AP_DEAD_DETECT_TIMEOUT config NRF_WIFI_RPU_RECOVERY bool "RPU recovery mechanism" + depends on NRF_WIFI_LOW_POWER + default y select EXPERIMENTAL help Enable RPU recovery mechanism to recover from RPU (nRF70) hang. @@ -664,7 +674,7 @@ if NRF_WIFI_RPU_RECOVERY config NRF_WIFI_RPU_RECOVERY_PROPAGATION_DELAY_MS int "RPU recovery propagation delay in milliseconds" - default 10 + default 2000 help Propagation delay in milliseconds to wait after RPU is powered down before powering it up. This delay is required to ensure that the recovery @@ -674,6 +684,66 @@ config NRF_WIFI_RPU_RECOVERY_PROPAGATION_DELAY_MS config NET_MGMT_EVENT_QUEUE_SIZE # Doing interface down and up even with delay puts a lot of events in the queue default 16 + +config NRF_WIFI_RPU_RECOVERY_PROPAGATION_DELAY_MS + int "RPU recovery propagation delay in milliseconds" + default 10 + help + Propagation delay in milliseconds to wait after RPU is powered down + before powering it up. This delay is required to ensure that the recovery + is propagated to all the applications and stack and have enough time to + clean up the resources. + +config NRF_WIFI_RPU_RECOVERY_PS_ACTIVE_TIMEOUT_MS + int "RPU recovery power save active timeout in milliseconds" + default 50000 + help + Power save active timeout in milliseconds after which RPU recovery + mechanism will be triggered. This timeout is used to ensure that the + RPU attempts to enter power save mode in case of inactivity. + +config NRF_WIFI_RPU_MIN_TIME_TO_ENTER_SLEEP_MS + int "Minimum idle time to enter sleep in milliseconds" + range 100 5000 + default 1000 + help + Minimum time the host should de-assert WAKEUP_NOW and let RPU enter + sleep mode, assuming there is no activity. + +config NRF_WIFI_RPU_RECOVERY_DEBUG + bool "RPU recovery debug logs" + help + Enable RPU recovery debug logs to help debug RPU recovery mechanism. + +config NRF_WIFI_RPU_RECOVERY_QUIET_PERIOD_MS + int "RPU recovery quiet period in milliseconds" + default 5000 + help + Quiet period in milliseconds after RPU recovery is triggered. During + this period, no new RPU recovery will be triggered. + +config NRF_WIFI_RPU_RECOVERY_MAX_RETRIES + int "Maximum number of consecutive RPU recovery retries, 0 to disable" + default 0 + help + Maximum number of consecutive RPU recovery retries before giving up + and resetting the system. Set to 0 to keep retrying indefinitely. + +config NRF_WIFI_RPU_RECOVERY_RETRY_WINDOW_S + int "RPU recovery retry window in seconds" + default 900 + help + Window in seconds during which the number of consecutive RPU recovery + retries are counted. If the number of consecutive RPU recovery retries + exceeds NRF_WIFI_RPU_RECOVERY_MAX_RETRIES within this window, the system + will be reset. + +config NRF_WIFI_RPU_RECOVERY_PS_STATE_DEBUG + bool "RPU recovery power save state debug logs" + help + Enable RPU recovery power save state debug logs to help debug RPU recovery mechanism. + + endif # NRF_WIFI_RPU_RECOVERY config NRF_WIFI_FEAT_WMM @@ -705,4 +775,57 @@ config NRF_WIFI_QOS_NULL_BASED_RETRIEVAL endchoice +config NRF_WIFI_MGMT_BUFF_OFFLOAD + bool "management buffer offload" + default y + help + This option offloads the refilling of management buffers to UMAC, saves host + having to exchange commands and events for every management packet even if it is + consumed by UMAC. + +config NRF_WIFI_FEAT_KEEPALIVE + bool "Wi-Fi keepalive feature for connection maintenance" + depends on NRF70_STA_MODE + help + Enable Wi-Fi keepalive feature to keep the connection alive by sending + keepalive packets to the AP. Primarily intended to interoperate with APs + that disconnect idle clients without any explicit checks. Slightly increases + power consumption. + +if NRF_WIFI_FEAT_KEEPALIVE +config NRF_WIFI_KEEPALIVE_PERIOD_S + int "Keepalive period in seconds" + range 30 3600 + default 60 + help + Keepalive period in seconds to send keepalive packets to the AP. +endif + +choice NRF_WIFI_PS_EXIT_STRATEGY + prompt "Power save exit strategy" + default NRF_WIFI_PS_INT_PS + help + Select the power save exit strategy to retrieve buffered data from AP. + +config NRF_WIFI_PS_EXIT_EVERY_TIM + bool "Exit power save every time to retrieve buffered data from AP" + help + Exit power save every time to retrieve buffered data from AP. Entering back to + power save mode might take some time and power. + +config NRF_WIFI_PS_INT_PS + bool "Exit power save based on an intelligent algorithm" + help + Exit power save based on an intelligent algorithm to retrieve buffered data from AP. + The algorithm tracks the buffered data at the AP and then dynamically decides + whether to stay in PS (for lower amount of buffered data) or exit PS (for higher + amount of buffered data). +endchoice + +config NRF70_PASSIVE_SCAN_ONLY + bool "Forced Passive scan" + depends on NRF70_SCAN_ONLY + help + Enable this configuration to force passive scan on all channels. + This will override application specified scan type. endif # WIFI_NRF70 diff --git a/drivers/wifi/nrfwifi/inc/fmac_main.h b/drivers/wifi/nrfwifi/inc/fmac_main.h index 92bc2ac28f84..57d4b8b9df54 100644 --- a/drivers/wifi/nrfwifi/inc/fmac_main.h +++ b/drivers/wifi/nrfwifi/inc/fmac_main.h @@ -34,6 +34,7 @@ #define NRF70_DRIVER_VERSION "1."KERNEL_VERSION_STRING +#ifndef CONFIG_NRF70_OFFLOADED_RAW_TX #ifndef CONFIG_NRF70_RADIO_TEST struct nrf_wifi_vif_ctx_zep { const struct device *zep_dev_ctx; @@ -108,6 +109,11 @@ struct nrf_wifi_ctx_zep { unsigned char *extended_capa, *extended_capa_mask; unsigned int extended_capa_len; struct k_mutex rpu_lock; +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY + bool rpu_recovery_in_progress; + unsigned long last_rpu_recovery_time_ms; + unsigned int rpu_recovery_retries; +#endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */ }; struct nrf_wifi_drv_priv_zep { @@ -119,6 +125,7 @@ struct nrf_wifi_drv_priv_zep { extern struct nrf_wifi_drv_priv_zep rpu_drv_priv_zep; void nrf_wifi_scan_timeout_work(struct k_work *work); + void configure_tx_pwr_settings(struct nrf_wifi_tx_pwr_ctrl_params *tx_pwr_ctrl_params, struct nrf_wifi_tx_pwr_ceil_params *tx_pwr_ceil_params); void configure_board_dep_params(struct nrf_wifi_board_params *board_params); @@ -126,6 +133,13 @@ void set_tx_pwr_ceil_default(struct nrf_wifi_tx_pwr_ceil_params *pwr_ceil_params const char *nrf_wifi_get_drv_version(void); enum nrf_wifi_status nrf_wifi_fmac_dev_add_zep(struct nrf_wifi_drv_priv_zep *drv_priv_zep); enum nrf_wifi_status nrf_wifi_fmac_dev_rem_zep(struct nrf_wifi_drv_priv_zep *drv_priv_zep); +struct nrf_wifi_vif_ctx_zep *nrf_wifi_get_vif_ctx(struct net_if *iface); +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY +void nrf_wifi_rpu_recovery_cb(void *vif_ctx, + void *event_data, + unsigned int event_len); +#endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */ +#endif /* !CONFIG_NRF70_OFFLOADED_RAW_TX */ #ifdef CONFIG_NRF_WIFI_BUILD_ONLY_MODE inline enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx) { @@ -136,9 +150,4 @@ inline enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx) #else enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx); #endif /* CONFIG_NRF_WIFI_BUILD_ONLY_MODE */ -struct nrf_wifi_vif_ctx_zep *nrf_wifi_get_vif_ctx(struct net_if *iface); -void nrf_wifi_rpu_recovery_cb(void *vif_ctx, - void *event_data, - unsigned int event_len); - #endif /* __ZEPHYR_FMAC_MAIN_H__ */ diff --git a/drivers/wifi/nrfwifi/inc/wpa_supp_if.h b/drivers/wifi/nrfwifi/inc/wpa_supp_if.h index 06a13261a706..c543644e3128 100644 --- a/drivers/wifi/nrfwifi/inc/wpa_supp_if.h +++ b/drivers/wifi/nrfwifi/inc/wpa_supp_if.h @@ -123,6 +123,8 @@ int nrf_wifi_supp_get_conn_info(void *if_priv, struct wpa_conn_info *info); void nrf_wifi_supp_event_proc_get_conn_info(void *os_vif_ctx, struct nrf_wifi_umac_event_conn_info *info, unsigned int event_len); +int nrf_wifi_supp_set_country(void *if_priv, const char *alpha2); +int nrf_wifi_supp_get_country(void *if_priv, char *alpha2); #endif /* CONFIG_NRF70_STA_MODE */ #ifdef CONFIG_NRF70_AP_MODE diff --git a/drivers/wifi/nrfwifi/off_raw_tx/inc/off_raw_tx.h b/drivers/wifi/nrfwifi/off_raw_tx/inc/off_raw_tx.h new file mode 100644 index 000000000000..1cb6e2584621 --- /dev/null +++ b/drivers/wifi/nrfwifi/off_raw_tx/inc/off_raw_tx.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @brief File containing internal structures for the offloaded raw TX feature in the driver. + */ + +#include "fmac_structs_common.h" +#include "osal_api.h" + +struct nrf_wifi_ctx_zep { + void *drv_priv_zep; + void *rpu_ctx; + uint8_t mac_addr[6]; +}; + + +struct nrf_wifi_off_raw_tx_drv_priv { + struct nrf_wifi_fmac_priv *fmac_priv; + /* TODO: Replace with a linked list to handle unlimited RPUs */ + struct nrf_wifi_ctx_zep rpu_ctx_zep; + struct k_spinlock lock; +}; + +enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx); diff --git a/drivers/wifi/nrfwifi/off_raw_tx/src/off_raw_tx_api.c b/drivers/wifi/nrfwifi/off_raw_tx/src/off_raw_tx_api.c new file mode 100644 index 000000000000..155c8a5cd5e6 --- /dev/null +++ b/drivers/wifi/nrfwifi/off_raw_tx/src/off_raw_tx_api.c @@ -0,0 +1,482 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @brief File containing API definitions for the Offloaded raw TX feature. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define DT_DRV_COMPAT nordic_wlan +LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL); + +struct nrf_wifi_off_raw_tx_drv_priv off_raw_tx_drv_priv; +extern const struct nrf_wifi_osal_ops nrf_wifi_os_zep_ops; + +static const int valid_data_rates[] = { 1, 2, 55, 11, 6, 9, 12, 18, 24, 36, 48, 54, + 0, 1, 2, 3, 4, 5, 6, 7, -1 }; + +/* DTS uses 1dBm as the unit for TX power, while the RPU uses 0.25dBm */ +#define MAX_TX_PWR(label) DT_PROP(DT_NODELABEL(nrf70), label) * 4 +static void configure_tx_pwr_settings(struct nrf_wifi_tx_pwr_ctrl_params *ctrl_params, + struct nrf_wifi_tx_pwr_ceil_params *ceil_params) +{ + ctrl_params->ant_gain_2g = CONFIG_NRF70_ANT_GAIN_2G; + ctrl_params->ant_gain_5g_band1 = CONFIG_NRF70_ANT_GAIN_5G_BAND1; + ctrl_params->ant_gain_5g_band2 = CONFIG_NRF70_ANT_GAIN_5G_BAND2; + ctrl_params->ant_gain_5g_band3 = CONFIG_NRF70_ANT_GAIN_5G_BAND3; + ctrl_params->band_edge_2g_lo_dss = CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_DSSS; + ctrl_params->band_edge_2g_lo_ht = CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_2g_lo_he = CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_2g_hi_dsss = CONFIG_NRF70_BAND_2G_UPPER_EDGE_BACKOFF_DSSS; + ctrl_params->band_edge_2g_hi_ht = CONFIG_NRF70_BAND_2G_UPPER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_2g_hi_he = CONFIG_NRF70_BAND_2G_UPPER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_1_lo_ht = + CONFIG_NRF70_BAND_UNII_1_LOWER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_1_lo_he = + CONFIG_NRF70_BAND_UNII_1_LOWER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_1_hi_ht = + CONFIG_NRF70_BAND_UNII_1_UPPER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_1_hi_he = + CONFIG_NRF70_BAND_UNII_1_UPPER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_2a_lo_ht = + CONFIG_NRF70_BAND_UNII_2A_LOWER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_2a_lo_he = + CONFIG_NRF70_BAND_UNII_2A_LOWER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_2a_hi_ht = + CONFIG_NRF70_BAND_UNII_2A_UPPER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_2a_hi_he = + CONFIG_NRF70_BAND_UNII_2A_UPPER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_2c_lo_ht = + CONFIG_NRF70_BAND_UNII_2C_LOWER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_2c_lo_he = + CONFIG_NRF70_BAND_UNII_2C_LOWER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_2c_hi_ht = + CONFIG_NRF70_BAND_UNII_2C_UPPER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_2c_hi_he = + CONFIG_NRF70_BAND_UNII_2C_UPPER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_3_lo_ht = + CONFIG_NRF70_BAND_UNII_3_LOWER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_3_lo_he = + CONFIG_NRF70_BAND_UNII_3_LOWER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_3_hi_ht = + CONFIG_NRF70_BAND_UNII_3_UPPER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_3_hi_he = + CONFIG_NRF70_BAND_UNII_3_UPPER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_4_lo_ht = + CONFIG_NRF70_BAND_UNII_4_LOWER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_4_lo_he = + CONFIG_NRF70_BAND_UNII_4_LOWER_EDGE_BACKOFF_HE; + ctrl_params->band_edge_5g_unii_4_hi_ht = + CONFIG_NRF70_BAND_UNII_4_UPPER_EDGE_BACKOFF_HT; + ctrl_params->band_edge_5g_unii_4_hi_he = + CONFIG_NRF70_BAND_UNII_4_UPPER_EDGE_BACKOFF_HE; + ceil_params->max_pwr_2g_dsss = MAX_TX_PWR(wifi_max_tx_pwr_2g_dsss); + ceil_params->max_pwr_2g_mcs7 = MAX_TX_PWR(wifi_max_tx_pwr_2g_mcs7); + ceil_params->max_pwr_2g_mcs0 = MAX_TX_PWR(wifi_max_tx_pwr_2g_mcs0); +#ifndef CONFIG_NRF70_2_4G_ONLY + ceil_params->max_pwr_5g_low_mcs7 = MAX_TX_PWR(wifi_max_tx_pwr_5g_low_mcs7); + ceil_params->max_pwr_5g_mid_mcs7 = MAX_TX_PWR(wifi_max_tx_pwr_5g_mid_mcs7); + ceil_params->max_pwr_5g_high_mcs7 = MAX_TX_PWR(wifi_max_tx_pwr_5g_high_mcs7); + ceil_params->max_pwr_5g_low_mcs0 = MAX_TX_PWR(wifi_max_tx_pwr_5g_low_mcs0); + ceil_params->max_pwr_5g_mid_mcs0 = MAX_TX_PWR(wifi_max_tx_pwr_5g_mid_mcs0); + ceil_params->max_pwr_5g_high_mcs0 = MAX_TX_PWR(wifi_max_tx_pwr_5g_high_mcs0); +#endif /* CONFIG_NRF70_2_4G_ONLY */ +} + +static void configure_board_dep_params(struct nrf_wifi_board_params *board_params) +{ + board_params->pcb_loss_2g = CONFIG_NRF70_PCB_LOSS_2G; +#ifndef CONFIG_NRF70_2_4G_ONLY + board_params->pcb_loss_5g_band1 = CONFIG_NRF70_PCB_LOSS_5G_BAND1; + board_params->pcb_loss_5g_band2 = CONFIG_NRF70_PCB_LOSS_5G_BAND2; + board_params->pcb_loss_5g_band3 = CONFIG_NRF70_PCB_LOSS_5G_BAND3; +#endif /* CONFIG_NRF70_2_4G_ONLY */ +} + +#ifdef CONFIG_WIFI_FIXED_MAC_ADDRESS_ENABLED +static int bytes_from_str(uint8_t *buf, int buf_len, const char *src) +{ + size_t i; + size_t src_len = strlen(src); + char *endptr; + + for (i = 0U; i < src_len; i++) { + if (!isxdigit((unsigned char)src[i]) && + src[i] != ':') { + return -EINVAL; + } + } + + (void)memset(buf, 0, buf_len); + + for (i = 0U; i < (size_t)buf_len; i++) { + buf[i] = (uint8_t)strtol(src, &endptr, 16); + src = ++endptr; + } + + return 0; +} +#endif /* CONFIG_WIFI_FIXED_MAC_ADDRESS_ENABLED */ + +int nrf70_off_raw_tx_init(uint8_t *mac_addr, unsigned char *country_code) +{ + enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; + struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL; + void *rpu_ctx = NULL; + struct nrf_wifi_tx_pwr_ctrl_params ctrl_params; + struct nrf_wifi_tx_pwr_ceil_params ceil_params; + struct nrf_wifi_board_params board_params; + unsigned int fw_ver = 0; + k_spinlock_key_t key; + + /* The OSAL layer needs to be initialized before any other initialization + * so that other layers (like FW IF,HW IF etc) have access to OS ops + */ + nrf_wifi_osal_init(&nrf_wifi_os_zep_ops); + + key = k_spin_lock(&off_raw_tx_drv_priv.lock); + + off_raw_tx_drv_priv.fmac_priv = nrf_wifi_fmac_off_raw_tx_init(); + + if (off_raw_tx_drv_priv.fmac_priv == NULL) { + LOG_ERR("%s: Failed to initialize nRF70 driver", + __func__); + goto err; + } + + rpu_ctx_zep = &off_raw_tx_drv_priv.rpu_ctx_zep; + + rpu_ctx_zep->drv_priv_zep = &off_raw_tx_drv_priv; + + rpu_ctx = nrf_wifi_fmac_dev_add(off_raw_tx_drv_priv.fmac_priv, + rpu_ctx_zep); + if (!rpu_ctx) { + LOG_ERR("%s: Failed to add nRF70 device", __func__); + rpu_ctx_zep = NULL; + goto err; + } + + rpu_ctx_zep->rpu_ctx = rpu_ctx; + + status = nrf_wifi_fw_load(rpu_ctx); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: Failed to load the nRF70 firmware patch", __func__); + goto err; + } + + status = nrf_wifi_fmac_ver_get(rpu_ctx, + &fw_ver); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: Failed to read the nRF70 firmware version", __func__); + goto err; + } + + LOG_DBG("nRF70 firmware (v%d.%d.%d.%d) booted successfully", + NRF_WIFI_UMAC_VER(fw_ver), + NRF_WIFI_UMAC_VER_MAJ(fw_ver), + NRF_WIFI_UMAC_VER_MIN(fw_ver), + NRF_WIFI_UMAC_VER_EXTRA(fw_ver)); + + memset(&ctrl_params, 0, sizeof(ctrl_params)); + memset(&ceil_params, 0, sizeof(ceil_params)); + + configure_tx_pwr_settings(&ctrl_params, + &ceil_params); + + memset(&board_params, 0, sizeof(board_params)); + + configure_board_dep_params(&board_params); + + status = nrf_wifi_fmac_off_raw_tx_dev_init(rpu_ctx_zep->rpu_ctx, +#ifdef CONFIG_NRF_WIFI_LOW_POWER + HW_SLEEP_ENABLE, +#endif /* CONFIG_NRF_WIFI_LOW_POWER */ + NRF_WIFI_DEF_PHY_CALIB, + CONFIG_NRF_WIFI_OP_BAND, + IS_ENABLED(CONFIG_NRF_WIFI_BEAMFORMING), + &ctrl_params, + &ceil_params, + &board_params, + country_code); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: nRF70 firmware initialization failed", __func__); + goto err; + } + + if (mac_addr) { + memcpy(rpu_ctx_zep->mac_addr, mac_addr, 6); + } else { +#ifdef CONFIG_WIFI_FIXED_MAC_ADDRESS_ENABLED + int ret = -1; + + ret = bytes_from_str(rpu_ctx_zep->mac_addr, + 6, + CONFIG_WIFI_FIXED_MAC_ADDRESS); + if (ret < 0) { + LOG_ERR("%s: Failed to parse MAC address: %s", + __func__, + CONFIG_WIFI_FIXED_MAC_ADDRESS); + goto err; + } +#elif CONFIG_WIFI_OTP_MAC_ADDRESS + status = nrf_wifi_fmac_otp_mac_addr_get(off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx, + 0, + rpu_ctx_zep->mac_addr); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: Fetching of MAC address from OTP failed", + __func__); + goto err; + } +#endif /* CONFIG_WIFI_FIXED_MAC_ADDRESS_ENABLED */ + + if (!nrf_wifi_utils_is_mac_addr_valid(rpu_ctx_zep->mac_addr)) { + LOG_ERR("%s: Invalid MAC address: %02X:%02X:%02X:%02X:%02X:%02X", + __func__, + rpu_ctx_zep->mac_addr[0], + rpu_ctx_zep->mac_addr[1], + rpu_ctx_zep->mac_addr[2], + rpu_ctx_zep->mac_addr[3], + rpu_ctx_zep->mac_addr[4], + rpu_ctx_zep->mac_addr[5]); + goto err; + } + } + + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); + + return 0; +err: + if (rpu_ctx) { + nrf_wifi_fmac_off_raw_tx_dev_rem(rpu_ctx); + rpu_ctx_zep->rpu_ctx = NULL; + } + + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); + nrf70_off_raw_tx_deinit(); + return -1; +} + + +void nrf70_off_raw_tx_deinit(void) +{ + k_spinlock_key_t key; + + key = k_spin_lock(&off_raw_tx_drv_priv.lock); + + if (!off_raw_tx_drv_priv.fmac_priv) { + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); + return; + } + + nrf_wifi_fmac_off_raw_tx_deinit(off_raw_tx_drv_priv.fmac_priv); + + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); +} + +static bool validate_rate(enum nrf_wifi_off_raw_tx_tput_mode tput_mode, + enum nrf_wifi_off_raw_tx_rate rate) +{ + if (tput_mode == TPUT_MODE_LEGACY) { + if (rate > RATE_54M) { + return false; + } + } else { + if (rate <= RATE_54M) { + return false; + } + } + + return true; +} + +int nrf70_off_raw_tx_conf_update(struct nrf_wifi_off_raw_tx_conf *conf) +{ + int ret = -1; + enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; + struct nrf_wifi_offload_ctrl_params *off_ctrl_params = NULL; + struct nrf_wifi_offload_tx_ctrl *off_tx_params = NULL; + struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL; + k_spinlock_key_t key; + + if (!conf) { + LOG_ERR("%s: Config params is NULL", __func__); + goto out; + } + + off_ctrl_params = nrf_wifi_osal_mem_zalloc(sizeof(*off_ctrl_params)); + if (!off_ctrl_params) { + LOG_ERR("%s: Failed to allocate memory for off_ctrl_params", __func__); + goto out; + } + + key = k_spin_lock(&off_raw_tx_drv_priv.lock); + + fmac_dev_ctx = off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx; + + if (!fmac_dev_ctx) { + LOG_ERR("%s: FMAC device context is NULL", __func__); + goto out; + } + + off_tx_params = nrf_wifi_osal_mem_zalloc(sizeof(*off_tx_params)); + if (!off_tx_params) { + LOG_ERR("%s Failed to allocate memory for off_tx_params: ", __func__); + goto out; + } + + if (!validate_rate(conf->tput_mode, conf->rate)) { + LOG_ERR("%s Invalid rate. Throughput mode: %d, rate: %d\n", __func__, + conf->tput_mode, conf->rate); + goto out; + } + + off_ctrl_params->channel_no = conf->chan; + off_ctrl_params->period_in_us = conf->period_us; + off_ctrl_params->tx_pwr = conf->tx_pwr; + off_tx_params->he_gi_type = conf->he_gi; + off_tx_params->he_ltf = conf->he_ltf; + off_tx_params->pkt_ram_ptr = RPU_MEM_PKT_BASE; + off_tx_params->pkt_length = conf->pkt_len; + off_tx_params->rate_flags = conf->tput_mode; + off_tx_params->rate = valid_data_rates[conf->rate]; + off_tx_params->rate_preamble_type = conf->short_preamble; + off_tx_params->rate_retries = conf->num_retries; + + status = hal_rpu_mem_write(fmac_dev_ctx->hal_dev_ctx, + RPU_MEM_PKT_BASE, + conf->pkt, + conf->pkt_len); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: hal_rpu_mem_write failed", __func__); + goto out; + } + + status = nrf_wifi_fmac_off_raw_tx_conf(fmac_dev_ctx, + off_ctrl_params, + off_tx_params); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: nRF70 offloaded raw TX configuration failed", + __func__); + goto out; + } + + ret = 0; +out: + nrf_wifi_osal_mem_free(off_ctrl_params); + nrf_wifi_osal_mem_free(off_tx_params); + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); + return ret; +} + + +int nrf70_off_raw_tx_start(struct nrf_wifi_off_raw_tx_conf *conf) +{ + int ret = -1; + enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; + k_spinlock_key_t key; + + status = nrf70_off_raw_tx_conf_update(conf); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: nRF70 offloaded raw TX configuration failed", + __func__); + goto out; + } + + key = k_spin_lock(&off_raw_tx_drv_priv.lock); + if (!off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx) { + LOG_ERR("%s: FMAC device context is NULL", __func__); + goto out; + } + + status = nrf_wifi_fmac_off_raw_tx_start(off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: nRF70 offloaded raw TX start failed", + __func__); + goto out; + } + + ret = 0; +out: + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); + return ret; +} + + +int nrf70_off_raw_tx_stop(void) +{ + int ret = -1; + enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; + k_spinlock_key_t key; + + key = k_spin_lock(&off_raw_tx_drv_priv.lock); + + if (!off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx) { + LOG_ERR("%s: FMAC device context is NULL", __func__); + goto out; + } + + status = nrf_wifi_fmac_off_raw_tx_stop(off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: nRF70 offloaded raw TX stop failed", + __func__); + goto out; + } + + ret = 0; +out: + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); + return ret; +} + + +int nrf70_off_raw_tx_mac_addr_get(uint8_t *mac_addr) +{ + if (!mac_addr) { + LOG_ERR("%s: Invalid param", __func__); + return -EINVAL; + } + + memcpy(mac_addr, off_raw_tx_drv_priv.rpu_ctx_zep.mac_addr, 6); + return 0; +} + +int nrf70_off_raw_tx_stats(struct nrf_wifi_off_raw_tx_stats *off_raw_tx_stats) +{ + int ret = -1; + enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; + struct rpu_op_stats stats; + k_spinlock_key_t key; + + memset(&stats, 0, sizeof(struct rpu_op_stats)); + + key = k_spin_lock(&off_raw_tx_drv_priv.lock); + + if (!off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx) { + LOG_ERR("%s: FMAC device context is NULL", __func__); + goto out; + } + + status = nrf_wifi_fmac_stats_get(off_raw_tx_drv_priv.rpu_ctx_zep.rpu_ctx, 0, &stats); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: nRF70 offloaded raw TX stats failed", + __func__); + goto out; + } + + off_raw_tx_stats->off_raw_tx_pkt_sent = stats.fw.offloaded_raw_tx.offload_raw_tx_cnt; + + ret = 0; +out: + k_spin_unlock(&off_raw_tx_drv_priv.lock, key); + return ret; +} diff --git a/drivers/wifi/nrfwifi/src/fmac_main.c b/drivers/wifi/nrfwifi/src/fmac_main.c index 5c0e4f336e62..470be6c80557 100644 --- a/drivers/wifi/nrfwifi/src/fmac_main.c +++ b/drivers/wifi/nrfwifi/src/fmac_main.c @@ -252,7 +252,7 @@ static void nrf_wifi_process_rssi_from_rx(void *vif_ctx, rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep; - if (!rpu_ctx_zep) { + if (!(rpu_ctx_zep && rpu_ctx_zep->rpu_ctx)) { LOG_ERR("%s: rpu_ctx_zep is NULL", __func__); return; } @@ -320,51 +320,31 @@ int nrf_wifi_reg_domain(const struct device *dev, struct wifi_reg_domain *reg_do k_mutex_lock(®_lock, K_FOREVER); if (!dev || !reg_domain) { - goto err; + goto out; } vif_ctx_zep = dev->data; if (!vif_ctx_zep) { LOG_ERR("%s: vif_ctx_zep is NULL", __func__); - goto err; + goto out; } rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep; if (!rpu_ctx_zep) { LOG_ERR("%s: rpu_ctx_zep is NULL", __func__); - goto err; + goto out; } fmac_dev_ctx = rpu_ctx_zep->rpu_ctx; if (!fmac_dev_ctx) { LOG_ERR("%s: fmac_dev_ctx is NULL", __func__); - goto err; + goto out; } +#ifdef CONFIG_NRF70_SCAN_ONLY if (reg_domain->oper == WIFI_MGMT_SET) { -#ifndef CONFIG_NRF70_RADIO_TEST -#ifdef CONFIG_NRF70_STA_MODE - /* Need to check if WPA supplicant is initialized or not. - * Must be checked when CONFIG_WIFI_NM_WPA_SUPPLICANT is enabled. - * Not applicable for RADIO_TEST or when - * CONFIG_WIFI_NM_WPA_SUPPLICANT is not enabled. - */ - /* It is possbile that during supplicant initialization driver may - * get the command. lock will try to ensure that supplicant - * initialization is complete. - */ - k_mutex_lock(&vif_ctx_zep->vif_lock, K_FOREVER); - if ((!vif_ctx_zep->supp_drv_if_ctx) || - (!wifi_nm_get_instance_iface(vif_ctx_zep->zep_net_if_ctx))) { - LOG_ERR("%s: WPA supplicant initialization not complete yet", __func__); - k_mutex_unlock(&vif_ctx_zep->vif_lock); - goto err; - } - k_mutex_unlock(&vif_ctx_zep->vif_lock); -#endif /* CONFIG_NRF70_STA_MODE */ -#endif /* !CONFIG_NRF70_RADIO_TEST */ memcpy(reg_domain_info.alpha2, reg_domain->country_code, WIFI_COUNTRY_CODE_LEN); reg_domain_info.force = reg_domain->force; @@ -372,40 +352,43 @@ int nrf_wifi_reg_domain(const struct device *dev, struct wifi_reg_domain *reg_do status = nrf_wifi_fmac_set_reg(fmac_dev_ctx, ®_domain_info); if (status != NRF_WIFI_STATUS_SUCCESS) { LOG_ERR("%s: Failed to set regulatory domain", __func__); - goto err; + goto out; } - } else if (reg_domain->oper == WIFI_MGMT_GET) { - if (!reg_domain->chan_info) { - LOG_ERR("%s: Invalid regulatory info (NULL)\n", __func__); - goto err; - } + goto out; + } +#endif + if (reg_domain->oper != WIFI_MGMT_GET) { + LOG_ERR("%s: Invalid operation: %d", __func__, reg_domain->oper); + goto out; + } - status = nrf_wifi_fmac_get_reg(fmac_dev_ctx, ®_domain_info); - if (status != NRF_WIFI_STATUS_SUCCESS) { - LOG_ERR("%s: Failed to get regulatory domain", __func__); - goto err; - } + if (!reg_domain->chan_info) { + LOG_ERR("%s: Invalid regulatory info (NULL)\n", __func__); + goto out; + } - memcpy(reg_domain->country_code, reg_domain_info.alpha2, WIFI_COUNTRY_CODE_LEN); - reg_domain->num_channels = reg_domain_info.reg_chan_count; - - for (chan_idx = 0; chan_idx < reg_domain_info.reg_chan_count; chan_idx++) { - chan_info = &(reg_domain->chan_info[chan_idx]); - reg_domain_chan_info = &(reg_domain_info.reg_chan_info[chan_idx]); - chan_info->center_frequency = reg_domain_chan_info->center_frequency; - chan_info->dfs = !!reg_domain_chan_info->dfs; - chan_info->max_power = reg_domain_chan_info->max_power; - chan_info->passive_only = !!reg_domain_chan_info->passive_channel; - chan_info->supported = !!reg_domain_chan_info->supported; - } - } else { - LOG_ERR("%s: Invalid operation: %d", __func__, reg_domain->oper); - goto err; + status = nrf_wifi_fmac_get_reg(fmac_dev_ctx, ®_domain_info); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: Failed to get regulatory domain", __func__); + goto out; + } + + memcpy(reg_domain->country_code, reg_domain_info.alpha2, WIFI_COUNTRY_CODE_LEN); + reg_domain->num_channels = reg_domain_info.reg_chan_count; + + for (chan_idx = 0; chan_idx < reg_domain_info.reg_chan_count; chan_idx++) { + chan_info = &(reg_domain->chan_info[chan_idx]); + reg_domain_chan_info = &(reg_domain_info.reg_chan_info[chan_idx]); + chan_info->center_frequency = reg_domain_chan_info->center_frequency; + chan_info->dfs = !!reg_domain_chan_info->dfs; + chan_info->max_power = reg_domain_chan_info->max_power; + chan_info->passive_only = !!reg_domain_chan_info->passive_channel; + chan_info->supported = !!reg_domain_chan_info->supported; } ret = 0; -err: +out: k_mutex_unlock(®_lock); return ret; } @@ -453,6 +436,8 @@ void reg_change_callbk_fn(void *vif_ctx, struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL; struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL; + LOG_DBG("%s: Regulatory change event received", __func__); + vif_ctx_zep = vif_ctx; if (!vif_ctx_zep) { @@ -472,6 +457,12 @@ void reg_change_callbk_fn(void *vif_ctx, return; } + if (!fmac_dev_ctx->waiting_for_reg_event) { + LOG_DBG("%s: Unsolicited regulatory change event", __func__); + /* TODO: Handle unsolicited regulatory change event */ + return; + } + fmac_dev_ctx->reg_change = k_malloc(sizeof(struct nrf_wifi_event_regulatory_change)); if (!fmac_dev_ctx->reg_change) { LOG_ERR("%s: Failed to allocate memory for reg_change", __func__); @@ -636,7 +627,8 @@ enum nrf_wifi_status nrf_wifi_fmac_dev_add_zep(struct nrf_wifi_drv_priv_zep *drv IS_ENABLED(CONFIG_NRF_WIFI_BEAMFORMING), &tx_pwr_ctrl_params, &tx_pwr_ceil_params, - &board_params); + &board_params, + STRINGIFY(CONFIG_NRF70_REG_DOMAIN)); #else status = nrf_wifi_fmac_dev_init(rpu_ctx_zep->rpu_ctx, #ifdef CONFIG_NRF_WIFI_LOW_POWER @@ -647,7 +639,8 @@ enum nrf_wifi_status nrf_wifi_fmac_dev_add_zep(struct nrf_wifi_drv_priv_zep *drv IS_ENABLED(CONFIG_NRF_WIFI_BEAMFORMING), &tx_pwr_ctrl_params, &tx_pwr_ceil_params, - &board_params); + &board_params, + STRINGIFY(CONFIG_NRF70_REG_DOMAIN)); #endif /* CONFIG_NRF70_RADIO_TEST */ @@ -656,8 +649,6 @@ enum nrf_wifi_status nrf_wifi_fmac_dev_add_zep(struct nrf_wifi_drv_priv_zep *drv goto err; } - k_mutex_init(&rpu_ctx_zep->rpu_lock); - return status; err: if (rpu_ctx) { @@ -717,7 +708,7 @@ static int nrf_wifi_drv_main_zep(const struct device *dev) callbk_fns.if_carr_state_chg_callbk_fn = nrf_wifi_if_carr_state_chg; callbk_fns.rx_frm_callbk_fn = nrf_wifi_if_rx_frm; #if defined(CONFIG_NRF70_RAW_DATA_RX) || defined(CONFIG_NRF70_PROMISC_DATA_RX) - callbk_fns.rx_sniffer_frm_callbk_fn = nrf_wifi_if_sniffer_rx_frm; + callbk_fns.sniffer_callbk_fn = nrf_wifi_if_sniffer_rx_frm; #endif /* CONFIG_NRF70_RAW_DATA_RX || CONFIG_NRF70_PROMISC_DATA_RX */ #endif rx_buf_pools[0].num_bufs = rx1_num_bufs; @@ -816,6 +807,7 @@ static int nrf_wifi_drv_main_zep(const struct device *dev) nrf_wifi_scan_timeout_work); #endif /* CONFIG_NRF70_RADIO_TEST */ + k_mutex_init(&rpu_drv_priv_zep.rpu_ctx_zep.rpu_lock); return 0; #ifdef CONFIG_NRF70_RADIO_TEST fmac_deinit: @@ -841,7 +833,7 @@ static struct wifi_mgmt_ops nrf_wifi_mgmt_ops = { .get_power_save_config = nrf_wifi_get_power_save_config, .set_rts_threshold = nrf_wifi_set_rts_threshold, .get_rts_threshold = nrf_wifi_get_rts_threshold, -#endif /* CONFIG_NRF70_STA_MODE */ +#endif #ifdef CONFIG_NRF70_SYSTEM_WITH_RAW_MODES .mode = nrf_wifi_mode, #endif @@ -874,6 +866,8 @@ static struct zep_wpa_supp_dev_ops wpa_supp_ops = { .register_frame = nrf_wifi_supp_register_frame, .get_capa = nrf_wifi_supp_get_capa, .get_conn_info = nrf_wifi_supp_get_conn_info, + .set_country = nrf_wifi_supp_set_country, + .get_country = nrf_wifi_supp_get_country, #ifdef CONFIG_NRF70_AP_MODE .init_ap = nrf_wifi_wpa_supp_init_ap, .start_ap = nrf_wifi_wpa_supp_start_ap, diff --git a/drivers/wifi/nrfwifi/src/net_if.c b/drivers/wifi/nrfwifi/src/net_if.c index 4d4125e8c8ae..19b232b6fe34 100644 --- a/drivers/wifi/nrfwifi/src/net_if.c +++ b/drivers/wifi/nrfwifi/src/net_if.c @@ -18,6 +18,8 @@ #include LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL); +#include + #include "net_private.h" #include "util.h" @@ -71,6 +73,7 @@ static void nrf_wifi_rpu_recovery_work_handler(struct k_work *work) struct nrf_wifi_vif_ctx_zep, nrf_wifi_rpu_recovery_work); struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL; + int ret; if (!vif_ctx_zep) { LOG_ERR("%s: vif_ctx_zep is NULL", __func__); @@ -88,14 +91,79 @@ static void nrf_wifi_rpu_recovery_work_handler(struct k_work *work) return; } + if (rpu_ctx_zep->rpu_recovery_in_progress) { +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG + LOG_ERR("%s: RPU recovery already in progress", __func__); +#else + LOG_DBG("%s: RPU recovery already in progress", __func__); +#endif + return; + } + + if (rpu_ctx_zep->last_rpu_recovery_time_ms && + ((k_uptime_get() - rpu_ctx_zep->last_rpu_recovery_time_ms) < + CONFIG_NRF_WIFI_RPU_RECOVERY_QUIET_PERIOD_MS)) { +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG + LOG_ERR("%s: In quiet period (last_rpu_recovery_time_ms=%ld), ignoring", + __func__, rpu_ctx_zep->last_rpu_recovery_time_ms); +#else + LOG_DBG("%s: In quiet period (last_rpu_recovery_time_ms=%ld), ignoring", + __func__, rpu_ctx_zep->last_rpu_recovery_time_ms); +#endif + return; + } + +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG + LOG_ERR("%s: Starting RPU recovery", __func__); +#else + LOG_DBG("%s: Starting RPU recovery", __func__); +#endif k_mutex_lock(&rpu_ctx_zep->rpu_lock, K_FOREVER); +#if CONFIG_NRF_WIFI_RPU_RECOVERY_MAX_RETRIES > 0 + if (!rpu_ctx_zep->last_rpu_recovery_time_ms || + (k_uptime_get() - rpu_ctx_zep->last_rpu_recovery_time_ms) < + CONFIG_NRF_WIFI_RPU_RECOVERY_RETRY_WINDOW_S * MSEC_PER_SEC) { + if (rpu_ctx_zep->rpu_recovery_retries >= + CONFIG_NRF_WIFI_RPU_RECOVERY_MAX_RETRIES) { + LOG_ERR("%s: Maximum recovery retries reached, rebooting system", + __func__); + sys_reboot(SYS_REBOOT_COLD); + } + rpu_ctx_zep->rpu_recovery_retries++; + } else { + rpu_ctx_zep->rpu_recovery_retries = 0; + } +#endif + rpu_ctx_zep->rpu_recovery_in_progress = true; +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG + LOG_ERR("%s: Bringing the interface down", __func__); +#else LOG_DBG("%s: Bringing the interface down", __func__); +#endif /* This indirectly does a cold-boot of RPU */ - net_if_down(vif_ctx_zep->zep_net_if_ctx); + ret = net_if_down(vif_ctx_zep->zep_net_if_ctx); + if (ret) { + LOG_ERR("%s: net_if_down failed: %d", __func__, ret); + /* Continue with the recovery */ + } k_msleep(CONFIG_NRF_WIFI_RPU_RECOVERY_PROPAGATION_DELAY_MS); +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG + LOG_ERR("%s: Bringing the interface up", __func__); +#else LOG_DBG("%s: Bringing the interface up", __func__); - net_if_up(vif_ctx_zep->zep_net_if_ctx); +#endif + ret = net_if_up(vif_ctx_zep->zep_net_if_ctx); + if (ret) { + LOG_ERR("%s: net_if_up failed: %d", __func__, ret); + } + rpu_ctx_zep->rpu_recovery_in_progress = false; + rpu_ctx_zep->last_rpu_recovery_time_ms = k_uptime_get(); k_mutex_unlock(&rpu_ctx_zep->rpu_lock); +#ifdef CONFIG_NRF_WIFI_RPU_RECOVERY_DEBUG + LOG_ERR("%s: RPU recovery done", __func__); +#else + LOG_DBG("%s: RPU recovery done", __func__); +#endif } void nrf_wifi_rpu_recovery_cb(void *vif_ctx_handle, @@ -321,7 +389,7 @@ int nrf_wifi_if_send(const struct device *dev, #ifdef CONFIG_NRF70_RAW_DATA_TX if ((*(unsigned int *)pkt->frags->data) == NRF_WIFI_MAGIC_NUM_RAWTX) { if (vif_ctx_zep->if_carr_state != NRF_WIFI_FMAC_IF_CARR_STATE_ON) { - goto unlock; + goto drop; } ret = nrf_wifi_fmac_start_rawpkt_xmit(rpu_ctx_zep->rpu_ctx, @@ -331,7 +399,7 @@ int nrf_wifi_if_send(const struct device *dev, #endif /* CONFIG_NRF70_RAW_DATA_TX */ if ((vif_ctx_zep->if_carr_state != NRF_WIFI_FMAC_IF_CARR_STATE_ON) || (!vif_ctx_zep->authorized && !is_eapol(pkt))) { - goto unlock; + goto drop; } ret = nrf_wifi_fmac_start_xmit(rpu_ctx_zep->rpu_ctx, @@ -340,6 +408,10 @@ int nrf_wifi_if_send(const struct device *dev, #ifdef CONFIG_NRF70_RAW_DATA_TX } #endif /* CONFIG_NRF70_RAW_DATA_TX */ + goto unlock; +drop: + host_stats->total_tx_drop_pkts++; + nrf_wifi_osal_nbuf_free(nbuf); unlock: k_mutex_unlock(&vif_ctx_zep->vif_lock); #else @@ -372,7 +444,7 @@ static void ip_maddr_event_handler(struct net_if *iface, ret = k_mutex_lock(&vif_ctx_zep->vif_lock, K_FOREVER); if (ret != 0) { LOG_ERR("%s: Failed to lock vif_lock", __func__); - goto out; + return; } rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep; @@ -387,7 +459,7 @@ static void ip_maddr_event_handler(struct net_if *iface, if (!mcast_info) { LOG_ERR("%s: Unable to allocate memory of size %d " "for mcast_info", __func__, sizeof(*mcast_info)); - return; + goto unlock; } switch (addr->family) { @@ -424,9 +496,8 @@ static void ip_maddr_event_handler(struct net_if *iface, sizeof(mac_string_buf))); } unlock: - k_mutex_unlock(&vif_ctx_zep->vif_lock); -out: k_free(mcast_info); + k_mutex_unlock(&vif_ctx_zep->vif_lock); } #endif /* CONFIG_NRF70_STA_MODE */ @@ -802,14 +873,14 @@ int nrf_wifi_if_stop_zep(const struct device *dev) ret = k_mutex_lock(&vif_ctx_zep->vif_lock, K_FOREVER); if (ret != 0) { LOG_ERR("%s: Failed to lock vif_lock", __func__); - goto out; + goto unlock; } rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep; - if (!rpu_ctx_zep) { + if (!rpu_ctx_zep || !rpu_ctx_zep->rpu_ctx) { LOG_ERR("%s: rpu_ctx_zep is NULL", __func__); - goto out; + goto unlock; } #ifdef CONFIG_NRF70_STA_MODE @@ -821,7 +892,6 @@ int nrf_wifi_if_stop_zep(const struct device *dev) if (status != NRF_WIFI_STATUS_SUCCESS) { LOG_ERR("%s: nrf_wifi_fmac_set_power_save failed", __func__); - goto unlock; } #endif /* CONFIG_NRF_WIFI_LOW_POWER */ #endif /* CONFIG_NRF70_STA_MODE */ @@ -840,7 +910,6 @@ int nrf_wifi_if_stop_zep(const struct device *dev) if (status != NRF_WIFI_STATUS_SUCCESS) { LOG_ERR("%s: nrf_wifi_fmac_chg_vif_state failed", __func__); - goto unlock; } status = nrf_wifi_fmac_del_vif(rpu_ctx_zep->rpu_ctx, @@ -849,11 +918,8 @@ int nrf_wifi_if_stop_zep(const struct device *dev) if (status != NRF_WIFI_STATUS_SUCCESS) { LOG_ERR("%s: nrf_wifi_fmac_del_vif failed", __func__); - goto unlock; } - vif_ctx_zep->if_op_state = NRF_WIFI_FMAC_IF_OP_STATE_DOWN; - if (nrf_wifi_fmac_get_num_vifs(rpu_ctx_zep->rpu_ctx) == 0) { nrf_wifi_fmac_dev_rem_zep(&rpu_drv_priv_zep); } @@ -914,10 +980,23 @@ int nrf_wifi_if_get_config_zep(const struct device *dev, goto unlock; } + memset(config, 0, sizeof(struct ethernet_config)); + if (type == ETHERNET_CONFIG_TYPE_TXINJECTION_MODE) { config->txinjection_mode = def_dev_ctx->vif_ctx[vif_ctx_zep->vif_idx]->txinjection_mode; } +#ifdef CONFIG_NRF70_TCP_IP_CHECKSUM_OFFLOAD + if (type == ETHERNET_CONFIG_TYPE_TX_CHECKSUM_SUPPORT || + type == ETHERNET_CONFIG_TYPE_RX_CHECKSUM_SUPPORT) { + config->chksum_support = ETHERNET_CHECKSUM_SUPPORT_IPV4_HEADER | + ETHERNET_CHECKSUM_SUPPORT_IPV4_ICMP | + ETHERNET_CHECKSUM_SUPPORT_IPV6_HEADER | + ETHERNET_CHECKSUM_SUPPORT_IPV6_ICMP | + ETHERNET_CHECKSUM_SUPPORT_TCP | + ETHERNET_CHECKSUM_SUPPORT_UDP; + } +#endif ret = 0; unlock: k_mutex_unlock(&vif_ctx_zep->vif_lock); diff --git a/drivers/wifi/nrfwifi/src/qspi/src/qspi_if.c b/drivers/wifi/nrfwifi/src/qspi/src/qspi_if.c index 26d9249248cb..754fe1497135 100644 --- a/drivers/wifi/nrfwifi/src/qspi/src/qspi_if.c +++ b/drivers/wifi/nrfwifi/src/qspi/src/qspi_if.c @@ -85,7 +85,7 @@ BUILD_ASSERT(QSPI_IF_DEVICE_FREQUENCY >= (NRF_QSPI_BASE_CLOCK_FREQ / 16), * PCLK192M frequency"), but after that operation is complete, the default * divider needs to be restored to avoid increased current consumption. */ -#if (INST_0_SCK_FREQUENCY >= NRF_QSPI_BASE_CLOCK_FREQ) +#if (QSPI_IF_DEVICE_FREQUENCY >= NRF_QSPI_BASE_CLOCK_FREQ) /* For requested SCK >= 96 MHz, use HFCLK192M / 1 / (2*1) = 96 MHz */ #define BASE_CLOCK_DIV NRF_CLOCK_HFCLK_DIV_1 #define INST_0_SCK_CFG NRF_QSPI_FREQ_DIV1 @@ -93,12 +93,12 @@ BUILD_ASSERT(QSPI_IF_DEVICE_FREQUENCY >= (NRF_QSPI_BASE_CLOCK_FREQ / 16), #elif NRF53_ERRATA_159_ENABLE_WORKAROUND #define BASE_CLOCK_DIV NRF_CLOCK_HFCLK_DIV_1 #define INST_0_SCK_CFG (DIV_ROUND_UP(NRF_QSPI_BASE_CLOCK_FREQ, \ - INST_0_SCK_FREQUENCY) - 1) -#elif (INST_0_SCK_FREQUENCY >= (NRF_QSPI_BASE_CLOCK_FREQ / 2)) + QSPI_IF_DEVICE_FREQUENCY) - 1) +#elif (QSPI_IF_DEVICE_FREQUENCY >= (NRF_QSPI_BASE_CLOCK_FREQ / 2)) /* For 96 MHz > SCK >= 48 MHz, use HFCLK192M / 2 / (2*1) = 48 MHz */ #define BASE_CLOCK_DIV NRF_CLOCK_HFCLK_DIV_2 #define INST_0_SCK_CFG NRF_QSPI_FREQ_DIV1 -#elif (INST_0_SCK_FREQUENCY >= (NRF_QSPI_BASE_CLOCK_FREQ / 3)) +#elif (QSPI_IF_DEVICE_FREQUENCY >= (NRF_QSPI_BASE_CLOCK_FREQ / 3)) /* For 48 MHz > SCK >= 32 MHz, use HFCLK192M / 1 / (2*3) = 32 MHz */ #define BASE_CLOCK_DIV NRF_CLOCK_HFCLK_DIV_1 #define INST_0_SCK_CFG NRF_QSPI_FREQ_DIV3 @@ -125,7 +125,10 @@ BUILD_ASSERT(QSPI_IF_DEVICE_FREQUENCY >= (NRF_QSPI_BASE_CLOCK_FREQ / 16), * starts. It was measured with a logic analyzer (unfortunately, the nRF5340 * specification does not provide any numbers in this regard). */ -#define BASE_CLOCK_SWITCH_DELAY_US 7 +/* FIXME: This has adverse impact on performance, ~3Mbps, so, for now, it is + * disabled till further investigation. + */ +#define BASE_CLOCK_SWITCH_DELAY_US 0 #else /* diff --git a/drivers/wifi/nrfwifi/src/qspi/src/rpu_hw_if.c b/drivers/wifi/nrfwifi/src/qspi/src/rpu_hw_if.c index c5f909b4c3a2..6fac74123621 100644 --- a/drivers/wifi/nrfwifi/src/qspi/src/rpu_hw_if.c +++ b/drivers/wifi/nrfwifi/src/qspi/src/rpu_hw_if.c @@ -405,6 +405,31 @@ int rpu_clks_on(void) return 0; } +#define RPU_EXP_SIG 0x42000020 +/* Read a known value from RPU memory to validate RPU communication */ +int rpu_validate_comms(void) +{ + uint32_t rpu_test; + int ret; + + /* UCCP_SOC_FAB_MST_READ_IDLE - HW reset value */ + ret = rpu_read(0x0005C, &rpu_test, 4); + if (ret) { + LOG_ERR("Error: RPU comms test: read failed\n"); + return ret; + } + + if (rpu_test != RPU_EXP_SIG) { + LOG_ERR("Error: RPU comms test: sig failed: expected 0x%x, got 0x%x\n", + RPU_EXP_SIG, rpu_test); + return -1; + } + + LOG_DBG("RPU comms test passed\n"); + + return 0; +} + int rpu_init(void) { int ret; @@ -458,6 +483,11 @@ int rpu_enable(void) goto rpu_pwroff; } + ret = rpu_validate_comms(); + if (ret) { + goto rpu_pwroff; + } + return 0; rpu_pwroff: rpu_pwroff(); diff --git a/drivers/wifi/nrfwifi/src/qspi/src/spi_if.c b/drivers/wifi/nrfwifi/src/qspi/src/spi_if.c index 2cdf3662fd5c..4bf9f4643910 100644 --- a/drivers/wifi/nrfwifi/src/qspi/src/spi_if.c +++ b/drivers/wifi/nrfwifi/src/qspi/src/spi_if.c @@ -58,6 +58,7 @@ static int spim_xfer_rx(unsigned int addr, void *data, unsigned int len, unsigne addr & 0xFF, 0 /* dummy byte */ }; + uint8_t discard[sizeof(hdr) + 2 * 4]; const struct spi_buf tx_buf[] = { {.buf = hdr, .len = sizeof(hdr) }, @@ -67,12 +68,17 @@ static int spim_xfer_rx(unsigned int addr, void *data, unsigned int len, unsigne const struct spi_buf_set tx = { .buffers = tx_buf, .count = 2 }; const struct spi_buf rx_buf[] = { - {.buf = NULL, .len = sizeof(hdr) + discard_bytes}, + {.buf = discard, .len = sizeof(hdr) + discard_bytes}, {.buf = data, .len = len }, }; const struct spi_buf_set rx = { .buffers = rx_buf, .count = 2 }; + if (rx_buf[0].len > sizeof(discard)) { + LOG_ERR("Discard bytes too large, please adjust buf size"); + return -EINVAL; + } + return spi_transceive_dt(&spi_spec, &tx, &rx); } diff --git a/drivers/wifi/nrfwifi/src/shim.c b/drivers/wifi/nrfwifi/src/shim.c index 19660f727e7b..93cafa905c2e 100644 --- a/drivers/wifi/nrfwifi/src/shim.c +++ b/drivers/wifi/nrfwifi/src/shim.c @@ -116,7 +116,7 @@ static void zep_shim_qspi_cpy_to(void *priv, unsigned long addr, const void *src static void *zep_shim_spinlock_alloc(void) { - struct k_sem *lock = NULL; + struct k_mutex *lock = NULL; lock = k_malloc(sizeof(*lock)); @@ -134,27 +134,29 @@ static void zep_shim_spinlock_free(void *lock) static void zep_shim_spinlock_init(void *lock) { - k_sem_init(lock, 1, 1); + k_mutex_init(lock); } static void zep_shim_spinlock_take(void *lock) { - k_sem_take(lock, K_FOREVER); + k_mutex_lock(lock, K_FOREVER); } static void zep_shim_spinlock_rel(void *lock) { - k_sem_give(lock); + k_mutex_unlock(lock); } static void zep_shim_spinlock_irq_take(void *lock, unsigned long *flags) { - k_sem_take(lock, K_FOREVER); + ARG_UNUSED(flags); + k_mutex_lock(lock, K_FOREVER); } static void zep_shim_spinlock_irq_rel(void *lock, unsigned long *flags) { - k_sem_give(lock); + ARG_UNUSED(flags); + k_mutex_unlock(lock); } static int zep_shim_pr_dbg(const char *fmt, va_list args) @@ -235,6 +237,10 @@ static void *zep_shim_nbuf_alloc(unsigned int size) static void zep_shim_nbuf_free(void *nbuf) { + if (!nbuf) { + return; + } + k_free(((struct nwb *)nbuf)->priv); k_free(nbuf); } @@ -618,6 +624,20 @@ static unsigned int zep_shim_time_elapsed_us(unsigned long start_time_us) return curr_time_us - start_time_us; } +static unsigned long zep_shim_time_get_curr_ms(void) +{ + return k_uptime_get(); +} + +static unsigned int zep_shim_time_elapsed_ms(unsigned long start_time_ms) +{ + unsigned long curr_time_ms = 0; + + curr_time_ms = zep_shim_time_get_curr_ms(); + + return curr_time_ms - start_time_ms; +} + static enum nrf_wifi_status zep_shim_bus_qspi_dev_init(void *os_qspi_dev_ctx) { ARG_UNUSED(os_qspi_dev_ctx); @@ -733,6 +753,11 @@ static void irq_work_handler(struct k_work *work) { int ret = 0; + if (!intr_priv || !intr_priv->callbk_fn || !intr_priv->callbk_data) { + LOG_ERR("%s: Invalid intr_priv handler", __func__); + return; + } + ret = intr_priv->callbk_fn(intr_priv->callbk_data); if (ret) { @@ -748,6 +773,11 @@ static void zep_shim_irq_handler(const struct device *dev, struct gpio_callback ARG_UNUSED(cb); ARG_UNUSED(pins); + if (!(intr_priv && intr_priv->callbk_fn && intr_priv->callbk_data)) { + LOG_ERR("%s: Invalid intr_priv", __func__); + return; + } + k_work_schedule_for_queue(&zep_wifi_intr_q, &intr_priv->work, K_NO_WAIT); } @@ -938,6 +968,8 @@ const struct nrf_wifi_osal_ops nrf_wifi_os_zep_ops = { .delay_us = k_usleep, .time_get_curr_us = zep_shim_time_get_curr_us, .time_elapsed_us = zep_shim_time_elapsed_us, + .time_get_curr_ms = zep_shim_time_get_curr_ms, + .time_elapsed_ms = zep_shim_time_elapsed_ms, .bus_qspi_init = zep_shim_bus_qspi_init, .bus_qspi_deinit = zep_shim_bus_qspi_deinit, diff --git a/drivers/wifi/nrfwifi/src/shim.h b/drivers/wifi/nrfwifi/src/shim.h index a4162bf89314..be26fd6355e6 100644 --- a/drivers/wifi/nrfwifi/src/shim.h +++ b/drivers/wifi/nrfwifi/src/shim.h @@ -19,7 +19,6 @@ /** * struct zep_shim_bus_qspi_priv - Structure to hold context information for the Linux OS * shim. - * @opriv: Pointer to OSAL context. * @pcie_callbk_data: Callback data to be passed to the PCIe callback functions. * @pcie_prb_callbk: The callback function to be called when a PCIe device * has been probed. diff --git a/drivers/wifi/nrfwifi/src/wifi_mgmt.c b/drivers/wifi/nrfwifi/src/wifi_mgmt.c index 6232ad245cdc..5effb759fa42 100644 --- a/drivers/wifi/nrfwifi/src/wifi_mgmt.c +++ b/drivers/wifi/nrfwifi/src/wifi_mgmt.c @@ -115,6 +115,24 @@ int nrf_wifi_set_power_save(const struct device *dev, vif_ctx_zep->vif_idx, params->wakeup_mode); break; + case WIFI_PS_PARAM_EXIT_STRATEGY: + unsigned int exit_strategy; + + if (params->exit_strategy == WIFI_PS_EXIT_EVERY_TIM) { + exit_strategy = EVERY_TIM; + } else if (params->exit_strategy == WIFI_PS_EXIT_CUSTOM_ALGO) { + exit_strategy = INT_PS; + } else { + params->fail_reason = + WIFI_PS_PARAM_FAIL_INVALID_EXIT_STRATEGY; + return -EINVAL; + } + + status = nrf_wifi_fmac_set_ps_exit_strategy( + rpu_ctx_zep->rpu_ctx, + vif_ctx_zep->vif_idx, + exit_strategy); + break; default: params->fail_reason = WIFI_PS_PARAM_FAIL_CMD_EXEC_FAIL; @@ -379,6 +397,11 @@ void nrf_wifi_event_proc_get_power_save_info(void *vif_ctx, vif_ctx_zep->ps_info->ps_params.timeout_ms = ps_info->ps_timeout; vif_ctx_zep->ps_info->ps_params.listen_interval = ps_info->listen_interval; vif_ctx_zep->ps_info->ps_params.wakeup_mode = ps_info->extended_ps; + if (ps_info->ps_exit_strategy == EVERY_TIM) { + vif_ctx_zep->ps_info->ps_params.exit_strategy = WIFI_PS_EXIT_EVERY_TIM; + } else if (ps_info->ps_exit_strategy == INT_PS) { + vif_ctx_zep->ps_info->ps_params.exit_strategy = WIFI_PS_EXIT_CUSTOM_ALGO; + } for (int i = 0; i < ps_info->num_twt_flows; i++) { struct twt_interval_float twt_interval_fp; @@ -912,6 +935,21 @@ int nrf_wifi_filter(const struct device *dev, def_dev_ctx = wifi_dev_priv(fmac_dev_ctx); if (filter->oper == WIFI_MGMT_SET) { + /** + * If promiscuous mode is enabled, filter settings + * cannot be plumbed to the lower layers as that might + * affect connectivity. Save the filter settings in the + * driver and filter packet type on packet receive by + * checking the 802.11 header in the packet + */ + if (((def_dev_ctx->vif_ctx[vif_ctx_zep->vif_idx]->mode) & + (NRF_WIFI_PROMISCUOUS_MODE)) == NRF_WIFI_PROMISCUOUS_MODE) { + def_dev_ctx->vif_ctx[vif_ctx_zep->vif_idx]->packet_filter = + filter->filter; + ret = 0; + goto out; + } + /** * In case a user sets data + management + ctrl bits * or all the filter bits. Map it to bit 0 set to diff --git a/drivers/wifi/nrfwifi/src/wifi_mgmt_scan.c b/drivers/wifi/nrfwifi/src/wifi_mgmt_scan.c index c5c6f18804ec..e30f572aeb32 100644 --- a/drivers/wifi/nrfwifi/src/wifi_mgmt_scan.c +++ b/drivers/wifi/nrfwifi/src/wifi_mgmt_scan.c @@ -206,6 +206,10 @@ int nrf_wifi_disp_scan_zep(const struct device *dev, struct wifi_scan_params *pa vif_ctx_zep->scan_res_cnt = 0; +#ifdef CONFIG_NRF70_PASSIVE_SCAN_ONLY + scan_info->scan_params.passive_scan = 1; +#endif /* CONFIG_NRF70_PASSIVE_SCAN_ONLY */ + status = nrf_wifi_fmac_scan(rpu_ctx_zep->rpu_ctx, vif_ctx_zep->vif_idx, scan_info); if (status != NRF_WIFI_STATUS_SUCCESS) { diff --git a/drivers/wifi/nrfwifi/src/wifi_util.c b/drivers/wifi/nrfwifi/src/wifi_util.c index 43c527a4b7d7..528c41fa1843 100644 --- a/drivers/wifi/nrfwifi/src/wifi_util.c +++ b/drivers/wifi/nrfwifi/src/wifi_util.c @@ -273,6 +273,7 @@ static int nrf_wifi_util_tx_stats(const struct shell *sh, void *queue = NULL; unsigned int tx_pending_pkts = 0; struct nrf_wifi_fmac_dev_ctx_def *def_dev_ctx = NULL; + int ret; vif_index = atoi(argv[1]); if ((vif_index < 0) || (vif_index >= max_vif_index)) { @@ -284,6 +285,15 @@ static int nrf_wifi_util_tx_stats(const struct shell *sh, return -ENOEXEC; } + k_mutex_lock(&ctx->rpu_lock, K_FOREVER); + if (!ctx->rpu_ctx) { + shell_fprintf(sh, + SHELL_ERROR, + "RPU context not initialized\n"); + ret = -ENOEXEC; + goto unlock; + } + fmac_dev_ctx = ctx->rpu_ctx; def_dev_ctx = wifi_dev_priv(fmac_dev_ctx); @@ -306,7 +316,11 @@ static int nrf_wifi_util_tx_stats(const struct shell *sh, tx_pending_pkts); } - return 0; + ret = 0; + +unlock: + k_mutex_unlock(&ctx->rpu_lock); + return ret; } #endif /* CONFIG_NRF70_STA_MODE */ @@ -435,7 +449,7 @@ static int nrf_wifi_util_show_vers(const struct shell *sh, return status; } -#ifndef CONFIG_NRF70_RADIO_TEST +#if !defined(CONFIG_NRF70_RADIO_TEST) && !defined(CONFIG_NRF70_OFFLOADED_RAW_TX) static int nrf_wifi_util_dump_rpu_stats(const struct shell *sh, size_t argc, const char *argv[]) @@ -444,6 +458,7 @@ static int nrf_wifi_util_dump_rpu_stats(const struct shell *sh, struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL; struct rpu_op_stats stats; enum rpu_stats_type stats_type = RPU_STATS_TYPE_ALL; + int ret; if (argc == 2) { const char *type = argv[1]; @@ -465,6 +480,14 @@ static int nrf_wifi_util_dump_rpu_stats(const struct shell *sh, } } + k_mutex_lock(&ctx->rpu_lock, K_FOREVER); + if (!ctx->rpu_ctx) { + shell_fprintf(sh, + SHELL_ERROR, + "RPU context not initialized\n"); + ret = -ENOEXEC; + goto unlock; + } fmac_dev_ctx = ctx->rpu_ctx; memset(&stats, 0, sizeof(struct rpu_op_stats)); @@ -474,7 +497,8 @@ static int nrf_wifi_util_dump_rpu_stats(const struct shell *sh, shell_fprintf(sh, SHELL_ERROR, "Failed to get stats\n"); - return -ENOEXEC; + ret = -ENOEXEC; + goto unlock; } if (stats_type == RPU_STATS_TYPE_UMAC || stats_type == RPU_STATS_TYPE_ALL) { @@ -847,9 +871,12 @@ static int nrf_wifi_util_dump_rpu_stats(const struct shell *sh, phy->dsss_crc32_fail_cnt); } - return 0; + ret = 0; +unlock: + k_mutex_unlock(&ctx->rpu_lock); + return ret; } -#endif /* CONFIG_NRF70_RADIO_TEST */ +#endif /* !CONFIG_NRF70_RADIO_TEST && !CONFIG_NRF70_OFFLOADED_RAW_TX */ #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY static int nrf_wifi_util_trigger_rpu_recovery(const struct shell *sh, @@ -858,12 +885,15 @@ static int nrf_wifi_util_trigger_rpu_recovery(const struct shell *sh, { enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL; + int ret; + k_mutex_lock(&ctx->rpu_lock, K_FOREVER); if (!ctx || !ctx->rpu_ctx) { shell_fprintf(sh, SHELL_ERROR, "RPU context not initialized\n"); - return -ENOEXEC; + ret = -ENOEXEC; + goto unlock; } fmac_dev_ctx = ctx->rpu_ctx; @@ -880,7 +910,10 @@ static int nrf_wifi_util_trigger_rpu_recovery(const struct shell *sh, SHELL_INFO, "RPU recovery triggered\n"); - return 0; + ret = 0; +unlock: + k_mutex_unlock(&ctx->rpu_lock); + return ret; } #endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */ @@ -964,7 +997,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE( nrf_wifi_util_show_vers, 1, 0), -#ifndef CONFIG_NRF70_RADIO_TEST +#if !defined(CONFIG_NRF70_RADIO_TEST) && !defined(CONFIG_NRF70_OFFLOADED_RAW_TX) SHELL_CMD_ARG(rpu_stats, NULL, "Display RPU stats " @@ -972,7 +1005,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE( nrf_wifi_util_dump_rpu_stats, 1, 1), -#endif /* CONFIG_NRF70_RADIO_TEST */ +#endif /* !CONFIG_NRF70_RADIO_TEST && !CONFIG_NRF70_OFFLOADED_RAW_TX*/ #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY SHELL_CMD_ARG(rpu_recovery_test, NULL, diff --git a/drivers/wifi/nrfwifi/src/wpa_supp_if.c b/drivers/wifi/nrfwifi/src/wpa_supp_if.c index b022c8d5af19..292c1b9117a6 100644 --- a/drivers/wifi/nrfwifi/src/wpa_supp_if.c +++ b/drivers/wifi/nrfwifi/src/wpa_supp_if.c @@ -1861,6 +1861,79 @@ int nrf_wifi_supp_get_conn_info(void *if_priv, struct wpa_conn_info *info) return ret; } +int nrf_wifi_supp_set_country(void *if_priv, const char *alpha2) +{ + struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL; + struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL; + enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; + struct nrf_wifi_fmac_reg_info reg_domain_info = {0}; + + if (!if_priv || !alpha2) { + LOG_ERR("%s: Invalid params", __func__); + return -1; + } + + vif_ctx_zep = if_priv; + rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep; + if (!rpu_ctx_zep) { + LOG_ERR("%s: rpu_ctx_zep is NULL", __func__); + return -1; + } + + k_mutex_lock(&vif_ctx_zep->vif_lock, K_FOREVER); + if (!rpu_ctx_zep->rpu_ctx) { + LOG_DBG("%s: RPU context not initialized", __func__); + goto out; + } + + memcpy(reg_domain_info.alpha2, alpha2, NRF_WIFI_COUNTRY_CODE_LEN); + + status = nrf_wifi_fmac_set_reg(rpu_ctx_zep->rpu_ctx, ®_domain_info); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: nrf_wifi_fmac_set_reg failed", __func__); + goto out; + } +out: + k_mutex_unlock(&vif_ctx_zep->vif_lock); + return status; +} + +int nrf_wifi_supp_get_country(void *if_priv, char *alpha2) +{ + struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL; + struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL; + enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; + struct nrf_wifi_fmac_reg_info reg_domain_info = {0}; + + if (!if_priv || !alpha2) { + LOG_ERR("%s: Invalid params", __func__); + return -1; + } + + vif_ctx_zep = if_priv; + rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep; + if (!rpu_ctx_zep) { + LOG_ERR("%s: rpu_ctx_zep is NULL", __func__); + return -1; + } + + k_mutex_lock(&vif_ctx_zep->vif_lock, K_FOREVER); + if (!rpu_ctx_zep->rpu_ctx) { + LOG_DBG("%s: RPU context not initialized", __func__); + goto out; + } + + status = nrf_wifi_fmac_get_reg(rpu_ctx_zep->rpu_ctx, ®_domain_info); + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: nrf_wifi_fmac_get_reg failed", __func__); + goto out; + } + + memcpy(alpha2, reg_domain_info.alpha2, NRF_WIFI_COUNTRY_CODE_LEN); +out: + k_mutex_unlock(&vif_ctx_zep->vif_lock); + return status; +} void nrf_wifi_supp_event_proc_get_conn_info(void *if_priv, struct nrf_wifi_umac_event_conn_info *info, diff --git a/dts/arm/nordic/nrf52810.dtsi b/dts/arm/nordic/nrf52810.dtsi index 8758a6354b82..a67d677e7a2a 100644 --- a/dts/arm/nordic/nrf52810.dtsi +++ b/dts/arm/nordic/nrf52810.dtsi @@ -269,7 +269,6 @@ reg = <0x40013000 0x1000>; interrupts = <19 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; - #io-channel-cells = <1>; }; egu0: swi0: egu@40014000 { diff --git a/dts/arm/nordic/nrf52811.dtsi b/dts/arm/nordic/nrf52811.dtsi index b14df8b567a9..41391b7eb3da 100644 --- a/dts/arm/nordic/nrf52811.dtsi +++ b/dts/arm/nordic/nrf52811.dtsi @@ -301,7 +301,6 @@ reg = <0x40013000 0x1000>; interrupts = <19 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; - #io-channel-cells = <1>; }; egu0: swi0: egu@40014000 { diff --git a/dts/arm/nordic/nrf52820.dtsi b/dts/arm/nordic/nrf52820.dtsi index 601a4f8c7ed7..4d05bc741a02 100644 --- a/dts/arm/nordic/nrf52820.dtsi +++ b/dts/arm/nordic/nrf52820.dtsi @@ -313,7 +313,6 @@ reg = <0x40013000 0x1000>; interrupts = <19 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; - #io-channel-cells = <1>; }; egu0: swi0: egu@40014000 { diff --git a/dts/arm/nordic/nrf52832.dtsi b/dts/arm/nordic/nrf52832.dtsi index b722d183da8e..32245608a801 100644 --- a/dts/arm/nordic/nrf52832.dtsi +++ b/dts/arm/nordic/nrf52832.dtsi @@ -310,16 +310,13 @@ comp: comparator@40013000 { /* - * This comparator node can be COMP or LPCOMP, - * for the user to pick: - * compatible = "nordic,nrf-comp" or - * "nordic,nrf-lpcomp". + * Use compatible "nordic,nrf-comp" to configure as COMP + * Use compatible "nordic,nrf-lpcomp" to configure as LPCOMP */ compatible = "nordic,nrf-comp"; reg = <0x40013000 0x1000>; interrupts = <19 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; - #io-channel-cells = <1>; }; egu0: swi0: egu@40014000 { diff --git a/dts/arm/nordic/nrf52833.dtsi b/dts/arm/nordic/nrf52833.dtsi index d81a8953fda7..b576401803a8 100644 --- a/dts/arm/nordic/nrf52833.dtsi +++ b/dts/arm/nordic/nrf52833.dtsi @@ -325,16 +325,13 @@ comp: comparator@40013000 { /* - * This comparator node can be COMP or LPCOMP, - * for the user to pick: - * compatible = "nordic,nrf-comp" or - * "nordic,nrf-lpcomp". + * Use compatible "nordic,nrf-comp" to configure as COMP + * Use compatible "nordic,nrf-lpcomp" to configure as LPCOMP */ compatible = "nordic,nrf-comp"; reg = <0x40013000 0x1000>; interrupts = <19 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; - #io-channel-cells = <1>; }; egu0: swi0: egu@40014000 { diff --git a/dts/arm/nordic/nrf52840.dtsi b/dts/arm/nordic/nrf52840.dtsi index fd7c1aeaa87b..3965c4f3b116 100644 --- a/dts/arm/nordic/nrf52840.dtsi +++ b/dts/arm/nordic/nrf52840.dtsi @@ -312,16 +312,13 @@ comp: comparator@40013000 { /* - * This comparator node can be COMP or LPCOMP, - * for the user to pick: - * compatible = "nordic,nrf-comp" or - * "nordic,nrf-lpcomp". + * Use compatible "nordic,nrf-comp" to configure as COMP + * Use compatible "nordic,nrf-lpcomp" to configure as LPCOMP */ compatible = "nordic,nrf-comp"; reg = <0x40013000 0x1000>; interrupts = <19 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; - #io-channel-cells = <1>; }; egu0: swi0: egu@40014000 { diff --git a/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi b/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi index 7d79b227be24..50842fb38011 100644 --- a/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi +++ b/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi @@ -350,16 +350,13 @@ wdt1: watchdog@19000 { comp: comparator@1a000 { /* - * This comparator node can be COMP or LPCOMP, - * for the user to pick: - * compatible = "nordic,nrf-comp" or - * "nordic,nrf-lpcomp". + * Use compatible "nordic,nrf-comp" to configure as COMP + * Use compatible "nordic,nrf-lpcomp" to configure as LPCOMP */ compatible = "nordic,nrf-comp"; reg = <0x1a000 0x1000>; interrupts = <26 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; - #io-channel-cells = <1>; }; egu0: egu@1b000 { diff --git a/dts/arm/nxp/nxp_ke1xf.dtsi b/dts/arm/nxp/nxp_ke1xf.dtsi index 6aff4315889a..8c880c06dafd 100644 --- a/dts/arm/nxp/nxp_ke1xf.dtsi +++ b/dts/arm/nxp/nxp_ke1xf.dtsi @@ -575,7 +575,6 @@ interrupts = <40 0>; clocks = <&scg KINETIS_SCG_BUS_CLK>; status = "disabled"; - #io-channel-cells = <2>; }; cmp1: cmp@40074000 { @@ -584,7 +583,6 @@ interrupts = <41 0>; clocks = <&scg KINETIS_SCG_BUS_CLK>; status = "disabled"; - #io-channel-cells = <2>; }; cmp2: cmp@40075000 { @@ -593,7 +591,6 @@ interrupts = <70 0>; clocks = <&scg KINETIS_SCG_BUS_CLK>; status = "disabled"; - #io-channel-cells = <2>; }; flexio1: flexio@4005a000 { diff --git a/dts/arm/nxp/nxp_ke1xz.dtsi b/dts/arm/nxp/nxp_ke1xz.dtsi index 577f0e894fe2..8e34d5648457 100644 --- a/dts/arm/nxp/nxp_ke1xz.dtsi +++ b/dts/arm/nxp/nxp_ke1xz.dtsi @@ -419,7 +419,6 @@ interrupts = <16 0>; clocks = <&scg KINETIS_SCG_BUS_CLK>; status = "disabled"; - #io-channel-cells = <2>; }; lpspi0: spi@4002c000 { diff --git a/dts/arm/nxp/nxp_rt118x.dtsi b/dts/arm/nxp/nxp_rt118x.dtsi index b0f7c5e078aa..4bb645e89798 100644 --- a/dts/arm/nxp/nxp_rt118x.dtsi +++ b/dts/arm/nxp/nxp_rt118x.dtsi @@ -299,7 +299,6 @@ reg = <0x2dc0000 0x4000>; interrupts = <200 0>; status = "disabled"; - #io-channel-cells = <2>; }; acmp2: cmp@2dd0000 { @@ -307,7 +306,6 @@ reg = <0x2dd0000 0x4000>; interrupts = <201 0>; status = "disabled"; - #io-channel-cells = <2>; }; acmp3: cmp@2de0000 { @@ -315,7 +313,6 @@ reg = <0x2de0000 0x4000>; interrupts = <202 0>; status = "disabled"; - #io-channel-cells = <2>; }; acmp4: cmp@2df0000 { @@ -323,7 +320,6 @@ reg = <0x2df0000 0x4000>; interrupts = <203 0>; status = "disabled"; - #io-channel-cells = <2>; }; }; diff --git a/dts/arm/nxp/nxp_rt11xx.dtsi b/dts/arm/nxp/nxp_rt11xx.dtsi index 6e3644f58fa0..5dd41ed398b6 100644 --- a/dts/arm/nxp/nxp_rt11xx.dtsi +++ b/dts/arm/nxp/nxp_rt11xx.dtsi @@ -1011,7 +1011,6 @@ reg = <0x401a4000 0x4000>; interrupts = <157 0>; status = "disabled"; - #io-channel-cells = <2>; }; acmp2: cmp@401a8000 { @@ -1019,7 +1018,6 @@ reg = <0x401a8000 0x4000>; interrupts = <158 0>; status = "disabled"; - #io-channel-cells = <2>; }; acmp3: cmp@401ac000 { @@ -1027,7 +1025,6 @@ reg = <0x401ac000 0x4000>; interrupts = <159 0>; status = "disabled"; - #io-channel-cells = <2>; }; acmp4: cmp@401b0000 { @@ -1035,7 +1032,6 @@ reg = <0x401b0000 0x4000>; interrupts = <160 0>; status = "disabled"; - #io-channel-cells = <2>; }; anatop: anatop@40c84000 { diff --git a/dts/bindings/arm/nordic,nrf-uicr-v2.yaml b/dts/bindings/arm/nordic,nrf-uicr-v2.yaml index f509fdf40612..9000cce94c5b 100644 --- a/dts/bindings/arm/nordic,nrf-uicr-v2.yaml +++ b/dts/bindings/arm/nordic,nrf-uicr-v2.yaml @@ -17,10 +17,3 @@ properties: description: | Domain ID of the domain associated with this UICR instance. Must be unique across all UICR instances in the system. - - ptr-ext-uicr: - type: phandle - required: true - description: | - Handle of a memory region reserved to contain an Extended UICR instance. - The address of that node will be stored in the UICR.PTREXTUICR register. diff --git a/dts/bindings/comparator/nordic,nrf-comp.yaml b/dts/bindings/comparator/nordic,nrf-comp.yaml new file mode 100644 index 000000000000..a6f7f32db5fc --- /dev/null +++ b/dts/bindings/comparator/nordic,nrf-comp.yaml @@ -0,0 +1,128 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: | + Nordic nRF COMP (analog COMParator) + + This comparator has varying configurations which require varying + properties be set in the devicetree. + + The following example displays the minimum node layout: + + comp: comp@deadbeef { + compatible = "nordic,nrf-comp"; + reg = <0xdeadbeef 0x1000>; + interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; + }; + + Enabling the comparator node requires setting the default + configuration of the comparator. + + The following example displays enabling the comparator in + single-ended mode, selecting an internal reference: + + &comp { + status = "okay"; + main-mode = "SE"; + psel = "AIN0"; + refsel = "INT_1V2"; + sp-mode = "NORMAL"; + th-up = <36>; + th-down = <30>; + isource = "OFF"; + }; + + To select an external reference, select the "AREF" + reference and add the external reference: + + &comp { + ... + refsel = "AREF"; + extrefsel = "AIN1"; + ... + }; + + The following example displays enabling the comparator + in differential mode: + + &comp { + status = "okay"; + main-mode = "DIFF"; + psel = "AIN0"; + extrefsel = "AIN1"; + sp-mode = "NORMAL"; + hyst = "50MV"; + isource = "OFF"; + }; + +compatible: "nordic,nrf-comp" + +include: base.yaml + +properties: + main-mode: + type: string + enum: + - "SE" + - "DIFF" + + psel: + type: string + enum: + - "AIN0" + - "AIN1" + - "AIN2" + - "AIN3" + - "AIN4" + - "AIN5" + - "AIN6" + - "AIN7" + - "VDD_DIV2" + - "VDDH_DIV5" + + extrefsel: + type: string + enum: + - "AIN0" + - "AIN1" + - "AIN2" + - "AIN3" + - "AIN4" + - "AIN5" + - "AIN6" + - "AIN7" + + refsel: + type: string + enum: + - "INT_1V2" + - "INT_1V8" + - "INT_2V4" + - "AVDDAO1V8" + - "VDD" + - "AREF" + + enable-hyst: + type: boolean + + sp-mode: + type: string + enum: + - "LOW" + - "NORMAL" + - "HIGH" + + th-up: + type: int + + th-down: + type: int + + isource: + type: string + enum: + - "DISABLED" + - "2UA5" + - "5UA" + - "10UA" diff --git a/dts/bindings/comparator/nordic,nrf-lpcomp.yaml b/dts/bindings/comparator/nordic,nrf-lpcomp.yaml new file mode 100644 index 000000000000..8f9cd91a6b79 --- /dev/null +++ b/dts/bindings/comparator/nordic,nrf-lpcomp.yaml @@ -0,0 +1,83 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: | + Nordic nRF LPCOMP (analog Low-Power COMParator) + + The following example displays the minimum node layout: + + comp: comp@deadbeef { + compatible = "nordic,nrf-lpcomp"; + reg = <0xdeadbeef 0x1000>; + interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; + }; + + Enabling the comparator node requires setting the default + configuration of the comparator. + + The following example displays enabling the comparator + using an internal reference: + + &comp { + status = "okay"; + psel = "AIN0"; + refsel = "VDD_4_8"; + hyst = "ENABLED"; + }; + + To select an external reference, select the "AREF" + reference and add the external reference: + + &comp { + ... + refsel = "AREF"; + extrefsel = "AIN1"; + ... + }; + +compatible: "nordic,nrf-lpcomp" + +include: base.yaml + +properties: + psel: + type: string + enum: + - "AIN0" + - "AIN1" + - "AIN2" + - "AIN3" + - "AIN4" + - "AIN5" + - "AIN6" + - "AIN7" + + extrefsel: + type: string + enum: + - "AIN0" + - "AIN1" + + refsel: + type: string + enum: + - "VDD_1_8" + - "VDD_2_8" + - "VDD_3_8" + - "VDD_4_8" + - "VDD_5_8" + - "VDD_6_8" + - "VDD_7_8" + - "VDD_1_16" + - "VDD_3_16" + - "VDD_5_16" + - "VDD_7_16" + - "VDD_9_16" + - "VDD_11_16" + - "VDD_13_16" + - "VDD_15_16" + - "AREF" + + enable-hyst: + type: boolean diff --git a/dts/bindings/comparator/nxp,kinetis-acmp.yaml b/dts/bindings/comparator/nxp,kinetis-acmp.yaml new file mode 100644 index 000000000000..21db936c2bf8 --- /dev/null +++ b/dts/bindings/comparator/nxp,kinetis-acmp.yaml @@ -0,0 +1,227 @@ +# Copyright (c) 2020 Vestas Wind Systems A/S +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: | + NXP Kinetis ACMP (Analog CoMParator) + + The following example displays the minimum node layout: + + acmp0: acmp@deadbeef { + compatible = "nxp,kinetis-acmp"; + reg = <0xdeadbeef 0x1000>; + interrupts = <0 0>; + clocks = <&scg KINETIS_SCG_BUS_CLK>; + status = "disabled"; + }; + + Enabling the comparator node requires setting the minimum default + configuration of the comparator. This includes selecting the + positive and negative inputs, and routing them using pinctrl: + + &pinctrl { + acmp0_default: acmp0_default { + group0 { + ... + }; + }; + }; + + &acmp0 { + status = "okay"; + pinctrl-0 = <&acmp0_default>; + pinctrl-names = "default"; + + positive-mux-input = "IN0"; + negative-mux-input = "IN1"; + }; + +compatible: "nxp,kinetis-acmp" + +include: + - base.yaml + - pinctrl-device.yaml + +properties: + interrupts: + required: true + + reg: + required: true + + nxp,enable-output-pin: + type: boolean + deprecated: true + description: Deprecated. Please use enable-pin-out instead + + nxp,use-unfiltered-output: + type: boolean + deprecated: true + description: Deprecated. Please use use-unfiltered-output instead + + nxp,high-speed-mode: + type: boolean + deprecated: true + description: Deprecated. Please use enable-high-speed-mode instead + + nxp,enable-sample: + type: boolean + deprecated: true + description: Deprecated. Please use filter-enable-sample instead + + nxp,filter-count: + type: int + deprecated: true + description: Deprecated. Please use filter-count instead + + nxp,filter-period: + type: int + deprecated: true + description: Deprecated. Please use filter-period instead + + nxp,window-mode: + type: boolean + deprecated: true + description: Deprecated. Please use enable-window-mode instead + + offset-mode: + type: string + enum: + - "LEVEL0" + - "LEVEL1" + + hysteresis-mode: + type: string + enum: + - "LEVEL0" + - "LEVEL1" + - "LEVEL2" + - "LEVEL3" + + enable-high-speed-mode: + type: boolean + + invert-output: + type: boolean + + use-unfiltered-output: + type: boolean + + enable-pin-out: + type: boolean + + enable-window-mode: + type: boolean + + positive-mux-input: + type: string + enum: + - IN0 + - IN1 + - IN2 + - IN3 + - IN4 + - IN5 + - IN6 + - IN7 + + negative-mux-input: + type: string + enum: + - IN0 + - IN1 + - IN2 + - IN3 + - IN4 + - IN5 + - IN6 + - IN7 + + positive-port-input: + type: string + enum: + - DAC + - MUX + + negative-port-input: + type: string + enum: + - DAC + - MUX + + filter-enable-sample: + type: boolean + + filter-count: + type: int + description: Filter sample count (0 to 7). + + filter-period: + type: int + description: Filter sample period in bus clock cycles (0 to 255). + + dac-vref-source: + type: string + enum: + - "VIN1" + - "VIN2" + + dac-value: + type: int + + dac-enable: + type: boolean + + dac-enable-high-speed: + type: boolean + + discrete-mode-enable-positive-channel: + type: boolean + + discrete-mode-enable-negative-channel: + type: boolean + + discrete-mode-enable-resistor-divider: + type: boolean + + discrete-mode-clock-source: + type: string + enum: + - "SLOW" + - "FAST" + + discrete-mode-sample-time: + type: string + enum: + - "T1" + - "T2" + - "T4" + - "T8" + - "T16" + - "T32" + - "T64" + - "T256" + + discrete-mode-phase1-time: + type: string + enum: + - "ALT0" + - "ALT1" + - "ALT2" + - "ALT3" + - "ALT4" + - "ALT5" + - "ALT6" + - "ALT7" + + discrete-mode-phase2-time: + type: string + enum: + - "ALT0" + - "ALT1" + - "ALT2" + - "ALT3" + - "ALT4" + - "ALT5" + - "ALT6" + - "ALT7" diff --git a/dts/bindings/comparator/zephyr,comp-fake.yaml b/dts/bindings/comparator/zephyr,comp-fake.yaml new file mode 100644 index 000000000000..ac344f4639cb --- /dev/null +++ b/dts/bindings/comparator/zephyr,comp-fake.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: Fake comparator device used as stub or mock for testing + +compatible: "zephyr,fake-comp" + +include: base.yaml diff --git a/dts/bindings/ipc/zephyr,ipc-icmsg.yaml b/dts/bindings/ipc/zephyr,ipc-icmsg.yaml index 417930053734..13a9e2b84b69 100644 --- a/dts/bindings/ipc/zephyr,ipc-icmsg.yaml +++ b/dts/bindings/ipc/zephyr,ipc-icmsg.yaml @@ -32,7 +32,7 @@ properties: For example: Side A: no data cache Side B: 32 Bytes write-back size, 16 Bytes invalidation size - dcache-alignment = 32; for both + dcache-alignment = <32>; for both mboxes: description: phandle to the MBOX controller (TX and RX are required) diff --git a/dts/bindings/sensor/nordic,nrf-comp.yaml b/dts/bindings/sensor/nordic,nrf-comp.yaml deleted file mode 100644 index cc964015ba18..000000000000 --- a/dts/bindings/sensor/nordic,nrf-comp.yaml +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (c) 2022, Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -description: Nordic nRF family COMP (Comparator) - -compatible: "nordic,nrf-comp" - -include: base.yaml - -properties: - reg: - required: true - - interrupts: - required: true - - "#io-channel-cells": - type: int - const: 1 - required: true - -io-channel-cells: - - input diff --git a/dts/bindings/sensor/nordic,nrf-lpcomp.yaml b/dts/bindings/sensor/nordic,nrf-lpcomp.yaml deleted file mode 100644 index 132b0980ac5a..000000000000 --- a/dts/bindings/sensor/nordic,nrf-lpcomp.yaml +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (c) 2022, Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -description: Nordic nRF family LPCOMP (Low-power Comparator) - -compatible: "nordic,nrf-lpcomp" - -include: base.yaml - -properties: - reg: - required: true - - interrupts: - required: true - - "#io-channel-cells": - type: int - const: 1 - required: true - -io-channel-cells: - - input diff --git a/dts/bindings/sensor/nxp,kinetis-acmp.yaml b/dts/bindings/sensor/nxp,kinetis-acmp.yaml deleted file mode 100644 index 9608f9305c9c..000000000000 --- a/dts/bindings/sensor/nxp,kinetis-acmp.yaml +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright (c) 2020 Vestas Wind Systems A/S -# SPDX-License-Identifier: Apache-2.0 - -description: NXP Kinetis Analog Comparator (ACMP) - -compatible: "nxp,kinetis-acmp" - -include: [sensor-device.yaml, pinctrl-device.yaml] - -properties: - interrupts: - required: true - - reg: - required: true - - nxp,enable-output-pin: - type: boolean - description: | - Make the comparator output (CMP0) available on a packaged pin. - - nxp,use-unfiltered-output: - type: boolean - description: | - Use the unfiltered comparator output for CMP0. - - nxp,high-speed-mode: - type: boolean - description: | - Enable high speed comparison mode. - - nxp,enable-sample: - type: boolean - description: | - Enable external sample signal as clock input. - - nxp,filter-count: - type: int - description: | - Filter sample count (0 to 7). - - nxp,filter-period: - type: int - description: | - Filter sample period in bus clock cycles (0 to 255). - - nxp,window-mode: - type: boolean - description: | - Enable windowing mode. - - "#io-channel-cells": - type: int - const: 2 - -io-channel-cells: - - positive - - negative diff --git a/dts/bindings/serial/nordic,nrf-uarte.yaml b/dts/bindings/serial/nordic,nrf-uarte.yaml index c1361d54e1ba..e6ba4c0b2147 100644 --- a/dts/bindings/serial/nordic,nrf-uarte.yaml +++ b/dts/bindings/serial/nordic,nrf-uarte.yaml @@ -9,3 +9,8 @@ properties: type: boolean description: | UARTE has ENDTX_STOPTX HW short. + + frame-timeout-supported: + type: boolean + description: | + UARTE has RX frame timeout HW feature. diff --git a/dts/bindings/wifi/nordic,nrf70-coex.yaml b/dts/bindings/wifi/nordic,nrf70-coex.yaml index 208657f3fb53..0a9c12f587ec 100644 --- a/dts/bindings/wifi/nordic,nrf70-coex.yaml +++ b/dts/bindings/wifi/nordic,nrf70-coex.yaml @@ -27,9 +27,3 @@ properties: description: | GPIO of the SOC controlling the Priority (STATUS1) pin (in 4-wire coex case) of the nRF7002 - - srrf-switch-gpios: - type: phandle-array - description: | - GPIO of the RF Switch to control SR RF output to either SR Antenna - or shared Antenna with Wi-Fi diff --git a/dts/bindings/wifi/nordic,nrf70.yaml b/dts/bindings/wifi/nordic,nrf70.yaml index ff9021739ace..abdc7ec2cb06 100644 --- a/dts/bindings/wifi/nordic,nrf70.yaml +++ b/dts/bindings/wifi/nordic,nrf70.yaml @@ -1,9 +1,6 @@ # Copyright (c) 2024 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -# GPIO lines for controlling the nRF70 Series Wi-Fi chip. -include: nordic,nrf70-coex.yaml - properties: iovdd-ctrl-gpios: type: phandle-array @@ -19,3 +16,9 @@ properties: type: phandle-array required: true description: GPIO of the SoC controlling the HOST_IRQ pin of the nRF70 + + srrf-switch-gpios: + type: phandle-array + description: | + GPIO of the RF Switch to control SR RF output to either SR Antenna + or shared Antenna with Wi-Fi diff --git a/dts/bindings/wifi/nordic,nrf7000-coex.yaml b/dts/bindings/wifi/nordic,nrf7000-coex.yaml new file mode 100644 index 000000000000..94dcc2181d33 --- /dev/null +++ b/dts/bindings/wifi/nordic,nrf7000-coex.yaml @@ -0,0 +1,9 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: This is a representation of the nRF7000 Wi-Fi chip with COEX interface. + +compatible: nordic,nrf7000-coex + +include: + - "nordic,nrf70-coex.yaml" diff --git a/dts/bindings/wifi/nordic,nrf7001-coex.yaml b/dts/bindings/wifi/nordic,nrf7001-coex.yaml new file mode 100644 index 000000000000..d58afe7d44cb --- /dev/null +++ b/dts/bindings/wifi/nordic,nrf7001-coex.yaml @@ -0,0 +1,9 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: This is a representation of the nRF7001 Wi-Fi chip with COEX interface. + +compatible: nordic,nrf7001-coex + +include: + - "nordic,nrf70-coex.yaml" diff --git a/dts/bindings/wifi/nordic,nrf7002-coex.yaml b/dts/bindings/wifi/nordic,nrf7002-coex.yaml new file mode 100644 index 000000000000..1df61d0bf987 --- /dev/null +++ b/dts/bindings/wifi/nordic,nrf7002-coex.yaml @@ -0,0 +1,9 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: This is a representation of the nRF7002 Wi-Fi chip with COEX interface. + +compatible: nordic,nrf7002-coex + +include: + - "nordic,nrf70-coex.yaml" diff --git a/dts/common/nordic/nrf54h20.dtsi b/dts/common/nordic/nrf54h20.dtsi index 041b63ee1933..0c891161ab28 100644 --- a/dts/common/nordic/nrf54h20.dtsi +++ b/dts/common/nordic/nrf54h20.dtsi @@ -148,16 +148,8 @@ #address-cells = <1>; #size-cells = <1>; - suit_storage_partition: memory@e1eb000 { - reg = <0xe1eb000 DT_SIZE_K(24)>; - }; - - cpurad_uicr_ext: memory@e1ff000 { - reg = <0xe1ff000 DT_SIZE_K(2)>; - }; - - cpuapp_uicr_ext: memory@e1ff800 { - reg = <0xe1ff800 DT_SIZE_K(2)>; + suit_storage_partition: memory@e1ed000 { + reg = <0xe1ed000 DT_SIZE_K(20)>; }; }; @@ -220,14 +212,12 @@ compatible = "nordic,nrf-uicr-v2"; reg = <0xfff8000 DT_SIZE_K(2)>; domain = <2>; - ptr-ext-uicr = <&cpuapp_uicr_ext>; }; cpurad_uicr: uicr@fffa000 { compatible = "nordic,nrf-uicr-v2"; reg = <0xfffa000 DT_SIZE_K(2)>; domain = <3>; - ptr-ext-uicr = <&cpurad_uicr_ext>; }; ficr: ficr@fffe000 { @@ -657,6 +647,7 @@ interrupts = <230 NRF_DEFAULT_IRQ_PRIORITY>; clocks = <&hsfll120>; endtx-stoptx-supported; + frame-timeout-supported; }; spi121: spi@8e7000 { @@ -837,11 +828,14 @@ }; comp: comparator@983000 { + /* + * Use compatible "nordic,nrf-comp" to configure as COMP + * Use compatible "nordic,nrf-lpcomp" to configure as LPCOMP + */ compatible = "nordic,nrf-comp"; reg = <0x983000 0x1000>; status = "disabled"; interrupts = <387 NRF_DEFAULT_IRQ_PRIORITY>; - #io-channel-cells = <1>; }; temp: temperature-sensor@984000 { @@ -966,6 +960,7 @@ clocks = <&fll16m>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; i2c131: i2c@9a6000 { @@ -1007,6 +1002,7 @@ clocks = <&fll16m>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; dppic134: dppic@9b1000 { @@ -1085,6 +1081,7 @@ clocks = <&fll16m>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; i2c133: i2c@9b6000 { @@ -1126,6 +1123,7 @@ clocks = <&fll16m>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; dppic135: dppic@9c1000 { @@ -1204,6 +1202,7 @@ clocks = <&fll16m>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; i2c135: i2c@9c6000 { @@ -1245,6 +1244,7 @@ clocks = <&fll16m>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; dppic136: dppic@9d1000 { @@ -1323,6 +1323,7 @@ clocks = <&fll16m>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; i2c137: i2c@9d6000 { @@ -1364,6 +1365,7 @@ clocks = <&fll16m>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; }; }; diff --git a/dts/common/nordic/nrf54l15.dtsi b/dts/common/nordic/nrf54l15.dtsi index 1df4c4f53c54..d3c0c551823d 100644 --- a/dts/common/nordic/nrf54l15.dtsi +++ b/dts/common/nordic/nrf54l15.dtsi @@ -138,6 +138,7 @@ interrupts = <74 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; endtx-stoptx-supported; + frame-timeout-supported; }; cpuflpr_vpr: vpr@4c000 { @@ -271,6 +272,7 @@ interrupts = <198 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; endtx-stoptx-supported; + frame-timeout-supported; }; i2c21: i2c@c7000 { @@ -309,6 +311,7 @@ interrupts = <199 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; endtx-stoptx-supported; + frame-timeout-supported; }; i2c22: i2c@c8000 { @@ -347,6 +350,7 @@ interrupts = <200 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; endtx-stoptx-supported; + frame-timeout-supported; }; egu20: egu@c9000 { @@ -556,6 +560,18 @@ interrupts = <260 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; endtx-stoptx-supported; + frame-timeout-supported; + }; + + comp: comparator@106000 { + /* + * Use compatible "nordic,nrf-comp" to configure as COMP + * Use compatible "nordic,nrf-lpcomp" to configure as LPCOMP + */ + compatible = "nordic,nrf-comp"; + reg = <0x106000 0x1000>; + status = "disabled"; + interrupts = <262 NRF_DEFAULT_IRQ_PRIORITY>; }; #ifdef USE_NON_SECURE_ADDRESS_MAP @@ -601,6 +617,32 @@ status = "disabled"; }; + power: power@10e000 { + compatible = "nordic,nrf-power"; + reg = <0x10e000 0x1000>; + ranges = <0x0 0x10e000 0x1000>; + interrupts = <270 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; + #address-cells = <1>; + #size-cells = <1>; + + gpregret1: gpregret1@51c { + #address-cells = <1>; + #size-cells = <1>; + compatible = "nordic,nrf-gpregret"; + reg = <0x51c 0x1>; + status = "disabled"; + }; + + gpregret2: gpregret2@520 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "nordic,nrf-gpregret"; + reg = <0x520 0x1>; + status = "disabled"; + }; + }; + regulators: regulator@120000 { compatible = "nordic,nrf54l-regulators"; reg = <0x120000 0x1000>; diff --git a/dts/common/nordic/nrf54l20.dtsi b/dts/common/nordic/nrf54l20.dtsi index 17d871d2bfc1..dfe8d7b4531b 100644 --- a/dts/common/nordic/nrf54l20.dtsi +++ b/dts/common/nordic/nrf54l20.dtsi @@ -107,6 +107,7 @@ interrupts = <77 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; endtx-stoptx-supported; + frame-timeout-supported; }; gpio2: gpio@50400 { @@ -221,6 +222,7 @@ interrupts = <198 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; endtx-stoptx-supported; + frame-timeout-supported; }; i2c21: i2c@c7000 { @@ -259,6 +261,7 @@ interrupts = <199 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; endtx-stoptx-supported; + frame-timeout-supported; }; i2c22: i2c@c8000 { @@ -297,6 +300,7 @@ interrupts = <200 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; endtx-stoptx-supported; + frame-timeout-supported; }; egu20: egu@c9000 { @@ -497,6 +501,7 @@ interrupts = <260 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; endtx-stoptx-supported; + frame-timeout-supported; }; wdt30: watchdog@108000 { diff --git a/dts/common/nordic/nrf9280.dtsi b/dts/common/nordic/nrf9280.dtsi index dc688a89f25d..45b05f9262ee 100644 --- a/dts/common/nordic/nrf9280.dtsi +++ b/dts/common/nordic/nrf9280.dtsi @@ -74,14 +74,6 @@ reserved-memory { #address-cells = <1>; #size-cells = <1>; - - cpurad_uicr_ext: memory@e401000 { - reg = <0xe401000 DT_SIZE_K(2)>; - }; - - cpuapp_uicr_ext: memory@e401800 { - reg = <0xe401800 DT_SIZE_K(2)>; - }; }; clocks { @@ -113,14 +105,12 @@ compatible = "nordic,nrf-uicr-v2"; reg = <0xfff8000 DT_SIZE_K(2)>; domain = <2>; - ptr-ext-uicr = <&cpuapp_uicr_ext>; }; cpurad_uicr: uicr@fffa000 { compatible = "nordic,nrf-uicr-v2"; reg = <0xfffa000 DT_SIZE_K(2)>; domain = <3>; - ptr-ext-uicr = <&cpurad_uicr_ext>; }; ficr: ficr@fffe000 { @@ -517,6 +507,7 @@ status = "disabled"; interrupts = <230 NRF_DEFAULT_IRQ_PRIORITY>; endtx-stoptx-supported; + frame-timeout-supported; }; spi121: spi@8e7000 { @@ -736,11 +727,14 @@ }; comp: comparator@983000 { + /* + * Use compatible "nordic,nrf-comp" to configure as COMP + * Use compatible "nordic,nrf-lpcomp" to configure as LPCOMP + */ compatible = "nordic,nrf-comp"; reg = <0x983000 0x1000>; status = "disabled"; interrupts = <387 NRF_DEFAULT_IRQ_PRIORITY>; - #io-channel-cells = <1>; }; temp: temperature-sensor@984000 { @@ -847,6 +841,7 @@ interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; i2c131: i2c@9a6000 { @@ -885,6 +880,7 @@ interrupts = <422 NRF_DEFAULT_IRQ_PRIORITY>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; dppic134: dppic@9b1000 { @@ -957,6 +953,7 @@ interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; i2c133: i2c@9b6000 { @@ -995,6 +992,7 @@ interrupts = <438 NRF_DEFAULT_IRQ_PRIORITY>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; dppic135: dppic@9c1000 { @@ -1067,6 +1065,7 @@ interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; i2c135: i2c@9c6000 { @@ -1105,6 +1104,7 @@ interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; dppic136: dppic@9d1000 { @@ -1177,6 +1177,7 @@ interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; i2c137: i2c@9d6000 { @@ -1215,6 +1216,7 @@ interrupts = <470 NRF_DEFAULT_IRQ_PRIORITY>; nordic,clockpin-enable = ; endtx-stoptx-supported; + frame-timeout-supported; }; }; }; diff --git a/include/zephyr/arch/common/pm_s2ram.h b/include/zephyr/arch/common/pm_s2ram.h index 34c544c769b9..ad9ab8ad7a40 100644 --- a/include/zephyr/arch/common/pm_s2ram.h +++ b/include/zephyr/arch/common/pm_s2ram.h @@ -65,6 +65,11 @@ int arch_pm_s2ram_suspend(pm_s2ram_system_off_fn_t system_off); * * Default implementation is setting a magic word in RAM. CONFIG_PM_S2RAM_CUSTOM_MARKING * allows custom implementation. + * The following requirements must be fulfilled: + * - the function cannot use stack (asm function or function with 'naked' attribute) + * - the content of the R1 and R4 registers must remain unchanged + * - returning from the function should be performed with the `bx lr` instruction + * */ void pm_s2ram_mark_set(void); @@ -76,6 +81,11 @@ void pm_s2ram_mark_set(void); * * Default implementation is checking a magic word in RAM. CONFIG_PM_S2RAM_CUSTOM_MARKING * allows custom implementation. + * The following requirements must be fulfilled: + * - the function cannot use stack (most likely asm function) + * - the content of the R1 and R4 registers must remain unchanged + * - the function's return value is passed by R0 register + * - returning from the function should be performed with the `bx lr` instruction * * @retval true if marking is found which indicates resuming after suspend-to-RAM. * @retval false if marking is not found which indicates standard boot. diff --git a/include/zephyr/bluetooth/audio/bap.h b/include/zephyr/bluetooth/audio/bap.h index 83159bed43ff..9f13cd2fdee7 100644 --- a/include/zephyr/bluetooth/audio/bap.h +++ b/include/zephyr/bluetooth/audio/bap.h @@ -640,13 +640,13 @@ struct bt_bap_unicast_server_register_param { /** * @brief Sink Count to register. * - * Should be in range [0, @kconfig{CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT}] + * Should be in range 0 to @kconfig{CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT} */ uint8_t snk_cnt; /** @brief Source Count to register. * - * Should be in range [0, @kconfig{CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT}] + * Should be in range 0 to @kconfig{CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT} */ uint8_t src_cnt; }; diff --git a/include/zephyr/bluetooth/bluetooth.h b/include/zephyr/bluetooth/bluetooth.h index 6f565bd400f2..bc5b7b0731c4 100644 --- a/include/zephyr/bluetooth/bluetooth.h +++ b/include/zephyr/bluetooth/bluetooth.h @@ -2065,7 +2065,7 @@ struct bt_le_scan_param { uint8_t type; /** Bit-field of scanning options. */ - uint32_t options; + uint8_t options; /** Scan interval (N * 0.625 ms). * diff --git a/include/zephyr/bluetooth/conn.h b/include/zephyr/bluetooth/conn.h index 23dd9fb89f8e..b4cf1c5c6bab 100644 --- a/include/zephyr/bluetooth/conn.h +++ b/include/zephyr/bluetooth/conn.h @@ -1336,7 +1336,9 @@ struct bt_conn_le_create_param { * Allows initiate new LE link to remote peer using its address. * * The caller gets a new reference to the connection object which must be - * released with bt_conn_unref() once done using the object. + * released with bt_conn_unref() once done using the object. If + * @kconfig{CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE} is enabled, this function + * will return -EINVAL if dereferenced @p conn is not NULL. * * This uses the General Connection Establishment procedure. * @@ -1375,7 +1377,9 @@ struct bt_conn_le_create_synced_param { * with Responses (PAwR) train. * * The caller gets a new reference to the connection object which must be - * released with bt_conn_unref() once done using the object. + * released with bt_conn_unref() once done using the object. If + * @kconfig{CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE} is enabled, this function + * will return -EINVAL if dereferenced @p conn is not NULL. * * This uses the Periodic Advertising Connection Procedure. * @@ -1980,6 +1984,17 @@ static inline const char *bt_security_err_to_str(enum bt_security_err err) */ void bt_set_bondable(bool enable); +/** @brief Get bonding flag. + * + * Get current bonding flag. + * The initial value of this flag depends on @kconfig{CONFIG_BT_BONDABLE} Kconfig + * setting. + * The Bonding flag can be updated using bt_set_bondable(). + * + * @return Current bonding flag. + */ +bool bt_get_bondable(void); + /** @brief Set/clear the bonding flag for a given connection. * * Set/clear the Bonding flag in the Authentication Requirements of diff --git a/include/zephyr/device.h b/include/zephyr/device.h index 52b8604db809..5f93954a9ff9 100644 --- a/include/zephyr/device.h +++ b/include/zephyr/device.h @@ -309,7 +309,7 @@ typedef int16_t device_handle_t; * @return a @ref device reference for the node identifier, which may be `NULL`. */ #define DEVICE_DT_GET_OR_NULL(node_id) \ - COND_CODE_1(DT_NODE_HAS_STATUS(node_id, okay), \ + COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(node_id), \ (DEVICE_DT_GET(node_id)), (NULL)) /** diff --git a/include/zephyr/devicetree.h b/include/zephyr/devicetree.h index 38c5656079c3..eb894a1f9a90 100644 --- a/include/zephyr/devicetree.h +++ b/include/zephyr/devicetree.h @@ -3403,6 +3403,28 @@ #define DT_NODE_HAS_STATUS(node_id, status) \ DT_NODE_HAS_STATUS_INTERNAL(node_id, status) +/** + * @brief Does a node identifier refer to a node with a status `okay`? + * + * Example uses: + * + * @code{.c} + * DT_NODE_HAS_STATUS_OKAY(DT_PATH(soc, i2c_12340000)) + * @endcode + * + * Tests whether a node identifier refers to a node which: + * + * - exists in the devicetree, and + * - has a status property as `okay` + * + * As usual, both a missing status and an `ok` status are treated as + * `okay`. + * + * @param node_id a node identifier + * @return 1 if the node has status as `okay`, 0 otherwise. + */ +#define DT_NODE_HAS_STATUS_OKAY(node_id) DT_NODE_HAS_STATUS(node_id, okay) + /** * @brief Does the devicetree have a status `okay` node with a compatible? * diff --git a/include/zephyr/drivers/clock_control/stm32_clock_control.h b/include/zephyr/drivers/clock_control/stm32_clock_control.h index c33714be9762..b03fa7900270 100644 --- a/include/zephyr/drivers/clock_control/stm32_clock_control.h +++ b/include/zephyr/drivers/clock_control/stm32_clock_control.h @@ -250,7 +250,7 @@ #endif /** PLL/PLL1 clock source */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pll), okay) && \ +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pll)) && \ DT_NODE_HAS_PROP(DT_NODELABEL(pll), clocks) #define DT_PLL_CLOCKS_CTRL DT_CLOCKS_CTLR(DT_NODELABEL(pll)) #if DT_SAME_NODE(DT_PLL_CLOCKS_CTRL, DT_NODELABEL(clk_msi)) @@ -275,7 +275,7 @@ #endif /** PLL2 clock source */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pll2), okay) && \ +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pll2)) && \ DT_NODE_HAS_PROP(DT_NODELABEL(pll2), clocks) #define DT_PLL2_CLOCKS_CTRL DT_CLOCKS_CTLR(DT_NODELABEL(pll2)) #if DT_SAME_NODE(DT_PLL2_CLOCKS_CTRL, DT_NODELABEL(clk_msis)) @@ -291,7 +291,7 @@ #endif /** PLL3 clock source */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pll3), okay) && \ +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pll3)) && \ DT_NODE_HAS_PROP(DT_NODELABEL(pll3), clocks) #define DT_PLL3_CLOCKS_CTRL DT_CLOCKS_CTLR(DT_NODELABEL(pll3)) #if DT_SAME_NODE(DT_PLL3_CLOCKS_CTRL, DT_NODELABEL(clk_msis)) diff --git a/include/zephyr/drivers/comparator.h b/include/zephyr/drivers/comparator.h new file mode 100644 index 000000000000..3d246fea5ff1 --- /dev/null +++ b/include/zephyr/drivers/comparator.h @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_DRIVERS_COMPARATOR_H_ +#define ZEPHYR_INCLUDE_DRIVERS_COMPARATOR_H_ + +/** + * @brief Comparator Interface + * @defgroup comparator_interface Comparator Interface + * @since 3.7 + * @version 0.1.0 + * @ingroup io_interfaces + * @{ + */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Comparator trigger enumerations */ +enum comparator_trigger { + /** No trigger */ + COMPARATOR_TRIGGER_NONE = 0, + /** Trigger on rising edge of comparator output */ + COMPARATOR_TRIGGER_RISING_EDGE, + /** Trigger on falling edge of comparator output */ + COMPARATOR_TRIGGER_FALLING_EDGE, + /** Trigger on both edges of comparator output */ + COMPARATOR_TRIGGER_BOTH_EDGES +}; + +/** Comparator callback template */ +typedef void (*comparator_callback_t)(const struct device *dev, void *user_data); + +/** @cond INTERNAL_HIDDEN */ + +typedef int (*comparator_api_get_output)(const struct device *dev); +typedef int (*comparator_api_set_trigger)(const struct device *dev, + enum comparator_trigger trigger); +typedef int (*comparator_api_set_trigger_callback)(const struct device *dev, + comparator_callback_t callback, + void *user_data); +typedef int (*comparator_api_trigger_is_pending)(const struct device *dev); + +__subsystem struct comparator_driver_api { + comparator_api_get_output get_output; + comparator_api_set_trigger set_trigger; + comparator_api_set_trigger_callback set_trigger_callback; + comparator_api_trigger_is_pending trigger_is_pending; +}; + +/** @endcond */ + +/** + * @brief Get comparator's output state + * + * @param dev Comparator device + * + * @retval 1 Output state is high + * @retval 0 Output state is low + * @retval -errno code Failure + */ +__syscall int comparator_get_output(const struct device *dev); + +static inline int z_impl_comparator_get_output(const struct device *dev) +{ + const struct comparator_driver_api *api = + (const struct comparator_driver_api *)dev->api; + + return api->get_output(dev); +} + +/** + * @brief Set comparator's trigger + * + * @param dev Comparator device + * @param trigger Trigger for signal and callback + * + * @retval 0 Successful + * @retval -errno code Failure + */ +__syscall int comparator_set_trigger(const struct device *dev, + enum comparator_trigger trigger); + +static inline int z_impl_comparator_set_trigger(const struct device *dev, + enum comparator_trigger trigger) +{ + const struct comparator_driver_api *api = + (const struct comparator_driver_api *)dev->api; + + return api->set_trigger(dev, trigger); +} + +/** + * @brief Set comparator's trigger callback + * + * @param dev Comparator device + * @param callback Trigger callback + * @param user_data User data passed to callback + * + * @retval 0 Successful + * @retval -errno code Failure + * + * @note Set callback to NULL to disable callback + * @note Callback is called immediately if trigger is pending + */ +static inline int comparator_set_trigger_callback(const struct device *dev, + comparator_callback_t callback, + void *user_data) +{ + const struct comparator_driver_api *api = + (const struct comparator_driver_api *)dev->api; + + return api->set_trigger_callback(dev, callback, user_data); +} + +/** + * @brief Check if comparator's trigger is pending and clear it + * + * @param dev Comparator device + * + * @retval 1 Trigger was pending + * @retval 0 Trigger was cleared + * @retval -errno code Failure + */ +__syscall int comparator_trigger_is_pending(const struct device *dev); + +static inline int z_impl_comparator_trigger_is_pending(const struct device *dev) +{ + const struct comparator_driver_api *api = + (const struct comparator_driver_api *)dev->api; + + return api->trigger_is_pending(dev); +} + +#ifdef __cplusplus +} +#endif + +/** @} */ + +#include + +#endif /* ZEPHYR_INCLUDE_DRIVERS_COMPARATOR_H_ */ diff --git a/include/zephyr/drivers/comparator/fake_comp.h b/include/zephyr/drivers/comparator/fake_comp.h new file mode 100644 index 000000000000..c24858c1997e --- /dev/null +++ b/include/zephyr/drivers/comparator/fake_comp.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_DRIVERS_COMPARATOR_FAKE_H_ +#define ZEPHYR_INCLUDE_DRIVERS_COMPARATOR_FAKE_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +DECLARE_FAKE_VALUE_FUNC(int, + comp_fake_comp_get_output, + const struct device *); + +DECLARE_FAKE_VALUE_FUNC(int, + comp_fake_comp_set_trigger, + const struct device *, + enum comparator_trigger); + +DECLARE_FAKE_VALUE_FUNC(int, + comp_fake_comp_set_trigger_callback, + const struct device *, + comparator_callback_t, + void *); + +DECLARE_FAKE_VALUE_FUNC(int, + comp_fake_comp_trigger_is_pending, + const struct device *); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_DRIVERS_COMPARATOR_FAKE_H_ */ diff --git a/include/zephyr/drivers/comparator/mcux_acmp.h b/include/zephyr/drivers/comparator/mcux_acmp.h new file mode 100644 index 000000000000..3d06644f0e84 --- /dev/null +++ b/include/zephyr/drivers/comparator/mcux_acmp.h @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_DRIVERS_COMP_MCUX_ACMP_H_ +#define ZEPHYR_INCLUDE_DRIVERS_COMP_MCUX_ACMP_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +enum comp_mcux_acmp_offset_mode { + COMP_MCUX_ACMP_OFFSET_MODE_LEVEL0 = 0, + COMP_MCUX_ACMP_OFFSET_MODE_LEVEL1, +}; + +enum comp_mcux_acmp_hysteresis_mode { + COMP_MCUX_ACMP_HYSTERESIS_MODE_LEVEL0 = 0, + COMP_MCUX_ACMP_HYSTERESIS_MODE_LEVEL1, + COMP_MCUX_ACMP_HYSTERESIS_MODE_LEVEL2, + COMP_MCUX_ACMP_HYSTERESIS_MODE_LEVEL3, +}; + +struct comp_mcux_acmp_mode_config { + enum comp_mcux_acmp_offset_mode offset_mode; + enum comp_mcux_acmp_hysteresis_mode hysteresis_mode; + bool enable_high_speed_mode; + bool invert_output; + bool use_unfiltered_output; + bool enable_pin_output; +}; + +enum comp_mcux_acmp_mux_input { + COMP_MCUX_ACMP_MUX_INPUT_IN0 = 0, + COMP_MCUX_ACMP_MUX_INPUT_IN1, + COMP_MCUX_ACMP_MUX_INPUT_IN2, + COMP_MCUX_ACMP_MUX_INPUT_IN3, + COMP_MCUX_ACMP_MUX_INPUT_IN4, + COMP_MCUX_ACMP_MUX_INPUT_IN5, + COMP_MCUX_ACMP_MUX_INPUT_IN6, + COMP_MCUX_ACMP_MUX_INPUT_IN7, +}; + +enum comp_mcux_acmp_port_input { + COMP_MCUX_ACMP_PORT_INPUT_DAC = 0, + COMP_MCUX_ACMP_PORT_INPUT_MUX, +}; + +struct comp_mcux_acmp_input_config { + enum comp_mcux_acmp_mux_input positive_mux_input; + enum comp_mcux_acmp_mux_input negative_mux_input; + enum comp_mcux_acmp_port_input positive_port_input; + enum comp_mcux_acmp_port_input negative_port_input; +}; + +struct comp_mcux_acmp_filter_config { + bool enable_sample; + uint8_t filter_count; + uint8_t filter_period; +}; + +enum comp_mcux_acmp_dac_vref_source { + COMP_MCUX_ACMP_DAC_VREF_SOURCE_VIN1 = 0, + COMP_MCUX_ACMP_DAC_VREF_SOURCE_VIN2, +}; + +struct comp_mcux_acmp_dac_config { + enum comp_mcux_acmp_dac_vref_source vref_source; + uint8_t value; + bool enable_output; + bool enable_high_speed_mode; +}; + +enum comp_mcux_acmp_dm_clock { + COMP_MCUX_ACMP_DM_CLOCK_SLOW = 0, + COMP_MCUX_ACMP_DM_CLOCK_FAST, +}; + +enum comp_mcux_acmp_dm_sample_time { + COMP_MCUX_ACMP_DM_SAMPLE_TIME_T1 = 0, + COMP_MCUX_ACMP_DM_SAMPLE_TIME_T2, + COMP_MCUX_ACMP_DM_SAMPLE_TIME_T4, + COMP_MCUX_ACMP_DM_SAMPLE_TIME_T8, + COMP_MCUX_ACMP_DM_SAMPLE_TIME_T16, + COMP_MCUX_ACMP_DM_SAMPLE_TIME_T32, + COMP_MCUX_ACMP_DM_SAMPLE_TIME_T64, + COMP_MCUX_ACMP_DM_SAMPLE_TIME_T256, +}; + +enum comp_mcux_acmp_dm_phase_time { + COMP_MCUX_ACMP_DM_PHASE_TIME_ALT0 = 0, + COMP_MCUX_ACMP_DM_PHASE_TIME_ALT1, + COMP_MCUX_ACMP_DM_PHASE_TIME_ALT2, + COMP_MCUX_ACMP_DM_PHASE_TIME_ALT3, + COMP_MCUX_ACMP_DM_PHASE_TIME_ALT4, + COMP_MCUX_ACMP_DM_PHASE_TIME_ALT5, + COMP_MCUX_ACMP_DM_PHASE_TIME_ALT6, + COMP_MCUX_ACMP_DM_PHASE_TIME_ALT7, +}; + +struct comp_mcux_acmp_dm_config { + bool enable_positive_channel; + bool enable_negative_channel; + bool enable_resistor_divider; + enum comp_mcux_acmp_dm_clock clock_source; + enum comp_mcux_acmp_dm_sample_time sample_time; + enum comp_mcux_acmp_dm_phase_time phase1_time; + enum comp_mcux_acmp_dm_phase_time phase2_time; +}; + +int comp_mcux_acmp_set_mode_config(const struct device *dev, + const struct comp_mcux_acmp_mode_config *config); + +int comp_mcux_acmp_set_input_config(const struct device *dev, + const struct comp_mcux_acmp_input_config *config); + +int comp_mcux_acmp_set_filter_config(const struct device *dev, + const struct comp_mcux_acmp_filter_config *config); + +int comp_mcux_acmp_set_dac_config(const struct device *dev, + const struct comp_mcux_acmp_dac_config *config); + +int comp_mcux_acmp_set_dm_config(const struct device *dev, + const struct comp_mcux_acmp_dm_config *config); + +int comp_mcux_acmp_set_window_mode(const struct device *dev, bool enable); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_DRIVERS_COMP_MCUX_ACMP_H_ */ diff --git a/include/zephyr/drivers/comparator/nrf_comp.h b/include/zephyr/drivers/comparator/nrf_comp.h new file mode 100644 index 000000000000..59e1cbbb3ce9 --- /dev/null +++ b/include/zephyr/drivers/comparator/nrf_comp.h @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_DRIVERS_COMP_NRF_COMP_H_ +#define ZEPHYR_INCLUDE_DRIVERS_COMP_NRF_COMP_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Positive input selection */ +enum comp_nrf_comp_psel { + /** AIN0 external input */ + COMP_NRF_COMP_PSEL_AIN0, + /** AIN1 external input */ + COMP_NRF_COMP_PSEL_AIN1, + /** AIN2 external input */ + COMP_NRF_COMP_PSEL_AIN2, + /** AIN3 external input */ + COMP_NRF_COMP_PSEL_AIN3, + /** AIN4 external input */ + COMP_NRF_COMP_PSEL_AIN4, + /** AIN5 external input */ + COMP_NRF_COMP_PSEL_AIN5, + /** AIN6 external input */ + COMP_NRF_COMP_PSEL_AIN6, + /** AIN7 external input */ + COMP_NRF_COMP_PSEL_AIN7, + /** VDD / 2 */ + COMP_NRF_COMP_PSEL_VDD_DIV2, + /** VDDH / 5 */ + COMP_NRF_COMP_PSEL_VDDH_DIV5, +}; + +/** External reference selection */ +enum comp_nrf_comp_extrefsel { + /** AIN0 external input */ + COMP_NRF_COMP_EXTREFSEL_AIN0, + /** AIN1 external input */ + COMP_NRF_COMP_EXTREFSEL_AIN1, + /** AIN2 external input */ + COMP_NRF_COMP_EXTREFSEL_AIN2, + /** AIN3 external input */ + COMP_NRF_COMP_EXTREFSEL_AIN3, + /** AIN4 external input */ + COMP_NRF_COMP_EXTREFSEL_AIN4, + /** AIN5 external input */ + COMP_NRF_COMP_EXTREFSEL_AIN5, + /** AIN6 external input */ + COMP_NRF_COMP_EXTREFSEL_AIN6, + /** AIN7 external input */ + COMP_NRF_COMP_EXTREFSEL_AIN7, +}; + +/** Reference selection */ +enum comp_nrf_comp_refsel { + /** Internal 1.2V reference */ + COMP_NRF_COMP_REFSEL_INT_1V2, + /** Internal 1.8V reference */ + COMP_NRF_COMP_REFSEL_INT_1V8, + /** Internal 2.4V reference */ + COMP_NRF_COMP_REFSEL_INT_2V4, + /** AVDD 1.8V reference */ + COMP_NRF_COMP_REFSEL_AVDDAO1V8, + /** VDD reference */ + COMP_NRF_COMP_REFSEL_VDD, + /** Use external analog reference */ + COMP_NRF_COMP_REFSEL_AREF, +}; + +/** Speed mode selection */ +enum comp_nrf_comp_sp_mode { + /** Low-power mode */ + COMP_NRF_COMP_SP_MODE_LOW, + /** Normal mode */ + COMP_NRF_COMP_SP_MODE_NORMAL, + /** High-speed mode */ + COMP_NRF_COMP_SP_MODE_HIGH, +}; + +/** Current source configuration */ +enum comp_nrf_comp_isource { + /** Current source disabled */ + COMP_NRF_COMP_ISOURCE_DISABLED, + /** 2.5uA current source enabled */ + COMP_NRF_COMP_ISOURCE_2UA5, + /** 5uA current source enabled */ + COMP_NRF_COMP_ISOURCE_5UA, + /** 10uA current source enabled */ + COMP_NRF_COMP_ISOURCE_10UA, +}; + +/** + * @brief Single-ended mode configuration structure + * + * @note extrefsel is only used if refsel == COMP_NRF_COMP_REFSEL_AREF + * @note Hysteresis down in volts = ((th_down + 1) / 64) * ref + * @note Hysteresis up in volts = ((th_up + 1) / 64) * ref + */ +struct comp_nrf_comp_se_config { + /** Positive input selection */ + enum comp_nrf_comp_psel psel; + /** Speed mode selection */ + enum comp_nrf_comp_sp_mode sp_mode; + /** Current source configuration */ + enum comp_nrf_comp_isource isource; + /** External reference selection */ + enum comp_nrf_comp_extrefsel extrefsel; + /** Reference selection */ + enum comp_nrf_comp_refsel refsel; + /** Hysteresis down threshold configuration */ + uint8_t th_down; + /** Hysteresis up threshold configuration */ + uint8_t th_up; +}; + +/** + * @brief Configure comparator in single-ended mode + * + * @param dev Comparator device instance + * @param config Single-ended mode configuration + * + * @retval 0 if successful + * @retval negative errno-code otherwise + */ +int comp_nrf_comp_configure_se(const struct device *dev, + const struct comp_nrf_comp_se_config *config); + +/** Differential mode configuration structure */ +struct comp_nrf_comp_diff_config { + /** Positive input selection */ + enum comp_nrf_comp_psel psel; + /** Speed mode selection */ + enum comp_nrf_comp_sp_mode sp_mode; + /** Current source configuration */ + enum comp_nrf_comp_isource isource; + /** Negative input selection */ + enum comp_nrf_comp_extrefsel extrefsel; + /** Hysteresis configuration */ + bool enable_hyst; +}; + +/** + * @brief Configure comparator in differential mode + * + * @param dev Comparator device instance + * @param config Differential mode configuration + * + * @retval 0 if successful + * @retval negative errno-code otherwise + */ +int comp_nrf_comp_configure_diff(const struct device *dev, + const struct comp_nrf_comp_diff_config *config); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_DRIVERS_COMP_NRF_COMP_H_ */ diff --git a/include/zephyr/drivers/comparator/nrf_lpcomp.h b/include/zephyr/drivers/comparator/nrf_lpcomp.h new file mode 100644 index 000000000000..e1f2343a8de8 --- /dev/null +++ b/include/zephyr/drivers/comparator/nrf_lpcomp.h @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_DRIVERS_COMP_NRF_LPCOMP_H_ +#define ZEPHYR_INCLUDE_DRIVERS_COMP_NRF_LPCOMP_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Positive input selection */ +enum comp_nrf_lpcomp_psel { + /** AIN0 external input */ + COMP_NRF_LPCOMP_PSEL_AIN0, + /** AIN1 external input */ + COMP_NRF_LPCOMP_PSEL_AIN1, + /** AIN2 external input */ + COMP_NRF_LPCOMP_PSEL_AIN2, + /** AIN3 external input */ + COMP_NRF_LPCOMP_PSEL_AIN3, + /** AIN4 external input */ + COMP_NRF_LPCOMP_PSEL_AIN4, + /** AIN5 external input */ + COMP_NRF_LPCOMP_PSEL_AIN5, + /** AIN6 external input */ + COMP_NRF_LPCOMP_PSEL_AIN6, + /** AIN7 external input */ + COMP_NRF_LPCOMP_PSEL_AIN7, +}; + +/** External reference selection */ +enum comp_nrf_lpcomp_extrefsel { + /** AIN0 external input */ + COMP_NRF_LPCOMP_EXTREFSEL_AIN0, + /** AIN1 external input */ + COMP_NRF_LPCOMP_EXTREFSEL_AIN1, +}; + +/** Reference selection */ +enum comp_nrf_lpcomp_refsel { + /** Use (VDD * (1/8)) as reference */ + COMP_NRF_LPCOMP_REFSEL_VDD_1_8, + /** Use (VDD * (2/8)) as reference */ + COMP_NRF_LPCOMP_REFSEL_VDD_2_8, + /** Use (VDD * (3/8)) as reference */ + COMP_NRF_LPCOMP_REFSEL_VDD_3_8, + /** Use (VDD * (4/8)) as reference */ + COMP_NRF_LPCOMP_REFSEL_VDD_4_8, + /** Use (VDD * (5/8)) as reference */ + COMP_NRF_LPCOMP_REFSEL_VDD_5_8, + /** Use (VDD * (6/8)) as reference */ + COMP_NRF_LPCOMP_REFSEL_VDD_6_8, + /** Use (VDD * (7/8)) as reference */ + COMP_NRF_LPCOMP_REFSEL_VDD_7_8, + /** Use (VDD * (1/16)) as reference */ + COMP_NRF_LPCOMP_REFSEL_VDD_1_16, + /** Use (VDD * (3/16)) as reference */ + COMP_NRF_LPCOMP_REFSEL_VDD_3_16, + /** Use (VDD * (5/16)) as reference */ + COMP_NRF_LPCOMP_REFSEL_VDD_5_16, + /** Use (VDD * (7/16)) as reference */ + COMP_NRF_LPCOMP_REFSEL_VDD_7_16, + /** Use (VDD * (9/16)) as reference */ + COMP_NRF_LPCOMP_REFSEL_VDD_9_16, + /** Use (VDD * (11/16)) as reference */ + COMP_NRF_LPCOMP_REFSEL_VDD_11_16, + /** Use (VDD * (13/16)) as reference */ + COMP_NRF_LPCOMP_REFSEL_VDD_13_16, + /** Use (VDD * (15/16)) as reference */ + COMP_NRF_LPCOMP_REFSEL_VDD_15_16, + /** Use external analog reference */ + COMP_NRF_LPCOMP_REFSEL_AREF, +}; + +/** + * @brief Configuration structure + * + * @note extrefsel is only used if refsel == COMP_NRF_LPCOMP_REFSEL_AREF + */ +struct comp_nrf_lpcomp_config { + /** Positive input selection */ + enum comp_nrf_lpcomp_psel psel; + /** External reference selection */ + enum comp_nrf_lpcomp_extrefsel extrefsel; + /** Reference selection */ + enum comp_nrf_lpcomp_refsel refsel; + /** Hysteresis configuration */ + bool enable_hyst; +}; + +/** + * @brief Configure comparator + * + * @param dev Comparator device instance + * @param config Configuration + * + * @retval 0 if successful + * @retval negative errno-code otherwise + */ +int comp_nrf_lpcomp_configure(const struct device *dev, + const struct comp_nrf_lpcomp_config *config); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_DRIVERS_COMP_NRF_LPCOMP_H_ */ diff --git a/include/zephyr/drivers/emul.h b/include/zephyr/drivers/emul.h index c0830bb02055..a20679573e4c 100644 --- a/include/zephyr/drivers/emul.h +++ b/include/zephyr/drivers/emul.h @@ -195,7 +195,7 @@ struct emul { * @return a @ref emul reference for the node identifier, which may be `NULL`. */ #define EMUL_DT_GET_OR_NULL(node_id) \ - COND_CODE_1(DT_NODE_HAS_STATUS(node_id, okay), (EMUL_DT_GET(node_id)), (NULL)) + COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(node_id), (EMUL_DT_GET(node_id)), (NULL)) /** * @brief Set up a list of emulators diff --git a/include/zephyr/drivers/wifi/nrfwifi/off_raw_tx/off_raw_tx_api.h b/include/zephyr/drivers/wifi/nrfwifi/off_raw_tx/off_raw_tx_api.h new file mode 100644 index 000000000000..b14ae39488d9 --- /dev/null +++ b/include/zephyr/drivers/wifi/nrfwifi/off_raw_tx/off_raw_tx_api.h @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +/** @file + * + * @addtogroup nrf70_off_raw_tx_api nRF70 Offloaded raw TX API + * @{ + * + * @brief File containing API's for the Offloaded raw TX feature. + */ + +#ifndef INCLUDE_ZEPHYR_DRIVERS_OFF_RAW_TX_API_H_ +#define INCLUDE_ZEPHYR_DRIVERS_OFF_RAW_TX_API_H_ + +#include +#include +#include "osal_api.h" + +/* Minimum frame size for raw packet transmission */ +#define NRF_WIFI_OFF_RAW_TX_FRAME_SIZE_MIN 26 +/* Maximum frame size for raw packet transmission */ +#define NRF_WIFI_OFF_RAW_TX_FRAME_SIZE_MAX 600 +/* Maximum length of country code*/ +#define NRF_WIFI_COUNTRY_CODE_LEN 2 +/** + * @brief- Transmission rates + * Rate to be used for transmitting a packet. + */ +enum nrf_wifi_off_raw_tx_rate { + /** 1 Mbps */ + RATE_1M, + /** 2 Mbps */ + RATE_2M, + /** 5.5 Mbps */ + RATE_5_5M, + /** 11 Mbps */ + RATE_11M, + /** 6 Mbps */ + RATE_6M, + /** 9 Mbps */ + RATE_9M, + /** 12 Mbps */ + RATE_12M, + /** 18 Mbps */ + RATE_18M, + /** 24 Mbps */ + RATE_24M, + /** 36 Mbps */ + RATE_36M, + /** 48 Mbps */ + RATE_48M, + /** 54 Mbps */ + RATE_54M, + /** MCS 0 */ + RATE_MCS0, + /** MCS 1 */ + RATE_MCS1, + /** MCS 2 */ + RATE_MCS2, + /** MCS 3 */ + RATE_MCS3, + /** MCS 4 */ + RATE_MCS4, + /** MCS 5 */ + RATE_MCS5, + /** MCS 6 */ + RATE_MCS6, + /** MCS 7 */ + RATE_MCS7, + /** Invalid rate */ + RATE_MAX +}; + + +/** + * @brief- HE guard interval value + * Value of the guard interval to be used between symbols when transmitting using HE. + */ +enum nrf_wifi_off_raw_tx_he_gi { + /** 800 ns */ + HE_GI_800NS, + /** 1600 ns */ + HE_GI_1600NS, + /** 3200 ns */ + HE_GI_3200NS, + /** Invalid value */ + HE_GI_MAX +}; + + +/** + * @brief- HE long training field duration + * Value of the long training field duration to be used when transmitting using HE. + */ +enum nrf_wifi_off_raw_tx_he_ltf { + /** 3.2us */ + HE_LTF_3200NS, + /** 6.4us */ + HE_LTF_6400NS, + /** 12.8us */ + HE_LTF_12800NS, + /** Invalid value */ + HE_LTF_MAX +}; + +/** + * @brief- Throughput mode + * Throughput mode to be used for transmitting the packet. + */ +enum nrf_wifi_off_raw_tx_tput_mode { + /** Legacy mode */ + TPUT_MODE_LEGACY, + /** High Throughput mode (11n) */ + TPUT_MODE_HT, + /** Very high throughput mode (11ac) */ + TPUT_MODE_VHT, + /** HE SU mode */ + TPUT_MODE_HE_SU, + /** HE ER SU mode */ + TPUT_MODE_HE_ER_SU, + /** HE TB mode */ + TPUT_MODE_HE_TB, + /** Highest throughput mode currently defined */ + TPUT_MODE_MAX +}; + +/** + * @brief This structure defines the Offloaded raw tx debug statistics. + * + */ +struct nrf_wifi_off_raw_tx_stats { + /** Number of packets sent */ + unsigned int off_raw_tx_pkt_sent; +}; + +/** + * @brief- Configuration parameters for offloaded raw TX + * Parameters which can be used to configure the offloaded raw TX operation. + */ +struct nrf_wifi_off_raw_tx_conf { + /** Time interval (in microseconds) between transmissions */ + unsigned int period_us; + /** Transmit power in dBm (0 to 20) */ + unsigned int tx_pwr; + /** Channel number on which to transmit */ + unsigned int chan; + /** Set to TRUE to use short preamble for FALSE to disable short preamble */ + bool short_preamble; + /* Number of times a packet should be retried at each possible rate */ + unsigned int num_retries; + /** Throughput mode for packet transmittion. Refer &enum nrf_wifi_off_raw_tx_tput_mode */ + enum nrf_wifi_off_raw_tx_tput_mode tput_mode; + /* Rate at which packet needs to be transmitted. Refer &enum nrf_wifi_off_raw_tx_rate */ + enum nrf_wifi_off_raw_tx_rate rate; + /** HE GI. Refer &enum nrf_wifi_off_raw_tx_he_gi */ + enum nrf_wifi_off_raw_tx_he_gi he_gi; + /** HE GI. Refer &enum nrf_wifi_off_raw_tx_he_ltf */ + enum nrf_wifi_off_raw_tx_he_ltf he_ltf; + /* Pointer to packet to be transmitted */ + void *pkt; + /** Packet length of the frame to be transmitted, (min 26 bytes and max 600 bytes) */ + unsigned int pkt_len; +}; + + +/** + * @brief Initialize the nRF70 for operating in the offloaded raw TX mode. + * @param mac_addr MAC address to be used for the nRF70 device. + * @param country_code Country code to be set for regularity domain. + * + * This function is initializes the nRF70 device for offloaded raw TX mode by: + * - Powering it up, + * - Downloading a firmware patch (if any). + * - Initializing the firmware to accept further commands + * + * The mac_addr parameter is used to set the MAC address of the nRF70 device. + * This address can be used to override the MAC addresses programmed in the OTP and + * the value configured (if any) in CONFIG_WIFI_FIXED_MAC_ADDRESS. + * The priority order in which the MAC address values for the nRF70 device are used is: + * - If mac_addr is provided, the MAC address is set to the value provided. + * - If CONFIG_WIFI_FIXED_MAC_ADDRESS is enabled, the MAC address uses the Kconfig value. + * - If none of the above are provided, the MAC address is set to the value programmed in the OTP. + * + * @retval 0 If the operation was successful. + * @retval -1 If the operation failed. + */ +int nrf70_off_raw_tx_init(uint8_t *mac_addr, unsigned char *country_code); + +/** + * @brief Initialize the nRF70 for operating in the offloaded raw TX mode. + * + * This function is deinitializes the nRF70 device. + * + */ +void nrf70_off_raw_tx_deinit(void); + +/** + * @brief Update the configured offloaded raw TX parameters. + * @param conf Configuration parameters to be updated for the offloaded raw TX operation. + * + * This function is used to update configured parameters for offloaded raw TX operation. + * This function should be used to when the parameters need to be updated during an ongoing + * raw TX operation without having to stop it. + * + * @retval 0 If the operation was successful. + * @retval -1 If the operation failed. + */ +int nrf70_off_raw_tx_conf_update(struct nrf_wifi_off_raw_tx_conf *conf); + +/** + * @brief Start the offloaded raw TX. + * @param conf Configuration parameters necessary for the offloaded raw TX operation. + * + * This function is used to start offloaded raw TX operation. When this function is invoked + * the nRF70 device will start transmitting frames as per the configuration specified by @p conf. + * + * @retval 0 If the operation was successful. + * @retval -1 If the operation failed. + */ +int nrf70_off_raw_tx_start(struct nrf_wifi_off_raw_tx_conf *conf); + +/** + * @brief Stop the offloaded raw TX. + * + * This function is used to stop offloaded raw TX operation. When this function is invoked + * the nRF70 device will stop transmitting frames. + * + * @retval 0 If the operation was successful. + * @retval -1 If the operation failed. + */ +int nrf70_off_raw_tx_stop(void); + +/** + * @brief Get the MAC address of the nRF70 device. + * @param mac_addr Buffer to store the MAC address. + * + * This function is used to get the MAC address of the nRF70 device. + * The MAC address is stored in the buffer pointed by mac_addr. + * The MAC address is expected to be a 6 byte value. + * + * @retval 0 If the operation was successful. + * @retval -1 If the operation failed. + */ +int nrf70_off_raw_tx_mac_addr_get(uint8_t *mac_addr); + +/** + * @brief Get statistics of the offloaded raw TX. + * @param off_raw_tx_stats Statistics of the offloaded raw TX operation. + * + * This function is used to get statistics of offloaded raw TX operation. When this function + * is invoked the nRF70 device will show statistics. + * + * @retval 0 If the operation was successful. + * @retval -1 If the operation failed. + */ +int nrf70_off_raw_tx_stats(struct nrf_wifi_off_raw_tx_stats *off_raw_tx_stats); +/** + * @} + */ +#endif /* INCLUDE_ZEPHYR_DRIVERS_OFF_RAW_TX_API_H_ */ diff --git a/include/zephyr/fs/zms.h b/include/zephyr/fs/zms.h index 1155319d7924..0f0fbb82cc94 100644 --- a/include/zephyr/fs/zms.h +++ b/include/zephyr/fs/zms.h @@ -1,14 +1,14 @@ -/* ZMS: Zephyr Memory Storage - * - * Copyright (c) 2024 BayLibre SAS +/* Copyright (c) 2024 BayLibre SAS * * SPDX-License-Identifier: Apache-2.0 + * + * ZMS: Zephyr Memory Storage */ #ifndef ZEPHYR_INCLUDE_FS_ZMS_H_ #define ZEPHYR_INCLUDE_FS_ZMS_H_ -#include #include +#include #include #include #include @@ -18,7 +18,6 @@ extern "C" { #endif /** - * @brief Zephyr Memory Storage (ZMS) * @defgroup zms Zephyr Memory Storage (ZMS) * @ingroup file_system_storage * @{ @@ -26,37 +25,34 @@ extern "C" { */ /** - * @brief Zephyr Memory Storage Data Structures - * @defgroup zms_data_structures Zephyr Memory Storage Data Structures + * @defgroup zms_data_structures ZMS data structures * @ingroup zms * @{ */ -/** - * @brief Zephyr Memory Storage File system structure - */ +/** Zephyr Memory Storage file system structure */ struct zms_fs { - /** File system offset in flash **/ + /** File system offset in flash */ off_t offset; - /** Allocation table entry write address. - * Addresses are stored as uint64_t: + /** Allocation Table Entry (ATE) write address. + * Addresses are stored as `uint64_t`: * - high 4 bytes correspond to the sector * - low 4 bytes are the offset in the sector */ uint64_t ate_wra; /** Data write address */ uint64_t data_wra; - /** Storage system is split into sectors, each sector size must be multiple of erase-blocks - * if the device has erase capabilities + /** Storage system is split into sectors. The sector size must be a multiple of + * `erase-block-size` if the device has erase capabilities */ uint32_t sector_size; /** Number of sectors in the file system */ uint32_t sector_count; - /** Current cycle counter of the active sector (pointed by ate_wra)*/ + /** Current cycle counter of the active sector (pointed to by `ate_wra`) */ uint8_t sector_cycle; /** Flag indicating if the file system is initialized */ bool ready; - /** Mutex */ + /** Mutex used to lock flash writes */ struct k_mutex zms_lock; /** Flash device runtime structure */ const struct device *flash_device; @@ -65,7 +61,7 @@ struct zms_fs { /** Size of an Allocation Table Entry */ size_t ate_size; #if CONFIG_ZMS_LOOKUP_CACHE - /** Lookup table used to cache ATE address of a written ID */ + /** Lookup table used to cache ATE addresses of written IDs */ uint64_t lookup_cache[CONFIG_ZMS_LOOKUP_CACHE_SIZE]; #endif }; @@ -75,78 +71,77 @@ struct zms_fs { */ /** - * @brief Zephyr Memory Storage APIs - * @defgroup zms_high_level_api Zephyr Memory Storage APIs + * @defgroup zms_high_level_api ZMS API * @ingroup zms * @{ */ /** - * @brief Mount a ZMS file system onto the device specified in @p fs. + * @brief Mount a ZMS file system onto the device specified in `fs`. * - * @param fs Pointer to file system + * @param fs Pointer to the file system. * @retval 0 Success - * @retval -ERRNO errno code if error + * @retval -ERRNO Negative errno code on error */ int zms_mount(struct zms_fs *fs); /** * @brief Clear the ZMS file system from device. * - * @param fs Pointer to file system + * @param fs Pointer to the file system. * @retval 0 Success - * @retval -ERRNO errno code if error + * @retval -ERRNO Negative errno code on error */ int zms_clear(struct zms_fs *fs); /** * @brief Write an entry to the file system. * - * @note When @p len parameter is equal to @p 0 then entry is effectively removed (it is - * equivalent to calling of zms_delete). It is not possible to distinguish between a deleted + * @note When the `len` parameter is equal to `0` the entry is effectively removed (it is + * equivalent to calling @ref zms_delete()). It is not possible to distinguish between a deleted * entry and an entry with data of length 0. * - * @param fs Pointer to file system - * @param id Id of the entry to be written + * @param fs Pointer to the file system. + * @param id ID of the entry to be written * @param data Pointer to the data to be written - * @param len Number of bytes to be written (maximum 64 KB) + * @param len Number of bytes to be written (maximum 64 KiB) * * @return Number of bytes written. On success, it will be equal to the number of bytes requested - * to be written. When a rewrite of the same data already stored is attempted, nothing is written - * to flash, thus 0 is returned. On error, returns negative value of errno.h defined error codes. + * to be written or 0. + * When a rewrite of the same data already stored is attempted, nothing is written to flash, + * thus 0 is returned. On error, returns negative value of error codes defined in `errno.h`. */ ssize_t zms_write(struct zms_fs *fs, uint32_t id, const void *data, size_t len); /** * @brief Delete an entry from the file system * - * @param fs Pointer to file system - * @param id Id of the entry to be deleted + * @param fs Pointer to the file system. + * @param id ID of the entry to be deleted * @retval 0 Success - * @retval -ERRNO errno code if error + * @retval -ERRNO Negative errno code on error */ int zms_delete(struct zms_fs *fs, uint32_t id); /** * @brief Read an entry from the file system. * - * @param fs Pointer to file system - * @param id Id of the entry to be read + * @param fs Pointer to the file system. + * @param id ID of the entry to be read * @param data Pointer to data buffer - * @param len Number of bytes to be read (or size of the allocated read buffer) + * @param len Number of bytes to read at most * * @return Number of bytes read. On success, it will be equal to the number of bytes requested - * to be read. When the return value is less than the number of bytes requested to read this - * indicates that ATE contain less data than requested. On error, returns negative value of - * errno.h defined error codes. + * to be read or less than that if the stored data has a smaller size than the requested one. + * On error, returns negative value of error codes defined in `errno.h`. */ ssize_t zms_read(struct zms_fs *fs, uint32_t id, void *data, size_t len); /** * @brief Read a history entry from the file system. * - * @param fs Pointer to file system - * @param id Id of the entry to be read + * @param fs Pointer to the file system. + * @param id ID of the entry to be read * @param data Pointer to data buffer * @param len Number of bytes to be read * @param cnt History counter: 0: latest entry, 1: one before latest ... @@ -154,40 +149,41 @@ ssize_t zms_read(struct zms_fs *fs, uint32_t id, void *data, size_t len); * @return Number of bytes read. On success, it will be equal to the number of bytes requested * to be read. When the return value is larger than the number of bytes requested to read this * indicates not all bytes were read, and more data is available. On error, returns negative - * value of errno.h defined error codes. + * value of error codes defined in `errno.h`. */ ssize_t zms_read_hist(struct zms_fs *fs, uint32_t id, void *data, size_t len, uint32_t cnt); /** - * @brief Gets the data size that is stored in an entry with a given id + * @brief Gets the length of the data that is stored in an entry with a given ID * - * @param fs Pointer to file system - * @param id Id of the entry that we want to get its data length + * @param fs Pointer to the file system. + * @param id ID of the entry whose data length to retrieve. * * @return Data length contained in the ATE. On success, it will be equal to the number of bytes - * in the ATE. On error, returns negative value of errno.h defined error codes. + * in the ATE. On error, returns negative value of error codes defined in `errno.h`. */ ssize_t zms_get_data_length(struct zms_fs *fs, uint32_t id); + /** * @brief Calculate the available free space in the file system. * - * @param fs Pointer to file system + * @param fs Pointer to the file system. * - * @return Number of bytes free. On success, it will be equal to the number of bytes that can + * @return Number of free bytes. On success, it will be equal to the number of bytes that can * still be written to the file system. - * Calculating the free space is a time consuming operation, especially on spi flash. - * On error, returns negative value of errno.h defined error codes. + * Calculating the free space is a time-consuming operation, especially on SPI flash. + * On error, returns negative value of error codes defined in `errno.h`. */ ssize_t zms_calc_free_space(struct zms_fs *fs); /** - * @brief Tell how many contiguous free space remains in the currently active ZMS sector. + * @brief Tell how much contiguous free space remains in the currently active ZMS sector. * * @param fs Pointer to the file system. * * @return Number of free bytes. */ -size_t zms_sector_max_data_size(struct zms_fs *fs); +size_t zms_active_sector_free_space(struct zms_fs *fs); /** * @brief Close the currently active sector and switch to the next one. @@ -195,12 +191,12 @@ size_t zms_sector_max_data_size(struct zms_fs *fs); * @note The garbage collector is called on the new sector. * * @warning This routine is made available for specific use cases. - * It collides with the ZMS goal of avoiding any unnecessary flash erase operations. + * It collides with ZMS's goal of avoiding any unnecessary flash erase operations. * Using this routine extensively can result in premature failure of the flash device. * * @param fs Pointer to the file system. * - * @return 0 on success. On error, returns negative value of errno.h defined error codes. + * @return 0 on success. On error, returns negative value of error codes defined in `errno.h`. */ int zms_sector_use_next(struct zms_fs *fs); diff --git a/include/zephyr/linker/linker-defs.h b/include/zephyr/linker/linker-defs.h index 5c1089c0fcfe..ff3cbe6ca6cf 100644 --- a/include/zephyr/linker/linker-defs.h +++ b/include/zephyr/linker/linker-defs.h @@ -32,6 +32,7 @@ */ #ifdef ZTEST_UNITTEST #define DT_NODE_HAS_STATUS(node, status) 0 +#define DT_NODE_HAS_STATUS_OKAY(node) 0 #else #include #endif @@ -159,7 +160,7 @@ extern char __gcov_bss_size[]; /* end address of image, used by newlib for the heap */ extern char _end[]; -#if (DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay)) +#if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ccm))) extern char __ccm_data_rom_start[]; extern char __ccm_start[]; extern char __ccm_data_start[]; @@ -171,14 +172,14 @@ extern char __ccm_noinit_end[]; extern char __ccm_end[]; #endif -#if (DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay)) +#if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_itcm))) extern char __itcm_start[]; extern char __itcm_end[]; extern char __itcm_size[]; extern char __itcm_load_start[]; #endif -#if (DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay)) +#if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm))) extern char __dtcm_data_start[]; extern char __dtcm_data_end[]; extern char __dtcm_bss_start[]; @@ -190,7 +191,7 @@ extern char __dtcm_start[]; extern char __dtcm_end[]; #endif -#if (DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ocm), okay)) +#if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ocm))) extern char __ocm_data_start[]; extern char __ocm_data_end[]; extern char __ocm_bss_start[]; diff --git a/include/zephyr/net/coap.h b/include/zephyr/net/coap.h index 11d2c3711f26..09df1e98f8a8 100644 --- a/include/zephyr/net/coap.h +++ b/include/zephyr/net/coap.h @@ -64,6 +64,7 @@ enum coap_option_num { COAP_OPTION_PROXY_SCHEME = 39, /**< Proxy-Scheme */ COAP_OPTION_SIZE1 = 60, /**< Size1 */ COAP_OPTION_ECHO = 252, /**< Echo (RFC 9175) */ + COAP_OPTION_NO_RESPONSE = 258, /**< No-Response (RFC 7967) */ COAP_OPTION_REQUEST_TAG = 292 /**< Request-Tag (RFC 9175) */ }; @@ -222,6 +223,22 @@ enum coap_content_format { COAP_CONTENT_FORMAT_APP_CBOR = 60 /**< application/cbor */ }; +/** + * @brief Set of No-Response option values for CoAP. + * + * To be used when encoding or decoding a No-Response option defined + * in RFC 7967. + */ +enum coap_no_response { + COAP_NO_RESPONSE_SUPPRESS_2_XX = 0x02, + COAP_NO_RESPONSE_SUPPRESS_4_XX = 0x08, + COAP_NO_RESPONSE_SUPPRESS_5_XX = 0x10, + + COAP_NO_RESPONSE_SUPPRESS_ALL = COAP_NO_RESPONSE_SUPPRESS_2_XX | + COAP_NO_RESPONSE_SUPPRESS_4_XX | + COAP_NO_RESPONSE_SUPPRESS_5_XX, +}; + /** @cond INTERNAL_HIDDEN */ /* block option helper */ @@ -338,8 +355,15 @@ typedef int (*coap_reply_t)(const struct coap_packet *response, * @brief CoAP transmission parameters. */ struct coap_transmission_parameters { - /** Initial ACK timeout. Value is used as a base value to retry pending CoAP packets. */ + /** Initial ACK timeout. Value is used as a base value to retry pending CoAP packets. */ uint32_t ack_timeout; +#if defined(CONFIG_COAP_RANDOMIZE_ACK_TIMEOUT) || defined(__DOXYGEN__) + /** + * Set CoAP ack random factor. A value of 150 means a factor of 1.5. A value of 0 defaults + * to @kconfig{CONFIG_COAP_ACK_RANDOM_PERCENT}. The value must be >= 100. + */ + uint16_t ack_random_percent; +#endif /* defined(CONFIG_COAP_RANDOMIZE_ACK_TIMEOUT) */ /** Set CoAP retry backoff factor. A value of 200 means a factor of 2.0. */ uint16_t coap_backoff_percent; /** Maximum number of retransmissions. */ @@ -528,6 +552,21 @@ int coap_packet_init(struct coap_packet *cpkt, uint8_t *data, uint16_t max_len, int coap_ack_init(struct coap_packet *cpkt, const struct coap_packet *req, uint8_t *data, uint16_t max_len, uint8_t code); +/** + * @brief Create a new CoAP Reset message for given request. + * + * This function works like @ref coap_packet_init, filling CoAP header type, + * and CoAP header message id fields. + * + * @param cpkt New packet to be initialized using the storage from @a data. + * @param req CoAP request packet that is being acknowledged + * @param data Data that will contain a CoAP packet information + * @param max_len Maximum allowable length of data + * + * @return 0 in case of success or negative in case of error. + */ +int coap_rst_init(struct coap_packet *cpkt, const struct coap_packet *req, + uint8_t *data, uint16_t max_len); /** * @brief Returns a randomly generated array of 8 bytes, that can be * used as a message's token. diff --git a/include/zephyr/net/coap_client.h b/include/zephyr/net/coap_client.h index a4f35374c93b..1d68661da3b0 100644 --- a/include/zephyr/net/coap_client.h +++ b/include/zephyr/net/coap_client.h @@ -88,7 +88,7 @@ struct coap_client_option { struct coap_client_internal_request { uint8_t request_token[COAP_TOKEN_MAX_LEN]; uint32_t offset; - uint32_t last_id; + uint16_t last_id; uint8_t request_tkl; bool request_ongoing; atomic_t in_callback; @@ -108,7 +108,6 @@ struct coap_client { int fd; struct sockaddr address; socklen_t socklen; - bool response_ready; struct k_mutex lock; uint8_t send_buf[MAX_COAP_MSG_LEN]; uint8_t recv_buf[MAX_COAP_MSG_LEN]; diff --git a/include/zephyr/net/coap_service.h b/include/zephyr/net/coap_service.h index 718d1fb1cfcd..f5bf3f8405b7 100644 --- a/include/zephyr/net/coap_service.h +++ b/include/zephyr/net/coap_service.h @@ -59,7 +59,7 @@ struct coap_service { }; #define __z_coap_service_define(_name, _host, _port, _flags, _res_begin, _res_end) \ - static struct coap_service_data coap_service_data_##_name = { \ + static struct coap_service_data _CONCAT(coap_service_data_, _name) = { \ .sock_fd = -1, \ }; \ const STRUCT_SECTION_ITERABLE(coap_service, _name) = { \ @@ -69,7 +69,7 @@ struct coap_service { .flags = _flags, \ .res_begin = (_res_begin), \ .res_end = (_res_end), \ - .data = &coap_service_data_##_name, \ + .data = &_CONCAT(coap_service_data_, _name), \ } /** @endcond */ @@ -111,8 +111,8 @@ struct coap_service { * @param _service Name of the associated service. */ #define COAP_RESOURCE_DEFINE(_name, _service, ...) \ - STRUCT_SECTION_ITERABLE_ALTERNATE(coap_resource_##_service, coap_resource, _name) \ - = __VA_ARGS__ + STRUCT_SECTION_ITERABLE_ALTERNATE(_CONCAT(coap_resource_, _service), coap_resource, \ + _name) = __VA_ARGS__ /** * @brief Define a CoAP service with static resources. @@ -132,11 +132,11 @@ struct coap_service { * @param _flags Configuration flags @see @ref COAP_SERVICE_FLAGS. */ #define COAP_SERVICE_DEFINE(_name, _host, _port, _flags) \ - extern struct coap_resource _CONCAT(_coap_resource_##_name, _list_start)[]; \ - extern struct coap_resource _CONCAT(_coap_resource_##_name, _list_end)[]; \ + extern struct coap_resource _CONCAT(_CONCAT(_coap_resource_, _name), _list_start)[]; \ + extern struct coap_resource _CONCAT(_CONCAT(_coap_resource_, _name), _list_end)[]; \ __z_coap_service_define(_name, _host, _port, _flags, \ - &_CONCAT(_coap_resource_##_name, _list_start)[0], \ - &_CONCAT(_coap_resource_##_name, _list_end)[0]) + &_CONCAT(_CONCAT(_coap_resource_, _name), _list_start)[0], \ + &_CONCAT(_CONCAT(_coap_resource_, _name), _list_end)[0]) /** * @brief Count the number of CoAP services. @@ -177,7 +177,7 @@ struct coap_service { * @param _it Name of iterator (of type @ref coap_resource) */ #define COAP_RESOURCE_FOREACH(_service, _it) \ - STRUCT_SECTION_FOREACH_ALTERNATE(coap_resource_##_service, coap_resource, _it) + STRUCT_SECTION_FOREACH_ALTERNATE(_CONCAT(coap_resource_, _service), coap_resource, _it) /** * @brief Iterate over all static resources associated with @p _service . diff --git a/include/zephyr/net/socket.h b/include/zephyr/net/socket.h index 34211d837599..05351c8cef02 100644 --- a/include/zephyr/net/socket.h +++ b/include/zephyr/net/socket.h @@ -333,13 +333,11 @@ __syscall void *zsock_get_context_object(int sock); * @brief Create a network socket * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html * for normative description. - * This function is also exposed as ``socket()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `socket()` + * if @kconfig{CONFIG_POSIX_API} is defined. * * If CONFIG_USERSPACE is enabled, the caller will be granted access to the * context object associated with the returned file descriptor. @@ -352,13 +350,11 @@ __syscall int zsock_socket(int family, int type, int proto); * @brief Create an unnamed pair of connected sockets * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * https://pubs.opengroup.org/onlinepubs/009695399/functions/socketpair.html * for normative description. - * This function is also exposed as ``socketpair()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `socketpair()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall int zsock_socketpair(int family, int type, int proto, int *sv); @@ -366,12 +362,10 @@ __syscall int zsock_socketpair(int family, int type, int proto, int *sv); * @brief Close a network socket * * @details - * @rst * Close a network socket. - * This function is also exposed as ``close()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined (in which case it - * may conflict with generic POSIX ``close()`` function). - * @endrst + * This function is also exposed as `close()` + * if @kconfig{CONFIG_POSIX_API} is defined (in which case it + * may conflict with generic POSIX `close()` function). */ __syscall int zsock_close(int sock); @@ -379,14 +373,12 @@ __syscall int zsock_close(int sock); * @brief Shutdown socket send/receive operations * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/shutdown.html * for normative description, but currently this function has no effect in * Zephyr and provided solely for compatibility with existing code. - * This function is also exposed as ``shutdown()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `shutdown()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall int zsock_shutdown(int sock, int how); @@ -394,13 +386,11 @@ __syscall int zsock_shutdown(int sock, int how); * @brief Bind a socket to a local network address * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html * for normative description. - * This function is also exposed as ``bind()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `bind()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall int zsock_bind(int sock, const struct sockaddr *addr, socklen_t addrlen); @@ -409,13 +399,11 @@ __syscall int zsock_bind(int sock, const struct sockaddr *addr, * @brief Connect a socket to a peer network address * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html * for normative description. - * This function is also exposed as ``connect()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `connect()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall int zsock_connect(int sock, const struct sockaddr *addr, socklen_t addrlen); @@ -424,13 +412,11 @@ __syscall int zsock_connect(int sock, const struct sockaddr *addr, * @brief Set up a STREAM socket to accept peer connections * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html * for normative description. - * This function is also exposed as ``listen()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `listen()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall int zsock_listen(int sock, int backlog); @@ -438,13 +424,11 @@ __syscall int zsock_listen(int sock, int backlog); * @brief Accept a connection on listening socket * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html * for normative description. - * This function is also exposed as ``accept()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `accept()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall int zsock_accept(int sock, struct sockaddr *addr, socklen_t *addrlen); @@ -452,13 +436,11 @@ __syscall int zsock_accept(int sock, struct sockaddr *addr, socklen_t *addrlen); * @brief Send data to an arbitrary network address * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html * for normative description. - * This function is also exposed as ``sendto()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `sendto()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall ssize_t zsock_sendto(int sock, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, @@ -468,13 +450,11 @@ __syscall ssize_t zsock_sendto(int sock, const void *buf, size_t len, * @brief Send data to a connected peer * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html * for normative description. - * This function is also exposed as ``send()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `send()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ static inline ssize_t zsock_send(int sock, const void *buf, size_t len, int flags) @@ -486,13 +466,11 @@ static inline ssize_t zsock_send(int sock, const void *buf, size_t len, * @brief Send data to an arbitrary network address * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html * for normative description. - * This function is also exposed as ``sendmsg()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `sendmsg()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall ssize_t zsock_sendmsg(int sock, const struct msghdr *msg, int flags); @@ -501,13 +479,11 @@ __syscall ssize_t zsock_sendmsg(int sock, const struct msghdr *msg, * @brief Receive data from an arbitrary network address * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html * for normative description. - * This function is also exposed as ``recvfrom()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `recvfrom()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall ssize_t zsock_recvfrom(int sock, void *buf, size_t max_len, int flags, struct sockaddr *src_addr, @@ -517,13 +493,11 @@ __syscall ssize_t zsock_recvfrom(int sock, void *buf, size_t max_len, * @brief Receive a message from an arbitrary network address * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html * for normative description. - * This function is also exposed as ``recvmsg()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `recvmsg()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall ssize_t zsock_recvmsg(int sock, struct msghdr *msg, int flags); @@ -531,13 +505,11 @@ __syscall ssize_t zsock_recvmsg(int sock, struct msghdr *msg, int flags); * @brief Receive data from a connected peer * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html * for normative description. - * This function is also exposed as ``recv()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `recv()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ static inline ssize_t zsock_recv(int sock, void *buf, size_t max_len, int flags) @@ -549,13 +521,11 @@ static inline ssize_t zsock_recv(int sock, void *buf, size_t max_len, * @brief Control blocking/non-blocking mode of a socket * * @details - * @rst * This functions allow to (only) configure a socket for blocking or * non-blocking operation (O_NONBLOCK). - * This function is also exposed as ``fcntl()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined (in which case - * it may conflict with generic POSIX ``fcntl()`` function). - * @endrst + * This function is also exposed as `fcntl()` + * if @kconfig{CONFIG_POSIX_API} is defined (in which case + * it may conflict with generic POSIX `fcntl()` function). */ __syscall int zsock_fcntl_impl(int sock, int cmd, int flags); @@ -584,18 +554,16 @@ static inline int zsock_fcntl_wrapper(int sock, int cmd, ...) * @brief Control underlying socket parameters * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * https://pubs.opengroup.org/onlinepubs/9699919799/functions/ioctl.html * for normative description. * This function enables querying or manipulating underlying socket parameters. - * Currently supported @p request values include ``ZFD_IOCTL_FIONBIO``, and - * ``ZFD_IOCTL_FIONREAD``, to set non-blocking mode, and query the number of + * Currently supported @p request values include `ZFD_IOCTL_FIONBIO`, and + * `ZFD_IOCTL_FIONREAD`, to set non-blocking mode, and query the number of * bytes available to read, respectively. - * This function is also exposed as ``ioctl()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined (in which case - * it may conflict with generic POSIX ``ioctl()`` function). - * @endrst + * This function is also exposed as `ioctl()` + * if @kconfig{CONFIG_POSIX_API} is defined (in which case + * it may conflict with generic POSIX `ioctl()` function). */ __syscall int zsock_ioctl_impl(int sock, unsigned long request, va_list ap); @@ -621,14 +589,12 @@ static inline int zsock_ioctl_wrapper(int sock, unsigned long request, ...) * @brief Efficiently poll multiple sockets for events * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html * for normative description. - * This function is also exposed as ``poll()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined (in which case - * it may conflict with generic POSIX ``poll()`` function). - * @endrst + * This function is also exposed as `poll()` + * if @kconfig{CONFIG_POSIX_API} is defined (in which case + * it may conflict with generic POSIX `poll()` function). */ __syscall int zsock_poll(struct zsock_pollfd *fds, int nfds, int timeout); @@ -636,16 +602,14 @@ __syscall int zsock_poll(struct zsock_pollfd *fds, int nfds, int timeout); * @brief Get various socket options * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html * for normative description. In Zephyr this function supports a subset of * socket options described by POSIX, but also some additional options * available in Linux (some options are dummy and provided to ease porting * of existing code). - * This function is also exposed as ``getsockopt()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `getsockopt()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall int zsock_getsockopt(int sock, int level, int optname, void *optval, socklen_t *optlen); @@ -654,16 +618,14 @@ __syscall int zsock_getsockopt(int sock, int level, int optname, * @brief Set various socket options * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html * for normative description. In Zephyr this function supports a subset of * socket options described by POSIX, but also some additional options * available in Linux (some options are dummy and provided to ease porting * of existing code). - * This function is also exposed as ``setsockopt()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `setsockopt()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall int zsock_setsockopt(int sock, int level, int optname, const void *optval, socklen_t optlen); @@ -672,13 +634,11 @@ __syscall int zsock_setsockopt(int sock, int level, int optname, * @brief Get peer name * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html * for normative description. - * This function is also exposed as ``getpeername()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `getpeername()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall int zsock_getpeername(int sock, struct sockaddr *addr, socklen_t *addrlen); @@ -687,13 +647,11 @@ __syscall int zsock_getpeername(int sock, struct sockaddr *addr, * @brief Get socket name * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html * for normative description. - * This function is also exposed as ``getsockname()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `getsockname()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall int zsock_getsockname(int sock, struct sockaddr *addr, socklen_t *addrlen); @@ -702,13 +660,11 @@ __syscall int zsock_getsockname(int sock, struct sockaddr *addr, * @brief Get local host name * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/gethostname.html * for normative description. - * This function is also exposed as ``gethostname()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `gethostname()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall int zsock_gethostname(char *buf, size_t len); @@ -716,13 +672,11 @@ __syscall int zsock_gethostname(char *buf, size_t len); * @brief Convert network address from internal to numeric ASCII form * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_ntop.html * for normative description. - * This function is also exposed as ``inet_ntop()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `inet_ntop()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ static inline char *zsock_inet_ntop(sa_family_t family, const void *src, char *dst, size_t size) @@ -734,13 +688,11 @@ static inline char *zsock_inet_ntop(sa_family_t family, const void *src, * @brief Convert network address from numeric ASCII form to internal representation * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_pton.html * for normative description. - * This function is also exposed as ``inet_pton()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `inet_pton()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ __syscall int zsock_inet_pton(sa_family_t family, const char *src, void *dst); @@ -779,13 +731,11 @@ __syscall int z_zsock_getaddrinfo_internal(const char *host, * @brief Resolve a domain name to one or more network addresses * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html * for normative description. - * This function is also exposed as ``getaddrinfo()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `getaddrinfo()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ int zsock_getaddrinfo(const char *host, const char *service, const struct zsock_addrinfo *hints, @@ -795,13 +745,11 @@ int zsock_getaddrinfo(const char *host, const char *service, * @brief Free results returned by zsock_getaddrinfo() * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/freeaddrinfo.html * for normative description. - * This function is also exposed as ``freeaddrinfo()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `freeaddrinfo()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ void zsock_freeaddrinfo(struct zsock_addrinfo *ai); @@ -809,13 +757,11 @@ void zsock_freeaddrinfo(struct zsock_addrinfo *ai); * @brief Convert zsock_getaddrinfo() error code to textual message * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/gai_strerror.html * for normative description. - * This function is also exposed as ``gai_strerror()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `gai_strerror()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ const char *zsock_gai_strerror(int errcode); @@ -846,13 +792,11 @@ const char *zsock_gai_strerror(int errcode); * @brief Resolve a network address to a domain name or ASCII address * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/getnameinfo.html * for normative description. - * This function is also exposed as ``getnameinfo()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `getnameinfo()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ int zsock_getnameinfo(const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen, diff --git a/include/zephyr/net/socket_select.h b/include/zephyr/net/socket_select.h index 5fca2950d6a5..b0754d5fc864 100644 --- a/include/zephyr/net/socket_select.h +++ b/include/zephyr/net/socket_select.h @@ -35,17 +35,15 @@ typedef struct zsock_fd_set { * @brief Legacy function to poll multiple sockets for events * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html * for normative description. This function is provided to ease porting of * existing code and not recommended for usage due to its inefficiency, * use zsock_poll() instead. In Zephyr this function works only with * sockets, not arbitrary file descriptors. - * This function is also exposed as ``select()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined (in which case - * it may conflict with generic POSIX ``select()`` function). - * @endrst + * This function is also exposed as `select()` + * if @kconfig{CONFIG_POSIX_API} is defined (in which case + * it may conflict with generic POSIX `select()` function). */ __syscall int zsock_select(int nfds, zsock_fd_set *readfds, zsock_fd_set *writefds, @@ -59,13 +57,11 @@ __syscall int zsock_select(int nfds, zsock_fd_set *readfds, * @brief Initialize (clear) fd_set * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html * for normative description. - * This function is also exposed as ``FD_ZERO()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `FD_ZERO()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ void ZSOCK_FD_ZERO(zsock_fd_set *set); @@ -73,13 +69,11 @@ void ZSOCK_FD_ZERO(zsock_fd_set *set); * @brief Check whether socket is a member of fd_set * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html * for normative description. - * This function is also exposed as ``FD_ISSET()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `FD_ISSET()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ int ZSOCK_FD_ISSET(int fd, zsock_fd_set *set); @@ -87,13 +81,11 @@ int ZSOCK_FD_ISSET(int fd, zsock_fd_set *set); * @brief Remove socket from fd_set * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html * for normative description. - * This function is also exposed as ``FD_CLR()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `FD_CLR()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ void ZSOCK_FD_CLR(int fd, zsock_fd_set *set); @@ -101,13 +93,11 @@ void ZSOCK_FD_CLR(int fd, zsock_fd_set *set); * @brief Add socket to fd_set * * @details - * @rst - * See `POSIX.1-2017 article - * `__ + * See POSIX.1-2017 article + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html * for normative description. - * This function is also exposed as ``FD_SET()`` - * if :kconfig:option:`CONFIG_POSIX_API` is defined. - * @endrst + * This function is also exposed as `FD_SET()` + * if @kconfig{CONFIG_POSIX_API} is defined. */ void ZSOCK_FD_SET(int fd, zsock_fd_set *set); diff --git a/include/zephyr/net/wifi.h b/include/zephyr/net/wifi.h index f8a2645f558b..36a62f02cade 100644 --- a/include/zephyr/net/wifi.h +++ b/include/zephyr/net/wifi.h @@ -68,6 +68,16 @@ enum wifi_security_type { WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL, /** DPP security */ WIFI_SECURITY_TYPE_DPP, + /** EAP PEAP MSCHAPV2 security - Enterprise. */ + WIFI_SECURITY_TYPE_EAP_PEAP_MSCHAPV2, + /** EAP PEAP GTC security - Enterprise. */ + WIFI_SECURITY_TYPE_EAP_PEAP_GTC, + /** EAP TTLS MSCHAPV2 security - Enterprise. */ + WIFI_SECURITY_TYPE_EAP_TTLS_MSCHAPV2, + /** EAP PEAP security - Enterprise. */ + WIFI_SECURITY_TYPE_EAP_PEAP_TLS, + /** EAP TLS SHA256 security - Enterprise. */ + WIFI_SECURITY_TYPE_EAP_TLS_SHA256, /** @cond INTERNAL_HIDDEN */ __WIFI_SECURITY_TYPE_AFTER_LAST, @@ -76,6 +86,91 @@ enum wifi_security_type { /** @endcond */ }; +/** @brief EPA method Types. */ +enum wifi_eap_type { + /** No EPA security. */ + WIFI_EAP_TYPE_NONE = 0, + /** EPA GTC security, refer to rfc3748 chapter 5. */ + WIFI_EAP_TYPE_GTC = 6, + /** EPA TLS security, refer to rfc5216. */ + WIFI_EAP_TYPE_TLS = 13, + /** EPA TTLS security, refer to rfc5281. */ + WIFI_EAP_TYPE_TTLS = 21, + /** EPA PEAP security, refer to draft-josefsson-pppext-eap-tls-eap-06.txt. */ + WIFI_EAP_TYPE_PEAP = 25, + /** EPA MSCHAPV2 security, refer to draft-kamath-pppext-eap-mschapv2-00.txt. */ + WIFI_EAP_TYPE_MSCHAPV2 = 26, +}; + +/** @brief Enterprise security WPA3 suiteb types. */ +enum wifi_suiteb_type { + /** suiteb. */ + WIFI_SUITEB = 1, + /** suiteb-192. */ + WIFI_SUITEB_192, +}; + +/** @brief Group cipher and pairwise cipher types. */ +enum wifi_cipher_type { + /** AES in counter mode with CBC-MAC (CCMP-128). */ + WPA_CAPA_ENC_CCMP, + /** 128-bit Galois/Counter Mode Protocol. */ + WPA_CAPA_ENC_GCMP, + /** 256-bit Galois/Counter Mode Protocol. */ + WPA_CAPA_ENC_GCMP_256, +}; + +/** @brief group mgmt cipher types. */ +enum wifi_group_mgmt_cipher_type { + /** 128-bit Broadcast/Multicast Integrity Protocol + * Cipher-based Message Authentication Code . + */ + WPA_CAPA_ENC_BIP, + /** 128-bit Broadcast/Multicast Integrity Protocol + * Galois Message Authentication Code . + */ + WPA_CAPA_ENC_BIP_GMAC_128, + /** 256-bit Broadcast/Multicast Integrity Protocol + * Galois Message Authentication Code . + */ + WPA_CAPA_ENC_BIP_GMAC_256, +}; + +struct wifi_cipher_desc { + /** Cipher capability. */ + unsigned int capa; + /** Cipher name string. */ + char *name; +}; + +struct wifi_eap_cipher_config { + /** Key management type string. */ + char *key_mgmt; + /** OpenSSL cipher string. */ + char *openssl_ciphers; + /** Group cipher cipher string. */ + char *group_cipher; + /** Pairwise_cipher cipher string. */ + char *pairwise_cipher; + /** Group management cipher string. */ + char *group_mgmt_cipher; + /** Used to confiure TLS features. */ + char *tls_flags; +}; + +struct wifi_eap_config { + /** Security type. */ + unsigned int type; + /** EPA method type of phase1. */ + enum wifi_eap_type eap_type_phase1; + /** EPA method type of phase2. */ + enum wifi_eap_type eap_type_phase2; + /** EPA method string. */ + char *method; + /** Phase2 setting string. */ + char *phase2; +}; + /** Helper function to get user-friendly security type name. */ const char *wifi_security_txt(enum wifi_security_type security); @@ -450,6 +545,8 @@ enum wifi_ps_param_type { WIFI_PS_PARAM_WAKEUP_MODE, /** Power save mode. */ WIFI_PS_PARAM_MODE, + /** Power save exit strategy. */ + WIFI_PS_PARAM_EXIT_STRATEGY, /** Power save timeout. */ WIFI_PS_PARAM_TIMEOUT, }; @@ -465,6 +562,24 @@ enum wifi_ps_wakeup_mode { /** Helper function to get user-friendly ps wakeup mode name. */ const char *wifi_ps_wakeup_mode_txt(enum wifi_ps_wakeup_mode ps_wakeup_mode); +/** + * @brief Wi-Fi power save exit strategy + */ +enum wifi_ps_exit_strategy { + /** PS-Poll frame based */ + WIFI_PS_EXIT_CUSTOM_ALGO = 0, + /** QoS NULL frame based */ + WIFI_PS_EXIT_EVERY_TIM, + +/** @cond INTERNAL_HIDDEN */ + WIFI_PS_EXIT_LAST, + WIFI_PS_EXIT_MAX = WIFI_PS_EXIT_LAST - 1, +/** @endcond */ +}; + +/** Helper function to get user-friendly ps exit strategy name. */ +const char * const wifi_ps_exit_strategy_txt(enum wifi_ps_exit_strategy ps_exit_strategy); + /** @brief Wi-Fi power save error codes. */ enum wifi_config_ps_param_fail_reason { /** Unspecified error */ @@ -481,6 +596,8 @@ enum wifi_config_ps_param_fail_reason { WIFI_PS_PARAM_FAIL_DEVICE_CONNECTED, /** Listen interval out of range */ WIFI_PS_PARAM_LISTEN_INTERVAL_RANGE_INVALID, + /** Invalid exit strategy */ + WIFI_PS_PARAM_FAIL_INVALID_EXIT_STRATEGY, }; /** @cond INTERNAL_HIDDEN */ diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 899cb2f095bd..c67cab30a0e0 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -106,7 +106,9 @@ enum net_request_wifi_cmd { NET_REQUEST_WIFI_CMD_ENTERPRISE_CREDS, /** Get RTS threshold */ NET_REQUEST_WIFI_CMD_RTS_THRESHOLD_CONFIG, -/** @cond INTERNAL_HIDDEN */ + /** WPS config */ + NET_REQUEST_WIFI_CMD_WPS_CONFIG, + /** @cond INTERNAL_HIDDEN */ NET_REQUEST_WIFI_CMD_MAX /** @endcond */ }; @@ -252,6 +254,10 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_ENTERPRISE_CREDS); NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_RTS_THRESHOLD_CONFIG); +#define NET_REQUEST_WIFI_WPS_CONFIG (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_WPS_CONFIG) + +NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_WPS_CONFIG); + /** @brief Wi-Fi management events */ enum net_event_wifi_cmd { /** Scan results available */ @@ -282,6 +288,8 @@ enum net_event_wifi_cmd { NET_EVENT_WIFI_CMD_AP_STA_CONNECTED, /** STA disconnected from AP */ NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED, + /** Supplicant specific event */ + NET_EVENT_WIFI_CMD_SUPPLICANT, }; /** Event emitted for Wi-Fi scan result */ @@ -458,12 +466,28 @@ struct wifi_connect_req_params { int timeout; /** anonymous identity */ const uint8_t *anon_id; - /** anon_id length */ - uint8_t aid_length; /* Max 64 */ + /** anon_id length, max 64 */ + uint8_t aid_length; /** Private key passwd for enterprise mode */ const uint8_t *key_passwd; - /** Private key passwd length */ - uint8_t key_passwd_length; /* Max 128 */ + /** Private key passwd length, max 128 */ + uint8_t key_passwd_length; + /** private key2 passwd */ + const uint8_t *key2_passwd; + /** key2 passwd length, max 128 */ + uint8_t key2_passwd_length; + /** suiteb or suiteb-192 */ + uint8_t suiteb_type; + /** eap version */ + uint8_t eap_ver; + /** Identity for EAP */ + const uint8_t *eap_identity; + /** eap identity length, max 64 */ + uint8_t eap_id_length; + /** Password string for EAP. */ + const uint8_t *eap_password; + /** eap passwd length, max 128 */ + uint8_t eap_passwd_length; }; /** @brief Wi-Fi connect result codes. To be overlaid on top of \ref wifi_status @@ -602,6 +626,8 @@ struct wifi_ps_params { enum wifi_ps_param_type type; /** Wi-Fi power save fail reason */ enum wifi_config_ps_param_fail_reason fail_reason; + /** Wi-Fi power save exit strategy */ + enum wifi_ps_exit_strategy exit_strategy; }; /** @brief Wi-Fi TWT parameters */ @@ -701,6 +727,18 @@ struct wifi_enterprise_creds_params { uint8_t *client_key; /** Client key length */ uint32_t client_key_len; + /** CA certification of phase2*/ + uint8_t *ca_cert2; + /** Phase2 CA certification length */ + uint32_t ca_cert2_len; + /** Client certification of phase2*/ + uint8_t *client_cert2; + /** Phase2 Client certification length */ + uint32_t client_cert2_len; + /** Client key of phase2*/ + uint8_t *client_key2; + /** Phase2 Client key length */ + uint32_t client_key2_len; }; /** @brief Wi-Fi power save configuration */ @@ -939,6 +977,76 @@ enum wifi_dpp_bootstrap_type { WIFI_DPP_BOOTSTRAP_TYPE_NFC_URI }; +/** Params to add DPP configurator */ +struct wifi_dpp_configurator_add_params { + /** ECP curves for private key */ + int curve; + /** ECP curves for net access key */ + int net_access_key_curve; +}; + +/** Params to initiate a DPP auth procedure */ +struct wifi_dpp_auth_init_params { + /** Peer bootstrap id */ + int peer; + /** Configuration parameter id */ + int configurator; + /** Role configurator or enrollee */ + int role; + /** Security type */ + int conf; + /** SSID in string */ + char ssid[WIFI_SSID_MAX_LEN + 1]; +}; + +/** Params to do DPP chirp */ +struct wifi_dpp_chirp_params { + /** Own bootstrap id */ + int id; + /** Chirp on frequency */ + int freq; +}; + +/** Params to do DPP listen */ +struct wifi_dpp_listen_params { + /** Listen on frequency */ + int freq; + /** Role configurator or enrollee */ + int role; +}; + +/** Params to generate a DPP bootstrap */ +struct wifi_dpp_bootstrap_gen_params { + /** Bootstrap type */ + int type; + /** Own operating class */ + int op_class; + /** Own working channel */ + int chan; + /** ECP curves */ + int curve; + /** Own mac address */ + uint8_t mac[WIFI_MAC_ADDR_LEN]; +}; + +/** Params to set specific DPP configurator */ +struct wifi_dpp_configurator_set_params { + /** Peer bootstrap id */ + int peer; + /** Configuration parameter id */ + int configurator; + /** Role configurator or enrollee */ + int role; + /** Security type */ + int conf; + /** ECP curves for private key */ + int curve; + /** ECP curves for net access key */ + int net_access_key_curve; + /** Own mac address */ + char ssid[WIFI_SSID_MAX_LEN + 1]; +}; + /** Wi-Fi DPP params for various operations */ struct wifi_dpp_params { @@ -946,69 +1054,17 @@ struct wifi_dpp_params { int action; union { /** Params to add DPP configurator */ - struct wifi_dpp_configurator_add_params { - /** ECP curves for private key */ - int curve; - /** ECP curves for net access key */ - int net_access_key_curve; - } configurator_add; + struct wifi_dpp_configurator_add_params configurator_add; /** Params to initiate a DPP auth procedure */ - struct wifi_dpp_auth_init_params { - /** Peer bootstrap id */ - int peer; - /** Configuration parameter id */ - int configurator; - /** Role configurator or enrollee */ - int role; - /** Security type */ - int conf; - /** SSID in string */ - char ssid[WIFI_SSID_MAX_LEN + 1]; - } auth_init; + struct wifi_dpp_auth_init_params auth_init; /** Params to do DPP chirp */ - struct wifi_dpp_chirp_params { - /** Own bootstrap id */ - int id; - /** Chirp on frequency */ - int freq; - } chirp; + struct wifi_dpp_chirp_params chirp; /** Params to do DPP listen */ - struct wifi_dpp_listen_params { - /** Listen on frequency */ - int freq; - /** Role configurator or enrollee */ - int role; - } listen; + struct wifi_dpp_listen_params listen; /** Params to generate a DPP bootstrap */ - struct wifi_dpp_bootstrap_gen_params { - /** Bootstrap type */ - int type; - /** Own operating class */ - int op_class; - /** Own working channel */ - int chan; - /** ECP curves */ - int curve; - /** Own mac address */ - uint8_t mac[WIFI_MAC_ADDR_LEN]; - } bootstrap_gen; + struct wifi_dpp_bootstrap_gen_params bootstrap_gen; /** Params to set specific DPP configurator */ - struct wifi_dpp_configurator_set_params { - /** Peer bootstrap id */ - int peer; - /** Configuration parameter id */ - int configurator; - /** Role configurator or enrollee */ - int role; - /** Security type */ - int conf; - /** ECP curves for private key */ - int curve; - /** ECP curves for net access key */ - int net_access_key_curve; - /** Own mac address */ - char ssid[WIFI_SSID_MAX_LEN + 1]; - } configurator_set; + struct wifi_dpp_configurator_set_params configurator_set; /** Bootstrap get uri id */ int id; /** Timeout for DPP frame response rx */ @@ -1024,9 +1080,40 @@ struct wifi_dpp_params { char resp[WIFI_DPP_QRCODE_MAX_LEN + 1]; }; }; - #endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ +#define WIFI_WPS_PIN_MAX_LEN 8 + +/** Operation for WPS */ +enum wifi_wps_op { + /** WPS pbc */ + WIFI_WPS_PBC = 0, + /** Get WPS pin number */ + WIFI_WPS_PIN_GET = 1, + /** Set WPS pin number */ + WIFI_WPS_PIN_SET = 2, +}; + +/** Wi-Fi wps setup */ +struct wifi_wps_config_params { + /** wps operation */ + enum wifi_wps_op oper; + /** pin value*/ + char pin[WIFI_WPS_PIN_MAX_LEN + 1]; +}; + +/** Wi-Fi AP status + */ +enum wifi_hostapd_iface_state { + WIFI_HAPD_IFACE_UNINITIALIZED, + WIFI_HAPD_IFACE_DISABLED, + WIFI_HAPD_IFACE_COUNTRY_UPDATE, + WIFI_HAPD_IFACE_ACS, + WIFI_HAPD_IFACE_HT_SCAN, + WIFI_HAPD_IFACE_DFS, + WIFI_HAPD_IFACE_ENABLED +}; + #include /** Scan result callback @@ -1270,6 +1357,14 @@ struct wifi_mgmt_ops { * @return 0 if ok, < 0 if error */ int (*get_rts_threshold)(const struct device *dev, unsigned int *rts_threshold); + /** Start a WPS PBC/PIN connection + * + * @param dev Pointer to the device structure for the driver instance + * @param params wps operarion parameters + * + * @return 0 if ok, < 0 if error + */ + int (*wps_config)(const struct device *dev, struct wifi_wps_config_params *params); }; /** Wi-Fi management offload API */ diff --git a/include/zephyr/pm/policy.h b/include/zephyr/pm/policy.h index caba887805a5..e1e910f3e0a5 100644 --- a/include/zephyr/pm/policy.h +++ b/include/zephyr/pm/policy.h @@ -137,49 +137,6 @@ void pm_policy_state_lock_put(enum pm_state state, uint8_t substate_id); */ bool pm_policy_state_lock_is_active(enum pm_state state, uint8_t substate_id); -/** - * @brief Add a new latency requirement. - * - * The system will not enter any power state that would make the system to - * exceed the given latency value. - * - * @param req Latency request. - * @param value_us Maximum allowed latency in microseconds. - */ -void pm_policy_latency_request_add(struct pm_policy_latency_request *req, - uint32_t value_us); - -/** - * @brief Update a latency requirement. - * - * @param req Latency request. - * @param value_us New maximum allowed latency in microseconds. - */ -void pm_policy_latency_request_update(struct pm_policy_latency_request *req, - uint32_t value_us); - -/** - * @brief Remove a latency requirement. - * - * @param req Latency request. - */ -void pm_policy_latency_request_remove(struct pm_policy_latency_request *req); - -/** - * @brief Subscribe to maximum latency changes. - * - * @param req Subscription request. - * @param cb Callback function (NULL to disable). - */ -void pm_policy_latency_changed_subscribe(struct pm_policy_latency_subscription *req, - pm_policy_latency_changed_cb_t cb); - -/** - * @brief Unsubscribe to maximum latency changes. - * - * @param req Subscription request. - */ -void pm_policy_latency_changed_unsubscribe(struct pm_policy_latency_subscription *req); /** * @brief Register an event. @@ -277,26 +234,6 @@ static inline bool pm_policy_state_lock_is_active(enum pm_state state, uint8_t s return false; } -static inline void pm_policy_latency_request_add( - struct pm_policy_latency_request *req, uint32_t value_us) -{ - ARG_UNUSED(req); - ARG_UNUSED(value_us); -} - -static inline void pm_policy_latency_request_update( - struct pm_policy_latency_request *req, uint32_t value_us) -{ - ARG_UNUSED(req); - ARG_UNUSED(value_us); -} - -static inline void pm_policy_latency_request_remove( - struct pm_policy_latency_request *req) -{ - ARG_UNUSED(req); -} - static inline void pm_policy_event_register(struct pm_policy_event *evt, uint32_t cycle) { ARG_UNUSED(evt); @@ -331,6 +268,72 @@ static inline int32_t pm_policy_next_event_ticks(void) #endif /* CONFIG_PM */ +#if defined(CONFIG_PM) || defined(CONFIG_PM_POLICY_LATENCY_STANDALONE) || defined(__DOXYGEN__) +/** + * @brief Add a new latency requirement. + * + * The system will not enter any power state that would make the system to + * exceed the given latency value. + * + * @param req Latency request. + * @param value_us Maximum allowed latency in microseconds. + */ +void pm_policy_latency_request_add(struct pm_policy_latency_request *req, + uint32_t value_us); + +/** + * @brief Update a latency requirement. + * + * @param req Latency request. + * @param value_us New maximum allowed latency in microseconds. + */ +void pm_policy_latency_request_update(struct pm_policy_latency_request *req, + uint32_t value_us); + +/** + * @brief Remove a latency requirement. + * + * @param req Latency request. + */ +void pm_policy_latency_request_remove(struct pm_policy_latency_request *req); + +/** + * @brief Subscribe to maximum latency changes. + * + * @param req Subscription request. + * @param cb Callback function (NULL to disable). + */ +void pm_policy_latency_changed_subscribe(struct pm_policy_latency_subscription *req, + pm_policy_latency_changed_cb_t cb); + +/** + * @brief Unsubscribe to maximum latency changes. + * + * @param req Subscription request. + */ +void pm_policy_latency_changed_unsubscribe(struct pm_policy_latency_subscription *req); +#else +static inline void pm_policy_latency_request_add( + struct pm_policy_latency_request *req, uint32_t value_us) +{ + ARG_UNUSED(req); + ARG_UNUSED(value_us); +} + +static inline void pm_policy_latency_request_update( + struct pm_policy_latency_request *req, uint32_t value_us) +{ + ARG_UNUSED(req); + ARG_UNUSED(value_us); +} + +static inline void pm_policy_latency_request_remove( + struct pm_policy_latency_request *req) +{ + ARG_UNUSED(req); +} +#endif /* CONFIG_PM CONFIG_PM_POLICY_LATENCY_STANDALONE */ + /** * @} */ diff --git a/include/zephyr/pm/state.h b/include/zephyr/pm/state.h index 87363ea27d2e..6590b90c385e 100644 --- a/include/zephyr/pm/state.h +++ b/include/zephyr/pm/state.h @@ -194,7 +194,7 @@ struct pm_state_constraint { * @param idx Index within the array. */ #define Z_DT_PHANDLE_01(node_id, prop, idx) \ - COND_CODE_1(DT_NODE_HAS_STATUS(DT_PHANDLE_BY_IDX(node_id, prop, idx), okay), \ + COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_PHANDLE_BY_IDX(node_id, prop, idx)), \ (1), (0)) /** @@ -207,7 +207,7 @@ struct pm_state_constraint { * @param node_id A node identifier with compatible zephyr,power-state */ #define Z_PM_STATE_INFO_FROM_DT_CPU(i, node_id) \ - COND_CODE_1(DT_NODE_HAS_STATUS(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i), okay), \ + COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)), \ (PM_STATE_INFO_DT_INIT(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)),), ()) /** @@ -220,7 +220,7 @@ struct pm_state_constraint { * @param node_id A node identifier with compatible zephyr,power-state */ #define Z_PM_STATE_FROM_DT_CPU(i, node_id) \ - COND_CODE_1(DT_NODE_HAS_STATUS(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i), okay), \ + COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)), \ (PM_STATE_DT_INIT(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)),), ()) /** @endcond */ diff --git a/kernel/init.c b/kernel/init.c index 1c24c5fc2b25..cd361e749361 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -226,17 +226,17 @@ void z_bss_zero(void) } z_early_memset(__bss_start, 0, __bss_end - __bss_start); -#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ccm)) z_early_memset(&__ccm_bss_start, 0, (uintptr_t) &__ccm_bss_end - (uintptr_t) &__ccm_bss_start); #endif -#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)) z_early_memset(&__dtcm_bss_start, 0, (uintptr_t) &__dtcm_bss_end - (uintptr_t) &__dtcm_bss_start); #endif -#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ocm), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ocm)) z_early_memset(&__ocm_bss_start, 0, (uintptr_t) &__ocm_bss_end - (uintptr_t) &__ocm_bss_start); diff --git a/kernel/xip.c b/kernel/xip.c index a5752560c853..34e92ef18444 100644 --- a/kernel/xip.c +++ b/kernel/xip.c @@ -31,15 +31,15 @@ void z_data_copy(void) z_early_memcpy(&__ramfunc_start, &__ramfunc_load_start, (uintptr_t) &__ramfunc_size); #endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */ -#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ccm)) z_early_memcpy(&__ccm_data_start, &__ccm_data_rom_start, __ccm_data_end - __ccm_data_start); #endif -#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_itcm)) z_early_memcpy(&__itcm_start, &__itcm_load_start, (uintptr_t) &__itcm_size); #endif -#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)) z_early_memcpy(&__dtcm_data_start, &__dtcm_data_load_start, __dtcm_data_end - __dtcm_data_start); #endif diff --git a/modules/hal_nordic/CMakeLists.txt b/modules/hal_nordic/CMakeLists.txt index eb85fd58f5e1..3bed5a033b59 100644 --- a/modules/hal_nordic/CMakeLists.txt +++ b/modules/hal_nordic/CMakeLists.txt @@ -15,7 +15,7 @@ if(CONFIG_NRF_REGTOOL_GENERATE_BICR) list(APPEND nrf_regtool_components GENERATE:BICR) endif() if(DEFINED nrf_regtool_components) - find_package(nrf-regtool 5.6.0 REQUIRED + find_package(nrf-regtool 7.0.0 REQUIRED COMPONENTS ${nrf_regtool_components} PATHS ${CMAKE_CURRENT_LIST_DIR}/nrf-regtool NO_CMAKE_PATH diff --git a/modules/hal_nordic/Kconfig b/modules/hal_nordic/Kconfig index dd4e0a0859b1..9d54c15d7159 100644 --- a/modules/hal_nordic/Kconfig +++ b/modules/hal_nordic/Kconfig @@ -55,7 +55,7 @@ endchoice config NRF_802154_TEMPERATURE_UPDATE bool "nRF 802.15.4 temperature update" - default y if !SOC_NRF54H20 + default y if !SOC_NRF54H20 && !SOC_NRF54H20_ENGB help Enable temperature update for nRF 802.15.4 driver diff --git a/modules/hal_nordic/nrfs/CMakeLists.txt b/modules/hal_nordic/nrfs/CMakeLists.txt index c601b8a4233c..f470eea00e9f 100644 --- a/modules/hal_nordic/nrfs/CMakeLists.txt +++ b/modules/hal_nordic/nrfs/CMakeLists.txt @@ -25,6 +25,7 @@ if(CONFIG_NRFS) zephyr_library_sources_ifdef(CONFIG_NRFS_CLOCK_SERVICE_ENABLED ${SRC_DIR}/services/nrfs_clock.c) zephyr_library_sources_ifdef(CONFIG_NRFS_DIAG_SERVICE_ENABLED ${SRC_DIR}/services/nrfs_diag.c) zephyr_library_sources_ifdef(CONFIG_NRFS_DVFS_SERVICE_ENABLED ${SRC_DIR}/services/nrfs_dvfs.c) + zephyr_library_sources_ifdef(CONFIG_NRFS_GDPWR_SERVICE_ENABLED ${SRC_DIR}/services/nrfs_gdpwr.c) zephyr_library_sources_ifdef(CONFIG_NRFS_MRAM_SERVICE_ENABLED ${SRC_DIR}/services/nrfs_mram.c) zephyr_library_sources_ifdef(CONFIG_NRFS_PMIC_SERVICE_ENABLED ${SRC_DIR}/services/nrfs_pmic.c) zephyr_library_sources_ifdef(CONFIG_NRFS_RESET_SERVICE_ENABLED ${SRC_DIR}/services/nrfs_reset.c) diff --git a/modules/hal_nordic/nrfs/Kconfig b/modules/hal_nordic/nrfs/Kconfig index cf7c9be939be..8325c8db3bc2 100644 --- a/modules/hal_nordic/nrfs/Kconfig +++ b/modules/hal_nordic/nrfs/Kconfig @@ -19,6 +19,9 @@ config NRFS_HAS_DIAG_SERVICE config NRFS_HAS_DVFS_SERVICE bool +config NRFS_HAS_GDPWR_SERVICE + bool + config NRFS_HAS_MRAM_SERVICE bool @@ -103,7 +106,7 @@ config NRFS_PMIC_SERVICE_ENABLED config NRFS_DVFS_SERVICE_ENABLED bool "DVFS service" depends on NRFS_HAS_DVFS_SERVICE - default y if SOC_NRF54H20_CPUAPP || SOC_NRF9280_CPUAPP + default y if SOC_NRF54H20_CPUAPP || SOC_NRF54H20_ENGB_CPUAPP || SOC_NRF9280_CPUAPP config NRFS_DIAG_SERVICE_ENABLED bool "System Diagnostics service (only for development purposes)" @@ -113,6 +116,12 @@ config NRFS_CLOCK_SERVICE_ENABLED bool "Clock service" depends on NRFS_HAS_CLOCK_SERVICE default y + +config NRFS_GDPWR_SERVICE_ENABLED + bool "Global domain power request service" + depends on NRFS_HAS_GDPWR_SERVICE + default y + endmenu rsource "backends/Kconfig" diff --git a/modules/hal_nordic/nrfs/dvfs/ld_dvfs.c b/modules/hal_nordic/nrfs/dvfs/ld_dvfs.c index 1faffbdb3c26..57ee0bdc3751 100644 --- a/modules/hal_nordic/nrfs/dvfs/ld_dvfs.c +++ b/modules/hal_nordic/nrfs/dvfs/ld_dvfs.c @@ -269,7 +269,7 @@ int32_t ld_dvfs_configure_hsfll(enum dvfs_frequency_setting oppoint) freq_trim = 2; } -#if defined(CONFIG_SOC_NRF54H20_CPUAPP) || defined(CONFIG_SOC_NRF9280_CPUAPP) +#if defined(NRF_APPLICATION) hsfll_trim.vsup = NRF_FICR->TRIM.APPLICATION.HSFLL.TRIM.VSUP; hsfll_trim.coarse = NRF_FICR->TRIM.APPLICATION.HSFLL.TRIM.COARSE[freq_trim]; hsfll_trim.fine = NRF_FICR->TRIM.APPLICATION.HSFLL.TRIM.FINE[freq_trim]; diff --git a/modules/hal_nordic/nrfs/nrfs_config.h b/modules/hal_nordic/nrfs/nrfs_config.h index 20cf6cece0e3..a092adb7850f 100644 --- a/modules/hal_nordic/nrfs/nrfs_config.h +++ b/modules/hal_nordic/nrfs/nrfs_config.h @@ -40,6 +40,10 @@ #define NRFS_CLOCK_SERVICE_ENABLED #endif +#ifdef CONFIG_NRFS_GDPWR_SERVICE_ENABLED +#define NRFS_GDPWR_SERVICE_ENABLED +#endif + #ifdef CONFIG_SOC_POSIX #define NRFS_UNIT_TESTS_ENABLED #endif diff --git a/modules/hal_nordic/nrfx/CMakeLists.txt b/modules/hal_nordic/nrfx/CMakeLists.txt index cb4fe5f43d91..caf7002b30a8 100644 --- a/modules/hal_nordic/nrfx/CMakeLists.txt +++ b/modules/hal_nordic/nrfx/CMakeLists.txt @@ -75,11 +75,14 @@ zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF9230_ENGB_CPUPPR NRF9230_ENGB_XXA zephyr_compile_definitions_ifdef(CONFIG_NRF_APPROTECT_LOCK ENABLE_APPROTECT) zephyr_compile_definitions_ifdef(CONFIG_NRF_APPROTECT_USER_HANDLING - ENABLE_APPROTECT_USER_HANDLING) + ENABLE_APPROTECT_USER_HANDLING + ENABLE_AUTHENTICATED_APPROTECT) zephyr_compile_definitions_ifdef(CONFIG_NRF_SECURE_APPROTECT_LOCK - ENABLE_SECURE_APPROTECT) + ENABLE_SECURE_APPROTECT + ENABLE_SECUREAPPROTECT) zephyr_compile_definitions_ifdef(CONFIG_NRF_SECURE_APPROTECT_USER_HANDLING - ENABLE_SECURE_APPROTECT_USER_HANDLING) + ENABLE_SECURE_APPROTECT_USER_HANDLING + ENABLE_AUTHENTICATED_SECUREAPPROTECT) zephyr_library_compile_definitions_ifdef(CONFIG_NRF_TRACE_PORT ENABLE_TRACE) diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index c7a7f169c014..47a12f909250 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -1006,7 +1006,7 @@ #define NRFX_IPCT_PUB_OR_SUB_MASK(inst_num) \ COND_CODE_1(IS_EMPTY(inst_num), \ - (DT_NODE_HAS_STATUS(NRFX_CONFIG_IPCT_LOCAL_NODE, okay)), \ + (DT_NODE_HAS_STATUS_OKAY(NRFX_CONFIG_IPCT_LOCAL_NODE)), \ (DT_NODE_HAS_PROP(DT_NODELABEL(_CONCAT(ipct, inst_num)), owned_channels))) /* Variables names generation. */ diff --git a/modules/hal_nxp/Kconfig b/modules/hal_nxp/Kconfig index aaec4e84abac..4f055faa07d6 100644 --- a/modules/hal_nxp/Kconfig +++ b/modules/hal_nxp/Kconfig @@ -4,4 +4,5 @@ # SPDX-License-Identifier: Apache-2.0 # -# file is empty and kept as a place holder if/when Kconfig is needed +config MCUX_ACMP + bool "Include ACMP driver from MCUX SDK" diff --git a/modules/hostap/CMakeLists.txt b/modules/hostap/CMakeLists.txt index 6d6d61cfef45..7ad0d22bb6a8 100644 --- a/modules/hostap/CMakeLists.txt +++ b/modules/hostap/CMakeLists.txt @@ -46,6 +46,7 @@ zephyr_library_compile_definitions( CONFIG_SHA512 CONFIG_CTRL_IFACE_ZEPHYR CONFIG_SUITEB192 + CONFIG_SUITEB ) @@ -204,6 +205,7 @@ zephyr_library_sources_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_AP ${HOSTAP_SRC_BASE}/ap/mbo_ap.c ${HOSTAP_SRC_BASE}/ap/ctrl_iface_ap.c ${HOSTAP_SRC_BASE}/utils/crc32.c + ${HOSTAP_SRC_BASE}/utils/ip_addr.c ) zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_AP @@ -224,7 +226,6 @@ zephyr_include_directories_ifdef(CONFIG_WIFI_NM_HOSTAPD_AP zephyr_library_sources_ifdef(CONFIG_WIFI_NM_HOSTAPD_AP ${HOSTAP_SRC_BASE}/ap/acs.c - ${HOSTAP_SRC_BASE}/utils/ip_addr.c ${WIFI_NM_HOSTAPD_BASE}/config_file.c ${WIFI_NM_HOSTAPD_BASE}/ctrl_iface.c ${WIFI_NM_HOSTAPD_BASE}/ctrl_iface_zephyr.c @@ -241,6 +242,27 @@ zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_HOSTAPD_AP zephyr_library_sources_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE ${HOSTAP_SRC_BASE}/crypto/crypto_none.c ${HOSTAP_SRC_BASE}/crypto/tls_none.c + + # FIXME: why do we need these when crypto is not selected? + ${HOSTAP_SRC_BASE}/crypto/aes-wrap.c + ${HOSTAP_SRC_BASE}/crypto/aes-internal.c + ${HOSTAP_SRC_BASE}/crypto/aes-internal-enc.c + ${HOSTAP_SRC_BASE}/crypto/aes-omac1.c + ${HOSTAP_SRC_BASE}/crypto/md5.c + ${HOSTAP_SRC_BASE}/crypto/md5-internal.c + ${HOSTAP_SRC_BASE}/crypto/sha1.c + ${HOSTAP_SRC_BASE}/crypto/sha1-internal.c + ${HOSTAP_SRC_BASE}/crypto/sha1-pbkdf2.c + ${HOSTAP_SRC_BASE}/crypto/sha1-prf.c + ${HOSTAP_SRC_BASE}/crypto/sha256.c + ${HOSTAP_SRC_BASE}/crypto/sha256-internal.c + ${HOSTAP_SRC_BASE}/crypto/sha256-prf.c + ${HOSTAP_SRC_BASE}/crypto/sha384.c + ${HOSTAP_SRC_BASE}/crypto/sha384-internal.c + ${HOSTAP_SRC_BASE}/crypto/sha384-prf.c + ${HOSTAP_SRC_BASE}/crypto/sha512.c + ${HOSTAP_SRC_BASE}/crypto/sha512-internal.c + ${HOSTAP_SRC_BASE}/crypto/rc4.c ) zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE @@ -323,68 +345,176 @@ zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_WPS ) zephyr_library_sources_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE + ${HOSTAP_SRC_BASE}/eap_common/eap_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE + IEEE8021X_EAPOL + EAP_IKEv2 +) + +zephyr_library_sources_ifdef(CONFIG_EAP_TLS ${HOSTAP_SRC_BASE}/eap_peer/eap_tls.c ${HOSTAP_SRC_BASE}/eap_peer/eap_tls_common.c - ${HOSTAP_SRC_BASE}/eap_common/eap_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_TLS + EAP_TLS +) + +zephyr_library_sources_ifdef(CONFIG_EAP_TTLS + ${HOSTAP_SRC_BASE}/eap_peer/eap_ttls.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_TTLS + EAP_TTLS +) +zephyr_library_sources_ifdef(CONFIG_EAP_PEAP ${HOSTAP_SRC_BASE}/eap_peer/eap_peap.c ${HOSTAP_SRC_BASE}/eap_common/eap_peap_common.c - ${HOSTAP_SRC_BASE}/eap_peer/eap_ttls.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_PEAP + EAP_PEAP +) + +zephyr_library_sources_ifdef(CONFIG_EAP_MD5 ${HOSTAP_SRC_BASE}/eap_peer/eap_md5.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_MD5 + EAP_MD5 +) + +zephyr_library_sources_ifdef(CONFIG_EAP_GTC + ${HOSTAP_SRC_BASE}/eap_peer/eap_gtc.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_GTC + EAP_GTC +) + +zephyr_library_sources_ifdef(CONFIG_EAP_MSCHAPV2 ${HOSTAP_SRC_BASE}/eap_peer/eap_mschapv2.c - ${HOSTAP_SRC_BASE}/eap_common/chap.c ${HOSTAP_SRC_BASE}/eap_peer/mschapv2.c + ${HOSTAP_SRC_BASE}/eap_common/chap.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_MSCHAPV2 + EAP_MSCHAPv2 +) + +zephyr_library_sources_ifdef(CONFIG_EAP_LEAP ${HOSTAP_SRC_BASE}/eap_peer/eap_leap.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_LEAP + EAP_LEAP +) +zephyr_library_sources_ifdef(CONFIG_EAP_PSK ${HOSTAP_SRC_BASE}/eap_peer/eap_psk.c ${HOSTAP_SRC_BASE}/eap_common/eap_psk_common.c +) - ${HOSTAP_SRC_BASE}/eap_peer/eap_fast.c - ${HOSTAP_SRC_BASE}/eap_peer/eap_fast_pac.c - ${HOSTAP_SRC_BASE}/eap_common/eap_fast_common.c +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_PSK + EAP_PSK +) +zephyr_library_sources_ifdef(CONFIG_EAP_PAX ${HOSTAP_SRC_BASE}/eap_peer/eap_pax.c ${HOSTAP_SRC_BASE}/eap_common/eap_pax_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_PAX + EAP_PAX +) +zephyr_library_sources_ifdef(CONFIG_EAP_SAKE ${HOSTAP_SRC_BASE}/eap_peer/eap_sake.c ${HOSTAP_SRC_BASE}/eap_common/eap_sake_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_SAKE + EAP_SAKE +) +zephyr_library_sources_ifdef(CONFIG_EAP_GPSK ${HOSTAP_SRC_BASE}/eap_peer/eap_gpsk.c ${HOSTAP_SRC_BASE}/eap_common/eap_gpsk_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_GPSK + EAP_GPSK +) +zephyr_library_sources_ifdef(CONFIG_EAP_PWD ${HOSTAP_SRC_BASE}/eap_peer/eap_pwd.c ${HOSTAP_SRC_BASE}/eap_common/eap_pwd_common.c +) +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_PWD + EAP_PWD +) + +zephyr_library_sources_ifdef(CONFIG_EAP_EKE ${HOSTAP_SRC_BASE}/eap_peer/eap_eke.c ${HOSTAP_SRC_BASE}/eap_common/eap_eke_common.c +) +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_EKE + EAP_EKE +) + +zephyr_library_sources_ifdef(CONFIG_EAP_IKEV2 ${HOSTAP_SRC_BASE}/eap_peer/eap_ikev2.c ${HOSTAP_SRC_BASE}/eap_peer/ikev2.c ${HOSTAP_SRC_BASE}/eap_common/eap_ikev2_common.c ${HOSTAP_SRC_BASE}/eap_common/ikev2_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_IKEV2 + EAP_IKEV2 +) +zephyr_library_sources_ifdef(CONFIG_EAP_SIM ${HOSTAP_SRC_BASE}/eap_peer/eap_sim.c ${HOSTAP_SRC_BASE}/eap_common/eap_sim_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_SIM + EAP_SIM +) +zephyr_library_sources_ifdef(CONFIG_EAP_AKA ${HOSTAP_SRC_BASE}/eap_peer/eap_aka.c ) -zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE - EAP_TLS - IEEE8021X_EAPOL - EAP_PEAP - EAP_TTLS - EAP_MD5 - EAP_MSCHAPv2 - EAP_LEAP - EAP_PSK - EAP_FAST - EAP_PAX - EAP_SAKE - EAP_GPSK - EAP_PWD - EAP_EKE - EAP_IKEv2 +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_AKA + EAP_AKA +) + +# Needs TLS1.3 and SESSION_TICKETS +zephyr_library_sources_ifdef(CONFIG_EAP_FAST + ${HOSTAP_SRC_BASE}/eap_peer/eap_fast.c + ${HOSTAP_SRC_BASE}/eap_peer/eap_fast_pac.c + ${HOSTAP_SRC_BASE}/eap_common/eap_fast_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_FAST + EAP_FAST +) + +# Needs TLS1.3 and SESSION_TICKETS +zephyr_library_sources_ifdef(CONFIG_EAP_FAST + ${HOSTAP_SRC_BASE}/eap_peer/eap_fast.c + ${HOSTAP_SRC_BASE}/eap_peer/eap_fast_pac.c + ${HOSTAP_SRC_BASE}/eap_common/eap_fast_common.c +) + +zephyr_library_compile_definitions_ifdef(CONFIG_EAP_FAST + EAP_FAST ) zephyr_library_compile_definitions_ifndef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE @@ -482,15 +612,20 @@ zephyr_library_sources_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE ) endif() -if(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT) +if(DEFINED ONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT OR + DEFINED CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT_LEGACY_NCS) zephyr_include_directories( ${HOSTAP_BASE}/port/mbedtls ) zephyr_library_sources( ${HOSTAP_SRC_BASE}/crypto/crypto_mbedtls_alt.c - ${HOSTAP_SRC_BASE}/crypto/tls_mbedtls_alt.c ${HOSTAP_SRC_BASE}/crypto/rc4.c + ${HOSTAP_SRC_BASE}/crypto/aes-wrap.c + ${HOSTAP_SRC_BASE}/crypto/aes-unwrap.c + ${HOSTAP_SRC_BASE}/crypto/aes-internal-dec.c + ${HOSTAP_SRC_BASE}/crypto/aes-internal.c + ${HOSTAP_SRC_BASE}/crypto/aes-internal-enc.c ) zephyr_library_sources_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_MBEDTLS_PSA @@ -501,8 +636,41 @@ zephyr_library_sources_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE ${HOSTAP_SRC_BASE}/crypto/ms_funcs.c ${HOSTAP_SRC_BASE}/crypto/aes-eax.c ${HOSTAP_SRC_BASE}/crypto/md4-internal.c + ${HOSTAP_SRC_BASE}/crypto/sha1-internal.c ${HOSTAP_SRC_BASE}/crypto/fips_prf_internal.c ${HOSTAP_SRC_BASE}/crypto/milenage.c + ${HOSTAP_SRC_BASE}/crypto/tls_mbedtls_alt.c +) + +zephyr_library_sources_ifndef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE + ${HOSTAP_SRC_BASE}/crypto/tls_none.c +) + + +zephyr_library_sources_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_TEST + ${HOSTAP_SRC_BASE}/crypto/crypto_module_tests.c + ${HOSTAP_SRC_BASE}/crypto/fips_prf_internal.c + ${HOSTAP_SRC_BASE}/crypto/sha1-internal.c + ${HOSTAP_SRC_BASE}/crypto/sha1-tlsprf.c +) +endif() + +if(DEFINED CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT_NCS_PSA) +zephyr_include_directories( + ${HOSTAP_BASE}/port/mbedtls +) + +zephyr_library_sources( + ${HOSTAP_SRC_BASE}/crypto/aes-wrap.c + ${HOSTAP_SRC_BASE}/crypto/aes-unwrap.c + ${HOSTAP_SRC_BASE}/crypto/aes-internal-dec.c + ${HOSTAP_SRC_BASE}/crypto/aes-internal.c + ${HOSTAP_SRC_BASE}/crypto/aes-internal-enc.c + ${HOSTAP_SRC_BASE}/crypto/rc4.c + ${HOSTAP_SRC_BASE}/crypto/crypto_mbedtls_alt.c + ${HOSTAP_SRC_BASE}/crypto/sha256-kdf.c + ${HOSTAP_BASE}/port/mbedtls/supp_psa_api.c + ${HOSTAP_SRC_BASE}/crypto/tls_none.c ) endif() @@ -515,8 +683,4 @@ if(CONFIG_SAE_PWE_EARLY_EXIT) "please use it carefully and do not use it production.") endif() -zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT - MBEDTLS_NIST_KW_C -) - endif() diff --git a/modules/hostap/Kconfig b/modules/hostap/Kconfig index b329cd2e4f07..300a61e5cd68 100644 --- a/modules/hostap/Kconfig +++ b/modules/hostap/Kconfig @@ -23,13 +23,13 @@ config WIFI_NM_WPA_SUPPLICANT if WIFI_NM_WPA_SUPPLICANT -config COMMON_LIBC_MALLOC_ARENA_SIZE - default 85000 if WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE && !MBEDTLS_ENABLE_HEAP - default 40000 if WIFI_NM_WPA_SUPPLICANT_AP +config HEAP_MEM_POOL_ADD_SIZE_HOSTAP + def_int 85000 if WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE && !MBEDTLS_ENABLE_HEAP + def_int 40000 if WIFI_NM_WPA_SUPPLICANT_AP # 8192 for MbedTLS heap - default 21808 if MBEDTLS_ENABLE_HEAP + def_int 21808 if MBEDTLS_ENABLE_HEAP # 30K is mandatory, but might need more for long duration use cases - default 30000 + def_int 30000 config WIFI_NM_WPA_SUPPLICANT_THREAD_STACK_SIZE int "Stack size for wpa_supplicant thread" @@ -109,8 +109,9 @@ config WIFI_NM_WPA_SUPPLICANT_WEP choice WIFI_NM_WPA_SUPPLICANT_CRYPTO_BACKEND prompt "WPA supplicant crypto implementation" - default WIFI_NM_WPA_SUPPLICANT_CRYPTO_LEGACY_NCS - default WIFI_NM_WPA_SUPPLICANT_CRYPTO_LEGACY_NCS_PSA if SOC_SERIES_NRF54LX + default WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT_NCS_PSA if SOC_SERIES_NRF54HX + default WIFI_NM_WPA_SUPPLICANT_CRYPTO_LEGACY_NCS_PSA if SOC_SERIES_NRF54LX || BUILD_WITH_TFM + default WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT_LEGACY_NCS help Select the crypto implementation to use for WPA supplicant. WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT supports enterprise mode @@ -211,6 +212,79 @@ config WIFI_NM_WPA_SUPPLICANT_CRYPTO_LEGACY_NCS_PSA select MBEDTLS_PKCS5_C select MBEDTLS_ECP_DP_SECP256R1_ENABLED +config WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT_LEGACY_NCS + bool "Legacy Crypto support for WiFi using nRF security" + select MBEDTLS + select NRF_SECURITY + select MBEDTLS_CIPHER_MODE_CBC + select MBEDTLS_CIPHER_MODE_CTR + select MBEDTLS_LEGACY_CRYPTO_C + select MBEDTLS_ENTROPY_C + select MBEDTLS_CIPHER + select MBEDTLS_ECP_C + select MBEDTLS_CTR_DRBG_C + select MBEDTLS_PK_WRITE_C + select MBEDTLS_HKDF_C + select MBEDTLS_KEY_EXCHANGE_ALL_ENABLED + select MBEDTLS_MD_C + select MBEDTLS_MD5_C + select MBEDTLS_ENTROPY_C + select MBEDTLS_CIPHER_PADDING_PKCS7 + select MBEDTLS_PKCS5_C + +config WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT_LEGACY_NCS_PSA + bool "Legacy Crypto support for WiFi using nRF security" + select MBEDTLS + select NRF_SECURITY + select PSA_WANT_GENERATE_RANDOM + select MBEDTLS_CIPHER_MODE_CBC + select MBEDTLS_CIPHER_MODE_CTR + select MBEDTLS_LEGACY_CRYPTO_C + select MBEDTLS_SHA1_C + select MBEDTLS_ECP_C + select MBEDTLS_CTR_DRBG_C + select MBEDTLS_PK_C + select MBEDTLS_PKCS5_C + select MBEDTLS_PK_PARSE_C + select MBEDTLS_CMAC_C + select MBEDTLS_CIPHER_PADDING_PKCS7 + select MBEDTLS_PK_WRITE_C + select MBEDTLS_KEY_EXCHANGE_ALL_ENABLED + select MBEDTLS_ENTROPY_C + +config WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT_NCS_PSA + bool "PSA Crypto support for WiFi WPA2 using nRF security" + select MBEDTLS + select NRF_SECURITY + select PSA_WANT_GENERATE_RANDOM + select MBEDTLS_PK_C + select MBEDTLS_MD_C + select MBEDTLS_PK_WRITE_C + select MBEDTLS_ENABLE_HEAP + select MBEDTLS_PSA_CRYPTO_C + select MBEDTLS_USE_PSA_CRYPTO + select PSA_WANT_ALG_HMAC + select PSA_WANT_ALG_CMAC + select PSA_WANT_ALG_ECB_NO_PADDING + select PSA_WANT_ALG_CBC_PKCS7 + select PSA_ACCEL_CBC_MAC_AES_128 + select PSA_ACCEL_CBC_MAC_AES_192 + select PSA_ACCEL_CBC_MAC_AES_256 + select PSA_WANT_ALG_CCM + select PSA_WANT_ALG_GCM + select PSA_WANT_ALG_CTR + select PSA_WANT_ALG_MD5 + select PSA_ACCEL_MD5 + select PSA_WANT_ALG_SHA_1 + select PSA_WANT_ALG_SHA_256 + select PSA_WANT_ALG_SHA_224 + select PSA_WANT_ALG_SHA_384 + select PSA_WANT_ALG_SHA_512 + select PSA_WANT_ALG_PBKDF2_HMAC + select PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 + select PSA_WANT_KEY_TYPE_AES + select PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY + config WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE bool "No Crypto support for WiFi" @@ -218,17 +292,81 @@ endchoice config WIFI_NM_WPA_SUPPLICANT_CRYPTO_MBEDTLS_PSA bool "Crypto Platform Secure Architecture support for WiFi" + default y if WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT_NCS_PSA help Support Mbedtls 3.x to use PSA apis instead of legacy apis. config WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE bool "Enterprise Crypto support for WiFi" - select MBEDTLS_PEM_CERTIFICATE_FORMAT - depends on !WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE + select MBEDTLS_ECDH_C + select MBEDTLS_ECDSA_C + select MBEDTLS_DHM_C + select MBEDTLS_SSL_TLS_C + select MBEDTLS_SSL_SRV_C + select MBEDTLS_SSL_CLI_C + select MBEDTLS_X509_LIBRARY + select MBEDTLS_TLS_LIBRARY + select MBEDTLS_X509_CRL_PARSE_C + select MBEDTLS_TLS_VERSION_1_2 + select MBEDTLS_RSA_C + depends on !WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE && !WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT_NCS_PSA + +config EAP_TLS + bool "EAP-TLS support" + +config EAP_TTLS + bool "EAP-TTLS support" + +config EAP_PEAP + bool "EAP-PEAP support" + +config EAP_MD5 + bool "EAP-MD5 support" + +config EAP_GTC + bool "EAP-GTC support" + +config EAP_MSCHAPV2 + bool "EAP-MSCHAPv2 support" + +config EAP_LEAP + bool "EAP-LEAP support" + +config EAP_PSK + bool "EAP-PSK support" + +config EAP_PAX + bool "EAP-PAX support" + +config EAP_SAKE + bool "EAP-SAKE support" + +config EAP_GPSK + bool "EAP-GPSK support" + +config EAP_PWD + bool "EAP-PWD support" + +config EAP_EKE + bool "EAP-EKE support" + +config EAP_IKEV2 + bool "EAP-IKEv2 support" + +config EAP_SIM + bool "EAP-SIM support" + +config EAP_AKA + bool "EAP-AKA support" + +config EAP_ALL + bool "All EAP methods support" + select EAP_TLS + default y if WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE config WIFI_NM_WPA_SUPPLICANT_WPA3 bool "WPA3 support" - depends on !WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE + depends on !WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE && !WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT_NCS_PSA default y config WIFI_NM_WPA_SUPPLICANT_AP @@ -242,6 +380,7 @@ config WIFI_NM_WPA_SUPPLICANT_P2P bool "P2P mode support" select WIFI_NM_WPA_SUPPLICANT_AP select WIFI_NM_WPA_SUPPLICANT_WPS + select WIFI_NM_WPA_SUPPLICANT_EAPOL config WIFI_NM_WPA_SUPPLICANT_EAPOL bool "EAPoL supplicant" @@ -434,9 +573,6 @@ config EAP_EKE config EAP_IKEv2 bool -config IEEE8021X_EAPOL - bool - config CRYPTO_INTERNAL bool @@ -464,6 +600,9 @@ config SHA512 config SUITEB192 bool +config SUITEB + bool + config WEP bool default y if WIFI_NM_WPA_SUPPLICANT_WEP @@ -533,4 +672,15 @@ config SAE_PWE_EARLY_EXIT this can be intensive, so, add an option to exit early. Note that this is highly insecure and shouldn't be used in production +config WIFI_NM_WPA_SUPPLICANT_CRYPTO_TEST + bool + depends on WIFI_NM_WPA_SUPPLICANT_CRYPTO_MBEDTLS_PSA + +config WIFI_NM_WPA_CTRL_RESP_TIMEOUT_S + int "WPA supplicant control interface response timeout in seconds" + default 15 + help + Timeout for the control interface commands to get a response from the + supplicant. + endif # WIFI_NM_WPA_SUPPLICANT diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index 049223b69565..52772b4becfc 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -35,7 +35,9 @@ static struct wifi_connect_req_params last_wifi_conn_params; enum requested_ops { CONNECT = 0, - DISCONNECT + DISCONNECT, + WPS_PBC, + WPS_PIN, }; enum status_thread_state { @@ -269,7 +271,7 @@ static int wpa_supp_supported_channels(struct wpa_supplicant *wpa_s, uint8_t ban } size = ((mode->num_channels) * CHAN_NUM_LEN) + 1; - _chan_list = k_malloc(size); + _chan_list = os_malloc(size); if (!_chan_list) { wpa_printf(MSG_ERROR, "Mem alloc failed for channel list"); return -ENOMEM; @@ -360,6 +362,10 @@ static inline enum wifi_frequency_bands wpas_band_to_zephyr(enum wpa_radio_work_ static inline enum wifi_security_type wpas_key_mgmt_to_zephyr(int key_mgmt, int proto) { switch (key_mgmt) { + case WPA_KEY_MGMT_IEEE8021X: + case WPA_KEY_MGMT_IEEE8021X_SUITE_B: + case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: + return WIFI_SECURITY_TYPE_EAP_TLS; case WPA_KEY_MGMT_NONE: return WIFI_SECURITY_TYPE_NONE; case WPA_KEY_MGMT_PSK: @@ -372,6 +378,8 @@ static inline enum wifi_security_type wpas_key_mgmt_to_zephyr(int key_mgmt, int return WIFI_SECURITY_TYPE_PSK_SHA256; case WPA_KEY_MGMT_SAE: return WIFI_SECURITY_TYPE_SAE; + case WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_PSK: + return WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL; default: return WIFI_SECURITY_TYPE_UNKNOWN; } @@ -430,6 +438,100 @@ static int wpas_config_process_blob(struct wpa_config *config, char *name, uint8 return 0; } + +static const struct wifi_cipher_desc ciphers[] = { + {WPA_CAPA_ENC_GCMP_256, "GCMP-256"}, + {WPA_CAPA_ENC_CCMP, "CCMP"}, + {WPA_CAPA_ENC_GCMP, "GCMP"}, +}; + +static const struct wifi_cipher_desc ciphers_group_mgmt[] = { + {WPA_CAPA_ENC_BIP, "AES-128-CMAC"}, + {WPA_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128"}, + {WPA_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256"}, +}; + +static struct wifi_eap_config eap_config[] = { + {WIFI_SECURITY_TYPE_EAP_TLS, WIFI_EAP_TYPE_TLS, WIFI_EAP_TYPE_NONE, "TLS", NULL}, + {WIFI_SECURITY_TYPE_EAP_PEAP_MSCHAPV2, WIFI_EAP_TYPE_PEAP, WIFI_EAP_TYPE_MSCHAPV2, "PEAP", + "auth=MSCHAPV2"}, + {WIFI_SECURITY_TYPE_EAP_PEAP_GTC, WIFI_EAP_TYPE_PEAP, WIFI_EAP_TYPE_GTC, "PEAP", + "auth=GTC"}, + {WIFI_SECURITY_TYPE_EAP_TTLS_MSCHAPV2, WIFI_EAP_TYPE_TTLS, WIFI_EAP_TYPE_NONE, "TTLS", + "auth=MSCHAPV2"}, + {WIFI_SECURITY_TYPE_EAP_PEAP_TLS, WIFI_EAP_TYPE_PEAP, WIFI_EAP_TYPE_TLS, "PEAP", + "auth=TLS"}, + {WIFI_SECURITY_TYPE_EAP_TLS_SHA256, WIFI_EAP_TYPE_TLS, WIFI_EAP_TYPE_NONE, "TLS", NULL}, +}; + +int process_cipher_config(struct wifi_connect_req_params *params, + struct wifi_eap_cipher_config *cipher_config) +{ + unsigned int cipher_capa; + unsigned int gropu_mgmt_cipher_capa; + unsigned int index; + + if (params->suiteb_type == WIFI_SUITEB) { + cipher_capa = WPA_CAPA_ENC_GCMP; + gropu_mgmt_cipher_capa = WPA_CAPA_ENC_BIP_GMAC_128; + cipher_config->key_mgmt = "WPA-EAP-SUITE-B"; + cipher_config->openssl_ciphers = "SUITEB128"; + cipher_config->tls_flags = "[SUITEB]"; + } else if (params->suiteb_type == WIFI_SUITEB_192) { + cipher_capa = WPA_CAPA_ENC_GCMP_256; + gropu_mgmt_cipher_capa = WPA_CAPA_ENC_BIP_GMAC_256; + cipher_config->key_mgmt = "WPA-EAP-SUITE-B-192"; + cipher_config->openssl_ciphers = "SUITEB192"; + cipher_config->tls_flags = "[SUITEB]"; + } else { + cipher_capa = WPA_CAPA_ENC_CCMP; + gropu_mgmt_cipher_capa = WPA_CAPA_ENC_BIP; + cipher_config->key_mgmt = "WPA-EAP"; + } + + if (params->security == WIFI_SECURITY_TYPE_EAP_TLS_SHA256) { + cipher_config->key_mgmt = "WPA-EAP-SHA256"; + } + + for (index = 0; index < ARRAY_SIZE(ciphers); index++) { + if (cipher_capa == ciphers[index].capa) { + cipher_config->group_cipher = ciphers[index].name; + cipher_config->pairwise_cipher = ciphers[index].name; + break; + } + } + + if (index == ARRAY_SIZE(ciphers)) { + wpa_printf(MSG_ERROR, "Get ciphers error"); + goto out; + } + + for (index = 0; index < ARRAY_SIZE(ciphers_group_mgmt); index++) { + if (gropu_mgmt_cipher_capa == ciphers_group_mgmt[index].capa) { + cipher_config->group_mgmt_cipher = ciphers_group_mgmt[index].name; + break; + } + } + + if (index == ARRAY_SIZE(ciphers_group_mgmt)) { + wpa_printf(MSG_ERROR, "Get group mgmt ciphers error"); + goto out; + } + + return 0; +out: + return -EINVAL; +} + +static int is_eap_valid_security(int security) +{ + return (security == WIFI_SECURITY_TYPE_EAP_TLS || + security == WIFI_SECURITY_TYPE_EAP_PEAP_MSCHAPV2 || + security == WIFI_SECURITY_TYPE_EAP_PEAP_GTC || + security == WIFI_SECURITY_TYPE_EAP_TTLS_MSCHAPV2 || + security == WIFI_SECURITY_TYPE_EAP_PEAP_TLS || + security == WIFI_SECURITY_TYPE_EAP_TLS_SHA256); +} #endif static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s, @@ -443,6 +545,14 @@ static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s, uint8_t ssid_null_terminated[WIFI_SSID_MAX_LEN + 1]; uint8_t psk_null_terminated[WIFI_PSK_MAX_LEN + 1]; uint8_t sae_null_terminated[WIFI_SAE_PSWD_MAX_LEN + 1]; +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE + struct wifi_eap_cipher_config cipher_config = {NULL, "DEFAULT:!EXP:!LOW", "CCMP", + "CCMP", "AES-128-CMAC", NULL}; + char *method; + char phase1[128] = {0}; + char *phase2 = NULL; + unsigned int index; +#endif if (!wpa_cli_cmd_v("remove_network all")) { goto out; @@ -496,26 +606,16 @@ static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s, if (chan_list) { if (!wpa_cli_cmd_v("set_network %d scan_freq%s", resp.network_id, chan_list)) { - k_free(chan_list); + os_free(chan_list); goto out; } - k_free(chan_list); + os_free(chan_list); } } if (params->security != WIFI_SECURITY_TYPE_NONE) { - if (params->sae_password) { - if ((params->sae_password_length < WIFI_PSK_MIN_LEN) || - (params->sae_password_length > WIFI_SAE_PSWD_MAX_LEN)) { - wpa_printf(MSG_ERROR, - "Passphrase should be in range (%d-%d) characters", - WIFI_PSK_MIN_LEN, WIFI_SAE_PSWD_MAX_LEN); - goto out; - } - strncpy(sae_null_terminated, params->sae_password, WIFI_SAE_PSWD_MAX_LEN); - sae_null_terminated[params->sae_password_length] = '\0'; - } else { + if (params->psk) { if ((params->psk_length < WIFI_PSK_MIN_LEN) || (params->psk_length > WIFI_PSK_MAX_LEN)) { wpa_printf(MSG_ERROR, @@ -547,6 +647,16 @@ static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s, params->security == WIFI_SECURITY_TYPE_SAE_H2E || params->security == WIFI_SECURITY_TYPE_SAE_AUTO) { if (params->sae_password) { + if ((params->sae_password_length < WIFI_PSK_MIN_LEN) || + (params->sae_password_length > WIFI_SAE_PSWD_MAX_LEN)) { + wpa_printf(MSG_ERROR, + "Passphrase should be in range (%d-%d) characters", + WIFI_PSK_MIN_LEN, WIFI_SAE_PSWD_MAX_LEN); + goto out; + } + strncpy(sae_null_terminated, params->sae_password, + WIFI_SAE_PSWD_MAX_LEN); + sae_null_terminated[params->sae_password_length] = '\0'; if (!wpa_cli_cmd_v("set_network %d sae_password \"%s\"", resp.network_id, sae_null_terminated)) { goto out; @@ -599,23 +709,120 @@ static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s, goto out; } } -#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE - } else if (params->security == WIFI_SECURITY_TYPE_EAP_TLS) { - if (!wpa_cli_cmd_v("set_network %d key_mgmt WPA-EAP", + } else if (params->security == WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL) { + if (!wpa_cli_cmd_v("set_network %d psk \"%s\"", resp.network_id, + psk_null_terminated)) { + goto out; + } + + if (params->sae_password) { + if (!wpa_cli_cmd_v("set_network %d sae_password \"%s\"", + resp.network_id, sae_null_terminated)) { + goto out; + } + } else { + if (!wpa_cli_cmd_v("set_network %d sae_password \"%s\"", + resp.network_id, psk_null_terminated)) { + goto out; + } + } + + if (!wpa_cli_cmd_v("set sae_pwe 2")) { + goto out; + } + + if (!wpa_cli_cmd_v("set_network %d key_mgmt WPA-PSK SAE", resp.network_id)) { goto out; } +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE + } else if (is_eap_valid_security(params->security)) { + if (process_cipher_config(params, &cipher_config)) { + goto out; + } + + for (index = 0; index < ARRAY_SIZE(eap_config); index++) { + if (params->security == eap_config[index].type) { + method = eap_config[index].method; + phase2 = eap_config[index].phase2; + break; + } + } + + if (index == ARRAY_SIZE(eap_config)) { + wpa_printf(MSG_ERROR, "Get eap method error with security type: %d", + params->security); + goto out; + } + + if (!wpa_cli_cmd_v("set_network %d key_mgmt %s", resp.network_id, + cipher_config.key_mgmt)) { + goto out; + } + + if (!wpa_cli_cmd_v("set openssl_ciphers \"%s\"", + cipher_config.openssl_ciphers)) { + goto out; + } + + if (!wpa_cli_cmd_v("set_network %d group %s", resp.network_id, + cipher_config.group_cipher)) { + goto out; + } + + if (!wpa_cli_cmd_v("set_network %d pairwise %s", resp.network_id, + cipher_config.pairwise_cipher)) { + goto out; + } + + if (!wpa_cli_cmd_v("set_network %d group_mgmt %s", resp.network_id, + cipher_config.group_mgmt_cipher)) { + goto out; + } if (!wpa_cli_cmd_v("set_network %d proto RSN", resp.network_id)) { goto out; } - if (!wpa_cli_cmd_v("set_network %d eap TLS", - resp.network_id)) { + if (!wpa_cli_cmd_v("set_network %d eap %s", resp.network_id, method)) { goto out; } + if (params->security == WIFI_SECURITY_TYPE_EAP_PEAP_MSCHAPV2 || + params->security == WIFI_SECURITY_TYPE_EAP_PEAP_GTC || + params->security == WIFI_SECURITY_TYPE_EAP_PEAP_TLS) { + snprintk(phase1, sizeof(phase1), + "peapver=%d peaplabel=0 crypto_binding=0", + params->eap_ver); + + if (!wpa_cli_cmd_v("set_network %d phase1 \"%s\"", resp.network_id, + &phase1[0])) { + goto out; + } + } + + if (phase2 != NULL) { + if (!wpa_cli_cmd_v("set_network %d phase2 \"%s\"", resp.network_id, + phase2)) { + goto out; + } + } + + if (params->eap_id_length > 0) { + if (!wpa_cli_cmd_v("set_network %d identity \"%s\"", + resp.network_id, params->eap_identity)) { + goto out; + } + } + + if (params->eap_passwd_length > 0) { + if (!wpa_cli_cmd_v("set_network %d password \"%s\"", + resp.network_id, params->eap_password)) { + goto out; + } + } + if (!wpa_cli_cmd_v("set_network %d anonymous_identity \"%s\"", resp.network_id, params->anon_id)) { goto out; @@ -658,6 +865,44 @@ static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s, resp.network_id, params->key_passwd)) { goto out; } + + if (wpas_config_process_blob(wpa_s->conf, "ca_cert2", + enterprise_creds.ca_cert2, + enterprise_creds.ca_cert2_len)) { + goto out; + } + + if (!wpa_cli_cmd_v("set_network %d ca_cert2 \"blob://ca_cert2\"", + resp.network_id)) { + goto out; + } + + if (wpas_config_process_blob(wpa_s->conf, "client_cert2", + enterprise_creds.client_cert2, + enterprise_creds.client_cert2_len)) { + goto out; + } + + if (!wpa_cli_cmd_v("set_network %d client_cert2 \"blob://client_cert2\"", + resp.network_id)) { + goto out; + } + + if (wpas_config_process_blob(wpa_s->conf, "private_key2", + enterprise_creds.client_key2, + enterprise_creds.client_key2_len)) { + goto out; + } + + if (!wpa_cli_cmd_v("set_network %d private_key2 \"blob://private_key2\"", + resp.network_id)) { + goto out; + } + + if (!wpa_cli_cmd_v("set_network %d private_key2_passwd \"%s\"", + resp.network_id, params->key2_passwd)) { + goto out; + } #endif } else { ret = -1; @@ -810,6 +1055,10 @@ static int wpas_disconnect_network(const struct device *dev, int cur_mode) wifi_mgmt_raise_disconnect_complete_event(iface, ret); } + if (!wpa_cli_cmd_v("remove_network all")) { + wpa_printf(MSG_ERROR, "Failed to remove all networks"); + } + return ret; } @@ -867,6 +1116,45 @@ int supplicant_disconnect(const struct device *dev) return wpas_disconnect_network(dev, WPAS_MODE_INFRA); } +static enum wifi_mfp_options get_mfp(enum mfp_options supp_mfp_option) +{ + switch (supp_mfp_option) { + case NO_MGMT_FRAME_PROTECTION: + return WIFI_MFP_DISABLE; + case MGMT_FRAME_PROTECTION_OPTIONAL: + return WIFI_MFP_OPTIONAL; + case MGMT_FRAME_PROTECTION_REQUIRED: + return WIFI_MFP_REQUIRED; + default: + wpa_printf(MSG_ERROR, "Invalid mfp mapping %d", supp_mfp_option); + break; + } + + return WIFI_MFP_DISABLE; +} + +static enum wifi_iface_mode get_iface_mode(enum wpas_mode supp_mode) +{ + switch (supp_mode) { + case WPAS_MODE_INFRA: + return WIFI_MODE_INFRA; + case WPAS_MODE_IBSS: + return WIFI_MODE_IBSS; + case WPAS_MODE_AP: + return WIFI_MODE_AP; + case WPAS_MODE_P2P_GO: + return WIFI_MODE_P2P_GO; + case WPAS_MODE_P2P_GROUP_FORMATION: + return WIFI_MODE_P2P_GROUP_FORMATION; + case WPAS_MODE_MESH: + return WIFI_MODE_MESH; + default: + break; + } + + return WIFI_MODE_UNKNOWN; +} + int supplicant_status(const struct device *dev, struct wifi_iface_status *status) { struct net_if *iface = net_if_lookup_by_dev(dev); @@ -920,7 +1208,7 @@ int supplicant_status(const struct device *dev, struct wifi_iface_status *status os_memcpy(status->bssid, wpa_s->bssid, WIFI_MAC_ADDR_LEN); status->band = wpas_band_to_zephyr(wpas_freq_to_band(wpa_s->assoc_freq)); status->security = wpas_key_mgmt_to_zephyr(key_mgmt, proto); - status->mfp = ssid->ieee80211w; /* Same mapping */ + status->mfp = get_mfp(ssid->ieee80211w); ieee80211_freq_to_chan(wpa_s->assoc_freq, &channel); status->channel = channel; @@ -938,7 +1226,7 @@ int supplicant_status(const struct device *dev, struct wifi_iface_status *status os_memcpy(status->ssid, _ssid, ssid_len); status->ssid_len = ssid_len; - status->iface_mode = ssid->mode; + status->iface_mode = get_iface_mode(ssid->mode); if (wpa_s->connection_set == 1) { status->link_mode = wpa_s->connection_he ? WIFI_6 : @@ -1137,13 +1425,44 @@ int supplicant_reg_domain(const struct device *dev, struct wifi_reg_domain *reg_domain) { const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev); + struct wpa_supplicant *wpa_s; + int ret = -1; if (!wifi_mgmt_api || !wifi_mgmt_api->reg_domain) { wpa_printf(MSG_ERROR, "Regulatory domain not supported"); return -ENOTSUP; } - return wifi_mgmt_api->reg_domain(dev, reg_domain); + if (reg_domain->oper == WIFI_MGMT_GET) { + return wifi_mgmt_api->reg_domain(dev, reg_domain); + } + + if (reg_domain->oper == WIFI_MGMT_SET) { + k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER); + + wpa_s = get_wpa_s_handle(dev); + if (!wpa_s) { + wpa_printf(MSG_ERROR, "Interface %s not found", dev->name); + goto out; + } + + if (!wpa_cli_cmd_v("set country %s", reg_domain->country_code)) { + goto out; + } + +#ifdef CONFIG_WIFI_NM_HOSTAPD_AP + if (!hostapd_cli_cmd_v("set country_code %s", reg_domain->country_code)) { + goto out; + } +#endif + + ret = 0; + +out: + k_mutex_unlock(&wpa_supplicant_mutex); + } + + return ret; } int supplicant_mode(const struct device *dev, struct wifi_mode_info *mode) @@ -1255,6 +1574,91 @@ int supplicant_get_wifi_conn_params(const struct device *dev, return ret; } +static int supplicant_wps_pbc(const struct device *dev) +{ + struct wpa_supplicant *wpa_s; + int ret = -1; + + k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER); + + wpa_s = get_wpa_s_handle(dev); + if (!wpa_s) { + ret = -1; + wpa_printf(MSG_ERROR, "Interface %s not found", dev->name); + goto out; + } + + if (!wpa_cli_cmd_v("wps_pbc")) { + goto out; + } + + wpas_api_ctrl.dev = dev; + wpas_api_ctrl.requested_op = WPS_PBC; + + ret = 0; + +out: + k_mutex_unlock(&wpa_supplicant_mutex); + + return ret; +} + +static int supplicant_wps_pin(const struct device *dev, struct wifi_wps_config_params *params) +{ + struct wpa_supplicant *wpa_s; + char *get_pin_cmd = "WPS_PIN get"; + int ret = -1; + + k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER); + + wpa_s = get_wpa_s_handle(dev); + if (!wpa_s) { + ret = -1; + wpa_printf(MSG_ERROR, "Interface %s not found", dev->name); + goto out; + } + + if (params->oper == WIFI_WPS_PIN_GET) { + if (zephyr_wpa_cli_cmd_resp(get_pin_cmd, params->pin)) { + goto out; + } + } else if (params->oper == WIFI_WPS_PIN_SET) { + if (!wpa_cli_cmd_v("wps_check_pin %s", params->pin)) { + goto out; + } + + if (!wpa_cli_cmd_v("wps_pin any %s", params->pin)) { + goto out; + } + + wpas_api_ctrl.dev = dev; + wpas_api_ctrl.requested_op = WPS_PIN; + } else { + wpa_printf(MSG_ERROR, "Error wps pin operation : %d", params->oper); + goto out; + } + + ret = 0; + +out: + k_mutex_unlock(&wpa_supplicant_mutex); + + return ret; +} + +int supplicant_wps_config(const struct device *dev, struct wifi_wps_config_params *params) +{ + int ret = 0; + + if (params->oper == WIFI_WPS_PBC) { + ret = supplicant_wps_pbc(dev); + } else if (params->oper == WIFI_WPS_PIN_GET || params->oper == WIFI_WPS_PIN_SET) { + ret = supplicant_wps_pin(dev, params); + } + + return ret; +} + #ifdef CONFIG_AP #ifdef CONFIG_WIFI_NM_HOSTAPD_AP int hapd_state(const struct device *dev, int *state) @@ -1322,7 +1726,7 @@ int hapd_config_network(struct hostapd_iface *iface, if (!hostapd_cli_cmd_v("set wpa_key_mgmt WPA-PSK")) { goto out; } - if (!hostapd_cli_cmd_v("set wpa_passphrase \"%s\"", params->psk)) { + if (!hostapd_cli_cmd_v("set wpa_passphrase %s", params->psk)) { goto out; } if (!hostapd_cli_cmd_v("set wpa_pairwise CCMP")) { @@ -1335,7 +1739,7 @@ int hapd_config_network(struct hostapd_iface *iface, if (!hostapd_cli_cmd_v("set wpa_key_mgmt WPA-PSK")) { goto out; } - if (!hostapd_cli_cmd_v("set wpa_passphrase \"%s\"", params->psk)) { + if (!hostapd_cli_cmd_v("set wpa_passphrase %s", params->psk)) { goto out; } if (!hostapd_cli_cmd_v("set rsn_pairwise CCMP")) { @@ -1348,7 +1752,7 @@ int hapd_config_network(struct hostapd_iface *iface, if (!hostapd_cli_cmd_v("set wpa_key_mgmt WPA-PSK-SHA256")) { goto out; } - if (!hostapd_cli_cmd_v("set wpa_passphrase \"%s\"", params->psk)) { + if (!hostapd_cli_cmd_v("set wpa_passphrase %s", params->psk)) { goto out; } if (!hostapd_cli_cmd_v("set rsn_pairwise CCMP")) { @@ -1361,7 +1765,7 @@ int hapd_config_network(struct hostapd_iface *iface, if (!hostapd_cli_cmd_v("set wpa_key_mgmt SAE")) { goto out; } - if (!hostapd_cli_cmd_v("set sae_password \"%s\"", + if (!hostapd_cli_cmd_v("set sae_password %s", params->sae_password ? params->sae_password : params->psk)) { goto out; @@ -1372,7 +1776,32 @@ int hapd_config_network(struct hostapd_iface *iface, if (!hostapd_cli_cmd_v("set sae_pwe 2")) { goto out; } - iface->bss[0]->conf->sae_pwe = 2; + } else if (params->security == WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL) { + if (!hostapd_cli_cmd_v("set wpa 2")) { + goto out; + } + + if (!hostapd_cli_cmd_v("set wpa_key_mgmt WPA-PSK SAE")) { + goto out; + } + + if (!hostapd_cli_cmd_v("set wpa_passphrase \"%s\"", params->psk)) { + goto out; + } + + if (!hostapd_cli_cmd_v("set sae_password \"%s\"", + params->sae_password ? params->sae_password + : params->psk)) { + goto out; + } + + if (!hostapd_cli_cmd_v("set rsn_pairwise CCMP")) { + goto out; + } + + if (!hostapd_cli_cmd_v("set sae_pwe 2")) { + goto out; + } } else if (params->security == WIFI_SECURITY_TYPE_DPP) { if (!hostapd_cli_cmd_v("set wpa 2")) { goto out; @@ -1397,7 +1826,7 @@ int hapd_config_network(struct hostapd_iface *iface, if (!hostapd_cli_cmd_v("set wpa 0")) { goto out; } - iface->bss[0]->conf->wpa_key_mgmt = 0; + iface->bss[0]->conf->wpa_key_mgmt = WPA_KEY_MGMT_NONE; } if (!hostapd_cli_cmd_v("set ieee80211w %d", params->mfp)) { @@ -1406,7 +1835,132 @@ int hapd_config_network(struct hostapd_iface *iface, out: return ret; } -#endif + +int supplicant_ap_config_params(const struct device *dev, struct wifi_ap_config_params *params) +{ + struct hostapd_iface *iface; + const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev); + int ret = 0; + + if (params->type & WIFI_AP_CONFIG_PARAM_MAX_INACTIVITY) { + if (!wifi_mgmt_api || !wifi_mgmt_api->ap_config_params) { + wpa_printf(MSG_ERROR, "ap_config_params not supported"); + return -ENOTSUP; + } + + ret = wifi_mgmt_api->ap_config_params(dev, params); + if (ret) { + wpa_printf(MSG_ERROR, + "Failed to set maximum inactivity duration for stations"); + } else { + wpa_printf(MSG_INFO, "Set maximum inactivity duration for stations: %d (s)", + params->max_inactivity); + } + } + if (params->type & WIFI_AP_CONFIG_PARAM_MAX_NUM_STA) { + k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER); + + iface = get_hostapd_handle(dev); + if (!iface) { + ret = -ENOENT; + wpa_printf(MSG_ERROR, "Interface %s not found", dev->name); + goto out; + } + + if (iface->state > HAPD_IFACE_DISABLED) { + ret = -EBUSY; + wpa_printf(MSG_ERROR, "Interface %s is not in disable state", dev->name); + goto out; + } + + if (!hostapd_cli_cmd_v("set max_num_sta %d", params->max_num_sta)) { + ret = -EINVAL; + wpa_printf(MSG_ERROR, "Failed to set maximum number of stations"); + goto out; + } + wpa_printf(MSG_INFO, "Set maximum number of stations: %d", params->max_num_sta); + +out: + k_mutex_unlock(&wpa_supplicant_mutex); + } + + return ret; +} + +int supplicant_ap_status(const struct device *dev, struct wifi_iface_status *status) +{ + int ret = 0; + struct hostapd_iface *iface; + struct hostapd_config *conf; + struct hostapd_data *hapd; + struct hostapd_bss_config *bss; + struct hostapd_ssid *ssid; + struct hostapd_hw_modes *hw_mode; + int proto; /* Wi-Fi secure protocol */ + int key_mgmt; /* Wi-Fi key management */ + + k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER); + + iface = get_hostapd_handle(dev); + if (!iface) { + ret = -1; + wpa_printf(MSG_ERROR, "Interface %s not found", dev->name); + goto out; + } + + conf = iface->conf; + if (!conf) { + ret = -1; + wpa_printf(MSG_ERROR, "Conf %s not found", dev->name); + goto out; + } + + bss = conf->bss[0]; + if (!bss) { + ret = -1; + wpa_printf(MSG_ERROR, "Bss_conf %s not found", dev->name); + goto out; + } + + hapd = iface->bss[0]; + if (!hapd) { + ret = -1; + wpa_printf(MSG_ERROR, "Bss %s not found", dev->name); + goto out; + } + + status->state = iface->state; + ssid = &bss->ssid; + + os_memcpy(status->bssid, hapd->own_addr, WIFI_MAC_ADDR_LEN); + status->iface_mode = WIFI_MODE_AP; + status->band = wpas_band_to_zephyr(wpas_freq_to_band(iface->freq)); + key_mgmt = bss->wpa_key_mgmt; + proto = bss->wpa; + status->security = wpas_key_mgmt_to_zephyr(key_mgmt, proto); + status->mfp = get_mfp(bss->ieee80211w); + status->channel = conf->channel; + os_memcpy(status->ssid, ssid->ssid, ssid->ssid_len); + + status->dtim_period = bss->dtim_period; + status->beacon_interval = conf->beacon_int; + + hw_mode = iface->current_mode; + + status->link_mode = conf->ieee80211ax ? WIFI_6 + : conf->ieee80211ac ? WIFI_5 + : conf->ieee80211n ? WIFI_4 + : hw_mode->mode == HOSTAPD_MODE_IEEE80211G ? WIFI_3 + : hw_mode->mode == HOSTAPD_MODE_IEEE80211A ? WIFI_2 + : hw_mode->mode == HOSTAPD_MODE_IEEE80211B ? WIFI_1 + : WIFI_0; + status->twt_capable = (hw_mode->he_capab[IEEE80211_MODE_AP].mac_cap[0] & 0x04); + +out: + k_mutex_unlock(&wpa_supplicant_mutex); + return ret; +} +#endif /* CONFIG_WIFI_NM_HOSTAPD_AP */ int supplicant_ap_enable(const struct device *dev, struct wifi_connect_req_params *params) @@ -1437,6 +1991,8 @@ int supplicant_ap_enable(const struct device *dev, goto out; } + iface->owner = iface; + if (iface->state == HAPD_IFACE_ENABLED) { ret = -EBUSY; wpa_printf(MSG_ERROR, "Interface %s is not in disable state", dev->name); @@ -1487,8 +2043,10 @@ int supplicant_ap_enable(const struct device *dev, goto out; } - /* No need to check for existing network to join for SoftAP*/ + /* No need to check for existing network to join for SoftAP */ wpa_s->conf->ap_scan = 2; + /* Set BSS parameter max_num_sta to default configured value */ + wpa_s->conf->max_num_sta = CONFIG_WIFI_MGMT_AP_MAX_NUM_STA; ret = wpas_add_and_config_network(wpa_s, params, true); if (ret) { @@ -1916,7 +2474,6 @@ int supplicant_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *pa os_free(cmd); return 0; } -#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ #ifdef CONFIG_WIFI_NM_HOSTAPD_AP int hapd_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *params) @@ -1950,3 +2507,4 @@ int hapd_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *params) return 0; } #endif /* CONFIG_WIFI_NM_HOSTAPD_AP */ +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ diff --git a/modules/hostap/src/supp_api.h b/modules/hostap/src/supp_api.h index dbef7b77796d..f6584d861261 100644 --- a/modules/hostap/src/supp_api.h +++ b/modules/hostap/src/supp_api.h @@ -215,6 +215,15 @@ int supplicant_btm_query(const struct device *dev, uint8_t reason); int supplicant_get_wifi_conn_params(const struct device *dev, struct wifi_connect_req_params *params); +/** Start a WPS PBC/PIN connection + * + * @param dev Pointer to the device structure for the driver instance + * @param params wps operarion parameters + * + * @return 0 if ok, < 0 if error + */ +int supplicant_wps_config(const struct device *dev, struct wifi_wps_config_params *params); + #ifdef CONFIG_AP #ifdef CONFIG_WIFI_NM_HOSTAPD_AP /** @@ -225,6 +234,15 @@ int supplicant_get_wifi_conn_params(const struct device *dev, * @return 0 for OK; -1 for ERROR */ int hapd_state(const struct device *dev, int *state); + +/** + * @brief Wi-Fi AP configuration parameter. + * + * @param dev Wi-Fi device + * @param params AP parameters + * @return 0 for OK; -1 for ERROR + */ +int supplicant_ap_config_params(const struct device *dev, struct wifi_ap_config_params *params); #else static inline int hapd_state(const struct device *dev, int *state) { @@ -232,6 +250,15 @@ static inline int hapd_state(const struct device *dev, int *state) } #endif +/** + * @brief Get Wi-Fi SAP status + * + * @param dev Wi-Fi device + * @param status SAP status + * @return 0 for OK; -1 for ERROR + */ +int supplicant_ap_status(const struct device *dev, struct wifi_iface_status *status); + /** * @brief Set Wi-Fi AP configuration * @@ -269,7 +296,6 @@ int supplicant_ap_sta_disconnect(const struct device *dev, * @return 0 for OK; -1 for ERROR */ int supplicant_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *params); -#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ #ifdef CONFIG_WIFI_NM_HOSTAPD_AP /** @@ -281,4 +307,5 @@ int supplicant_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *pa */ int hapd_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *params); #endif /* CONFIG_WIFI_NM_HOSTAPD_AP */ +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ #endif /* ZEPHYR_SUPP_MGMT_H */ diff --git a/modules/hostap/src/supp_events.c b/modules/hostap/src/supp_events.c index 617779b4d441..9ac472b6bdb4 100644 --- a/modules/hostap/src/supp_events.c +++ b/modules/hostap/src/supp_events.c @@ -386,7 +386,7 @@ int supplicant_send_wifi_mgmt_event(const char *ifname, enum net_event_wifi_cmd (struct wifi_ap_sta_info *)supplicant_status); break; #endif /* CONFIG_AP */ - case NET_EVENT_SUPPLICANT_CMD_INT_EVENT: + case NET_EVENT_WIFI_CMD_SUPPLICANT: event_data.data = &data; if (supplicant_process_status(&event_data, (char *)supplicant_status) > 0) { net_mgmt_event_notify_with_info(NET_EVENT_SUPPLICANT_INT_EVENT, diff --git a/modules/hostap/src/supp_main.c b/modules/hostap/src/supp_main.c index 8a7382c7b39c..826e15e9d8d3 100644 --- a/modules/hostap/src/supp_main.c +++ b/modules/hostap/src/supp_main.c @@ -75,6 +75,7 @@ static const struct wifi_mgmt_ops mgmt_ops = { .btm_query = supplicant_btm_query, #endif .get_conn_params = supplicant_get_wifi_conn_params, + .wps_config = supplicant_wps_config, #ifdef CONFIG_AP .ap_enable = supplicant_ap_enable, .ap_disable = supplicant_ap_disable, @@ -93,14 +94,14 @@ DEFINE_WIFI_NM_INSTANCE(wifi_supplicant, &mgmt_ops); #ifdef CONFIG_WIFI_NM_HOSTAPD_AP static const struct wifi_mgmt_ops mgmt_ap_ops = { - .set_btwt = supplicant_set_btwt, .ap_enable = supplicant_ap_enable, .ap_disable = supplicant_ap_disable, .ap_sta_disconnect = supplicant_ap_sta_disconnect, - .ap_bandwidth = supplicant_ap_bandwidth, + .iface_status = supplicant_ap_status, #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP .dpp_dispatch = hapd_dpp_dispatch, #endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ + .ap_config_params = supplicant_ap_config_params, }; DEFINE_WIFI_NM_INSTANCE(hostapd, &mgmt_ap_ops); @@ -508,6 +509,12 @@ static void iface_cb(struct net_if *iface, void *user_data) return; } +#ifdef CONFIG_WIFI_NM_HOSTAPD_AP + if (wifi_nm_iface_is_sap(iface)) { + return; + } +#endif + if (!net_if_is_admin_up(iface)) { return; } @@ -866,7 +873,7 @@ struct hostapd_config *hostapd_config_read2(const char *fname) bss = conf->last_bss; bss->start_disabled = 1; - bss->max_num_sta = 8; + bss->max_num_sta = CONFIG_WIFI_MGMT_AP_MAX_NUM_STA; bss->dtim_period = 1; os_strlcpy(conf->bss[0]->iface, ifname, sizeof(conf->bss[0]->iface)); bss->logger_stdout_level = HOSTAPD_LEVEL_INFO; diff --git a/modules/hostap/src/supp_main.h b/modules/hostap/src/supp_main.h index 03f7461555e4..981bdf669585 100644 --- a/modules/hostap/src/supp_main.h +++ b/modules/hostap/src/supp_main.h @@ -6,6 +6,37 @@ #ifndef __SUPP_MAIN_H_ #define __SUPP_MAIN_H_ +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE +/* At least one of the EAP methods need to be enabled in enterprise mode */ +#if !defined(CONFIG_EAP_TLS) && !defined(CONFIG_EAP_TTLS) && \ + !defined(CONFIG_EAP_PEAP) && !defined(CONFIG_EAP_FAST) && \ + !defined(CONFIG_EAP_SIM) && !defined(CONFIG_EAP_AKA) && \ + !defined(CONFIG_EAP_MD5) && !defined(CONFIG_EAP_MSCHAPV2) && \ + !defined(CONFIG_EAP_PSK) && !defined(CONFIG_EAP_PAX) && \ + !defined(CONFIG_EAP_SAKE) && !defined(CONFIG_EAP_GPSK) && \ + !defined(CONFIG_EAP_PWD) && !defined(CONFIG_EAP_EKE) && \ + !defined(CONFIG_EAP_IKEV2) && !defined(CONFIG_EAP_GTC) +#error "At least one of the following EAP methods need to be defined \ + CONFIG_EAP_TLS \ + CONFIG_EAP_TTLS \ + CONFIG_EAP_PEAP \ + CONFIG_EAP_MD5 \ + CONFIG_EAP_MSCHAPV2 \ + CONFIG_EAP_LEAP \ + CONFIG_EAP_PSK \ + CONFIG_EAP_PAX \ + CONFIG_EAP_SAKE \ + CONFIG_EAP_GPSK \ + CONFIG_EAP_PWD \ + CONFIG_EAP_EKE \ + CONFIG_EAP_IKEV2 \ + CONFIG_EAP_SIM \ + CONFIG_EAP_AKA \ + CONFIG_EAP_GTC \ + CONFIG_EAP_ALL " +#endif /* EAP METHODS */ +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE */ + #if !defined(CONFIG_NET_DHCPV4) static inline void net_dhcpv4_start(struct net_if *iface) { @@ -21,12 +52,17 @@ static inline void net_dhcpv4_stop(struct net_if *iface) struct wpa_global *zephyr_get_default_supplicant_context(void); struct wpa_supplicant *zephyr_get_handle_by_ifname(const char *ifname); + #ifdef CONFIG_WIFI_NM_HOSTAPD_AP +#include "common.h" +#include "wpa_debug_zephyr.h" + struct hostapd_iface *zephyr_get_hapd_handle_by_ifname(const char *ifname); void wpa_supplicant_msg_send(void *ctx, int level, enum wpa_msg_type type, const char *txt, size_t len); void hostapd_msg_send(void *ctx, int level, enum wpa_msg_type type, const char *buf, size_t len); #endif + struct wpa_supplicant_event_msg { #ifdef CONFIG_WIFI_NM_HOSTAPD_AP int hostapd; diff --git a/samples/basic/button/src/main.c b/samples/basic/button/src/main.c index b181afcc34ee..a86407a65c25 100644 --- a/samples/basic/button/src/main.c +++ b/samples/basic/button/src/main.c @@ -18,7 +18,7 @@ * Get button configuration from the devicetree sw0 alias. This is mandatory. */ #define SW0_NODE DT_ALIAS(sw0) -#if !DT_NODE_HAS_STATUS(SW0_NODE, okay) +#if !DT_NODE_HAS_STATUS_OKAY(SW0_NODE) #error "Unsupported board: sw0 devicetree alias is not defined" #endif static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios, diff --git a/samples/basic/threads/src/main.c b/samples/basic/threads/src/main.c index 0554ddd9daf1..529df15908ad 100644 --- a/samples/basic/threads/src/main.c +++ b/samples/basic/threads/src/main.c @@ -20,11 +20,11 @@ #define LED0_NODE DT_ALIAS(led0) #define LED1_NODE DT_ALIAS(led1) -#if !DT_NODE_HAS_STATUS(LED0_NODE, okay) +#if !DT_NODE_HAS_STATUS_OKAY(LED0_NODE) #error "Unsupported board: led0 devicetree alias is not defined" #endif -#if !DT_NODE_HAS_STATUS(LED1_NODE, okay) +#if !DT_NODE_HAS_STATUS_OKAY(LED1_NODE) #error "Unsupported board: led1 devicetree alias is not defined" #endif diff --git a/samples/bluetooth/central_otc/src/main.c b/samples/bluetooth/central_otc/src/main.c index 23a2968e14a6..171bbe7187ca 100644 --- a/samples/bluetooth/central_otc/src/main.c +++ b/samples/bluetooth/central_otc/src/main.c @@ -77,8 +77,8 @@ static void print_hex_number(const uint8_t *num, size_t len) #define SW1_NODE DT_ALIAS(sw1) #define SW2_NODE DT_ALIAS(sw2) #define SW3_NODE DT_ALIAS(sw3) -#if !DT_NODE_HAS_STATUS(SW0_NODE, okay) || !DT_NODE_HAS_STATUS(SW1_NODE, okay) || \ - !DT_NODE_HAS_STATUS(SW2_NODE, okay) || !DT_NODE_HAS_STATUS(SW3_NODE, okay) +#if !DT_NODE_HAS_STATUS_OKAY(SW0_NODE) || !DT_NODE_HAS_STATUS_OKAY(SW1_NODE) || \ + !DT_NODE_HAS_STATUS_OKAY(SW2_NODE) || !DT_NODE_HAS_STATUS_OKAY(SW3_NODE) #error "Unsupported board: This sample need 4 buttons to run" #endif diff --git a/samples/bluetooth/encrypted_advertising/central/src/main.c b/samples/bluetooth/encrypted_advertising/central/src/main.c index 888940af780b..122641b311a4 100644 --- a/samples/bluetooth/encrypted_advertising/central/src/main.c +++ b/samples/bluetooth/encrypted_advertising/central/src/main.c @@ -30,7 +30,7 @@ LOG_MODULE_DECLARE(ead_central_sample, CONFIG_BT_EAD_LOG_LEVEL); * Get button configuration from the devicetree sw0 alias. This is mandatory. */ #define SW0_NODE DT_ALIAS(sw0) -#if !DT_NODE_HAS_STATUS(SW0_NODE, okay) +#if !DT_NODE_HAS_STATUS_OKAY(SW0_NODE) #error "Unsupported board: sw0 devicetree alias is not defined" #endif static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios, {0}); diff --git a/samples/bluetooth/encrypted_advertising/peripheral/src/main.c b/samples/bluetooth/encrypted_advertising/peripheral/src/main.c index 6b269d30513b..affa5430af2c 100644 --- a/samples/bluetooth/encrypted_advertising/peripheral/src/main.c +++ b/samples/bluetooth/encrypted_advertising/peripheral/src/main.c @@ -26,7 +26,7 @@ LOG_MODULE_DECLARE(ead_peripheral_sample, CONFIG_BT_EAD_LOG_LEVEL); * Get button configuration from the devicetree sw0 alias. This is mandatory. */ #define SW0_NODE DT_ALIAS(sw0) -#if !DT_NODE_HAS_STATUS(SW0_NODE, okay) +#if !DT_NODE_HAS_STATUS_OKAY(SW0_NODE) #error "Unsupported board: sw0 devicetree alias is not defined" #endif static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios, {0}); diff --git a/samples/bluetooth/iso_receive/src/main.c b/samples/bluetooth/iso_receive/src/main.c index 3b7c051f387f..989694907b4a 100644 --- a/samples/bluetooth/iso_receive/src/main.c +++ b/samples/bluetooth/iso_receive/src/main.c @@ -42,7 +42,7 @@ static K_SEM_DEFINE(sem_big_sync_lost, 0, BIS_ISO_CHAN_COUNT); /* The devicetree node identifier for the "led0" alias. */ #define LED0_NODE DT_ALIAS(led0) -#if DT_NODE_HAS_STATUS(LED0_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(LED0_NODE) static const struct gpio_dt_spec led_gpio = GPIO_DT_SPEC_GET(LED0_NODE, gpios); #define HAS_LED 1 #define BLINK_ONOFF K_MSEC(500) diff --git a/samples/bluetooth/mesh_provisioner/src/main.c b/samples/bluetooth/mesh_provisioner/src/main.c index 472dc020d438..d4be8601304f 100644 --- a/samples/bluetooth/mesh_provisioner/src/main.c +++ b/samples/bluetooth/mesh_provisioner/src/main.c @@ -20,7 +20,7 @@ static uint8_t node_uuid[16]; K_SEM_DEFINE(sem_unprov_beacon, 0, 1); K_SEM_DEFINE(sem_node_added, 0, 1); -#if DT_NODE_HAS_STATUS(SW0_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(SW0_NODE) K_SEM_DEFINE(sem_button_pressed, 0, 1); #endif @@ -315,7 +315,7 @@ static uint8_t check_unconfigured(struct bt_mesh_cdb_node *node, void *data) return BT_MESH_CDB_ITER_CONTINUE; } -#if DT_NODE_HAS_STATUS(SW0_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(SW0_NODE) static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios, {0}); static struct gpio_callback button_cb_data; @@ -366,7 +366,7 @@ int main(void) printk("Bluetooth initialized\n"); bt_ready(); -#if DT_NODE_HAS_STATUS(SW0_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(SW0_NODE) button_init(); #endif @@ -383,7 +383,7 @@ int main(void) bin2hex(node_uuid, 16, uuid_hex_str, sizeof(uuid_hex_str)); -#if DT_NODE_HAS_STATUS(SW0_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(SW0_NODE) k_sem_reset(&sem_button_pressed); printk("Device %s detected, press button 1 to provision.\n", uuid_hex_str); err = k_sem_take(&sem_button_pressed, K_SECONDS(30)); diff --git a/samples/bluetooth/periodic_sync/src/main.c b/samples/bluetooth/periodic_sync/src/main.c index 44c5a8530b4a..a8baf5d26006 100644 --- a/samples/bluetooth/periodic_sync/src/main.c +++ b/samples/bluetooth/periodic_sync/src/main.c @@ -24,7 +24,7 @@ static K_SEM_DEFINE(sem_per_sync_lost, 0, 1); /* The devicetree node identifier for the "led0" alias. */ #define LED0_NODE DT_ALIAS(led0) -#if DT_NODE_HAS_STATUS(LED0_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(LED0_NODE) #define HAS_LED 1 static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios); #define BLINK_ONOFF K_MSEC(500) diff --git a/samples/bluetooth/peripheral_hids/src/hog.c b/samples/bluetooth/peripheral_hids/src/hog.c index cf67521517d0..9aefdf2ea98c 100644 --- a/samples/bluetooth/peripheral_hids/src/hog.c +++ b/samples/bluetooth/peripheral_hids/src/hog.c @@ -180,7 +180,7 @@ void hog_init(void) void hog_button_loop(void) { -#if DT_NODE_HAS_STATUS(SW0_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(SW0_NODE) const struct gpio_dt_spec sw0 = GPIO_DT_SPEC_GET(SW0_NODE, gpios); gpio_pin_configure_dt(&sw0, GPIO_INPUT); diff --git a/samples/bluetooth/peripheral_hr/src/main.c b/samples/bluetooth/peripheral_hr/src/main.c index 8d7f73e54406..19c640ca91b5 100644 --- a/samples/bluetooth/peripheral_hr/src/main.c +++ b/samples/bluetooth/peripheral_hr/src/main.c @@ -123,7 +123,7 @@ static void hrs_notify(void) /* The devicetree node identifier for the "led0" alias. */ #define LED0_NODE DT_ALIAS(led0) -#if DT_NODE_HAS_STATUS(LED0_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(LED0_NODE) #include #define HAS_LED 1 static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios); diff --git a/samples/boards/espressif/deep_sleep/src/main.c b/samples/boards/espressif/deep_sleep/src/main.c index edf8b5597051..519a1a550df9 100644 --- a/samples/boards/espressif/deep_sleep/src/main.c +++ b/samples/boards/espressif/deep_sleep/src/main.c @@ -17,7 +17,7 @@ #endif #ifdef CONFIG_EXAMPLE_GPIO_WAKEUP -#if !DT_NODE_HAS_STATUS(DT_ALIAS(wakeup_button), okay) +#if !DT_NODE_HAS_STATUS_OKAY(DT_ALIAS(wakeup_button)) #error "Unsupported: wakeup-button alias is not defined" #else static const struct gpio_dt_spec wakeup_button = GPIO_DT_SPEC_GET(DT_ALIAS(wakeup_button), gpios); diff --git a/samples/boards/espressif/light_sleep/src/main.c b/samples/boards/espressif/light_sleep/src/main.c index 50cb920d159e..9134f6a2006c 100644 --- a/samples/boards/espressif/light_sleep/src/main.c +++ b/samples/boards/espressif/light_sleep/src/main.c @@ -16,7 +16,7 @@ */ #define SW0_NODE DT_ALIAS(sw0) -#if !DT_NODE_HAS_STATUS(SW0_NODE, okay) +#if !DT_NODE_HAS_STATUS_OKAY(SW0_NODE) #error "unsupported board: sw0 devicetree alias is not defined" #endif diff --git a/samples/boards/nordic/battery/src/battery.c b/samples/boards/nordic/battery/src/battery.c index a0fbb651b58b..3a31a91398b9 100644 --- a/samples/boards/nordic/battery/src/battery.c +++ b/samples/boards/nordic/battery/src/battery.c @@ -51,7 +51,7 @@ struct divider_config { }; static const struct divider_config divider_config = { -#if DT_NODE_HAS_STATUS(VBATT, okay) +#if DT_NODE_HAS_STATUS_OKAY(VBATT) .io_channel = { DT_IO_CHANNELS_INPUT(VBATT), }, @@ -72,7 +72,7 @@ struct divider_data { int16_t raw; }; static struct divider_data divider_data = { -#if DT_NODE_HAS_STATUS(VBATT, okay) +#if DT_NODE_HAS_STATUS_OKAY(VBATT) .adc = DEVICE_DT_GET(DT_IO_CHANNELS_CTLR(VBATT)), #else .adc = DEVICE_DT_GET(DT_IO_CHANNELS_CTLR(ZEPHYR_USER)), diff --git a/samples/boards/nordic/clock_control/configs/cpuapp_hsfll.conf b/samples/boards/nordic/clock_control/configs/cpuapp_hsfll.conf index 5c1bad08a80e..53eebac30bed 100644 --- a/samples/boards/nordic/clock_control/configs/cpuapp_hsfll.conf +++ b/samples/boards/nordic/clock_control/configs/cpuapp_hsfll.conf @@ -1,6 +1,6 @@ # Copyright (c) 2024 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -CONFIG_CLOCK_CONTROL_NRF2=y +CONFIG_CLOCK_CONTROL=y CONFIG_SAMPLE_CLOCK_FREQUENCY_HZ=320000000 diff --git a/samples/boards/nordic/clock_control/configs/fll16m.conf b/samples/boards/nordic/clock_control/configs/fll16m.conf index de9942857b9c..c5d3a84f661c 100644 --- a/samples/boards/nordic/clock_control/configs/fll16m.conf +++ b/samples/boards/nordic/clock_control/configs/fll16m.conf @@ -1,6 +1,6 @@ # Copyright (c) 2024 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -CONFIG_CLOCK_CONTROL_NRF2=y +CONFIG_CLOCK_CONTROL=y CONFIG_SAMPLE_CLOCK_ACCURACY_PPM=30 diff --git a/samples/boards/nordic/clock_control/configs/lfclk.conf b/samples/boards/nordic/clock_control/configs/lfclk.conf index 6cf09f0e4c71..b866d3d81d10 100644 --- a/samples/boards/nordic/clock_control/configs/lfclk.conf +++ b/samples/boards/nordic/clock_control/configs/lfclk.conf @@ -1,7 +1,7 @@ # Copyright (c) 2024 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -CONFIG_CLOCK_CONTROL_NRF2=y +CONFIG_CLOCK_CONTROL=y CONFIG_SAMPLE_CLOCK_ACCURACY_PPM=20 CONFIG_SAMPLE_CLOCK_PRECISION=1 diff --git a/samples/boards/nordic/clock_control/configs/uart135.conf b/samples/boards/nordic/clock_control/configs/uart135.conf index de9942857b9c..c5d3a84f661c 100644 --- a/samples/boards/nordic/clock_control/configs/uart135.conf +++ b/samples/boards/nordic/clock_control/configs/uart135.conf @@ -1,6 +1,6 @@ # Copyright (c) 2024 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -CONFIG_CLOCK_CONTROL_NRF2=y +CONFIG_CLOCK_CONTROL=y CONFIG_SAMPLE_CLOCK_ACCURACY_PPM=30 diff --git a/samples/boards/nordic/nrf_sys_event/CMakeLists.txt b/samples/boards/nordic/nrf_sys_event/CMakeLists.txt new file mode 100644 index 000000000000..5f7335b260e7 --- /dev/null +++ b/samples/boards/nordic/nrf_sys_event/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(soc_sys_event) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/samples/boards/nordic/nrf_sys_event/prj.conf b/samples/boards/nordic/nrf_sys_event/prj.conf new file mode 100644 index 000000000000..28f655a7e24e --- /dev/null +++ b/samples/boards/nordic/nrf_sys_event/prj.conf @@ -0,0 +1,4 @@ +# Copyright 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_NRF_SYS_EVENT=y diff --git a/samples/boards/nordic/nrf_sys_event/sample.yaml b/samples/boards/nordic/nrf_sys_event/sample.yaml new file mode 100644 index 000000000000..c5ea3d8a23de --- /dev/null +++ b/samples/boards/nordic/nrf_sys_event/sample.yaml @@ -0,0 +1,28 @@ +sample: + name: nRF System events +tests: + sample.boards.nordic.nrf_sys_event: + harness: console + harness_config: + type: one_line + regex: + - "constant latency mode disabled" + platform_allow: + - nrf52dk/nrf52810 + - nrf52dk/nrf52832 + - nrf52833dk/nrf52820 + - nrf52833dk/nrf52833 + - nrf52840dk/nrf52811 + - nrf52840dk/nrf52840 + - nrf5340dk/nrf5340/cpuapp + - nrf5340dk/nrf5340/cpunet + - nrf54h20dk/nrf54h20/cpuapp + - nrf54h20dk/nrf54h20/cpurad + - nrf54l15dk/nrf54l15/cpuapp + integration_platforms: + - nrf52840dk/nrf52840 + - nrf5340dk/nrf5340/cpuapp + - nrf5340dk/nrf5340/cpunet + - nrf54h20dk/nrf54h20/cpuapp + - nrf54h20dk/nrf54h20/cpurad + - nrf54l15dk/nrf54l15/cpuapp diff --git a/samples/boards/nordic/nrf_sys_event/src/main.c b/samples/boards/nordic/nrf_sys_event/src/main.c new file mode 100644 index 000000000000..e97d3c821f78 --- /dev/null +++ b/samples/boards/nordic/nrf_sys_event/src/main.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +int main(void) +{ + printf("request global constant latency mode\n"); + if (nrf_sys_event_request_global_constlat()) { + printf("failed to request global constant latency mode\n"); + return 0; + } + printf("constant latency mode enabled\n"); + + printf("request global constant latency mode again\n"); + if (nrf_sys_event_request_global_constlat()) { + printf("failed to request global constant latency mode\n"); + return 0; + } + + printf("release global constant latency mode\n"); + printf("constant latency mode will remain enabled\n"); + if (nrf_sys_event_release_global_constlat()) { + printf("failed to release global constant latency mode\n"); + return 0; + } + + printf("release global constant latency mode again\n"); + printf("constant latency mode will be disabled\n"); + if (nrf_sys_event_release_global_constlat()) { + printf("failed to release global constant latency mode\n"); + return 0; + } + + printf("constant latency mode disabled\n"); + return 0; +} diff --git a/samples/boards/nordic/system_off/README.rst b/samples/boards/nordic/system_off/README.rst index 7cf546d901d6..7c98a4e83362 100644 --- a/samples/boards/nordic/system_off/README.rst +++ b/samples/boards/nordic/system_off/README.rst @@ -22,7 +22,7 @@ RAM is configured to keep the containing section powered while in system-off mod Requirements ************ -This application uses nRF51 DK, nRF52 DK or nRF54L15 PDK board for the demo. +This application uses nRF51 DK, nRF52 DK or nRF54L15 DK board for the demo. Sample Output ============= diff --git a/samples/boards/nxp/mimxrt1060_evk/system_off/src/main.c b/samples/boards/nxp/mimxrt1060_evk/system_off/src/main.c index 57b0298f8614..af5dbf4b8453 100644 --- a/samples/boards/nxp/mimxrt1060_evk/system_off/src/main.c +++ b/samples/boards/nxp/mimxrt1060_evk/system_off/src/main.c @@ -17,12 +17,12 @@ #define SOFT_OFF_S 10U #define SW0_NODE DT_ALIAS(sw0) -#if !DT_NODE_HAS_STATUS(SW0_NODE, okay) +#if !DT_NODE_HAS_STATUS_OKAY(SW0_NODE) #error "Unsupported board: sw0 devicetree alias is not defined" #endif #define SNVS_RTC_NODE DT_NODELABEL(snvs_rtc) -#if !DT_NODE_HAS_STATUS(SNVS_RTC_NODE, okay) +#if !DT_NODE_HAS_STATUS_OKAY(SNVS_RTC_NODE) #error "Unsupported board: snvs_rtc node is not enabled" #endif diff --git a/samples/boards/st/i2c_timing/src/main.c b/samples/boards/st/i2c_timing/src/main.c index 41b8dfa2dee2..80f8001318db 100644 --- a/samples/boards/st/i2c_timing/src/main.c +++ b/samples/boards/st/i2c_timing/src/main.c @@ -10,7 +10,7 @@ #include -#if DT_NODE_HAS_STATUS(DT_ALIAS(i2c_0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_ALIAS(i2c_0)) #define I2C_DEV_NODE DT_ALIAS(i2c_0) #else #error "Please set the correct I2C device" diff --git a/samples/boards/st/mco/src/main.c b/samples/boards/st/mco/src/main.c index 966e80f8525b..7e79d1e8cd8d 100644 --- a/samples/boards/st/mco/src/main.c +++ b/samples/boards/st/mco/src/main.c @@ -25,7 +25,7 @@ int main(void) return -1; } -#if DT_NODE_HAS_STATUS(DT_NODELABEL(mco2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(mco2)) dev = DEVICE_DT_GET(DT_NODELABEL(mco2)); if (device_is_ready(dev)) { printk("MCO2 device successfully configured\n"); diff --git a/samples/boards/st/power_mgmt/standby_shutdown/src/main.c b/samples/boards/st/power_mgmt/standby_shutdown/src/main.c index 6610f01f955f..b74051bc99f9 100644 --- a/samples/boards/st/power_mgmt/standby_shutdown/src/main.c +++ b/samples/boards/st/power_mgmt/standby_shutdown/src/main.c @@ -23,7 +23,7 @@ #define SLEEP_TIME_MS 3000 #define SW0_NODE DT_ALIAS(sw0) -#if !DT_NODE_HAS_STATUS(SW0_NODE, okay) +#if !DT_NODE_HAS_STATUS_OKAY(SW0_NODE) #error "Unsupported board: sw0 devicetree alias is not defined" #endif diff --git a/samples/boards/st/power_mgmt/wkup_pins/src/main.c b/samples/boards/st/power_mgmt/wkup_pins/src/main.c index 2284a76b0356..c83db862d435 100644 --- a/samples/boards/st/power_mgmt/wkup_pins/src/main.c +++ b/samples/boards/st/power_mgmt/wkup_pins/src/main.c @@ -15,7 +15,7 @@ #define WAIT_TIME_US 4000000 #define WKUP_SRC_NODE DT_ALIAS(wkup_src) -#if !DT_NODE_HAS_STATUS(WKUP_SRC_NODE, okay) +#if !DT_NODE_HAS_STATUS_OKAY(WKUP_SRC_NODE) #error "Unsupported board: wkup_src devicetree alias is not defined" #endif diff --git a/samples/drivers/espi/src/main.c b/samples/drivers/espi/src/main.c index fff0998459db..aa6b92a47256 100644 --- a/samples/drivers/espi/src/main.c +++ b/samples/drivers/espi/src/main.c @@ -45,7 +45,7 @@ LOG_MODULE_DECLARE(espi, CONFIG_ESPI_LOG_LEVEL); /* The devicetree node identifier for the board power rails pins. */ #define BRD_PWR_NODE DT_NODELABEL(board_power) -#if DT_NODE_HAS_STATUS(BRD_PWR_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(BRD_PWR_NODE) static const struct gpio_dt_spec pwrgd_gpio = GPIO_DT_SPEC_GET(BRD_PWR_NODE, pwrg_gpios); static const struct gpio_dt_spec rsm_gpio = GPIO_DT_SPEC_GET(BRD_PWR_NODE, rsm_gpios); #endif @@ -911,7 +911,7 @@ int espi_init(void) return ret; } -#if DT_NODE_HAS_STATUS(BRD_PWR_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(BRD_PWR_NODE) static int wait_for_pin(const struct gpio_dt_spec *gpio, uint16_t timeout, int exp_level) { uint16_t loop_cnt = timeout; @@ -1172,7 +1172,7 @@ int espi_test(void) */ k_sleep(K_SECONDS(1)); -#if DT_NODE_HAS_STATUS(BRD_PWR_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(BRD_PWR_NODE) if (!gpio_is_ready_dt(&pwrgd_gpio)) { LOG_ERR("%s: device not ready.", pwrgd_gpio.port->name); return -ENODEV; @@ -1201,7 +1201,7 @@ int espi_test(void) LOG_INF("Hello eSPI test %s", CONFIG_BOARD); -#if DT_NODE_HAS_STATUS(BRD_PWR_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(BRD_PWR_NODE) ret = gpio_pin_configure_dt(&pwrgd_gpio, GPIO_INPUT); if (ret) { LOG_ERR("Unable to configure %d:%d", pwrgd_gpio.pin, ret); @@ -1252,7 +1252,7 @@ int espi_test(void) } #endif -#if DT_NODE_HAS_STATUS(BRD_PWR_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(BRD_PWR_NODE) ret = wait_for_pin(&pwrgd_gpio, PWR_SEQ_TIMEOUT, 1); if (ret) { LOG_ERR("RSMRST_PWRGD timeout"); diff --git a/samples/drivers/i2s/echo/src/main.c b/samples/drivers/i2s/echo/src/main.c index c0ac1505d7b3..bffa794158b3 100644 --- a/samples/drivers/i2s/echo/src/main.c +++ b/samples/drivers/i2s/echo/src/main.c @@ -30,12 +30,12 @@ #define TIMEOUT 1000 #define SW0_NODE DT_ALIAS(sw0) -#if DT_NODE_HAS_STATUS(SW0_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(SW0_NODE) static struct gpio_dt_spec sw0_spec = GPIO_DT_SPEC_GET(SW0_NODE, gpios); #endif #define SW1_NODE DT_ALIAS(sw1) -#if DT_NODE_HAS_STATUS(SW1_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(SW1_NODE) static struct gpio_dt_spec sw1_spec = GPIO_DT_SPEC_GET(SW1_NODE, gpios); #endif @@ -47,7 +47,7 @@ static int16_t echo_block[SAMPLES_PER_BLOCK]; static volatile bool echo_enabled = true; static K_SEM_DEFINE(toggle_transfer, 1, 1); -#if DT_NODE_HAS_STATUS(SW0_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(SW0_NODE) static void sw0_handler(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { @@ -58,7 +58,7 @@ static void sw0_handler(const struct device *dev, struct gpio_callback *cb, } #endif -#if DT_NODE_HAS_STATUS(SW1_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(SW1_NODE) static void sw1_handler(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { @@ -70,7 +70,7 @@ static bool init_buttons(void) { int ret; -#if DT_NODE_HAS_STATUS(SW0_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(SW0_NODE) static struct gpio_callback sw0_cb_data; if (!gpio_is_ready_dt(&sw0_spec)) { @@ -98,7 +98,7 @@ static bool init_buttons(void) printk("Press \"%s\" to toggle the echo effect\n", sw0_spec.port->name); #endif -#if DT_NODE_HAS_STATUS(SW1_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(SW1_NODE) static struct gpio_callback sw1_cb_data; if (!gpio_is_ready_dt(&sw1_spec)) { diff --git a/samples/drivers/lora/receive/src/main.c b/samples/drivers/lora/receive/src/main.c index 9b5033540011..e6ba6086ae06 100644 --- a/samples/drivers/lora/receive/src/main.c +++ b/samples/drivers/lora/receive/src/main.c @@ -11,7 +11,7 @@ #include #define DEFAULT_RADIO_NODE DT_ALIAS(lora0) -BUILD_ASSERT(DT_NODE_HAS_STATUS(DEFAULT_RADIO_NODE, okay), +BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(DEFAULT_RADIO_NODE), "No default LoRa radio specified in DT"); #define MAX_DATA_LEN 255 diff --git a/samples/drivers/lora/send/src/main.c b/samples/drivers/lora/send/src/main.c index 63cce8367af8..7988fa8762ee 100644 --- a/samples/drivers/lora/send/src/main.c +++ b/samples/drivers/lora/send/src/main.c @@ -11,7 +11,7 @@ #include #define DEFAULT_RADIO_NODE DT_ALIAS(lora0) -BUILD_ASSERT(DT_NODE_HAS_STATUS(DEFAULT_RADIO_NODE, okay), +BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(DEFAULT_RADIO_NODE), "No default LoRa radio specified in DT"); #define MAX_DATA_LEN 10 diff --git a/samples/net/wifi/boards/rd_rw612_bga.conf b/samples/net/wifi/boards/rd_rw612_bga.conf index 1df1baa0be7a..d6435e874b77 100644 --- a/samples/net/wifi/boards/rd_rw612_bga.conf +++ b/samples/net/wifi/boards/rd_rw612_bga.conf @@ -28,6 +28,7 @@ CONFIG_ZVFS_OPEN_MAX=30 CONFIG_SHELL_ARGC_MAX=48 CONFIG_WIFI_SHELL_MAX_AP_STA=8 CONFIG_WIFI_MGMT_AP_MAX_NUM_STA=8 +CONFIG_SHELL_CMD_BUFF_SIZE=512 # net CONFIG_NET_L2_ETHERNET=y @@ -85,12 +86,14 @@ CONFIG_WIFI_NM_WPA_SUPPLICANT_INF_MON=n CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES=2 CONFIG_SAE_PWE_EARLY_EXIT=y CONFIG_WIFI_NM_HOSTAPD_AP=y +CONFIG_WIFI_NM_WPA_SUPPLICANT_WPS=y # Enable mbedtls CONFIG_MBEDTLS=y CONFIG_MBEDTLS_BUILTIN=y CONFIG_MBEDTLS_USER_CONFIG_ENABLE=y CONFIG_MBEDTLS_USER_CONFIG_FILE="wpa_supp_els_pkc_mbedtls_config.h" +CONFIG_MBEDTLS_HAVE_TIME_DATE=y # Include els_pkc in build CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/net/wifi/overlay-enterprise-variable-bufs.conf b/samples/net/wifi/overlay-enterprise-variable-bufs.conf new file mode 100644 index 000000000000..627d77a92478 --- /dev/null +++ b/samples/net/wifi/overlay-enterprise-variable-bufs.conf @@ -0,0 +1,9 @@ +CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE=y +# EAP frames are ~1100 bytes, so, for efficiency, we set the data size to 1100 +CONFIG_NET_BUF_DATA_SIZE=1100 +# Use variable data size to reduce memory usage for small data packets +CONFIG_NET_BUF_VARIABLE_DATA_SIZE=y +# For TLS and X.509 processing MbedTLS needs large heap size and using separate heap +# for MbedTLS gives us more control over the heap size. +CONFIG_MBEDTLS_ENABLE_HEAP=y +CONFIG_MBEDTLS_HEAP_SIZE=55000 diff --git a/samples/net/wifi/overlay-enterprise.conf b/samples/net/wifi/overlay-enterprise.conf new file mode 100644 index 000000000000..ba6d958f9a53 --- /dev/null +++ b/samples/net/wifi/overlay-enterprise.conf @@ -0,0 +1,10 @@ +CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE=y +# EAP frames are ~1100 bytes, so, need higher packet counts as default packet size is 128 +CONFIG_NET_PKT_TX_COUNT=36 +CONFIG_NET_PKT_RX_COUNT=36 +CONFIG_NET_BUF_TX_COUNT=72 +CONFIG_NET_BUF_RX_COUNT=36 +# For TLS and X.509 processing MbedTLS needs large heap size and using separate heap +# for MbedTLS gives us more control over the heap size. +CONFIG_MBEDTLS_ENABLE_HEAP=y +CONFIG_MBEDTLS_HEAP_SIZE=70000 diff --git a/samples/net/wifi/prj.conf b/samples/net/wifi/prj.conf index e1a1b40a4098..ab3d718f06b1 100644 --- a/samples/net/wifi/prj.conf +++ b/samples/net/wifi/prj.conf @@ -31,6 +31,10 @@ CONFIG_NET_STATISTICS_PERIODIC_OUTPUT=n CONFIG_WIFI=y CONFIG_WIFI_LOG_LEVEL_ERR=y CONFIG_NET_L2_WIFI_SHELL=y + +CONFIG_MBEDTLS_ENABLE_HEAP=y +CONFIG_MBEDTLS_HEAP_SIZE=70000 + # printing of scan results puts pressure on queues in new locking # design in net_mgmt. So, use a higher timeout for a crowded # environment. diff --git a/samples/net/wifi/sample.yaml b/samples/net/wifi/sample.yaml index 51c52edbd6f9..c5234753a782 100644 --- a/samples/net/wifi/sample.yaml +++ b/samples/net/wifi/sample.yaml @@ -65,6 +65,7 @@ tests: - nucleo_h723zg sample.net.wifi.nrf7002eb: extra_args: + - CONFIG_NRF70_UTIL=y - SB_CONFIG_WIFI_NRF70=y - CONFIG_NRF_WIFI_BUILD_ONLY_MODE=y - SHIELD=nrf7002eb diff --git a/samples/net/wifi/test_certs/ca.pem b/samples/net/wifi/test_certs/ca.pem index 70a234dfdc35..2b872d2e30da 100644 --- a/samples/net/wifi/test_certs/ca.pem +++ b/samples/net/wifi/test_certs/ca.pem @@ -1,29 +1,24 @@ -----BEGIN CERTIFICATE----- -MIIE9zCCA9+gAwIBAgIUNX/wAWvB0xblUUghlsoear4f6kkwDQYJKoZIhvcNAQEL +MIIEBzCCAu+gAwIBAgIUK8+d+8IOzeX+DP3VSvdF3lHiCdcwDQYJKoZIhvcNAQEL BQAwgZIxCzAJBgNVBAYTAkZSMQ8wDQYDVQQIDAZSYWRpdXMxEjAQBgNVBAcMCVNv -bWV3aGVyZTEUMBIGA1UECgwLRXhhbXBsZSBJbmMxIDAeBgkqhkiG9w0BCQEWEWFk -bWluQGV4YW1wbGUub3JnMSYwJAYDVQQDDB1FeGFtcGxlIENlcnRpZmljYXRlIEF1 -dGhvcml0eTAeFw0yNDA4MDcxODQzMDZaFw0yNDEwMDYxODQzMDZaMIGSMQswCQYD +bWV3aGVyZTEUMBIGA1UECgwLRXhhbXBsZSBJbmMxJjAkBgNVBAMMHUV4YW1wbGUg +Q2VydGlmaWNhdGUgQXV0aG9yaXR5MSAwHgYJKoZIhvcNAQkBFhFhZG1pbkBleGFt +cGxlLm9yZzAeFw0yNDEwMDgxMDI0MDZaFw0zNDEwMDYxMDI0MDZaMIGSMQswCQYD VQQGEwJGUjEPMA0GA1UECAwGUmFkaXVzMRIwEAYDVQQHDAlTb21ld2hlcmUxFDAS -BgNVBAoMC0V4YW1wbGUgSW5jMSAwHgYJKoZIhvcNAQkBFhFhZG1pbkBleGFtcGxl -Lm9yZzEmMCQGA1UEAwwdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwggEi -MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCzR3RL3+70yN+1Nx0bAXT60qqf -AxCk/NXphq5cxUT5skXc97KUUnIQ1SaLAin8WHRS8Idajywlo0ULpCeoOj35aPI/ -kTUu4P2Rx5p1DYgquTGjW6fS4p5c65y75BWoukng5DQp/kVpo4OcRMUncexGxBET -1IkpuXGlvQyEKB5I+TgYe4eEXpdn+0A2Nytw9kpSzrd26JofWOO2ZtVCgISnj7ID -B7ErVzStuHg+rMKVI2SU966CH78lNuIIQFKrg8NoWRQI1zMMouU7hj6EL7cZcvA/ -MW9SIFpzkfC4xq0EnOMzg/D3p4k8ah6MikHf8FqDdBBfPUcYU0rG9+zpQdb3AgMB -AAGjggFBMIIBPTAdBgNVHQ4EFgQUQl34Jn7xx5zTXckus4k09ScmfUYwgdIGA1Ud -IwSByjCBx4AUQl34Jn7xx5zTXckus4k09ScmfUahgZikgZUwgZIxCzAJBgNVBAYT -AkZSMQ8wDQYDVQQIDAZSYWRpdXMxEjAQBgNVBAcMCVNvbWV3aGVyZTEUMBIGA1UE -CgwLRXhhbXBsZSBJbmMxIDAeBgkqhkiG9w0BCQEWEWFkbWluQGV4YW1wbGUub3Jn -MSYwJAYDVQQDDB1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eYIUNX/wAWvB -0xblUUghlsoear4f6kkwDwYDVR0TAQH/BAUwAwEB/zA2BgNVHR8ELzAtMCugKaAn -hiVodHRwOi8vd3d3LmV4YW1wbGUuY29tL2V4YW1wbGVfY2EuY3JsMA0GCSqGSIb3 -DQEBCwUAA4IBAQCP4qUyKkYD6hXaozV29opSo1sOdQ+voCe9lCTMnFEaCvCO22IX -ViyvNyR6cDt/wa2eeXCRzhOr8vXLyxUOZg0gMDuOxhMBWhdJUNowNrk5jLw2RdFG -OOB53m2JW2E7JNVsheRzKa+98xW7BFjkZKjrowFptZFDrtPFbGg1ETy+mPY74RVj -T+ebESqd/Q/hQUQYfvLUgbcVUF28nXzQ3EWxSL64wpheFDbYEdE97h3Z4tJX7MYi -nOdw+Hn8jss8xCjijk99MgI08GYqgYqCZP7Xka9tyOmD7FYFVnderU+aTCxEYbK3 -9/R7Y+PEaqamKZKXhYh8isjZz/EOiHYz2YjU +BgNVBAoMC0V4YW1wbGUgSW5jMSYwJAYDVQQDDB1FeGFtcGxlIENlcnRpZmljYXRl +IEF1dGhvcml0eTEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBsZS5vcmcwggEi +MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCWKIwjdRIp9IrpZELN/ZsN13Xj +qQI6n086PNJ7BZfLi0+tD164rmxFk2eukNNksFCPhvMkqUxouGhc4mJjeivvrZxR +oT3cblOQIkkdEci6iTKC2E1a20W/Ur7cTXoIsnKwjiUjXk+cujkrZu4fcHX+O4vy +wTd5tEbhmifT/4u5nN8U2vBcEZqkGHOCp30VZSxtlGwqp4lc+tVziF3uFViW9MXk +3bVt+s1E7ztwG7+WBgVlLYe3CNSWkMxfyYBafH/l7iep6AFjoTn1z3AAjYi7IUNN +0JkW8MTgafRQIu4QsV5luq/Tiar2vwAm/GNgUJdSzUKARsfQzb/XTIgnLQqtAgMB +AAGjUzBRMB0GA1UdDgQWBBSijSC03/Thi6EOdM91V33zsbQpgzAfBgNVHSMEGDAW +gBSijSC03/Thi6EOdM91V33zsbQpgzAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3 +DQEBCwUAA4IBAQAvKEfmCDoMTKC6bfP6DSs+MSAGc5tCr6w6cz2AKNJ2fOMhkq55 +JF47oBBGm9SdTB6Jqo6c109Ps69/+LMtEEGwvzL0RL0WAuTYGo6sudm9hj/jDHZh +pAqi/2BQQeVgTa6oW0jtNPFe+/cobXo9TJ7wECGrhvVbmfl5ZPc0YVOIjjR0/LhL +q7lqPAlJ5vx0WvsX+QReN97we8vD0x1D3mCySJTi3Irh+grE0yJOSN2fa7cyqi9+ +vSiNUB1eUgQwrO+S8ZazYNvAZXC2Xf4WB4SOifJD73pYPAdwOejc0FA+zfEKa/6/ +vTUs8cIhlmDWO+BEoc9wygMKMmhT5s7/T5Bv -----END CERTIFICATE----- diff --git a/samples/net/wifi/test_certs/ca2.pem b/samples/net/wifi/test_certs/ca2.pem new file mode 100644 index 000000000000..2b872d2e30da --- /dev/null +++ b/samples/net/wifi/test_certs/ca2.pem @@ -0,0 +1,24 @@ +-----BEGIN CERTIFICATE----- +MIIEBzCCAu+gAwIBAgIUK8+d+8IOzeX+DP3VSvdF3lHiCdcwDQYJKoZIhvcNAQEL +BQAwgZIxCzAJBgNVBAYTAkZSMQ8wDQYDVQQIDAZSYWRpdXMxEjAQBgNVBAcMCVNv +bWV3aGVyZTEUMBIGA1UECgwLRXhhbXBsZSBJbmMxJjAkBgNVBAMMHUV4YW1wbGUg +Q2VydGlmaWNhdGUgQXV0aG9yaXR5MSAwHgYJKoZIhvcNAQkBFhFhZG1pbkBleGFt +cGxlLm9yZzAeFw0yNDEwMDgxMDI0MDZaFw0zNDEwMDYxMDI0MDZaMIGSMQswCQYD +VQQGEwJGUjEPMA0GA1UECAwGUmFkaXVzMRIwEAYDVQQHDAlTb21ld2hlcmUxFDAS +BgNVBAoMC0V4YW1wbGUgSW5jMSYwJAYDVQQDDB1FeGFtcGxlIENlcnRpZmljYXRl +IEF1dGhvcml0eTEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBsZS5vcmcwggEi +MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCWKIwjdRIp9IrpZELN/ZsN13Xj +qQI6n086PNJ7BZfLi0+tD164rmxFk2eukNNksFCPhvMkqUxouGhc4mJjeivvrZxR +oT3cblOQIkkdEci6iTKC2E1a20W/Ur7cTXoIsnKwjiUjXk+cujkrZu4fcHX+O4vy +wTd5tEbhmifT/4u5nN8U2vBcEZqkGHOCp30VZSxtlGwqp4lc+tVziF3uFViW9MXk +3bVt+s1E7ztwG7+WBgVlLYe3CNSWkMxfyYBafH/l7iep6AFjoTn1z3AAjYi7IUNN +0JkW8MTgafRQIu4QsV5luq/Tiar2vwAm/GNgUJdSzUKARsfQzb/XTIgnLQqtAgMB +AAGjUzBRMB0GA1UdDgQWBBSijSC03/Thi6EOdM91V33zsbQpgzAfBgNVHSMEGDAW +gBSijSC03/Thi6EOdM91V33zsbQpgzAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3 +DQEBCwUAA4IBAQAvKEfmCDoMTKC6bfP6DSs+MSAGc5tCr6w6cz2AKNJ2fOMhkq55 +JF47oBBGm9SdTB6Jqo6c109Ps69/+LMtEEGwvzL0RL0WAuTYGo6sudm9hj/jDHZh +pAqi/2BQQeVgTa6oW0jtNPFe+/cobXo9TJ7wECGrhvVbmfl5ZPc0YVOIjjR0/LhL +q7lqPAlJ5vx0WvsX+QReN97we8vD0x1D3mCySJTi3Irh+grE0yJOSN2fa7cyqi9+ +vSiNUB1eUgQwrO+S8ZazYNvAZXC2Xf4WB4SOifJD73pYPAdwOejc0FA+zfEKa/6/ +vTUs8cIhlmDWO+BEoc9wygMKMmhT5s7/T5Bv +-----END CERTIFICATE----- diff --git a/samples/net/wifi/test_certs/client-key.pem b/samples/net/wifi/test_certs/client-key.pem index 20ca0796572f..6ab70da24524 100644 --- a/samples/net/wifi/test_certs/client-key.pem +++ b/samples/net/wifi/test_certs/client-key.pem @@ -1,30 +1,30 @@ -----BEGIN ENCRYPTED PRIVATE KEY----- -MIIFHDBOBgkqhkiG9w0BBQ0wQTApBgkqhkiG9w0BBQwwHAQIKh6bYnzze8sCAggA -MAwGCCqGSIb3DQIJBQAwFAYIKoZIhvcNAwcECNtt6KHyCgBPBIIEyPOdtbZFuRkf -NoEhloVT9ZbxSfYUOoD86w6OUgLW9I9zgH7v1lZ+Q6YnZ6lPxi+NthUvZZNd0M4f -rEAkJMeVqCImk9C5DYUdsEyVxxbWCiBKuO+j14S8RaetKvTVlYZjdkdbwW4chwLs -joPtKUtRMhWdQ5XF9qtVhmKjqHHTEFhOXP/VMCd6bNOkjzneuUDlLj+EOl8K1NVZ -tpZUi6D2p0tksrMokgl3n0Esee4W6XKemJ8KyLkA34QGG/c2MQyQnBzqo+9FnLvr -uX5DmApiichLMYDMssQjfyVUsDTz1bolTCWZcY2gz7zoHSJ3Twa4uf0D/Syi/pU5 -c4m1DvfY+BDt7GPG9S6eQHEIp/7m6jCKX90jYi297nEcJjYkXVUDe4Nx7a+oZkc4 -OIKP7VTVnhuUSjbN5h0UB1yNMA9t65IsXLPVVtn4b+eC/4RZyJAYuzJD8xpb9u4r -bXl0qMW1bPyU2qdC5oheM2oLIvuSBKuRf2vvqKt7c5mahTWIUxNckkNeSQghJxw5 -uEgG/ji+ggL9YfPQiMt8Ps4754/mtOfzXGX3UTniuSpo7ddonqDQpHBvNiRdy6Dl -pQTJczykNOe5HaMsfa/hyu22AVVKWQDLacFLvRqqps5JiH2A1dzBfU/GVeGYcl84 -BZUVO56tGMY64t/StqADVrW7AxTLB0tV90uNSg16oRQkRDIx5R5/Q9xlILCSPdvN -i8qR6jY0wLgEot5hweCnbYjQ79n7H8NKAHe52TNbYts/S6jjqdWNu19JpNHV8Z7v -aGlf5Puk4U+A8MhyjTVgWoOW+GNmyEiMXOTz66nrhtDFy3nzPjwQcMQtj3yTzHnS -0P80cdY/k2tfBPT4BTbIoKbuuuXLXKQ0jZ0AETu1Z12Q7G6C5f0fOJ5m97qLOvbE -dMgYPeeulbLr6Gw7CYfTE1wSj795z2d4SpbRSVNyN+iFccFD4tXhWk+lf8ym4/A2 -hsI2SS9TxBR93Fje6oTdeAlC0DIpY8117W4GhU+IZm9HqpD+DVcnLOAzRIl7urlW -jqpEkZXce+CV9L614hdAjUHQZOj43P3Q/zXEr/ZcVP6+yuLFCf+JbRXUglUgpdQh -McGVV09tL+Qbb/28yEygiw2m8HFAoUgMc2st4IkkO7XKX3Q8WVDSgqE4olAVE74g -1OB8w2R96+conCWYJfLCGM5lwsGeB1z8Q/NncKToulnqTKft7Rg8SFyMxVlzygPr -P9AMhS+wqXHbzhYb+dwD+DsbAtKl0Urp1ZjHSQrOrVtctDCnEX1Bx5ek+AgNExNp -tv2yBnsBcCLXy5UZYw9rAH+m7t8dAjGOYV3he4GotjCjyq+VcZgpzG2iWCHOhfob -1xtm030/Xuc4TfX76rWithXggSeKEhuqL2ERa/+OOC/JjE4omdmL9GVrr4vxt37U -MeJpxymYEP05QfRxcbvJB1L+cGv4Tgy3XgikK8ClUQqKvPntXIoX4cga8O5FE5KB -5H714hGK/JplhbCDDomi/hRHZHxae2MLnHgq4Rj7JWZ+iTUvLncfMdBBFdHF4qkr -ZbhwJ3KIAbCcSvXFoYJy1oOOitYhgoAKksyVNrzOMiYMfQ3YKc+6sF6lHOFllawD -RYTUnfN5ztaxB8OpKaPtig== +MIIFLTBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQILVdWyEWhWU0CAggA +MAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAEqBBDMFReIusCg7gSkoUQZV2flBIIE +0BIFQH7+0dc7wHIQQ1y0ao90rrK3ExtCABH6xp4OAHUNPR1549zSEak/9Ba6WLBp +YE0m/lpLz4oUJE4Kd3rg4ekSZk4mapZoW7g5ax4qAEblmM6rqmyjiU0Q6tsAb8n1 +x+RyjUILlgTH1HDmeNA53QNMCw++xIMIJPN29SvFN6vkU2Fd2f74/TuZRSaCEPLO +LKtNMwWCMTrlv0UewEryOvZegPQuEF/Ewmmw/9l5VfkPp6zAtZKzWsfk4jUo5tv2 +5dPoHR+RKjNNVwetnCq59QYMS2My6KLqX4Vzqnbu8K1nlbm85ZHnvLGi8cDn8EB7 +QtRL+Ev5IwcwYJgV5AMojouJLQdR655jeITWI1Gsohz28YG8c1qYX4ZN6albSd1G +fd1tMOWkeu4uEzJ7ijLDfnCzrklnLuAZx8yLzyrOa7i9AwwJmdgUEdbWWsru3L6C +zDJ45rpA0FobdlTem4kpoE9yiyHkIhf3wmI3X+0aodC11pdbHP260KIC8E1K9FUh +s/IoEQCYrBp8UltNTlezwq/E5uOuIu4EpfjEgH1Z3+hSDbnmMAXNX4DbL234x7iy +3Y256DtOeHSElnRz3kDnZVNtM1Kd5fgEYJ1ptYRPYaWyJka7/hC/0UObuM9w+QeO +OlG0QgumQFloyhDa9anPBK4sYJp4g1fK8golUDW4AdpFPNOJvvgOvQUzhPpHjr+N +lpZ75Y6I3JSSKJ/UMlSCOqjak8oZtMtJNMfbx1lgwwDtgjDSJvSdl735gI9VmXXH +qnlGEtyiQ7k1Z1a4HxiY2/CiDHvkymClir/Ik8gt+wmyT9c/9BcehLRf6PxMsDVy +PCkty1LlzN+5tSZJtJnOiTlgsRn/w49Ohp74ITheSdb30/6PnFI+o8rcJHmrjN4d +t3z/bCyWAeC8mS7m0wtXlyBeG9xvdyT8dDHAFOnqxX30dEwEbjNj58kWGAgRf9i3 +HlOAP8yRy7LAV7A4HEPnEzXBxYpsROUw/8d3Jtmr2nAp2hfKP339DYZPHZpRLjJr +WQlJasHHLxHKKjSsuM06WsCO+Tt2FTSgGJuU6nFVK75fssmmJYzj9qMHVM6YSjfY +sT0ZIWRgO9NLFx5O3QxY1wgMLhhv1FREy9NVnMU0W3A1u0F7dwHywZGha2IqEXgu ++UyWIJnePMvluV/s66AN/OpIxKU48c0B4l7XzXkHHd43tDUG3ztfRuPbWCHipuRO +eo+vHGD01iBLSE1ZhrYLHKQhJvIKx/PIEaqJHP/Vy35AD/2/GH09TiIBHzX9aXie +TiKFs30FQv7SpLNHNE7jUxsYGNUbYa70S/Vgn3wkKATcXpCc749XQV4OUbFoqkDm +vuZOjkIOlm/OtZkUuDWmk96mgoVG/gWSEJPynJHUpmWdu/BCdYOgxBk/bmPa1leS +Z5NbO0fGMnNhDMXYA5rqmVzABcNSYhgYw5aciWpBlgYHEYrPxZvCxWftIyb24oEk +wdHEaFbIYbOoVZqo7Ym2hrvVrJb8Qdukf1BmUgfSSSc7BFoSrBUO4SNFtZI55NOB +OM4rnkqfoYR0IpnxzPIpxpsWljG9QsgnTaffStDgIGXiAtBWJFy+44f1IS4EoC6B ++we1Q6atPwYSyPtG8mn4Ce0BNxLDUoFDLMQ7Bt8QBMeX -----END ENCRYPTED PRIVATE KEY----- diff --git a/samples/net/wifi/test_certs/client-key2.pem b/samples/net/wifi/test_certs/client-key2.pem new file mode 100644 index 000000000000..6ab70da24524 --- /dev/null +++ b/samples/net/wifi/test_certs/client-key2.pem @@ -0,0 +1,30 @@ +-----BEGIN ENCRYPTED PRIVATE KEY----- +MIIFLTBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQILVdWyEWhWU0CAggA +MAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAEqBBDMFReIusCg7gSkoUQZV2flBIIE +0BIFQH7+0dc7wHIQQ1y0ao90rrK3ExtCABH6xp4OAHUNPR1549zSEak/9Ba6WLBp +YE0m/lpLz4oUJE4Kd3rg4ekSZk4mapZoW7g5ax4qAEblmM6rqmyjiU0Q6tsAb8n1 +x+RyjUILlgTH1HDmeNA53QNMCw++xIMIJPN29SvFN6vkU2Fd2f74/TuZRSaCEPLO +LKtNMwWCMTrlv0UewEryOvZegPQuEF/Ewmmw/9l5VfkPp6zAtZKzWsfk4jUo5tv2 +5dPoHR+RKjNNVwetnCq59QYMS2My6KLqX4Vzqnbu8K1nlbm85ZHnvLGi8cDn8EB7 +QtRL+Ev5IwcwYJgV5AMojouJLQdR655jeITWI1Gsohz28YG8c1qYX4ZN6albSd1G +fd1tMOWkeu4uEzJ7ijLDfnCzrklnLuAZx8yLzyrOa7i9AwwJmdgUEdbWWsru3L6C +zDJ45rpA0FobdlTem4kpoE9yiyHkIhf3wmI3X+0aodC11pdbHP260KIC8E1K9FUh +s/IoEQCYrBp8UltNTlezwq/E5uOuIu4EpfjEgH1Z3+hSDbnmMAXNX4DbL234x7iy +3Y256DtOeHSElnRz3kDnZVNtM1Kd5fgEYJ1ptYRPYaWyJka7/hC/0UObuM9w+QeO +OlG0QgumQFloyhDa9anPBK4sYJp4g1fK8golUDW4AdpFPNOJvvgOvQUzhPpHjr+N +lpZ75Y6I3JSSKJ/UMlSCOqjak8oZtMtJNMfbx1lgwwDtgjDSJvSdl735gI9VmXXH +qnlGEtyiQ7k1Z1a4HxiY2/CiDHvkymClir/Ik8gt+wmyT9c/9BcehLRf6PxMsDVy +PCkty1LlzN+5tSZJtJnOiTlgsRn/w49Ohp74ITheSdb30/6PnFI+o8rcJHmrjN4d +t3z/bCyWAeC8mS7m0wtXlyBeG9xvdyT8dDHAFOnqxX30dEwEbjNj58kWGAgRf9i3 +HlOAP8yRy7LAV7A4HEPnEzXBxYpsROUw/8d3Jtmr2nAp2hfKP339DYZPHZpRLjJr +WQlJasHHLxHKKjSsuM06WsCO+Tt2FTSgGJuU6nFVK75fssmmJYzj9qMHVM6YSjfY +sT0ZIWRgO9NLFx5O3QxY1wgMLhhv1FREy9NVnMU0W3A1u0F7dwHywZGha2IqEXgu ++UyWIJnePMvluV/s66AN/OpIxKU48c0B4l7XzXkHHd43tDUG3ztfRuPbWCHipuRO +eo+vHGD01iBLSE1ZhrYLHKQhJvIKx/PIEaqJHP/Vy35AD/2/GH09TiIBHzX9aXie +TiKFs30FQv7SpLNHNE7jUxsYGNUbYa70S/Vgn3wkKATcXpCc749XQV4OUbFoqkDm +vuZOjkIOlm/OtZkUuDWmk96mgoVG/gWSEJPynJHUpmWdu/BCdYOgxBk/bmPa1leS +Z5NbO0fGMnNhDMXYA5rqmVzABcNSYhgYw5aciWpBlgYHEYrPxZvCxWftIyb24oEk +wdHEaFbIYbOoVZqo7Ym2hrvVrJb8Qdukf1BmUgfSSSc7BFoSrBUO4SNFtZI55NOB +OM4rnkqfoYR0IpnxzPIpxpsWljG9QsgnTaffStDgIGXiAtBWJFy+44f1IS4EoC6B ++we1Q6atPwYSyPtG8mn4Ce0BNxLDUoFDLMQ7Bt8QBMeX +-----END ENCRYPTED PRIVATE KEY----- diff --git a/samples/net/wifi/test_certs/client.pem b/samples/net/wifi/test_certs/client.pem index 0de5748bf036..9e815474cd8d 100644 --- a/samples/net/wifi/test_certs/client.pem +++ b/samples/net/wifi/test_certs/client.pem @@ -1,64 +1,22 @@ -Bag Attributes - localKeyID: DF 33 79 D4 52 3A 61 87 BF DD 0C BC BB 90 F5 1D 8C D0 02 1E -subject=C = FR, ST = Radius, O = Example Inc, CN = Example user, emailAddress = user.example@example.org -issuer=C = FR, ST = Radius, L = Somewhere, O = Example Inc, emailAddress = admin@example.org, CN = Example Certificate Authority -----BEGIN CERTIFICATE----- -MIIEgTCCA2mgAwIBAgIBAzANBgkqhkiG9w0BAQsFADCBkjELMAkGA1UEBhMCRlIx -DzANBgNVBAgMBlJhZGl1czESMBAGA1UEBwwJU29tZXdoZXJlMRQwEgYDVQQKDAtF -eGFtcGxlIEluYzEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBsZS5vcmcxJjAk -BgNVBAMMHUV4YW1wbGUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MB4XDTI0MDgwNzE4 -NDMwN1oXDTI0MTAwNjE4NDMwN1owdDELMAkGA1UEBhMCRlIxDzANBgNVBAgMBlJh -ZGl1czEUMBIGA1UECgwLRXhhbXBsZSBJbmMxFTATBgNVBAMMDEV4YW1wbGUgdXNl -cjEnMCUGCSqGSIb3DQEJARYYdXNlci5leGFtcGxlQGV4YW1wbGUub3JnMIIBIjAN -BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz6mI+213GsAcquAlq0/MMUDbbpjz -PxurB+9NoQ6xNpoUzK8x8hhC8tORkXi2stCbZbIFISMdtuDzshZ7BBLA32lX5/q0 -YNCS6czcuxnkbFgunfaA6VupK/dx+9GULTMKa7TVNyIhid9NQBowz2BB8n4lHQjS -g3fkZgR771e3xqZ8xaEKlA8+/lCRHUtjiUtzSFMbQDBA+Liu9cRpb+4xk93CNOk6 -WmHI7reGzJrC8YPc3ngFRvp1ujw0BHlp+AYfwnPPTn7mWYBgJQwfrkECzt/vTIhS -CJgsvM2bMI/HK30EvCLJb3NheSfZFo5fzkmWk8NK8B1p/d6/SPoul8L2QQIDAQAB -o4H+MIH7MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgXgMBMGA1UdJQQMMAoGCCsGAQUF -BwMCMDYGA1UdHwQvMC0wK6ApoCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhh -bXBsZV9jYS5jcmwwNwYIKwYBBQUHAQEEKzApMCcGCCsGAQUFBzABhhtodHRwOi8v -d3d3LmV4YW1wbGUub3JnL29jc3AwGwYDVR0RBBQwEoEQdXNlckBleGFtcGxlLm9y -ZzAdBgNVHQ4EFgQUpBSja2rvRXhlulUyZ8ZEDLS0j4AwHwYDVR0jBBgwFoAUQl34 -Jn7xx5zTXckus4k09ScmfUYwDQYJKoZIhvcNAQELBQADggEBAENOA88x6RMfT73L -hBQBT45qqvLK4GRGhqXDcj/E4hiZ0fX39r5PSUA+rbVbWjlJzW+gnsHWIdDASg4H -ZlMSYCgU6PN7hhJ1gmc0736V1t1vS63x6502fzNG7TMEvyWP3iadVjkn+sH8Q83d -AHwJjaKEq0SQYQof4QZZcxaBVLwh0buck4QLpeBYKeGpEiRK+AWireJMNFmBRHpG -R2E0I/B/duICWoL/8E/PCK7Ys7fUcGtIekEOCToDPW39uoU79mTjXrv+F3NO6Z6p -CwY9WqlHV0jLrfpdEMQuN2Pl0Qi8N2R0vJLrXRxbSrIkQbZtKyUG11XQBPgl5ZPz -KbHL9JU= +MIIDojCCAooCFGZ4UJXBKG70aewILFtsy4mbvaYZMA0GCSqGSIb3DQEBCwUAMIGS +MQswCQYDVQQGEwJGUjEPMA0GA1UECAwGUmFkaXVzMRIwEAYDVQQHDAlTb21ld2hl +cmUxFDASBgNVBAoMC0V4YW1wbGUgSW5jMSYwJAYDVQQDDB1FeGFtcGxlIENlcnRp +ZmljYXRlIEF1dGhvcml0eTEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBsZS5v +cmcwHhcNMjQxMDA4MTAyNjI1WhcNMzQxMDA2MTAyNjI1WjCBhzELMAkGA1UEBhMC +RlIxDzANBgNVBAgMBlJhZGl1czESMBAGA1UEBwwJU29tZXdoZXJlMRQwEgYDVQQK +DAtFeGFtcGxlIEluYzEbMBkGA1UEAwwSY2xpZW50LmV4YW1wbGUub3JnMSAwHgYJ +KoZIhvcNAQkBFhFhZG1pbkBleGFtcGxlLm9yZzCCASIwDQYJKoZIhvcNAQEBBQAD +ggEPADCCAQoCggEBAMu3HXJvi2Q4hQnLL4v/sCyEr5x+ZtBcSi2yETMViaf2EStW +UOs1A1pmCQbO7nadLQcWaX4tzefQCRrs1X4hIQuDIqRPNi6h6G1g5HEtqBWZhvwu +hDbmFiX8/Vtw/P0/9sox2DzyLG0mjJUAYAbKtyC1kQalybVBtrSaazyyAyh6oOuU +chAb7SmmNDsRB959TWM/mp+6yCcFGzCDKNBwlwthB6Uw92d3SfOyXEnZm8rPf0hV +4ICL5iB+xEYBv1LKmznFK/4UAyKpxAygc5fxKVWwlSsq8MrES5ak0n6H71wViaXK +BrH5yh9jEkK9XSeaUwg8C9eOOexyx/5JDY3TTE8CAwEAATANBgkqhkiG9w0BAQsF +AAOCAQEAUNddNiRUlJH0acJJv8ztXNWjNewd17tAk1BBHp6yyGAD8b52p6QbDAdS +xO3WsSc2bqSy599jp4GshO27TMQsBRMfoggCG21Aj6sIs0Hd4shTE4T0GUBEBxC2 +/HReuD+cGIzzKMYlvK8RPSaGLPvPw5SryvmOnjD368V0KCHwT04Z14i4sMxlkd5q +wB7fxTkVla9MR4uWObX62mJykmqT86chScJpldtBpRh8wrEa3Gt9FZoi/eqP0De8 +oCxmCZDrozGTZ4IIaNzchx3Ensh1RQwvvxd6ATerYdUjq4V2TlTksDRdCXtj+uNJ +FnB32sUHiIouxudAsqDf8UL9/99RCw== -----END CERTIFICATE----- -Bag Attributes - localKeyID: DF 33 79 D4 52 3A 61 87 BF DD 0C BC BB 90 F5 1D 8C D0 02 1E -Key Attributes: ------BEGIN ENCRYPTED PRIVATE KEY----- -MIIFLTBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQIj62qIYenEeYCAggA -MAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAEqBBD+aD/Nfhvs8bsr44gG36xRBIIE -0OA3BuJdNL3yo5SOVFXMbWeMj13B5yvQwqLRCPJmDesNSy6I2OLVQKr571IiuwBf -xNytF8MNfZ/OAI7FcMDqf/so9s9zQZlgR5jZKzoR8c0d6NiXboW7HHlO1tk7PhwW -T2dSFBcmfI0N4zug5vTYGVnOBtwk9F0BlFs8HZwa/5wXfdLnJVXT4l8enIU45Ssb -MJXrLNZ8SRMSjnsatrPqPhRMtLharGhOAItj4uQ770WbjdMgPejeZOMQ6NAEl1CL -NPeikRKZQzeBCBYnbAfOSTPNy0i2q28vKzc5e0gHPzqWg6r41/XsCGiKi/4pkwxE -ZDhbBCLeGdlB7KX4cv6KTp5PtBKMrh4BxGsWrAALqOdt/nsNl8oPBe8j6/iSWDDw -xJbemI8nFXAI6jAiz4RZS516eHJQT9uEpYdPUfluT17PPOotmjwkL2XuaMDjYOjD -LOFSIX1Y8L7DPhayViY7hGyBWFDgozIl+us7H7q27SIJQAtoG4gS6w2qTE6UmDbG -xqxluuQadfnrhtenpVJMwRQzf24txRsuHDTB/6EY3lqZhOvGZzwUV4RqJgg7G5Ix -YUCiRrNrWGgbViTGpR87GkhBc84pXlTdIVb/bxl1myJ4QFya2oG4PjMK+wxlGJ3q -8Ght0sz3xvDXLzoh3NYBBhqOj1zKHcUoVMLmxd+GinAy4FENc3cbZjAaTDprPbze -1368MvGQkcwgxHmqhPIRaz+GPtLhxjPO/SDIkZdzwAGvy8AKS5HTAGcSvbcjcjXE -3cY4DObY19MwUfsedXYcDzyEKS6OTgNSbfXPStBhijKA+joOzUKf36xEipV3J9fa -9YtXf5MALkUcLqGKCa4OybAktvN/VBnZfieOyCM3vcTHimmyDhuyjxzJptMTjiH3 -BaBxgZpm0FJVKjTJ3+xkmIeMA8p475Aocs8F7aHqIO/MEMHDB5MuCui3h+Mzccha -eR2e4Ldv5v8yFR+3Q+MIq8rELtIeNgG/ANldJEWt7paLsRXMXzNah1rdHb6oaDLa -iou8ZcOKI6kBxj6GxcGN2HicWbqAXgoHAVN59siVOSUGI2rmCxxj1v38oY61IahZ -k9nde23oAhTnO02ovRXkVNArBE3cEQPbBqwv09rrO/HQqHXRVNu/qFuA/oEopzjI -lZFUel4IjUQJgk7+1pY/OQzJQR9wfEXMOW4fXG+tL90sIypv115CbYXiUy3tOFcs -XX5QhDnrSo69Be4ZJQBBY9JEtOPlZCA9C+6Q0zxpNctfj091N7e8nWg2a+DHzpFz -Vdoa+xGCUMkJZopsnjEStfSTYqgCuPRSRIf8a1i9U2QnLXOFjmu2YUfa06JuQIXK -lpJxyMmUmd07KiTH3Da0/3V9W++zSlVpT4hHD6zvZ/OzpPKL74cGgtNFMOVkFCjr -KUcrg7JCxrVb1zZ/Y6CIdpRMFv5/94M67D8hX7aSiPgzGXwwuUzZlygbOZa97s3U -nKc7ZgVqiNCR6HH2Vhc2A2fuu9aErdnqr6tcbxiWTVORSQxIHCchX/+5+4XtKrHm -EOPmhwehDEsyFqHwBd/T8xdz/wb8ct+ce1HbzRe8UXjeGsTSPQVuMF4wjHP1MvEl -0BTRDQlqETtBvtxzZJ7cABWpZqdrZEUtrdD90jd6ZQrF ------END ENCRYPTED PRIVATE KEY----- diff --git a/samples/net/wifi/test_certs/client2.pem b/samples/net/wifi/test_certs/client2.pem new file mode 100644 index 000000000000..9e815474cd8d --- /dev/null +++ b/samples/net/wifi/test_certs/client2.pem @@ -0,0 +1,22 @@ +-----BEGIN CERTIFICATE----- +MIIDojCCAooCFGZ4UJXBKG70aewILFtsy4mbvaYZMA0GCSqGSIb3DQEBCwUAMIGS +MQswCQYDVQQGEwJGUjEPMA0GA1UECAwGUmFkaXVzMRIwEAYDVQQHDAlTb21ld2hl +cmUxFDASBgNVBAoMC0V4YW1wbGUgSW5jMSYwJAYDVQQDDB1FeGFtcGxlIENlcnRp +ZmljYXRlIEF1dGhvcml0eTEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBsZS5v +cmcwHhcNMjQxMDA4MTAyNjI1WhcNMzQxMDA2MTAyNjI1WjCBhzELMAkGA1UEBhMC +RlIxDzANBgNVBAgMBlJhZGl1czESMBAGA1UEBwwJU29tZXdoZXJlMRQwEgYDVQQK +DAtFeGFtcGxlIEluYzEbMBkGA1UEAwwSY2xpZW50LmV4YW1wbGUub3JnMSAwHgYJ +KoZIhvcNAQkBFhFhZG1pbkBleGFtcGxlLm9yZzCCASIwDQYJKoZIhvcNAQEBBQAD +ggEPADCCAQoCggEBAMu3HXJvi2Q4hQnLL4v/sCyEr5x+ZtBcSi2yETMViaf2EStW +UOs1A1pmCQbO7nadLQcWaX4tzefQCRrs1X4hIQuDIqRPNi6h6G1g5HEtqBWZhvwu +hDbmFiX8/Vtw/P0/9sox2DzyLG0mjJUAYAbKtyC1kQalybVBtrSaazyyAyh6oOuU +chAb7SmmNDsRB959TWM/mp+6yCcFGzCDKNBwlwthB6Uw92d3SfOyXEnZm8rPf0hV +4ICL5iB+xEYBv1LKmznFK/4UAyKpxAygc5fxKVWwlSsq8MrES5ak0n6H71wViaXK +BrH5yh9jEkK9XSeaUwg8C9eOOexyx/5JDY3TTE8CAwEAATANBgkqhkiG9w0BAQsF +AAOCAQEAUNddNiRUlJH0acJJv8ztXNWjNewd17tAk1BBHp6yyGAD8b52p6QbDAdS +xO3WsSc2bqSy599jp4GshO27TMQsBRMfoggCG21Aj6sIs0Hd4shTE4T0GUBEBxC2 +/HReuD+cGIzzKMYlvK8RPSaGLPvPw5SryvmOnjD368V0KCHwT04Z14i4sMxlkd5q +wB7fxTkVla9MR4uWObX62mJykmqT86chScJpldtBpRh8wrEa3Gt9FZoi/eqP0De8 +oCxmCZDrozGTZ4IIaNzchx3Ensh1RQwvvxd6ATerYdUjq4V2TlTksDRdCXtj+uNJ +FnB32sUHiIouxudAsqDf8UL9/99RCw== +-----END CERTIFICATE----- diff --git a/samples/net/wifi/test_certs/server-key.pem b/samples/net/wifi/test_certs/server-key.pem index c9defa1229b4..5f032cad701d 100644 --- a/samples/net/wifi/test_certs/server-key.pem +++ b/samples/net/wifi/test_certs/server-key.pem @@ -1,30 +1,30 @@ -----BEGIN ENCRYPTED PRIVATE KEY----- -MIIFHDBOBgkqhkiG9w0BBQ0wQTApBgkqhkiG9w0BBQwwHAQIU44Xbg9l+1kCAggA -MAwGCCqGSIb3DQIJBQAwFAYIKoZIhvcNAwcECBx6SOeZLPFiBIIEyBbU4bj1/Sq0 -W5O13hWtq34nTHG+HtgOG61u8659V+0Txbd6E6gBlMTUDtczKCb2BS7D2uugSwTR -Xj1CeLha1qfsWT3IEe38KB/r+TXA1CESblkHBeYjHYOhOoRSNjg8e+QddFim4uuN -6eCqgia4jJjC4jT7gLhoUgMtLKxGiw/iVsLme//p1czB2sNNy441Cp2smwvP6GqC -rymGKgmmEa3pqFm72jO77kev71gUYxPJLXg6bGJ3HBBD0iN79rlCgMTru4s/C/G6 -VoTLCxJrYNiRGsCNu1PM4DtZgQtL32il+u/thZzE6cmh6Yqzkv9G8JXRIakoZctN -JOwOgbyQLwbAV/0OpZcX0rWKGbO2AO1RmayEJrTBp98qbOW1SrJf2HVAqzevaxOy -ZqyLbq80x+6wH1sg200tnfwGO/2nz1U7yDTJ4tMuMeJYvAHB5luXYOBrL7AmUJjZ -CLY/BaN90amz3h1/ZeooMslB1ldjNznLYfrmYc7E1UKWUd5CRjbh6f+k/iYp1wuw -W2O9qW/aatQyrcWMLboJLTs9XarTFXYSA66bvhPfP/lP4BPm4eQM1xCS7qSjbJMK -OuTX9J++ZzNIiUJjFTAWW4cIEKkJ+PpljTgdcfnwUCGUcxuqJaVbWVrPstc2tyjJ -8Ravtr5Fp79dYsD5xSB31ATiAVehp0Zn7lorwmFZ1fhZNMOaFjDk0e3GJPrWgTGY -DUyeN2Ec/lY76+nTKLqpCPmP/aM3uOEsKEXmtuiYONnz1ZcRSXqAfZKW0Sv9iEQA -IK31lNuU6CULXM6aUn0lwdoYKZ1S7SPwK6UmqSimBb/5FF5zaZPgzHKhClsnd6EN -ToMDw18YD1rY6jaAxZdXiaI70i7V9S3RkfjlYkiaLEmjO44yg6Ae7xL0KbOut8iB -ZCyMHRjobFCLWPTdplQux0xzPD0FXrl8GgJBmiY8SkiFh9NKDNyB6SodjVKXsIhe -BPsdmh9E66XfHkI16LkkoK5eKgtVDpXVAJBAI2wURIwfIzfzOJ6SExQd3capXqfr -HpC+sJJjAPy0hHTkv3RnzX1NHqYK5gHq/WCSda/4cl8ZepF5eoyJ8h+9TJzlTDJX -REyt5iUvKbFT3bQ3WYwWUW6lEei16KK9Cm8ivZsEQqbeG0kP6lO3pG+WNsAYRXlE -aXg8wgFLJRS/7llaB8xiZHZ0mMsj9UAwZd7gUkp1EjDt7A6f1KlYEtIXtQ9TVXhS -kegWYMvJOpzJoOTcZ2Yu/wNUEAnnOnXzCrr5EAD3aHUwaSHfj75y44uHrYtEKEyO -Q1bhRhSC5rFcEEomHofy7PlJqoynxMxOd6VZdSpMr2fSDKO36aY8bGD7ST0hpHrs -6NNbywy23G68YX6QREwcuT4EDzIQOQsl7GCSx8KVibubsYcGSuXSVlBMI9sLOtsA -AwSAXOyGoVrmms79ekp4O4Pzq4vqE61KEh8K0/h5qDJ8+c2kqQl5eeDkDwtBYwjD -oYKRlmCkKzoo7qW4uIeVy4ZeQIuzWcCWnSZumtBa2mLlo4w9njmwgPR0wtDU8daW -+0CL828/eNfIN3awo0VeAJ8nbZlKL2ioyND9KNXjJ2fJNuwyrWv9c5fz/NeWgv9O -Z2S6ZI0xPgZJNQ6rLcPigA== +MIIFLTBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQIjI78fcZSH7oCAggA +MAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAEqBBDfF676hRrL290F0MgMDZiuBIIE +0Hkz7skRV8Ox0SoX5N8GsOPfN4PS1cLyHgokY6dUhJPU5vUzOn9iSiGQSEzSguQ7 +11mssjRC2T45wB/95VK2EPtRw1f/6VOUR6RJnnGb0PV1Rydp/x5TZ6vzcXpakqly +eljJR/20fIJClsZzhw0iu5la9fkF6G8WYFEkqex5jALSiN4qVLvkiqcTnh5+amem +8+OCKgvgooKD2ids4/0GGfJRQSC6DFf3kuxNl+MMvmDXmz/vrD85ONnyXzKXDA3N +3vRgL/YT6GzwIXb+7/c/tIMpnacxPAdbNOs3DY5ss4xcK68L5PwpM2BljzBa5dGw +Smgf2VRaYRVzmrte5j280QjfrlHRU2cHaxm0GCu2AOTGwMXcSNYMXfDNuxc57oQJ +vHXMeZD4K5lACbhYdZ5lJNFvv29YI7dZ7QOGu6nXlAuhZfbdc/cgT0som7eG8xpT +pERllhQ5ych9sP9nAccN6VUsWgmlF73lbSptBek1ccYkp9LIYCteJUPl2qPcz6zl +A7zrZ54f3Lg0fOm2pCtg+qKBiw1nd3MR/YbRCgyvudyZE2cCN/ZspWqxsavbGYOz +JOfIFNnyAcOYtEv1n1BGLfMa1THW2bDV8XmHVHUtM0k4z250QAmLygWLY2166iUF +qotBkvctKKdulzGdT4nVer1UEKTqcxhDf0dRiHN5spZtFrOee0uGIoQWHt2oecaK +pJovW+i0qO/1DG5spfU2m1bz6jR2u6nxi340oRrMSoe1ELVg3l1/wmM8yzh07GuK +pshzxwqAG/FnaKCvcKGUG2EfnAvOcbMgSa2w3GvyRkcDPn00arvX9nuXj0gkRDBi +eoVMkKKTeeYSGQ4ik+ja3xkgHcxh5W8aoezLvBbmUq206cmhLwfnYMhnvFTs6EBK +E0ENpCHwF/qoVBIzRCijG/eeCuf3a1YkJsWlvEeVrPeOmDFeDft3SSGOzHxE2A/7 +HWmHbWTm7dPOfgsU4zf+HglnBjN3kYU7StyM0EGxmB4lfB2BiWiL/3R13ERHQZfa +oOqa4/hOFXOXfTQk6ufXtBx8L9BemBqh36zbs2xVvIizJKeRMruoRblWZkHhUKR8 +K5GA7FYkU9ZPPP0UPKsO94xzwfbevi+7nWeUZoqcqAUy8Jt5aD2QpvFVbPBBOz17 +PGaubeVn/Ry8swPvkpddtmJ4mgF+3SVctmzY+EE/oN1XS8wa+XeuaThzk89Lvrfa +606nRWrNw3PSKjYoEEtRLhPeJCi9uOVenbOjtclio9mV5Sugwurolczvq8DAGpMG +W4WgALgOWDjQAudiNH5dtcMGkBONbYywkJc7cT2OZFmzkCbchPPWlKGopuaFGAoU +SPj7C9SenHmOWAFRX5jJrOZAuVqkdKN3ShWZUL+cDkOCCQlZ0E31u0m9yozY1MeO +Sx42GtZaSGff37FGYeMZM2ztlutw2zmv2B1g52SBHTjCqQU/ud2Q6/U0kUzjbsdF +/0KQY9wgZRdOvbnA2lBirN1rXzLWPdduOZ5QImfHfvToN+oOlEqVvvWG12DdA4e5 +y4Dumx00lfKEsGutjF3oKgE6jsjwqAwCoYEAFHTtsvA0hKPisQwNHZmpjGARvR56 +yMEmXynKvgyVGvVP2a9VdqBXSpstL24HfDIu+nlyEWGQ -----END ENCRYPTED PRIVATE KEY----- diff --git a/samples/net/wifi/test_certs/server-key2.pem b/samples/net/wifi/test_certs/server-key2.pem new file mode 100644 index 000000000000..5f032cad701d --- /dev/null +++ b/samples/net/wifi/test_certs/server-key2.pem @@ -0,0 +1,30 @@ +-----BEGIN ENCRYPTED PRIVATE KEY----- +MIIFLTBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQIjI78fcZSH7oCAggA +MAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAEqBBDfF676hRrL290F0MgMDZiuBIIE +0Hkz7skRV8Ox0SoX5N8GsOPfN4PS1cLyHgokY6dUhJPU5vUzOn9iSiGQSEzSguQ7 +11mssjRC2T45wB/95VK2EPtRw1f/6VOUR6RJnnGb0PV1Rydp/x5TZ6vzcXpakqly +eljJR/20fIJClsZzhw0iu5la9fkF6G8WYFEkqex5jALSiN4qVLvkiqcTnh5+amem +8+OCKgvgooKD2ids4/0GGfJRQSC6DFf3kuxNl+MMvmDXmz/vrD85ONnyXzKXDA3N +3vRgL/YT6GzwIXb+7/c/tIMpnacxPAdbNOs3DY5ss4xcK68L5PwpM2BljzBa5dGw +Smgf2VRaYRVzmrte5j280QjfrlHRU2cHaxm0GCu2AOTGwMXcSNYMXfDNuxc57oQJ +vHXMeZD4K5lACbhYdZ5lJNFvv29YI7dZ7QOGu6nXlAuhZfbdc/cgT0som7eG8xpT +pERllhQ5ych9sP9nAccN6VUsWgmlF73lbSptBek1ccYkp9LIYCteJUPl2qPcz6zl +A7zrZ54f3Lg0fOm2pCtg+qKBiw1nd3MR/YbRCgyvudyZE2cCN/ZspWqxsavbGYOz +JOfIFNnyAcOYtEv1n1BGLfMa1THW2bDV8XmHVHUtM0k4z250QAmLygWLY2166iUF +qotBkvctKKdulzGdT4nVer1UEKTqcxhDf0dRiHN5spZtFrOee0uGIoQWHt2oecaK +pJovW+i0qO/1DG5spfU2m1bz6jR2u6nxi340oRrMSoe1ELVg3l1/wmM8yzh07GuK +pshzxwqAG/FnaKCvcKGUG2EfnAvOcbMgSa2w3GvyRkcDPn00arvX9nuXj0gkRDBi +eoVMkKKTeeYSGQ4ik+ja3xkgHcxh5W8aoezLvBbmUq206cmhLwfnYMhnvFTs6EBK +E0ENpCHwF/qoVBIzRCijG/eeCuf3a1YkJsWlvEeVrPeOmDFeDft3SSGOzHxE2A/7 +HWmHbWTm7dPOfgsU4zf+HglnBjN3kYU7StyM0EGxmB4lfB2BiWiL/3R13ERHQZfa +oOqa4/hOFXOXfTQk6ufXtBx8L9BemBqh36zbs2xVvIizJKeRMruoRblWZkHhUKR8 +K5GA7FYkU9ZPPP0UPKsO94xzwfbevi+7nWeUZoqcqAUy8Jt5aD2QpvFVbPBBOz17 +PGaubeVn/Ry8swPvkpddtmJ4mgF+3SVctmzY+EE/oN1XS8wa+XeuaThzk89Lvrfa +606nRWrNw3PSKjYoEEtRLhPeJCi9uOVenbOjtclio9mV5Sugwurolczvq8DAGpMG +W4WgALgOWDjQAudiNH5dtcMGkBONbYywkJc7cT2OZFmzkCbchPPWlKGopuaFGAoU +SPj7C9SenHmOWAFRX5jJrOZAuVqkdKN3ShWZUL+cDkOCCQlZ0E31u0m9yozY1MeO +Sx42GtZaSGff37FGYeMZM2ztlutw2zmv2B1g52SBHTjCqQU/ud2Q6/U0kUzjbsdF +/0KQY9wgZRdOvbnA2lBirN1rXzLWPdduOZ5QImfHfvToN+oOlEqVvvWG12DdA4e5 +y4Dumx00lfKEsGutjF3oKgE6jsjwqAwCoYEAFHTtsvA0hKPisQwNHZmpjGARvR56 +yMEmXynKvgyVGvVP2a9VdqBXSpstL24HfDIu+nlyEWGQ +-----END ENCRYPTED PRIVATE KEY----- diff --git a/samples/net/wifi/test_certs/server.pem b/samples/net/wifi/test_certs/server.pem index 12b9a5458bd2..d8f82faf6dd3 100644 --- a/samples/net/wifi/test_certs/server.pem +++ b/samples/net/wifi/test_certs/server.pem @@ -1,68 +1,22 @@ -Bag Attributes - localKeyID: 70 E4 1E 20 0B 8A 3E 65 06 98 99 29 C2 A4 26 33 38 D8 94 23 -subject=C = FR, ST = Radius, O = Example Inc, CN = Example Server Certificate, emailAddress = admin@example.org -issuer=C = FR, ST = Radius, L = Somewhere, O = Example Inc, emailAddress = admin@example.org, CN = Example Certificate Authority -----BEGIN CERTIFICATE----- -MIIFZzCCBE+gAwIBAgIBATANBgkqhkiG9w0BAQsFADCBkjELMAkGA1UEBhMCRlIx -DzANBgNVBAgMBlJhZGl1czESMBAGA1UEBwwJU29tZXdoZXJlMRQwEgYDVQQKDAtF -eGFtcGxlIEluYzEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBsZS5vcmcxJjAk -BgNVBAMMHUV4YW1wbGUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MB4XDTI0MDgwNzE4 -NDMwNloXDTI0MTAwNjE4NDMwNlowezELMAkGA1UEBhMCRlIxDzANBgNVBAgMBlJh -ZGl1czEUMBIGA1UECgwLRXhhbXBsZSBJbmMxIzAhBgNVBAMMGkV4YW1wbGUgU2Vy -dmVyIENlcnRpZmljYXRlMSAwHgYJKoZIhvcNAQkBFhFhZG1pbkBleGFtcGxlLm9y -ZzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKtkktsya+B8p8x5/P7t -IDIVcc0E6PPUklUmrcAzBuLNdnHH0FCbzqqsE+28L36gyriNv+l0EOvvnV3LJJdc -RO/6Ee4NHjO/GKcmTCDOC1KSl7yP+IaPog/f86UJ1rTOQpnpCi/uB3Gd3ZocZ+s+ -5fnPCVFdAaRfLs8fVbJ3Lt79E/FiVhXXjG4/wFMGHg/6P3fsq5B+VqUww8xUjfZ9 -MUuo+MYP5CPYJHfhuIwNHsunGKsmjMtQ4nR84huTOKy9+YVsKr+GRzGy4aC3ElCb -HTU+axLVcVPRgpsdCaFzXLAg5L//rufgWI7NKIV16t+6q/3euFWPHYW3lqdAWMD4 -yssCAwEAAaOCAdwwggHYMB0GA1UdDgQWBBT5kdLsBRD8WBlzoAmLWRMZf6PvOjCB -0gYDVR0jBIHKMIHHgBRCXfgmfvHHnNNdyS6ziTT1JyZ9RqGBmKSBlTCBkjELMAkG -A1UEBhMCRlIxDzANBgNVBAgMBlJhZGl1czESMBAGA1UEBwwJU29tZXdoZXJlMRQw -EgYDVQQKDAtFeGFtcGxlIEluYzEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBs -ZS5vcmcxJjAkBgNVBAMMHUV4YW1wbGUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5ghQ1 -f/ABa8HTFuVRSCGWyh5qvh/qSTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIF4DAdBgNV -HSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAw4wNgYDVR0fBC8wLTAroCmgJ4YlaHR0 -cDovL3d3dy5leGFtcGxlLmNvbS9leGFtcGxlX2NhLmNybDA3BggrBgEFBQcBAQQr -MCkwJwYIKwYBBQUHMAGGG2h0dHA6Ly93d3cuZXhhbXBsZS5vcmcvb2NzcDA6BgNV -HREEMzAxghJyYWRpdXMuZXhhbXBsZS5vcmegGwYIKwYBBQUHCAigDwwNKi5leGFt -cGxlLmNvbTANBgkqhkiG9w0BAQsFAAOCAQEAX5O3aUlupNs8C0blKzGJosqKoEP1 -D0/RUESK6443TlK2hAImSE/qz9JGQ4tMSO1bfnYUS9Mnk4hStlG4gg6F/B4nV1eZ -qbHEFWCyhCAlUUeDF+8Lz2G6wYXrw9pPe1GpQSFdHLTV2WKVK0IaRaote8bCQHBm -bgNbfZVXK4JJKX0Wg+ECNQv8bGA/WwZ+QKOcjemaa1kxwi9PFRNOIOdFfk1zKXHz -D6Ex0hFzl2dt+aSpmb93Fo4wDz1rtCJ7HGo1TtUbDdDwDoZv8SKsAI7XtDmrqqP/ -MZa+lI5xVXCsSBDppGZb6BVkl3AfUIIhbCDqj1MT9vXqjtaWsyG4F3iHuw== +MIIDojCCAooCFCPQcj7ej5jhr6/mLlAoLYgfgsYcMA0GCSqGSIb3DQEBCwUAMIGS +MQswCQYDVQQGEwJGUjEPMA0GA1UECAwGUmFkaXVzMRIwEAYDVQQHDAlTb21ld2hl +cmUxFDASBgNVBAoMC0V4YW1wbGUgSW5jMSYwJAYDVQQDDB1FeGFtcGxlIENlcnRp +ZmljYXRlIEF1dGhvcml0eTEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBsZS5v +cmcwHhcNMjQxMDA4MTAyNTI5WhcNMzQxMDA2MTAyNTI5WjCBhzELMAkGA1UEBhMC +RlIxDzANBgNVBAgMBlJhZGl1czESMBAGA1UEBwwJU29tZXdoZXJlMRQwEgYDVQQK +DAtFeGFtcGxlIEluYzEbMBkGA1UEAwwSc2VydmVyLmV4YW1wbGUub3JnMSAwHgYJ +KoZIhvcNAQkBFhFhZG1pbkBleGFtcGxlLm9yZzCCASIwDQYJKoZIhvcNAQEBBQAD +ggEPADCCAQoCggEBANcE/OPHQK/y1b6UsIktNK7WIZB528HECY7Bz18EGba0uHod +91RbzHSJ1qI3iQyldI1UW/kY5oYjBW3lhLH0BkD/EsqvNYCV+3YzAM3ITtdOdEU9 +CqjgXttehQHfXvc7jQlF8Q2gYPUz2dDLo/gcTkz1d+mCr6nQUjT8Kq/nG54T0NnD +k8udchjUlNaQsvx/WVs3TUYxMbWzQRtpJIbv99rAWq7YgQbkNZnSYC1VgrU/BiuQ +0KrP6rfkxvBCGwIh2JXIL3FV4N8AsgGZvjXQ3zXKXwuPhxWdSmjKWlioVM3mha2A +/1e1gX6nFY/uk46D60XWxcJ6tHGHoafU7EtN3zMCAwEAATANBgkqhkiG9w0BAQsF +AAOCAQEAWwdTMphD0jxLtYO0iq/+fMtq2R96ZUN9wprZ7qg1evUNQjqLR4jKX306 +ZJX5uw+6r5Ve/k368qvcSF/sSfvBm8yd3JcegTl5t8T2/Aks8o3sfyuS0uyJC1rS +zTrd7FmJG9YMosU1BqYobda64MXq7g+6MyrQoZ6fVdPvC6Sox3+a4fl9xjdm4CTY +MsWqBJMe26LptvRIJ01/B6PjVTvsn/fxxj7rHmnJ/j63AIiBntm0vV/85cwYy/4o +HlPH/Qjvn3hZjUlBcveiYat998F+s9gH2usvCkG3kly/n1/667LLCymmCHxtH8ka +7tF3siO1EANureFY8qj6ZvlKeTkZ6g== -----END CERTIFICATE----- -Bag Attributes - localKeyID: 70 E4 1E 20 0B 8A 3E 65 06 98 99 29 C2 A4 26 33 38 D8 94 23 -Key Attributes: ------BEGIN ENCRYPTED PRIVATE KEY----- -MIIFLTBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQI0/IqoquZd2sCAggA -MAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAEqBBA3/HwadBWDheQI/8p1u6j+BIIE -0N7R2UwLzLVPv/QR/hfYtK56iUtq0j5dqW/1Yos5IpkmUhOdXa149OGmzUkM6JQ/ -GaYQ5TbCn0+/HZx0k1nLIHL0fOUlorW/6i/pfw+KMR0bZrPUoZJyukG7iFIcD5yB -Pq6Q/QXVIH0qzB2lTTEa6TNSzM4PtcGd24Ivt7GwX8vz/bbW+gPCnAEbFKTrn1aP -Dr5LRIn9MOStPox/PmCEysdrdgJ8W9BD9J7iviUOmfJckl7hc10j87SvqHDYuPIP -a5QZnGanbsdOfYRCtg6jkLPiR7f3kS+aeITGx1iKdm+wqpcp1JelYmg3b9a0mSGk -fLgOS8z0hmdPrPT4yZtU1MvjxPpbVcpP+S5idWWD30bit2c7lqW3shXjan+voA4R -gYbJewXiJbjFCElj/EnvX5dFaJyBdeRcaIZcKhEwsTGJ/GI6S7nFdDNao4dXUESX -CWgVQNcdqiK/OJ8blQR6+1vxajJNLqx5GwbLJdMbN7d+o8m0O7O+lygF3BiDYpp0 -niLrB+qTM2H5jGRe2Vwhs5HxU1b0uN85xqUHRppeFmNB4mEcpT0XZ0a5kZZhuCQg -P48ONl46i1DAAKOAQ+WSiSQUBO+AmMlzNquCNstkSrEis4szfDOT/RQmlMwLEyb9 -3aXZwsHzZREi7gojsyEHyadeKhsblBITSD79MmVpPBhym6sok8QWgk4R4+Xsckll -cxqhsczmGv/tSz71/Soqql6KXmtk7YUAWDM1YtF1K2pb4zF9q0/mp3MgUB7sjcfm -HMFDD3KSMFGfP9ex4MTUlEFXoBS0jM1rC+L0OtSDsBs23BOJvgi3JArZD2WPUPeR -1dxcrtqYFy1DGkCMZ8+24GmqXbaL+iG/vgyAyhjcgWet2Xk8BHpuYPWSoGlnmJTP -tqLC13jU0to8S8H7vsrbUP5m+XN/sVXkYE86AOsMO+/g+1fcqQOu0fSdSOvNvw5c -/56yHA/+bJJfcQyqoEpPrpR2npazcG0cop3FOP9eTvNERRO6ayXJjrq1Tl9Ok39v -DRQy/TLt6tQtHjiTFDgiZI+PI7FVzSudCGa2oMKTyf8qDWUN65825oSL7e7jggFM -8VFf1MBXb1lCIFIrukNnXuXnYMWtQYjvHS/vN3jP/BGnVW+rEupj/hq4gtv1J2Pu -B5Qn8Q+szCz8ha6ziA9+iVt57SRakK87bZ7qEIIy4XTJBnCGHTVjQOn+aMHJ/76H -wiw8CPgKKQMwx0JyySMfZih+LgxlibPpk76zNIw0eYLM4DQEwmx9LGXZ4TIPCyAg -GiWeKYn4zD0ub634DBFRTmX5XGQhqmKSkCIKOs4/8yzmX3649vess85RJN4DjjGN -njzxuInblVxVg0YvzlGQHXwwCJuG48yoTa3UPvqft67kOoBLh8Kky1kMPPtPm8yR -ZT8E8VdYSg2ssyCpyfaV3RCnxsMpnFUER+JU0g6IxTpDqxA4zK5XS6Wt/KsdnU+1 -locA7O1+lcsDXf2FyDFtwPwNZIjchV1UDXSYr/fKyn10TDoSMeRTZsC0vwm2/9bW -peH+nk/x93j29VZVzGk6hlpLC9MBRq/qGhNqIwklxtfIKLr0l5oMcWwm4h4dAVBR -HUC0MTfbSTrC8mAsOglVa87dF9v1gnA2FVlRZEHJCGwe ------END ENCRYPTED PRIVATE KEY----- diff --git a/samples/net/wifi/test_certs/server2.pem b/samples/net/wifi/test_certs/server2.pem new file mode 100644 index 000000000000..d8f82faf6dd3 --- /dev/null +++ b/samples/net/wifi/test_certs/server2.pem @@ -0,0 +1,22 @@ +-----BEGIN CERTIFICATE----- +MIIDojCCAooCFCPQcj7ej5jhr6/mLlAoLYgfgsYcMA0GCSqGSIb3DQEBCwUAMIGS +MQswCQYDVQQGEwJGUjEPMA0GA1UECAwGUmFkaXVzMRIwEAYDVQQHDAlTb21ld2hl +cmUxFDASBgNVBAoMC0V4YW1wbGUgSW5jMSYwJAYDVQQDDB1FeGFtcGxlIENlcnRp +ZmljYXRlIEF1dGhvcml0eTEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBsZS5v +cmcwHhcNMjQxMDA4MTAyNTI5WhcNMzQxMDA2MTAyNTI5WjCBhzELMAkGA1UEBhMC +RlIxDzANBgNVBAgMBlJhZGl1czESMBAGA1UEBwwJU29tZXdoZXJlMRQwEgYDVQQK +DAtFeGFtcGxlIEluYzEbMBkGA1UEAwwSc2VydmVyLmV4YW1wbGUub3JnMSAwHgYJ +KoZIhvcNAQkBFhFhZG1pbkBleGFtcGxlLm9yZzCCASIwDQYJKoZIhvcNAQEBBQAD +ggEPADCCAQoCggEBANcE/OPHQK/y1b6UsIktNK7WIZB528HECY7Bz18EGba0uHod +91RbzHSJ1qI3iQyldI1UW/kY5oYjBW3lhLH0BkD/EsqvNYCV+3YzAM3ITtdOdEU9 +CqjgXttehQHfXvc7jQlF8Q2gYPUz2dDLo/gcTkz1d+mCr6nQUjT8Kq/nG54T0NnD +k8udchjUlNaQsvx/WVs3TUYxMbWzQRtpJIbv99rAWq7YgQbkNZnSYC1VgrU/BiuQ +0KrP6rfkxvBCGwIh2JXIL3FV4N8AsgGZvjXQ3zXKXwuPhxWdSmjKWlioVM3mha2A +/1e1gX6nFY/uk46D60XWxcJ6tHGHoafU7EtN3zMCAwEAATANBgkqhkiG9w0BAQsF +AAOCAQEAWwdTMphD0jxLtYO0iq/+fMtq2R96ZUN9wprZ7qg1evUNQjqLR4jKX306 +ZJX5uw+6r5Ve/k368qvcSF/sSfvBm8yd3JcegTl5t8T2/Aks8o3sfyuS0uyJC1rS +zTrd7FmJG9YMosU1BqYobda64MXq7g+6MyrQoZ6fVdPvC6Sox3+a4fl9xjdm4CTY +MsWqBJMe26LptvRIJ01/B6PjVTvsn/fxxj7rHmnJ/j63AIiBntm0vV/85cwYy/4o +HlPH/Qjvn3hZjUlBcveiYat998F+s9gH2usvCkG3kly/n1/667LLCymmCHxtH8ka +7tF3siO1EANureFY8qj6ZvlKeTkZ6g== +-----END CERTIFICATE----- diff --git a/samples/sensor/mcux_acmp/prj.conf b/samples/sensor/mcux_acmp/prj.conf index 8b70c7ae30b9..202fe6b85649 100644 --- a/samples/sensor/mcux_acmp/prj.conf +++ b/samples/sensor/mcux_acmp/prj.conf @@ -1,2 +1,2 @@ CONFIG_SENSOR=y -CONFIG_MCUX_ACMP_TRIGGER=y +CONFIG_SENSOR_MCUX_ACMP_TRIGGER=y diff --git a/samples/sensor/mcux_acmp/sample.yaml b/samples/sensor/mcux_acmp/sample.yaml index fa7782d896d2..a00773fdbb68 100644 --- a/samples/sensor/mcux_acmp/sample.yaml +++ b/samples/sensor/mcux_acmp/sample.yaml @@ -27,4 +27,4 @@ tests: sample.sensor.mcux_acmp.no_trigger: build_only: true extra_configs: - - CONFIG_MCUX_ACMP_TRIGGER=n + - CONFIG_SENSOR_MCUX_ACMP_TRIGGER=n diff --git a/samples/sensor/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay b/samples/sensor/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay index c4f6fc7876ae..654e778af97b 100644 --- a/samples/sensor/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay +++ b/samples/sensor/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay @@ -13,10 +13,10 @@ encoder-emulate { compatible = "gpio-leds"; phase_a: phase_a { - gpios = <&gpio7 2 GPIO_ACTIVE_HIGH>; + gpios = <&gpio2 9 GPIO_ACTIVE_HIGH>; }; phase_b: phase_b { - gpios = <&gpio1 3 GPIO_ACTIVE_HIGH>; + gpios = <&gpio2 11 GPIO_ACTIVE_HIGH>; }; }; }; @@ -24,17 +24,13 @@ &pinctrl { qdec_pinctrl: qdec_pinctrl { group1 { - psels = , - ; + psels = , + ; }; }; }; -&gpio1 { - status = "okay"; -}; - -&gpio7 { +&gpio2 { status = "okay"; }; diff --git a/samples/shields/x_nucleo_53l0a1/src/main.c b/samples/shields/x_nucleo_53l0a1/src/main.c index e2688eec21b3..9de9469ba7d7 100644 --- a/samples/shields/x_nucleo_53l0a1/src/main.c +++ b/samples/shields/x_nucleo_53l0a1/src/main.c @@ -15,7 +15,7 @@ * Get button configuration from the devicetree sw0 alias. This is mandatory. */ #define SW0_NODE DT_ALIAS(sw0) -#if !DT_NODE_HAS_STATUS(SW0_NODE, okay) +#if !DT_NODE_HAS_STATUS_OKAY(SW0_NODE) #error "Unsupported board: sw0 devicetree alias is not defined" #endif diff --git a/samples/subsys/fs/zms/src/main.c b/samples/subsys/fs/zms/src/main.c index a2166392724c..959d5ac5f3e5 100644 --- a/samples/subsys/fs/zms/src/main.c +++ b/samples/subsys/fs/zms/src/main.c @@ -83,7 +83,8 @@ int main(void) int rc = 0; char buf[16]; uint8_t key[8] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF}, longarray[128]; - uint32_t i_cnt = 0U, i; + uint32_t i_cnt = 0U; + uint32_t i; uint32_t id = 0; ssize_t free_space = 0; struct flash_pages_info info; @@ -144,7 +145,7 @@ int main(void) rc = zms_read(&fs, KEY_VALUE_ID, &key, sizeof(key)); if (rc > 0) { /* item was found, show it */ printk("Id: %x, Key: ", KEY_VALUE_ID); - for (int n = 0; n < 8; n++) { + for (uint8_t n = 0; n < 8; n++) { printk("%x ", key[n]); } printk("\n"); @@ -181,7 +182,7 @@ int main(void) if (rc > 0) { /* item was found, show it */ printk("Id: %d, Longarray: ", LONG_DATA_ID); - for (int n = 0; n < sizeof(longarray); n++) { + for (uint16_t n = 0; n < sizeof(longarray); n++) { printk("%x ", longarray[n]); } printk("\n"); @@ -204,7 +205,7 @@ int main(void) } if (i != MAX_ITERATIONS) { - printk("Error: Something went wrong at iteration %u rc=%d\n", i - 1, rc); + printk("Error: Something went wrong at iteration %u rc=%d\n", i, rc); return 0; } @@ -249,7 +250,7 @@ int main(void) * Let's compute free space in storage. But before doing that let's Garbage collect * all sectors where we deleted all entries and then compute the free space */ - for (uint32_t i = 0; i < fs.sector_count; i++) { + for (i = 0; i < fs.sector_count; i++) { rc = zms_sector_use_next(&fs); if (rc) { printk("Error while changing sector rc=%d\n", rc); @@ -261,6 +262,13 @@ int main(void) return 0; } printk("Free space in storage is %u bytes\n", free_space); + + /* Let's clean the storage now */ + rc = zms_clear(&fs); + if (rc < 0) { + printk("Error while cleaning the storage, rc=%d\n", rc); + } + printk("Sample code finished Successfully\n"); return 0; diff --git a/samples/subsys/ipc/ipc_service/icmsg/boards/nrf54l15dk_nrf54l15_cpuapp.overlay b/samples/subsys/ipc/ipc_service/icmsg/boards/nrf54l15dk_nrf54l15_cpuapp.overlay index b6f20acc42ac..56b3ae097d81 100644 --- a/samples/subsys/ipc/ipc_service/icmsg/boards/nrf54l15dk_nrf54l15_cpuapp.overlay +++ b/samples/subsys/ipc/ipc_service/icmsg/boards/nrf54l15dk_nrf54l15_cpuapp.overlay @@ -23,6 +23,7 @@ ipc { ipc0: ipc0 { compatible = "zephyr,ipc-icmsg"; + dcache-alignment = <32>; tx-region = <&sram_tx>; rx-region = <&sram_rx>; mboxes = <&cpuapp_vevif_rx 20>, <&cpuapp_vevif_tx 21>; diff --git a/samples/subsys/ipc/ipc_service/icmsg/boards/nrf54l15dk_nrf54l15_cpuapp_icbmsg.overlay b/samples/subsys/ipc/ipc_service/icmsg/boards/nrf54l15dk_nrf54l15_cpuapp_icbmsg.overlay index a3f853c6e3d5..639ad5e844b4 100644 --- a/samples/subsys/ipc/ipc_service/icmsg/boards/nrf54l15dk_nrf54l15_cpuapp_icbmsg.overlay +++ b/samples/subsys/ipc/ipc_service/icmsg/boards/nrf54l15dk_nrf54l15_cpuapp_icbmsg.overlay @@ -23,6 +23,7 @@ ipc { ipc0: ipc0 { compatible = "zephyr,ipc-icbmsg"; + dcache-alignment = <32>; tx-region = <&sram_tx>; rx-region = <&sram_rx>; tx-blocks = <16>; diff --git a/samples/subsys/ipc/ipc_service/icmsg/remote/boards/nrf54l15dk_nrf54l15_cpuflpr.overlay b/samples/subsys/ipc/ipc_service/icmsg/remote/boards/nrf54l15dk_nrf54l15_cpuflpr.overlay index c6e59f2b1312..b3e86e96361c 100644 --- a/samples/subsys/ipc/ipc_service/icmsg/remote/boards/nrf54l15dk_nrf54l15_cpuflpr.overlay +++ b/samples/subsys/ipc/ipc_service/icmsg/remote/boards/nrf54l15dk_nrf54l15_cpuflpr.overlay @@ -23,6 +23,7 @@ ipc { ipc0: ipc0 { compatible = "zephyr,ipc-icmsg"; + dcache-alignment = <32>; tx-region = <&sram_tx>; rx-region = <&sram_rx>; mboxes = <&cpuflpr_vevif_rx 21>, <&cpuflpr_vevif_tx 20>; diff --git a/samples/subsys/ipc/ipc_service/icmsg/remote/boards/nrf54l15dk_nrf54l15_cpuflpr_icbmsg.overlay b/samples/subsys/ipc/ipc_service/icmsg/remote/boards/nrf54l15dk_nrf54l15_cpuflpr_icbmsg.overlay index 0033e6221073..7fe78a716539 100644 --- a/samples/subsys/ipc/ipc_service/icmsg/remote/boards/nrf54l15dk_nrf54l15_cpuflpr_icbmsg.overlay +++ b/samples/subsys/ipc/ipc_service/icmsg/remote/boards/nrf54l15dk_nrf54l15_cpuflpr_icbmsg.overlay @@ -23,6 +23,7 @@ ipc { ipc0: ipc0 { compatible = "zephyr,ipc-icbmsg"; + dcache-alignment = <32>; tx-region = <&sram_tx>; rx-region = <&sram_rx>; tx-blocks = <18>; diff --git a/samples/subsys/mgmt/mcumgr/smp_svr/boards/nrf54l15pdk_nrf54l15_cpuapp_ext_flash.overlay b/samples/subsys/mgmt/mcumgr/smp_svr/boards/nrf54l15dk_nrf54l15_cpuapp_ext_flash..overlay similarity index 100% rename from samples/subsys/mgmt/mcumgr/smp_svr/boards/nrf54l15pdk_nrf54l15_cpuapp_ext_flash.overlay rename to samples/subsys/mgmt/mcumgr/smp_svr/boards/nrf54l15dk_nrf54l15_cpuapp_ext_flash..overlay diff --git a/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml b/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml index 3aa3ca449e58..8bbae88d9012 100644 --- a/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml +++ b/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml @@ -12,11 +12,11 @@ tests: - nrf52840dk/nrf52840 - pinnacle_100_dvk - mg100 - - nrf54l15pdk/nrf54l15/cpuapp + - nrf54l15dk/nrf54l15/cpuapp integration_platforms: - nrf52dk/nrf52832 - nrf52840dk/nrf52840 - - nrf54l15pdk/nrf54l15/cpuapp + - nrf54l15dk/nrf54l15/cpuapp sample.mcumgr.smp_svr.bt_static_svc: extra_args: OVERLAY_CONFIG="overlay-bt.conf" extra_configs: @@ -104,26 +104,26 @@ tests: - mg100 integration_platforms: - nrf52840dk/nrf52840 - sample.mcumgr.smp_svr.bt.nrf54l15pdk.ext_flash: + sample.mcumgr.smp_svr.bt.nrf54l15dk.ext_flash: extra_args: - OVERLAY_CONFIG="overlay-bt.conf" - - DTC_OVERLAY_FILE="boards/nrf54l15pdk_nrf54l15_cpuapp_ext_flash.overlay" - - mcuboot_CONF_FILE="boards/nrf54l15pdk_nrf54l15_cpuapp_ext_flash.conf" - - mcuboot_EXTRA_DTC_OVERLAY_FILE="boards/nrf54l15pdk_nrf54l15_cpuapp_ext_flash.overlay" + - DTC_OVERLAY_FILE="boards/nrf54l15dk_nrf54l15_cpuapp_ext_flash.overlay" + - mcuboot_CONF_FILE="boards/nrf54l15dk_nrf54l15_cpuapp_ext_flash.conf" + - mcuboot_EXTRA_DTC_OVERLAY_FILE="boards/nrf54l15dk_nrf54l15_cpuapp_ext_flash.overlay" extra_configs: - CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y platform_allow: - - nrf54l15pdk/nrf54l15/cpuapp + - nrf54l15dk/nrf54l15/cpuapp integration_platforms: - - nrf54l15pdk/nrf54l15/cpuapp - sample.mcumgr.smp_svr.bt.nrf54l15pdk.ext_flash.pure_dts: + - nrf54l15dk/nrf54l15/cpuapp + sample.mcumgr.smp_svr.bt.nrf54l15dk.ext_flash.pure_dts: extra_args: - OVERLAY_CONFIG="overlay-bt.conf" - - DTC_OVERLAY_FILE="boards/nrf54l15pdk_nrf54l15_cpuapp_ext_flash.overlay" - - mcuboot_CONF_FILE="boards/nrf54l15pdk_nrf54l15_cpuapp_ext_flash.conf" - - mcuboot_EXTRA_DTC_OVERLAY_FILE="boards/nrf54l15pdk_nrf54l15_cpuapp_ext_flash.overlay" + - DTC_OVERLAY_FILE="boards/nrf54l15dk_nrf54l15_cpuapp_ext_flash.overlay" + - mcuboot_CONF_FILE="boards/nrf54l15dk_nrf54l15_cpuapp_ext_flash.conf" + - mcuboot_EXTRA_DTC_OVERLAY_FILE="boards/nrf54l15dk_nrf54l15_cpuapp_ext_flash.overlay" - SB_CONFIG_PARTITION_MANAGER=n platform_allow: - - nrf54l15pdk/nrf54l15/cpuapp + - nrf54l15dk/nrf54l15/cpuapp integration_platforms: - - nrf54l15pdk/nrf54l15/cpuapp + - nrf54l15dk/nrf54l15/cpuapp diff --git a/samples/subsys/mgmt/osdp/control_panel/src/main.c b/samples/subsys/mgmt/osdp/control_panel/src/main.c index 1942e8227336..2b58692e9263 100644 --- a/samples/subsys/mgmt/osdp/control_panel/src/main.c +++ b/samples/subsys/mgmt/osdp/control_panel/src/main.c @@ -12,7 +12,7 @@ /* The devicetree node identifier for the "led0" alias. */ #define LED0_NODE DT_ALIAS(led0) -#if !DT_NODE_HAS_STATUS(LED0_NODE, okay) +#if !DT_NODE_HAS_STATUS_OKAY(LED0_NODE) #error "BOARD does not define a debug LED" #endif diff --git a/samples/subsys/mgmt/osdp/peripheral_device/src/main.c b/samples/subsys/mgmt/osdp/peripheral_device/src/main.c index 8ffdd10f0810..74d4fed6d2c8 100644 --- a/samples/subsys/mgmt/osdp/peripheral_device/src/main.c +++ b/samples/subsys/mgmt/osdp/peripheral_device/src/main.c @@ -12,7 +12,7 @@ /* The devicetree node identifier for the "led0" alias. */ #define LED0_NODE DT_ALIAS(led0) -#if !DT_NODE_HAS_STATUS(LED0_NODE, okay) +#if !DT_NODE_HAS_STATUS_OKAY(LED0_NODE) #error "BOARD does not define a debug LED" #endif diff --git a/samples/subsys/task_wdt/src/main.c b/samples/subsys/task_wdt/src/main.c index f06ef1faef29..a366b3683eba 100644 --- a/samples/subsys/task_wdt/src/main.c +++ b/samples/subsys/task_wdt/src/main.c @@ -21,7 +21,7 @@ * from there. Otherwise, the task watchdog will be used without a * hardware watchdog fallback. */ -#if DT_NODE_HAS_STATUS(DT_ALIAS(watchdog0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_ALIAS(watchdog0)) #define WDT_NODE DT_ALIAS(watchdog0) #elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32_window_watchdog) #define WDT_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(st_stm32_window_watchdog) diff --git a/scripts/west_commands/runners/nrf_common.py b/scripts/west_commands/runners/nrf_common.py index 6423253233c1..a42e841bdbdc 100644 --- a/scripts/west_commands/runners/nrf_common.py +++ b/scripts/west_commands/runners/nrf_common.py @@ -273,6 +273,11 @@ def program_hex(self): if self.erase: self.exec_op('erase', core='NRFDL_DEVICE_CORE_APPLICATION') self.exec_op('erase', core='NRFDL_DEVICE_CORE_NETWORK') + # A reset is needed if repartitioning the device memory + self.reset_target() + else: + # Ensure that firmware is not executing while erasing/programming + self.exec_op("reset", option="RESET_VIA_SECDOM") # Manage SUIT artifacts. # This logic should be executed only once per build. @@ -298,16 +303,8 @@ def program_hex(self): self.op_program(app_root_envelope_hex_file, 'ERASE_NONE', None, defer=True, core='NRFDL_DEVICE_CORE_APPLICATION') if cpuapp: - if not self.erase and self.build_conf.getboolean('CONFIG_NRF_REGTOOL_GENERATE_UICR'): - self.exec_op('erase', core='NRFDL_DEVICE_CORE_APPLICATION', - option={'chip_erase_mode': 'ERASE_UICR', - 'qspi_erase_mode': 'ERASE_NONE'}) core = 'NRFDL_DEVICE_CORE_APPLICATION' elif cpurad: - if not self.erase and self.build_conf.getboolean('CONFIG_NRF_REGTOOL_GENERATE_UICR'): - self.exec_op('erase', core='NRFDL_DEVICE_CORE_NETWORK', - option={'chip_erase_mode': 'ERASE_UICR', - 'qspi_erase_mode': 'ERASE_NONE'}) core = 'NRFDL_DEVICE_CORE_NETWORK' else: if self.erase: diff --git a/soc/arm/beetle/power.c b/soc/arm/beetle/power.c index 4377d79d3f0f..700969f46735 100644 --- a/soc/arm/beetle/power.c +++ b/soc/arm/beetle/power.c @@ -11,13 +11,13 @@ #include #include -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio0)) #define CLK_BIT_GPIO0 _BEETLE_GPIO0 #else #define CLK_BIT_GPIO0 0 #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) #define CLK_BIT_GPIO1 _BEETLE_GPIO1 #else #define CLK_BIT_GPIO1 0 @@ -25,13 +25,13 @@ #define AHB_CLK_BITS (CLK_BIT_GPIO0 | CLK_BIT_GPIO1) -#if DT_NODE_HAS_STATUS(DT_NODELABEL(timer0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(timer0)) #define CLK_BIT_TIMER0 _BEETLE_TIMER0 #else #define CLK_BIT_TIMER0 0 #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(timer1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(timer1)) #define CLK_BIT_TIMER1 _BEETLE_TIMER1 #else #define CLK_BIT_TIMER1 0 @@ -43,13 +43,13 @@ #define CLK_BIT_WDOG 0 #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart0)) #define CLK_BIT_UART0 _BEETLE_UART0 #else #define CLK_BIT_UART0 0 #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) #define CLK_BIT_UART1 _BEETLE_UART1 #else #define CLK_BIT_UART1 0 diff --git a/soc/atmel/sam/common/soc_power.c b/soc/atmel/sam/common/soc_power.c index 08499b98b102..0b477f9fbe9c 100644 --- a/soc/atmel/sam/common/soc_power.c +++ b/soc/atmel/sam/common/soc_power.c @@ -12,7 +12,7 @@ #endif #if defined(CONFIG_REBOOT) -#if DT_NODE_HAS_STATUS(SAM_DT_RSTC_DRIVER, okay) +#if DT_NODE_HAS_STATUS_OKAY(SAM_DT_RSTC_DRIVER) void sys_arch_reboot(int type) { @@ -33,5 +33,5 @@ void sys_arch_reboot(int type) } } -#endif /* DT_NODE_HAS_STATUS */ +#endif /* DT_NODE_HAS_STATUS_OKAY */ #endif /* CONFIG_REBOOT */ diff --git a/soc/intel/intel_adsp/common/clk.c b/soc/intel/intel_adsp/common/clk.c index 3cb4b0e2db72..ebcda7be1e73 100644 --- a/soc/intel/intel_adsp/common/clk.c +++ b/soc/intel/intel_adsp/common/clk.c @@ -129,10 +129,10 @@ struct adsp_clock_source_desc adsp_clk_src_info[ADSP_CLOCK_SOURCE_COUNT] = { */ [ADSP_CLOCK_SOURCE_XTAL_OSC] = { CONFIG_DAI_DMIC_HW_IOCLK }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(audioclk), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(audioclk)) [ADSP_CLOCK_SOURCE_AUDIO_CARDINAL] = { DT_PROP(DT_NODELABEL(audioclk), clock_frequency) }, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pllclk), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pllclk)) [ADSP_CLOCK_SOURCE_AUDIO_PLL_FIXED] = { DT_PROP(DT_NODELABEL(pllclk), clock_frequency) }, #endif [ADSP_CLOCK_SOURCE_MLCK_INPUT] = { 0 }, diff --git a/soc/intel/intel_adsp/common/include/adsp_clk.h b/soc/intel/intel_adsp/common/include/adsp_clk.h index ccfb5cdc7e7a..591116c5561e 100644 --- a/soc/intel/intel_adsp/common/include/adsp_clk.h +++ b/soc/intel/intel_adsp/common/include/adsp_clk.h @@ -64,10 +64,10 @@ struct adsp_cpu_clock_info *adsp_cpu_clocks_get(void); /* Clock sources used by dai */ #define ADSP_CLOCK_SOURCE_XTAL_OSC 0 -#if DT_NODE_HAS_STATUS(DT_NODELABEL(audioclk), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(audioclk)) #define ADSP_CLOCK_SOURCE_AUDIO_CARDINAL 1 #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pllclk), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pllclk)) #define ADSP_CLOCK_SOURCE_AUDIO_PLL_FIXED 2 #endif diff --git a/soc/intel/intel_adsp/common/mem_window.c b/soc/intel/intel_adsp/common/mem_window.c index 8ca591deb36a..ae5abcb77bf7 100644 --- a/soc/intel/intel_adsp/common/mem_window.c +++ b/soc/intel/intel_adsp/common/mem_window.c @@ -58,15 +58,15 @@ void mem_window_idle_exit(void) &mem_win_config_##n, PRE_KERNEL_1, \ CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); -#if DT_NODE_HAS_STATUS(MEM_WINDOW_NODE(0), okay) +#if DT_NODE_HAS_STATUS_OKAY(MEM_WINDOW_NODE(0)) MEM_WINDOW_DEFINE(0) #endif -#if DT_NODE_HAS_STATUS(MEM_WINDOW_NODE(1), okay) +#if DT_NODE_HAS_STATUS_OKAY(MEM_WINDOW_NODE(1)) MEM_WINDOW_DEFINE(1) #endif -#if DT_NODE_HAS_STATUS(MEM_WINDOW_NODE(2), okay) +#if DT_NODE_HAS_STATUS_OKAY(MEM_WINDOW_NODE(2)) MEM_WINDOW_DEFINE(2) #endif -#if DT_NODE_HAS_STATUS(MEM_WINDOW_NODE(3), okay) +#if DT_NODE_HAS_STATUS_OKAY(MEM_WINDOW_NODE(3)) MEM_WINDOW_DEFINE(3) #endif diff --git a/soc/ite/ec/it8xxx2/soc.c b/soc/ite/ec/it8xxx2/soc.c index 0f2501111be8..2c2660ac3b18 100644 --- a/soc/ite/ec/it8xxx2/soc.c +++ b/soc/ite/ec/it8xxx2/soc.c @@ -403,7 +403,7 @@ static int ite_it8xxx2_init(void) IT8XXX2_EGPIO_EGCR |= IT8XXX2_EGPIO_EEPODD; #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) /* UART1 board init */ /* bit2: clocks to UART1 modules are not gated. */ IT8XXX2_ECPM_CGCTRL3R &= ~BIT(2); @@ -417,9 +417,9 @@ static int ite_it8xxx2_init(void) /* switch UART1 on without hardware flow control */ gpio_regs->GPIO_GCR1 |= IT8XXX2_GPIO_U1CTRL_SIN0_SOUT0_EN; -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) /* UART2 board init */ /* setting voltage 3.3v */ gpio_regs->GPIO_GCR21 &= ~(IT8XXX2_GPIO_GPH1VS | IT8XXX2_GPIO_GPH2VS); @@ -435,7 +435,7 @@ static int ite_it8xxx2_init(void) /* switch UART2 on without hardware flow control */ gpio_regs->GPIO_GCR1 |= IT8XXX2_GPIO_U2CTRL_SIN1_SOUT1_EN; -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) */ #if (SOC_USBPD_ITE_PHY_PORT_COUNT > 0) int port; diff --git a/soc/microchip/mec/common/soc_dt.h b/soc/microchip/mec/common/soc_dt.h index cfaa8821da94..39f772f964f1 100644 --- a/soc/microchip/mec/common/soc_dt.h +++ b/soc/microchip/mec/common/soc_dt.h @@ -35,7 +35,7 @@ #define MCHP_DT_ESPI_VW_FLAG_RST_SRC_MSK0 0x7 #define MCHP_DT_NODE_FROM_VWTABLE(name) DT_CHILD(DT_PATH(mchp_xec_espi_vw_routing), name) -#define MCHP_DT_VW_NODE_HAS_STATUS(name) DT_NODE_HAS_STATUS(MCHP_DT_NODE_FROM_VWTABLE(name), okay) +#define MCHP_DT_VW_NODE_HAS_STATUS(name) DT_NODE_HAS_STATUS_OKAY(MCHP_DT_NODE_FROM_VWTABLE(name)) /* Macro to store eSPI virtual wire DT flags * b[0] = DT status property 0 is disabled, 1 enabled, diff --git a/soc/microchip/mec/mec172x/device_power.c b/soc/microchip/mec/mec172x/device_power.c index 8a35d6ddd00e..eab5bfb04196 100644 --- a/soc/microchip/mec/mec172x/device_power.c +++ b/soc/microchip/mec/mec172x/device_power.c @@ -93,14 +93,14 @@ void soc_deep_sleep_non_wake_dis(void) void soc_deep_sleep_wake_en(void) { #if defined(CONFIG_KSCAN) || \ - (!defined(CONFIG_PM_DEVICE) && DT_NODE_HAS_STATUS(DT_NODELABEL(ps2_0), okay)) + (!defined(CONFIG_PM_DEVICE) && DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ps2_0))) struct ecia_named_regs *regs = ECIA_XEC_REG_BASE; #if defined(CONFIG_KSCAN) /* Enable PLL wake via KSCAN */ regs->GIRQ21.SRC = MCHP_KEYSCAN_GIRQ_BIT; regs->GIRQ21.EN_SET = MCHP_KEYSCAN_GIRQ_BIT; #endif -#if !defined(CONFIG_PM_DEVICE) && DT_NODE_HAS_STATUS(DT_NODELABEL(ps2_0), okay) +#if !defined(CONFIG_PM_DEVICE) && DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ps2_0)) /* Enable PS2_0B_WK */ regs->GIRQ21.SRC = MCHP_PS2_0_PORT0B_WK_GIRQ_BIT; regs->GIRQ21.EN_SET = MCHP_PS2_0_PORT0B_WK_GIRQ_BIT; @@ -110,7 +110,7 @@ void soc_deep_sleep_wake_en(void) void soc_deep_sleep_wake_dis(void) { -#if !defined(CONFIG_PM_DEVICE) && DT_NODE_HAS_STATUS(DT_NODELABEL(ps2_0), okay) +#if !defined(CONFIG_PM_DEVICE) && DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ps2_0)) struct ecia_named_regs *regs = ECIA_XEC_REG_BASE; /* Enable PS2_0B_WK */ diff --git a/soc/nordic/Kconfig b/soc/nordic/Kconfig index e0063b858eda..f76b1d19acc3 100644 --- a/soc/nordic/Kconfig +++ b/soc/nordic/Kconfig @@ -98,15 +98,24 @@ config NFCT_PINS_AS_GPIOS choice NRF_APPROTECT_HANDLING bool "APPROTECT handling" - depends on SOC_SERIES_NRF52X || SOC_NRF5340_CPUNET || \ - SOC_NRF5340_CPUAPP || SOC_SERIES_NRF91X + depends on SOC_SERIES_NRF52X || SOC_SERIES_NRF53X || SOC_NRF54L15_CPUAPP || \ + SOC_SERIES_NRF91X + default NRF_APPROTECT_DISABLE if SOC_NRF54L15_CPUAPP default NRF_APPROTECT_USE_UICR help Specifies how the SystemInit() function should handle the APPROTECT mechanism. +config NRF_APPROTECT_DISABLE + bool "Disable" + depends on SOC_NRF54L15_CPUAPP + help + When this option is selected, the SystemInit() disables + the APPROTECT mechanism. + config NRF_APPROTECT_USE_UICR bool "Use UICR" + depends on SOC_SERIES_NRF52X || SOC_SERIES_NRF53X || SOC_SERIES_NRF91X help When this option is selected, the SystemInit() function loads the firmware branch state of the APPROTECT mechanism from UICR, so if @@ -131,14 +140,23 @@ endchoice choice NRF_SECURE_APPROTECT_HANDLING bool "Secure APPROTECT handling" - depends on SOC_NRF5340_CPUAPP || SOC_SERIES_NRF91X + depends on SOC_NRF5340_CPUAPP || SOC_NRF54L15_CPUAPP || SOC_SERIES_NRF91X + default NRF_SECURE_APPROTECT_DISABLE if SOC_NRF54L15_CPUAPP default NRF_SECURE_APPROTECT_USE_UICR help Specifies how the SystemInit() function should handle the secure APPROTECT mechanism. +config NRF_SECURE_APPROTECT_DISABLE + bool "Disable" + depends on SOC_NRF54L15_CPUAPP + help + When this option is selected, the SystemInit() disables + the secure APPROTECT mechanism. + config NRF_SECURE_APPROTECT_USE_UICR bool "Use UICR" + depends on SOC_NRF5340_CPUAPP || SOC_SERIES_NRF91X help When this option is selected, the SystemInit() function loads the firmware branch state of the secure APPROTECT mechanism from UICR, diff --git a/soc/nordic/Kconfig.defconfig b/soc/nordic/Kconfig.defconfig index c912861cc4bb..efa122aa5b50 100644 --- a/soc/nordic/Kconfig.defconfig +++ b/soc/nordic/Kconfig.defconfig @@ -7,13 +7,11 @@ if SOC_FAMILY_NORDIC_NRF rsource "*/Kconfig.defconfig" -# If the kernel has timer support, enable clock control -if SYS_CLOCK_EXISTS - +# If the kernel has timer support, enable clock control, except for SoCs +# based on the Haltium platform SoCs where clock control is not needed +# for the system timer config CLOCK_CONTROL - default y if !SOC_SERIES_NRF92X - -endif # SYS_CLOCK_EXISTS + default y if SYS_CLOCK_EXISTS && !NRF_PLATFORM_HALTIUM config SYS_CLOCK_HW_CYCLES_PER_SEC default 1000000 if NRF_GRTC_TIMER diff --git a/soc/nordic/common/CMakeLists.txt b/soc/nordic/common/CMakeLists.txt index 4e000006d41b..4808319557c7 100644 --- a/soc/nordic/common/CMakeLists.txt +++ b/soc/nordic/common/CMakeLists.txt @@ -32,3 +32,5 @@ if(CONFIG_TFM_PARTITION_PLATFORM) $/api_ns/interface/include ) endif() + +zephyr_library_sources_ifdef(CONFIG_NRF_SYS_EVENT nrf_sys_event.c) diff --git a/soc/nordic/common/Kconfig b/soc/nordic/common/Kconfig index 8de20c37dd4d..ef32e7403c12 100644 --- a/soc/nordic/common/Kconfig +++ b/soc/nordic/common/Kconfig @@ -4,4 +4,8 @@ config HAS_NORDIC_DMM bool +config NRF_SYS_EVENT + bool "nRF system event support" + select NRFX_POWER if !NRF_PLATFORM_HALTIUM + rsource "vpr/Kconfig" diff --git a/soc/nordic/common/dmm.h b/soc/nordic/common/dmm.h index e92f01d07b85..34b517c92dfc 100644 --- a/soc/nordic/common/dmm.h +++ b/soc/nordic/common/dmm.h @@ -23,12 +23,13 @@ extern "C" { /** @cond INTERNAL_HIDDEN */ +#ifdef CONFIG_DCACHE + /* Determine if memory region is cacheable. */ -#define DMM_IS_REG_CACHEABLE(node_id) \ - COND_CODE_1(CONFIG_DCACHE, \ - (COND_CODE_1(DT_NODE_HAS_PROP(node_id, zephyr_memory_attr), \ - ((DT_PROP(node_id, zephyr_memory_attr) & DT_MEM_CACHEABLE)), \ - (0))), (0)) +#define DMM_IS_REG_CACHEABLE(node_id) \ + COND_CODE_1(DT_NODE_HAS_PROP(node_id, zephyr_memory_attr), \ + ((DT_PROP(node_id, zephyr_memory_attr) & DT_MEM_CACHEABLE)), \ + (0)) /* Determine required alignment of the data buffers in specified memory region. * Cache line alignment is required if region is cacheable and data cache is enabled. @@ -36,6 +37,13 @@ extern "C" { #define DMM_REG_ALIGN_SIZE(node_id) \ (DMM_IS_REG_CACHEABLE(node_id) ? CONFIG_DCACHE_LINE_SIZE : sizeof(uint8_t)) +#else + +#define DMM_IS_REG_CACHEABLE(node_id) 0 +#define DMM_REG_ALIGN_SIZE(node_id) (sizeof(uint8_t)) + +#endif /* CONFIG_DCACHE */ + /* Determine required alignment of the data buffers in memory region * associated with specified device node. */ diff --git a/soc/nordic/common/nrf54hx_nrf92x_mpu_regions.c b/soc/nordic/common/nrf54hx_nrf92x_mpu_regions.c index 66659588411e..b76fac86bcd3 100644 --- a/soc/nordic/common/nrf54hx_nrf92x_mpu_regions.c +++ b/soc/nordic/common/nrf54hx_nrf92x_mpu_regions.c @@ -28,15 +28,15 @@ static struct arm_mpu_region mpu_regions[] = { REGION_RAM_ATTR(CONFIG_SRAM_BASE_ADDRESS, CONFIG_SRAM_SIZE * 1024)), -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usbhs), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usbhs)) MPU_REGION_ENTRY("USBHS_CORE", USBHS_BASE, REGION_RAM_NOCACHE_ATTR(USBHS_BASE, USBHS_SIZE)), #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(can120), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(can120)) MPU_REGION_ENTRY("CAN120_MCAN", CAN120_BASE, REGION_RAM_NOCACHE_ATTR(CAN120_BASE, CAN120_SIZE)), #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(can121), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(can121)) MPU_REGION_ENTRY("CAN121_MCAN", CAN121_BASE, REGION_RAM_NOCACHE_ATTR(CAN121_BASE, CAN121_SIZE)), #endif diff --git a/soc/nordic/common/nrf_sys_event.c b/soc/nordic/common/nrf_sys_event.c new file mode 100644 index 000000000000..47c02eadb961 --- /dev/null +++ b/soc/nordic/common/nrf_sys_event.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#if CONFIG_SOC_SERIES_NRF54HX + +/* + * The 54HX is not yet supported by an nrfx driver nor the system controller so + * we implement an ISR and concurrent access safe reference counting implementation + * here using the nrfx hal. + */ + +#include + +static struct k_spinlock global_constlat_lock; +static uint16_t global_constlat_count; + +int nrf_sys_event_request_global_constlat(void) +{ + K_SPINLOCK(&global_constlat_lock) { + if (global_constlat_count == 0) { +#if CONFIG_SOC_NRF54H20_CPUAPP + nrf_lrcconf_task_trigger(NRF_LRCCONF010, + NRF_LRCCONF_TASK_CONSTLAT_ENABLE); +#elif CONFIG_SOC_NRF54H20_CPURAD + nrf_lrcconf_task_trigger(NRF_LRCCONF000, + NRF_LRCCONF_TASK_CONSTLAT_ENABLE); + nrf_lrcconf_task_trigger(NRF_LRCCONF020, + NRF_LRCCONF_TASK_CONSTLAT_ENABLE); +#else +#error "unsupported" +#endif + } + + global_constlat_count++; + } + + return 0; +} + +int nrf_sys_event_release_global_constlat(void) +{ + K_SPINLOCK(&global_constlat_lock) { + if (global_constlat_count == 1) { +#if CONFIG_SOC_NRF54H20_CPUAPP + nrf_lrcconf_task_trigger(NRF_LRCCONF010, + NRF_LRCCONF_TASK_CONSTLAT_DISABLE); +#elif CONFIG_SOC_NRF54H20_CPURAD + nrf_lrcconf_task_trigger(NRF_LRCCONF000, + NRF_LRCCONF_TASK_CONSTLAT_DISABLE); + nrf_lrcconf_task_trigger(NRF_LRCCONF020, + NRF_LRCCONF_TASK_CONSTLAT_DISABLE); +#else +#error "unsupported" +#endif + } + + global_constlat_count--; + } + + return 0; +} + +#else + +/* + * The nrfx power driver already contains an ISR and concurrent access safe reference + * counting API so we just use it directly when available. + */ + +#include + +int nrf_sys_event_request_global_constlat(void) +{ + nrfx_err_t err; + + err = nrfx_power_constlat_mode_request(); + + return (err == NRFX_SUCCESS || err == NRFX_ERROR_ALREADY) ? 0 : -EAGAIN; +} + +int nrf_sys_event_release_global_constlat(void) +{ + nrfx_err_t err; + + err = nrfx_power_constlat_mode_free(); + + return (err == NRFX_SUCCESS || err == NRFX_ERROR_BUSY) ? 0 : -EAGAIN; +} + +#endif diff --git a/soc/nordic/common/nrf_sys_event.h b/soc/nordic/common/nrf_sys_event.h new file mode 100644 index 000000000000..a4d6d8050f05 --- /dev/null +++ b/soc/nordic/common/nrf_sys_event.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/** + * @brief Request lowest latency for system events + * + * @details System will be configured for lowest latency after first + * call to nrf_sys_event_request_global_constlat() and will remain + * configured for lowest latency until matching number of calls to + * nrf_sys_event_release_global_constlat() occur. + * + * @retval 0 if successful + * @retval -errno code otherwise + */ +int nrf_sys_event_request_global_constlat(void); + +/** + * @brief Release low latency request + * + * @see nrf_sys_event_request_global_constlat() + * + * @retval 0 if successful + * @retval -errno code otherwise + */ +int nrf_sys_event_release_global_constlat(void); diff --git a/soc/nordic/common/vpr/Kconfig.sysbuild b/soc/nordic/common/vpr/Kconfig.sysbuild index 54464f10bc4b..cfa42dd86678 100644 --- a/soc/nordic/common/vpr/Kconfig.sysbuild +++ b/soc/nordic/common/vpr/Kconfig.sysbuild @@ -4,7 +4,7 @@ config VPR_LAUNCHER bool "VPR launcher" default y - depends on (SOC_NRF54H20_CPUPPR || SOC_NRF54H20_CPUFLPR || SOC_NRF54L15_ENGA_CPUFLPR || SOC_NRF54L15_CPUFLPR || SOC_NRF9280_CPUPPR) + depends on (SOC_NRF54H20_CPUPPR || SOC_NRF54H20_ENGB_CPUPPR || SOC_NRF54H20_CPUFLPR || SOC_NRF54H20_ENGB_CPUFLPR || SOC_NRF54L15_ENGA_CPUFLPR || SOC_NRF54L15_CPUFLPR || SOC_NRF9280_CPUPPR) help Include VPR launcher in build. VPR launcher is a minimal sample built for an ARM core that starts given VPR core. diff --git a/soc/nordic/nrf52/soc.c b/soc/nordic/nrf52/soc.c index 3262b84bc85d..4bb3b8640e58 100644 --- a/soc/nordic/nrf52/soc.c +++ b/soc/nordic/nrf52/soc.c @@ -37,7 +37,7 @@ static int nordicsemi_nrf52_init(void) nrf_power_dcdcen_set(NRF_POWER, true); #endif #if NRF_POWER_HAS_DCDCEN_VDDH && (defined(CONFIG_SOC_DCDC_NRF52X_HV) || \ - DT_NODE_HAS_STATUS(DT_INST(0, nordic_nrf52x_regulator_hv), okay)) + DT_NODE_HAS_STATUS_OKAY(DT_INST(0, nordic_nrf52x_regulator_hv))) nrf_power_dcdcen_vddh_set(NRF_POWER, true); #endif diff --git a/soc/nordic/nrf53/soc.c b/soc/nordic/nrf53/soc.c index 46e8e5ca20d4..67eb5dfb67b7 100644 --- a/soc/nordic/nrf53/soc.c +++ b/soc/nordic/nrf53/soc.c @@ -531,7 +531,7 @@ static int nordicsemi_nrf53_init(void) (DT_PROP(DT_NODELABEL(vregradio), regulator_initial_mode) == NRF5X_REG_MODE_DCDC) nrf_regulators_vreg_enable_set(NRF_REGULATORS, NRF_REGULATORS_VREG_RADIO, true); #endif -#if defined(CONFIG_SOC_DCDC_NRF53X_HV) || DT_NODE_HAS_STATUS(DT_NODELABEL(vregh), okay) +#if defined(CONFIG_SOC_DCDC_NRF53X_HV) || DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(vregh)) nrf_regulators_vreg_enable_set(NRF_REGULATORS, NRF_REGULATORS_VREG_HIGH, true); #endif diff --git a/soc/nordic/nrf54h/Kconfig b/soc/nordic/nrf54h/Kconfig index 51dc4e074806..9132ca8458b8 100644 --- a/soc/nordic/nrf54h/Kconfig +++ b/soc/nordic/nrf54h/Kconfig @@ -24,6 +24,7 @@ config SOC_NRF54H20_CPUAPP_COMMON select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE select NRFS_HAS_CLOCK_SERVICE select NRFS_HAS_DVFS_SERVICE + select NRFS_HAS_GDPWR_SERVICE select NRFS_HAS_MRAM_SERVICE select NRFS_HAS_TEMP_SERVICE select NRFS_HAS_VBUS_DETECTOR_SERVICE @@ -49,6 +50,7 @@ config SOC_NRF54H20_CPURAD_COMMON select CPU_HAS_CUSTOM_FIXED_SOC_MPU_REGIONS select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE select NRFS_HAS_CLOCK_SERVICE + select NRFS_HAS_GDPWR_SERVICE select NRFS_HAS_MRAM_SERVICE select NRFS_HAS_TEMP_SERVICE select NRFS_HAS_VBUS_DETECTOR_SERVICE diff --git a/soc/nordic/nrf54h/pm_s2ram.c b/soc/nordic/nrf54h/pm_s2ram.c index 10cdd36a7621..88529c4bb755 100644 --- a/soc/nordic/nrf54h/pm_s2ram.c +++ b/soc/nordic/nrf54h/pm_s2ram.c @@ -127,25 +127,48 @@ int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off) return ret; } -void pm_s2ram_mark_set(void) +void __attribute__((naked)) pm_s2ram_mark_set(void) { /* empty */ + __asm__ volatile("bx lr\n"); } -bool pm_s2ram_mark_check_and_clear(void) +bool __attribute__((naked)) pm_s2ram_mark_check_and_clear(void) { - bool unretained_wake; - bool restore_valid; - uint32_t reset_reason = nrf_resetinfo_resetreas_local_get(NRF_RESETINFO); + __asm__ volatile( + /* Set return value to 0 */ + "mov r0, #0\n" - if (reset_reason != NRF_RESETINFO_RESETREAS_LOCAL_UNRETAINED_MASK) { - return false; - } - unretained_wake = reset_reason & NRF_RESETINFO_RESETREAS_LOCAL_UNRETAINED_MASK; - nrf_resetinfo_resetreas_local_set(NRF_RESETINFO, 0); + /* Load and check RESETREAS register */ + "ldr r3, [%[resetinfo_addr], %[resetreas_offs]]\n" + "cmp r3, %[resetreas_unretained_mask]\n" + + "bne exit\n" + + /* Clear RESETREAS register */ + "str r0, [%[resetinfo_addr], %[resetreas_offs]]\n" + + /* Load RESTOREVALID register */ + "ldr r3, [%[resetinfo_addr], %[restorevalid_offs]]\n" + + /* Clear RESTOREVALID */ + "str r0, [%[resetinfo_addr], %[restorevalid_offs]]\n" + + /* Check RESTOREVALID register */ + "cmp r3, %[restorevalid_present_mask]\n" + "bne exit\n" + + /* Set return value to 1 */ + "mov r0, #1\n" - restore_valid = nrf_resetinfo_restore_valid_check(NRF_RESETINFO); - nrf_resetinfo_restore_valid_set(NRF_RESETINFO, false); + "exit:\n" + "bx lr\n" + : + : [resetinfo_addr] "r"(NRF_RESETINFO), + [resetreas_offs] "r"(offsetof(NRF_RESETINFO_Type, RESETREAS.LOCAL)), + [resetreas_unretained_mask] "r"(NRF_RESETINFO_RESETREAS_LOCAL_UNRETAINED_MASK), + [restorevalid_offs] "r"(offsetof(NRF_RESETINFO_Type, RESTOREVALID)), + [restorevalid_present_mask] "r"(RESETINFO_RESTOREVALID_RESTOREVALID_Msk) - return (unretained_wake & restore_valid) ? true : false; + : "r0", "r1", "r3", "r4", "memory"); } diff --git a/soc/nordic/nrf54h/power.c b/soc/nordic/nrf54h/power.c index 1a59320d80b4..8b73dbaee30c 100644 --- a/soc/nordic/nrf54h/power.c +++ b/soc/nordic/nrf54h/power.c @@ -68,7 +68,7 @@ void nrf_poweroff(void) nrf_resetinfo_resetreas_local_set(NRF_RESETINFO, 0); nrf_resetinfo_restore_valid_set(NRF_RESETINFO, false); -#if !defined(CONFIG_SOC_NRF54H20_CPURAD) +#if !defined(NRF_RADIOCORE) /* Disable retention */ nrf_lrcconf_retain_set(NRF_LRCCONF010, NRF_LRCCONF_POWER_MAIN, false); nrf_lrcconf_retain_set(NRF_LRCCONF010, NRF_LRCCONF_POWER_DOMAIN_0, false); @@ -98,7 +98,7 @@ static void s2idle_enter(uint8_t substate_id) case 1: /* Substate for idle with cache retained - not implemented yet. */ break; case 2: /* Substate for idle with cache disabled. */ -#if !defined(CONFIG_SOC_NRF54H20_CPURAD) +#if !defined(NRF_RADIOCORE) soc_lrcconf_poweron_request(node, NRF_LRCCONF_POWER_MAIN); #endif common_suspend(); @@ -127,7 +127,7 @@ static void s2idle_exit(uint8_t substate_id) break; case 2: /* Substate for idle with cache disabled. */ common_resume(); -#if !defined(CONFIG_SOC_NRF54H20_CPURAD) +#if !defined(NRF_RADIOCORE) soc_lrcconf_poweron_release(node, NRF_LRCCONF_POWER_MAIN); #endif default: /* Unknown substate. */ @@ -140,7 +140,7 @@ static void s2idle_exit(uint8_t substate_id) static void s2ram_exit(void) { common_resume(); -#if !defined(CONFIG_SOC_NRF54H20_CPURAD) +#if !defined(NRF_RADIOCORE) /* Re-enable domain retention. */ nrf_lrcconf_retain_set(NRF_LRCCONF010, NRF_LRCCONF_POWER_DOMAIN_0, true); #endif @@ -156,7 +156,7 @@ static int sys_suspend_to_ram(void) NRF_RESETINFO_RESETREAS_LOCAL_UNRETAINED_MASK); nrf_resetinfo_restore_valid_set(NRF_RESETINFO, true); -#if !defined(CONFIG_SOC_NRF54H20_CPURAD) +#if !defined(NRF_RADIOCORE) /* Disable retention */ nrf_lrcconf_retain_set(NRF_LRCCONF010, NRF_LRCCONF_POWER_DOMAIN_0, false); #endif diff --git a/soc/nordic/nrf54h/soc.c b/soc/nordic/nrf54h/soc.c index ed4cb3f45d22..85570bd9ff37 100644 --- a/soc/nordic/nrf54h/soc.c +++ b/soc/nordic/nrf54h/soc.c @@ -145,7 +145,7 @@ static int nordicsemi_nrf54h_init(void) return err; } -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ccm030), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ccm030)) /* DMASEC is set to non-secure by default, which prevents CCM from * accessing secure memory. Change DMASEC to secure. */ diff --git a/soc/nordic/nrf54l/soc.c b/soc/nordic/nrf54l/soc.c index 56e48800ed41..65f6cc183ce1 100644 --- a/soc/nordic/nrf54l/soc.c +++ b/soc/nordic/nrf54l/soc.c @@ -154,6 +154,11 @@ static inline void power_and_clock_configuration(void) } #if (DT_PROP(DT_NODELABEL(vregmain), regulator_initial_mode) == NRF5X_REG_MODE_DCDC) +#if defined(__CORTEX_M) && !defined(NRF_TRUSTZONE_NONSECURE) && defined(__ARM_FEATURE_CMSE) + if (*(uint32_t volatile *)0x00FFC334 <= 0x180A1D00) { + *(uint32_t volatile *)0x50120640 = 0x1EA9E040; + } +#endif nrf_regulators_vreg_enable_set(NRF_REGULATORS, NRF_REGULATORS_VREG_MAIN, true); #endif diff --git a/soc/nordic/nrf92/Kconfig b/soc/nordic/nrf92/Kconfig index f6efecb6ad07..1f60b944b760 100644 --- a/soc/nordic/nrf92/Kconfig +++ b/soc/nordic/nrf92/Kconfig @@ -22,6 +22,7 @@ config SOC_NRF9230_ENGB_CPUAPP select HAS_NORDIC_DMM select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE select NRFS_HAS_CLOCK_SERVICE + select NRFS_HAS_GDPWR_SERVICE select NRFS_HAS_MRAM_SERVICE select NRFS_HAS_PMIC_SERVICE select NRFS_HAS_TEMP_SERVICE @@ -40,6 +41,7 @@ config SOC_NRF9230_ENGB_CPURAD select HAS_NORDIC_DMM select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE select NRFS_HAS_CLOCK_SERVICE + select NRFS_HAS_GDPWR_SERVICE select NRFS_HAS_MRAM_SERVICE select NRFS_HAS_PMIC_SERVICE select NRFS_HAS_TEMP_SERVICE diff --git a/soc/nordic/nrf92/soc.c b/soc/nordic/nrf92/soc.c index 1a40bb58ddae..d9a54e4f1aa6 100644 --- a/soc/nordic/nrf92/soc.c +++ b/soc/nordic/nrf92/soc.c @@ -93,7 +93,7 @@ static int nordicsemi_nrf92_init(void) trim_hsfll(); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ccm030), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ccm030)) /* DMASEC is set to non-secure by default, which prevents CCM from * accessing secure memory. Change DMASEC to secure. */ diff --git a/soc/nordic/validate_enabled_instances.c b/soc/nordic/validate_enabled_instances.c index b3e4dd70bbf1..afcfc6e8ca83 100644 --- a/soc/nordic/validate_enabled_instances.c +++ b/soc/nordic/validate_enabled_instances.c @@ -7,16 +7,16 @@ #include #define I2C_ENABLED(idx) (IS_ENABLED(CONFIG_I2C) && \ - DT_NODE_HAS_STATUS(DT_NODELABEL(i2c##idx), okay)) + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2c##idx))) #define SPI_ENABLED(idx) (IS_ENABLED(CONFIG_SPI) && \ - DT_NODE_HAS_STATUS(DT_NODELABEL(spi##idx), okay)) + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(spi##idx))) #define UART_ENABLED(idx) (IS_ENABLED(CONFIG_SERIAL) && \ (IS_ENABLED(CONFIG_SOC_SERIES_NRF53X) || \ IS_ENABLED(CONFIG_SOC_SERIES_NRF54LX) || \ IS_ENABLED(CONFIG_SOC_SERIES_NRF91X)) && \ - DT_NODE_HAS_STATUS(DT_NODELABEL(uart##idx), okay)) + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart##idx))) /* * In most Nordic SoCs, SPI and TWI peripherals with the same instance number diff --git a/soc/nxp/imx/imx6sx/Kconfig b/soc/nxp/imx/imx6sx/Kconfig index 901b2c90a649..f83d462be4c3 100644 --- a/soc/nxp/imx/imx6sx/Kconfig +++ b/soc/nxp/imx/imx6sx/Kconfig @@ -9,6 +9,7 @@ config SOC_SERIES_IMX6SX select CPU_HAS_FPU select CPU_HAS_ARM_MPU select CLOCK_CONTROL + select SOC_EARLY_INIT_HOOK config SOC_MCIMX6X_M4 select HAS_IMX_HAL diff --git a/soc/nxp/imx/imx6sx/soc.c b/soc/nxp/imx/imx6sx/soc.c index a968e5d5cb1f..516c2e9bcf62 100644 --- a/soc/nxp/imx/imx6sx/soc.c +++ b/soc/nxp/imx/imx6sx/soc.c @@ -23,55 +23,55 @@ static void SOC_RdcInit(void) RDC_DOMAIN_PERM(M4_DOMAIN_ID, RDC_DOMAIN_PERM_RW), false, false); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) /* Set access to UART_1 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapUart1, RDC_DT_VAL(uart1), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) /* Set access to UART_2 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapUart2, RDC_DT_VAL(uart2), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3)) /* Set access to UART_3 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapUart3, RDC_DT_VAL(uart3), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart4)) /* Set access to UART_4 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapUart4, RDC_DT_VAL(uart4), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart5), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart5)) /* Set access to UART_5 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapUart5, RDC_DT_VAL(uart5), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart6), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart6)) /* Set access to UART_6 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapUart6, RDC_DT_VAL(uart6), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) /* Set access to GPIO_1 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapGpio1, RDC_DT_VAL(gpio1), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio2)) /* Set access to GPIO_2 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapGpio2, RDC_DT_VAL(gpio2), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio3)) /* Set access to GPIO_3 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapGpio3, RDC_DT_VAL(gpio3), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio4)) /* Set access to GPIO_4 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapGpio4, RDC_DT_VAL(gpio4), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio5), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio5)) /* Set access to GPIO_5 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapGpio5, RDC_DT_VAL(gpio5), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio6), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio6)) /* Set access to GPIO_6 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapGpio6, RDC_DT_VAL(gpio6), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio7), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio7)) /* Set access to GPIO_7 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapGpio7, RDC_DT_VAL(gpio7), false, false); #endif @@ -81,69 +81,69 @@ static void SOC_RdcInit(void) RDC_SetPdapAccess(RDC, rdcPdapMuB, RDC_DT_VAL(mub), false, false); #endif /* CONFIG_IPM_IMX */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(epit1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(epit1)) /* Set access to EPIT_1 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapEpit1, RDC_DT_VAL(epit1), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(epit2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(epit2)) /* Set access to EPIT_2 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapEpit2, RDC_DT_VAL(epit2), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2c1)) /* Set access to I2C-1 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapI2c1, RDC_DT_VAL(i2c1), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2c2)) /* Set access to I2C-2 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapI2c2, RDC_DT_VAL(i2c2), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2c3)) /* Set access to I2C-3 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapI2c3, RDC_DT_VAL(i2c3), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2c4)) /* Set access to I2C-4 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapI2c4, RDC_DT_VAL(i2c4), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm1)) /* Set access to PWM-1 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapPwm1, RDC_DT_VAL(pwm1), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm2)) /* Set access to PWM-2 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapPwm2, RDC_DT_VAL(pwm2), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm3)) /* Set access to PWM-3 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapPwm3, RDC_DT_VAL(pwm3), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm4)) /* Set access to PWM-4 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapPwm4, RDC_DT_VAL(pwm4), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm5), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm5)) /* Set access to PWM-5 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapPwm5, RDC_DT_VAL(pwm5), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm6), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm6)) /* Set access to PWM-6 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapPwm6, RDC_DT_VAL(pwm6), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm7), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm7)) /* Set access to PWM-7 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapPwm7, RDC_DT_VAL(pwm7), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm8), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm8)) /* Set access to PWM-8 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapPwm8, RDC_DT_VAL(pwm8), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(adc1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(adc1)) /* Set access to ADC-1 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapAdc1, RDC_DT_VAL(adc1), false, false); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(adc2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(adc2)) /* Set access to ADC-2 for M4 core */ RDC_SetPdapAccess(RDC, rdcPdapAdc2, RDC_DT_VAL(adc2), false, false); #endif @@ -213,10 +213,10 @@ static void SOC_ClockInit(void) CCM_SetRootDivider(CCM, ccmRootPerclkPodf, 0); /* Enable EPIT clocks */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(epit1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(epit1)) CCM_ControlGate(CCM, ccmCcgrGateEpit1Clk, ccmClockNeededAll); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(epit2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(epit2)) CCM_ControlGate(CCM, ccmCcgrGateEpit2Clk, ccmClockNeededAll); #endif #endif /* CONFIG_COUNTER_IMX_EPIT */ @@ -229,16 +229,16 @@ static void SOC_ClockInit(void) CCM_SetRootDivider(CCM, ccmRootPerclkPodf, 0); /* Enable I2C clock */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2c1)) CCM_ControlGate(CCM, ccmCcgrGateI2c1Serialclk, ccmClockNeededAll); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2c2)) CCM_ControlGate(CCM, ccmCcgrGateI2c2Serialclk, ccmClockNeededAll); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2c3)) CCM_ControlGate(CCM, ccmCcgrGateI2c3Serialclk, ccmClockNeededAll); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2c4)) CCM_ControlGate(CCM, ccmCcgrGateI2c4Serialclk, ccmClockNeededAll); #endif #endif /* CONFIG_I2C_IMX */ @@ -251,28 +251,28 @@ static void SOC_ClockInit(void) CCM_SetRootDivider(CCM, ccmRootPerclkPodf, 0); /* Enable PWM clock */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm1)) CCM_ControlGate(CCM, ccmCcgrGatePwm1Clk, ccmClockNeededAll); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm2)) CCM_ControlGate(CCM, ccmCcgrGatePwm2Clk, ccmClockNeededAll); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm3)) CCM_ControlGate(CCM, ccmCcgrGatePwm3Clk, ccmClockNeededAll); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm4)) CCM_ControlGate(CCM, ccmCcgrGatePwm4Clk, ccmClockNeededAll); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm5), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm5)) CCM_ControlGate(CCM, ccmCcgrGatePwm5Clk, ccmClockNeededAll); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm6), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm6)) CCM_ControlGate(CCM, ccmCcgrGatePwm6Clk, ccmClockNeededAll); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm7), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm7)) CCM_ControlGate(CCM, ccmCcgrGatePwm7Clk, ccmClockNeededAll); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm8), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm8)) CCM_ControlGate(CCM, ccmCcgrGatePwm8Clk, ccmClockNeededAll); #endif #endif /* CONFIG_PWM_IMX */ @@ -287,7 +287,7 @@ static void SOC_ClockInit(void) * * @return 0 */ -static int mcimx6x_m4_init(void) +void soc_early_init_hook(void) { /* Configure RDC */ SOC_RdcInit(); @@ -300,8 +300,4 @@ static int mcimx6x_m4_init(void) /* Initialize clock */ SOC_ClockInit(); - - return 0; } - -SYS_INIT(mcimx6x_m4_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/imx/imx7d/Kconfig b/soc/nxp/imx/imx7d/Kconfig index fbebe524242d..1aa977342856 100644 --- a/soc/nxp/imx/imx7d/Kconfig +++ b/soc/nxp/imx/imx7d/Kconfig @@ -8,6 +8,7 @@ config SOC_SERIES_IMX7D select CLOCK_CONTROL select CPU_HAS_FPU select CPU_HAS_ARM_MPU + select SOC_EARLY_INIT_HOOK config SOC_MCIMX7D_M4 select HAS_IMX_HAL diff --git a/soc/nxp/imx/imx7d/soc.c b/soc/nxp/imx/imx7d/soc.c index 5ebf3ec07383..780c405a0bb9 100644 --- a/soc/nxp/imx/imx7d/soc.c +++ b/soc/nxp/imx/imx7d/soc.c @@ -57,21 +57,21 @@ void SOC_RdcInit(void) static void nxp_mcimx7_gpio_config(void) { -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) RDC_SetPdapAccess(RDC, rdcPdapGpio1, RDC_DT_VAL(gpio1), false, false); /* Enable gpio clock gate */ CCM_ControlGate(CCM, ccmCcgrGateGpio1, ccmClockNeededRunWait); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio2)) RDC_SetPdapAccess(RDC, rdcPdapGpio2, RDC_DT_VAL(gpio2), false, false); /* Enable gpio clock gate */ CCM_ControlGate(CCM, ccmCcgrGateGpio2, ccmClockNeededRunWait); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio7), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio7)) RDC_SetPdapAccess(RDC, rdcPdapGpio7, RDC_DT_VAL(gpio7), false, false); /* Enable gpio clock gate */ CCM_ControlGate(CCM, ccmCcgrGateGpio7, ccmClockNeededRunWait); @@ -84,7 +84,7 @@ static void nxp_mcimx7_gpio_config(void) static void nxp_mcimx7_uart_config(void) { -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) /* We need to grasp board uart exclusively */ RDC_SetPdapAccess(RDC, rdcPdapUart2, RDC_DT_VAL(uart2), false, false); /* Select clock derived from OSC clock(24M) */ @@ -99,7 +99,7 @@ static void nxp_mcimx7_uart_config(void) CCM_ControlGate(CCM, ccmCcgrGateUart2, ccmClockNeededAll); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart6), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart6)) /* We need to grasp board uart exclusively */ RDC_SetPdapAccess(RDC, rdcPdapUart6, RDC_DT_VAL(uart6), false, false); /* Select clock derived from OSC clock(24M) */ @@ -121,7 +121,7 @@ static void nxp_mcimx7_uart_config(void) static void nxp_mcimx7_i2c_config(void) { -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2c1)) /* In this example, we need to grasp board I2C exclusively */ RDC_SetPdapAccess(RDC, rdcPdapI2c1, RDC_DT_VAL(i2c1), false, false); /* Select I2C clock derived from OSC clock(24M) */ @@ -131,7 +131,7 @@ static void nxp_mcimx7_i2c_config(void) CCM_ControlGate(CCM, ccmCcgrGateI2c1, ccmClockNeededRunWait); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2c2)) /* In this example, we need to grasp board I2C exclusively */ RDC_SetPdapAccess(RDC, rdcPdapI2c2, RDC_DT_VAL(i2c2), false, false); /* Select I2C clock derived from OSC clock(24M) */ @@ -141,7 +141,7 @@ static void nxp_mcimx7_i2c_config(void) CCM_ControlGate(CCM, ccmCcgrGateI2c2, ccmClockNeededRunWait); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2c3)) /* In this example, we need to grasp board I2C exclusively */ RDC_SetPdapAccess(RDC, rdcPdapI2c3, RDC_DT_VAL(i2c3), false, false); /* Select I2C clock derived from OSC clock(24M) */ @@ -151,7 +151,7 @@ static void nxp_mcimx7_i2c_config(void) CCM_ControlGate(CCM, ccmCcgrGateI2c3, ccmClockNeededRunWait); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(i2c4)) /* In this example, we need to grasp board I2C exclusively */ RDC_SetPdapAccess(RDC, rdcPdapI2c4, RDC_DT_VAL(i2c4), false, false); /* Select I2C clock derived from OSC clock(24M) */ @@ -168,7 +168,7 @@ static void nxp_mcimx7_i2c_config(void) static void nxp_mcimx7_pwm_config(void) { -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm1)) /* We need to grasp board pwm exclusively */ RDC_SetPdapAccess(RDC, rdcPdapPwm1, RDC_DT_VAL(pwm1), false, false); /* Select clock derived from OSC clock(24M) */ @@ -178,7 +178,7 @@ static void nxp_mcimx7_pwm_config(void) CCM_ControlGate(CCM, ccmCcgrGatePwm1, ccmClockNeededAll); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm2)) /* We need to grasp board pwm exclusively */ RDC_SetPdapAccess(RDC, rdcPdapPwm2, RDC_DT_VAL(pwm2), false, false); /* Select clock derived from OSC clock(24M) */ @@ -188,7 +188,7 @@ static void nxp_mcimx7_pwm_config(void) CCM_ControlGate(CCM, ccmCcgrGatePwm2, ccmClockNeededAll); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm3)) /* We need to grasp board pwm exclusively */ RDC_SetPdapAccess(RDC, rdcPdapPwm3, RDC_DT_VAL(pwm3), false, false); /* Select clock derived from OSC clock(24M) */ @@ -198,7 +198,7 @@ static void nxp_mcimx7_pwm_config(void) CCM_ControlGate(CCM, ccmCcgrGatePwm3, ccmClockNeededAll); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm4)) /* We need to grasp board pwm exclusively */ RDC_SetPdapAccess(RDC, rdcPdapPwm4, RDC_DT_VAL(pwm4), false, false); /* Select clock derived from OSC clock(24M) */ @@ -222,7 +222,7 @@ static void nxp_mcimx7_mu_config(void) } #endif /* CONFIG_IPM_IMX */ -static int nxp_mcimx7_init(void) +void soc_early_init_hook(void) { /* SoC specific RDC settings */ @@ -250,8 +250,4 @@ static int nxp_mcimx7_init(void) #ifdef CONFIG_IPM_IMX nxp_mcimx7_mu_config(); #endif /* CONFIG_IPM_IMX */ - - return 0; } - -SYS_INIT(nxp_mcimx7_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/imx/imx8m/Kconfig b/soc/nxp/imx/imx8m/Kconfig index fe206de15270..a1344a8c38e2 100644 --- a/soc/nxp/imx/imx8m/Kconfig +++ b/soc/nxp/imx/imx8m/Kconfig @@ -10,6 +10,7 @@ config SOC_MIMX8MM6_A53 select HAS_MCUX_IOMUXC if PINCTRL select HAS_MCUX_RDC select HAS_MCUX_CACHE + select SOC_PREP_HOOK config SOC_MIMX8MM6_M4 select ARM @@ -21,6 +22,7 @@ config SOC_MIMX8MM6_M4 select HAS_MCUX_RDC select HAS_MCUX_IGPIO select HAS_MCUX_IOMUXC + select SOC_EARLY_INIT_HOOK config SOC_MIMX8ML8_A53 select ARM64 @@ -31,6 +33,7 @@ config SOC_MIMX8ML8_A53 select HAS_MCUX_IOMUXC if PINCTRL select HAS_MCUX_RDC select HAS_MCUX_CACHE + select SOC_PREP_HOOK config SOC_MIMX8MN6_A53 select ARM64 @@ -41,6 +44,7 @@ config SOC_MIMX8MN6_A53 select HAS_MCUX_IOMUXC if PINCTRL select HAS_MCUX_RDC select HAS_MCUX_CACHE + select SOC_PREP_HOOK config SOC_MIMX8ML8_ADSP select XTENSA @@ -71,6 +75,7 @@ config SOC_MIMX8ML8_M7 select ARM_MPU select HAS_MCUX_IGPIO select HAS_MCUX_IOMUXC + select SOC_EARLY_INIT_HOOK config SOC_MIMX8MQ6_M4 select ARM diff --git a/soc/nxp/imx/imx8m/a53/soc.c b/soc/nxp/imx/imx8m/a53/soc.c index 002b884daa04..a110213e2b63 100644 --- a/soc/nxp/imx/imx8m/a53/soc.c +++ b/soc/nxp/imx/imx8m/a53/soc.c @@ -12,41 +12,47 @@ #include #include +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(rdc)) + +#define rdc_inst ((RDC_Type *)DT_REG_ADDR(DT_NODELABEL(rdc))) + /* set RDC permission for peripherals */ static void soc_rdc_init(void) { rdc_domain_assignment_t assignment = {0}; rdc_periph_access_config_t periphConfig; - RDC_Init(RDC); + RDC_Init(rdc_inst); assignment.domainId = A53_DOMAIN_ID; - RDC_SetMasterDomainAssignment(RDC, kRDC_Master_A53, &assignment); + RDC_SetMasterDomainAssignment(rdc_inst, kRDC_Master_A53, &assignment); RDC_GetDefaultPeriphAccessConfig(&periphConfig); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) && DT_NODE_HAS_PROP(DT_NODELABEL(uart2), rdc) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) && DT_NODE_HAS_PROP(DT_NODELABEL(uart2), rdc) periphConfig.periph = kRDC_Periph_UART2; periphConfig.policy = RDC_DT_VAL(uart2); - RDC_SetPeriphAccessConfig(RDC, &periphConfig); + RDC_SetPeriphAccessConfig(rdc_inst, &periphConfig); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) && DT_NODE_HAS_PROP(DT_NODELABEL(uart4), rdc) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart4)) && DT_NODE_HAS_PROP(DT_NODELABEL(uart4), rdc) periphConfig.periph = kRDC_Periph_UART4; periphConfig.policy = RDC_DT_VAL(uart4); - RDC_SetPeriphAccessConfig(RDC, &periphConfig); + RDC_SetPeriphAccessConfig(rdc_inst, &periphConfig); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(enet), okay) && DT_NODE_HAS_PROP(DT_NODELABEL(enet), rdc) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(enet)) && DT_NODE_HAS_PROP(DT_NODELABEL(enet), rdc) periphConfig.periph = kRDC_Periph_ENET1; periphConfig.policy = RDC_DT_VAL(enet); - RDC_SetPeriphAccessConfig(RDC, &periphConfig); + RDC_SetPeriphAccessConfig(rdc_inst, &periphConfig); #endif } +#else + +#define soc_rdc_init() do { } while (false) -static int soc_init(void) +#endif + +void soc_prep_hook(void) { soc_rdc_init(); - return 0; } - -SYS_INIT(soc_init, EARLY, 1); diff --git a/soc/nxp/imx/imx8m/m4_mini/soc.c b/soc/nxp/imx/imx8m/m4_mini/soc.c index fab49d98bffc..b809a900e11f 100644 --- a/soc/nxp/imx/imx8m/m4_mini/soc.c +++ b/soc/nxp/imx/imx8m/m4_mini/soc.c @@ -104,25 +104,25 @@ static void SOC_ClockInit(void) CLOCK_SetRootMux(kCLOCK_RootAudioAhb, kCLOCK_AudioAhbRootmuxSysPll1); #if defined(CONFIG_UART_MCUX_IUART) -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart1, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootUart1, 1U, 1U); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart2, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootUart2, 1U, 1U); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3)) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart3, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootUart3, 1U, 1U); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart4)) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart4, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ @@ -148,7 +148,7 @@ static void SOC_ClockInit(void) CLOCK_EnableClock(kCLOCK_Sec_Debug); } -static int nxp_mimx8mm6_init(void) +void soc_early_init_hook(void) { /* SoC specific RDC settings */ @@ -156,8 +156,4 @@ static int nxp_mimx8mm6_init(void) /* SoC specific Clock settings */ SOC_ClockInit(); - - return 0; } - -SYS_INIT(nxp_mimx8mm6_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/imx/imx8m/m4_quad/soc.c b/soc/nxp/imx/imx8m/m4_quad/soc.c index e2849f62fe4c..eea984fc172a 100644 --- a/soc/nxp/imx/imx8m/m4_quad/soc.c +++ b/soc/nxp/imx/imx8m/m4_quad/soc.c @@ -67,25 +67,25 @@ static void SOC_ClockInit(void) CLOCK_SetRootMux(kCLOCK_RootM4, kCLOCK_M4RootmuxSysPll1Div3); #if defined(CONFIG_UART_MCUX_IUART) -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart1, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootUart1, 1U, 1U); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart2, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootUart2, 1U, 1U); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3)) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart3, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootUart3, 1U, 1U); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart4)) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart4, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ @@ -111,7 +111,7 @@ static void SOC_ClockInit(void) CLOCK_EnableClock(kCLOCK_Sec_Debug); } -static int nxp_mimx8mq6_init(void) +void soc_early_init_hook(void) { /* SoC specific RDC settings */ @@ -119,8 +119,4 @@ static int nxp_mimx8mq6_init(void) /* SoC specific Clock settings */ SOC_ClockInit(); - - return 0; } - -SYS_INIT(nxp_mimx8mq6_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/imx/imx8m/m7/soc.c b/soc/nxp/imx/imx8m/m7/soc.c index 724368eac377..7cd42b3bb5d7 100644 --- a/soc/nxp/imx/imx8m/m7/soc.c +++ b/soc/nxp/imx/imx8m/m7/soc.c @@ -107,25 +107,25 @@ static void SOC_ClockInit(void) CLOCK_SetRootMux(kCLOCK_RootAhb, kCLOCK_AhbRootmuxSysPll1Div6); #if defined(CONFIG_UART_MCUX_IUART) -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart1)) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart1, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootUart1, 1U, 1U); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart2)) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart2, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootUart2, 1U, 1U); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart3)) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart3, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootUart3, 1U, 1U); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart4)) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart4, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ @@ -134,21 +134,21 @@ static void SOC_ClockInit(void) #endif #if defined(CONFIG_SPI_MCUX_ECSPI) -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ecspi1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ecspi1)) /* Set ECSPI1 source to SYSTEM PLL1 800MHZ */ CLOCK_SetRootMux(kCLOCK_RootEcspi1, kCLOCK_EcspiRootmuxSysPll1); /* Set root clock to 800MHZ / 10 = 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootEcspi1, 2U, 5U); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ecspi2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ecspi2)) /* Set ECSPI2 source to SYSTEM PLL1 800MHZ */ CLOCK_SetRootMux(kCLOCK_RootEcspi2, kCLOCK_EcspiRootmuxSysPll1); /* Set root clock to 800MHZ / 10 = 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootEcspi2, 2U, 5U); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ecspi3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ecspi3)) /* Set ECSPI3 source to SYSTEM PLL1 800MHZ */ CLOCK_SetRootMux(kCLOCK_RootEcspi3, kCLOCK_EcspiRootmuxSysPll1); /* Set root clock to 800MHZ / 10 = 80MHZ */ @@ -175,27 +175,27 @@ static void gpio_init(void) { #if defined(CONFIG_GPIO_MCUX_IGPIO) -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio1)) CLOCK_EnableClock(kCLOCK_Gpio1); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio2)) CLOCK_EnableClock(kCLOCK_Gpio2); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio3)) CLOCK_EnableClock(kCLOCK_Gpio3); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio4), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio4)) CLOCK_EnableClock(kCLOCK_Gpio4); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio5), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpio5)) CLOCK_EnableClock(kCLOCK_Gpio5); @@ -203,7 +203,7 @@ static void gpio_init(void) #endif } -static int nxp_mimx8ml8_init(void) +void soc_early_init_hook(void) { /* SoC specific RDC settings */ @@ -213,8 +213,4 @@ static int nxp_mimx8ml8_init(void) SOC_ClockInit(); gpio_init(); - - return 0; } - -SYS_INIT(nxp_mimx8ml8_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/imxrt/imxrt10xx/Kconfig b/soc/nxp/imxrt/imxrt10xx/Kconfig index 05eb7b5e8acb..c86f946aab83 100644 --- a/soc/nxp/imxrt/imxrt10xx/Kconfig +++ b/soc/nxp/imxrt/imxrt10xx/Kconfig @@ -6,7 +6,6 @@ config SOC_SERIES_IMXRT10XX select CPU_CORTEX_M_HAS_DWT select CPU_HAS_ICACHE select CPU_HAS_DCACHE - select SOC_RESET_HOOK select CPU_HAS_CUSTOM_FIXED_SOC_MPU_REGIONS select ARM select CLOCK_CONTROL @@ -29,6 +28,8 @@ config SOC_SERIES_IMXRT10XX select HAS_MCUX_USB_EHCI select HAS_SWO select HAS_PM + select SOC_RESET_HOOK + select SOC_EARLY_INIT_HOOK config SOC_MIMXRT1011 select CPU_HAS_FPU diff --git a/soc/nxp/imxrt/imxrt10xx/flexspi.c b/soc/nxp/imxrt/imxrt10xx/flexspi.c index a6a6239e9e74..5f288747c1a3 100644 --- a/soc/nxp/imxrt/imxrt10xx/flexspi.c +++ b/soc/nxp/imxrt/imxrt10xx/flexspi.c @@ -28,7 +28,7 @@ uint32_t flexspi_clock_set_freq(uint32_t clock_name, uint32_t rate) div_sel = kCLOCK_FlexspiDiv; clk_name = kCLOCK_FlexSpi; break; -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexspi2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexspi2)) case IMX_CCM_FLEXSPI2_CLK: /* Get clock root frequency */ root_rate = CLOCK_GetClockRootFreq(kCLOCK_Flexspi2ClkRoot) * diff --git a/soc/nxp/imxrt/imxrt10xx/lpm_rt1064.c b/soc/nxp/imxrt/imxrt10xx/lpm_rt1064.c index c7cc46d03073..ad850f138f96 100644 --- a/soc/nxp/imxrt/imxrt10xx/lpm_rt1064.c +++ b/soc/nxp/imxrt/imxrt10xx/lpm_rt1064.c @@ -339,7 +339,7 @@ void clock_lpm_init(void) XTALOSC24M->OSC_CONFIG1 = tmp_reg; } -static int imxrt_lpm_init(void) +void imxrt_lpm_init(void) { struct clock_callbacks callbacks; @@ -464,8 +464,4 @@ static int imxrt_lpm_init(void) /* Install LPM callbacks */ imxrt_clock_pm_callbacks_register(&callbacks); - return 0; } - - -SYS_INIT(imxrt_lpm_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/imxrt/imxrt10xx/power.c b/soc/nxp/imxrt/imxrt10xx/power.c index fac3180c0db4..5936b70e02a9 100644 --- a/soc/nxp/imxrt/imxrt10xx/power.c +++ b/soc/nxp/imxrt/imxrt10xx/power.c @@ -240,7 +240,7 @@ void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id) } /* Initialize power system */ -static int rt10xx_power_init(void) +void rt10xx_power_init(void) { dcdc_internal_regulator_config_t reg_config; @@ -268,9 +268,4 @@ static int rt10xx_power_init(void) /* Enable high gate drive on power FETs to reduce leakage current */ PMU_CoreEnableIncreaseGateDrive(PMU, true); - - - return 0; } - -SYS_INIT(rt10xx_power_init, PRE_KERNEL_2, 0); diff --git a/soc/nxp/imxrt/imxrt10xx/soc.c b/soc/nxp/imxrt/imxrt10xx/soc.c index 9b197163567f..941ae1d34747 100644 --- a/soc/nxp/imxrt/imxrt10xx/soc.c +++ b/soc/nxp/imxrt/imxrt10xx/soc.c @@ -67,10 +67,10 @@ const clock_enet_pll_config_t ethPllConfig = { .enableClkOutput500M = true, #endif #if defined(CONFIG_ETH_NXP_ENET) || defined(CONFIG_ETH_MCUX) -#if DT_NODE_HAS_STATUS(DT_NODELABEL(enet), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(enet)) .enableClkOutput = true, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(enet2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(enet2)) .enableClkOutput1 = true, #endif #endif @@ -79,10 +79,10 @@ const clock_enet_pll_config_t ethPllConfig = { #else .enableClkOutput25M = false, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(enet), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(enet)) .loopDivider = 1, #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(enet2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(enet2)) .loopDivider1 = 1, #endif }; @@ -226,7 +226,7 @@ static ALWAYS_INLINE void clock_init(void) #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(enet), okay) && CONFIG_NET_L2_ETHERNET +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(enet)) && CONFIG_NET_L2_ETHERNET #if CONFIG_ETH_MCUX_RMII_EXT_CLK /* Enable clock input for ENET1 */ IOMUXC_EnableMode(IOMUXC_GPR, kIOMUXC_GPR_ENET1TxClkOutputDir, false); @@ -236,43 +236,43 @@ static ALWAYS_INLINE void clock_init(void) #endif #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(enet2), okay) && CONFIG_NET_L2_ETHERNET +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(enet2)) && CONFIG_NET_L2_ETHERNET /* Set ENET2 ref clock to be generated by External OSC,*/ /* direction as output and frequency to 50MHz */ IOMUXC_EnableMode(IOMUXC_GPR, kIOMUXC_GPR_ENET2TxClkOutputDir | kIOMUXC_GPR_ENET2RefClkMode, true); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usb1), okay) && \ +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usb1)) && \ (CONFIG_USB_DC_NXP_EHCI || CONFIG_UDC_NXP_EHCI) CLOCK_EnableUsbhs0PhyPllClock(kCLOCK_Usb480M, DT_PROP_BY_PHANDLE(DT_NODELABEL(usb1), clocks, clock_frequency)); CLOCK_EnableUsbhs0Clock(kCLOCK_Usb480M, DT_PROP_BY_PHANDLE(DT_NODELABEL(usb1), clocks, clock_frequency)); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usb1), okay) && CONFIG_USB_DC_NXP_EHCI +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usb1)) && CONFIG_USB_DC_NXP_EHCI USB_EhciPhyInit(kUSB_ControllerEhci0, CPU_XTAL_CLK_HZ, &usbPhyConfig); #endif #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usb2), okay) && \ +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usb2)) && \ (CONFIG_USB_DC_NXP_EHCI || CONFIG_UDC_NXP_EHCI) CLOCK_EnableUsbhs1PhyPllClock(kCLOCK_Usb480M, DT_PROP_BY_PHANDLE(DT_NODELABEL(usb2), clocks, clock_frequency)); CLOCK_EnableUsbhs1Clock(kCLOCK_Usb480M, DT_PROP_BY_PHANDLE(DT_NODELABEL(usb2), clocks, clock_frequency)); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usb1), okay) && CONFIG_USB_DC_NXP_EHCI +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usb1)) && CONFIG_USB_DC_NXP_EHCI USB_EhciPhyInit(kUSB_ControllerEhci1, CPU_XTAL_CLK_HZ, &usbPhyConfig); #endif #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usdhc1), okay) && CONFIG_IMX_USDHC +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usdhc1)) && CONFIG_IMX_USDHC /* Configure USDHC clock source and divider */ CLOCK_InitSysPfd(kCLOCK_Pfd0, 24U); CLOCK_SetDiv(kCLOCK_Usdhc1Div, 1U); CLOCK_SetMux(kCLOCK_Usdhc1Mux, 1U); CLOCK_EnableClock(kCLOCK_Usdhc1); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usdhc2), okay) && CONFIG_IMX_USDHC +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usdhc2)) && CONFIG_IMX_USDHC /* Configure USDHC clock source and divider */ CLOCK_InitSysPfd(kCLOCK_Pfd0, 24U); CLOCK_SetDiv(kCLOCK_Usdhc2Div, 1U); @@ -332,25 +332,29 @@ void imxrt_audio_codec_pll_init(uint32_t clock_name, uint32_t clk_src, } #endif +extern void rt10xx_power_init(void); +extern void imxrt_lpm_init(void); + /** * * @brief Perform basic hardware initialization * * Initialize the interrupt controller device drivers. * Also initialize the timer device driver, if required. - * - * @return 0 */ - -static int imxrt_init(void) +void soc_early_init_hook(void) { sys_cache_instr_enable(); sys_cache_data_enable(); /* Initialize system clock */ clock_init(); - - return 0; +#ifdef CONFIG_PM +#ifdef CONFIG_SOC_MIMXRT1064 + imxrt_lpm_init(); +#endif + rt10xx_power_init(); +#endif } #ifdef CONFIG_SOC_RESET_HOOK @@ -365,5 +369,3 @@ void soc_reset_hook(void) #endif } #endif - -SYS_INIT(imxrt_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/imxrt/imxrt118x/Kconfig b/soc/nxp/imxrt/imxrt118x/Kconfig index 10c8180c3000..8dc3afe19f99 100644 --- a/soc/nxp/imxrt/imxrt118x/Kconfig +++ b/soc/nxp/imxrt/imxrt118x/Kconfig @@ -21,6 +21,7 @@ config SOC_SERIES_IMXRT118X select HAS_MCUX_IOMUXC select HAS_SWO select HAS_MCUX_FLEXSPI + select SOC_EARLY_INIT_HOOK config SOC_MIMXRT1189_CM33 select CPU_CORTEX_M33 diff --git a/soc/nxp/imxrt/imxrt118x/soc.c b/soc/nxp/imxrt/imxrt118x/soc.c index 2576c858b9ed..1809d6b4b029 100644 --- a/soc/nxp/imxrt/imxrt118x/soc.c +++ b/soc/nxp/imxrt/imxrt118x/soc.c @@ -208,16 +208,16 @@ static ALWAYS_INLINE void clock_init(void) #endif #if defined(CONFIG_UART_MCUX_LPUART) && \ - (DT_NODE_HAS_STATUS(DT_NODELABEL(lpuart1), okay) \ - || DT_NODE_HAS_STATUS(DT_NODELABEL(lpuart2), okay)) + (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpuart1)) \ + || DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpuart2))) /* Configure LPUART0102 using SYS_PLL3_DIV2_CLK */ rootCfg.mux = kCLOCK_LPUART0102_ClockRoot_MuxSysPll3Div2; rootCfg.div = 10; #endif #if defined(CONFIG_I2C_MCUX_LPI2C) && \ - (DT_NODE_HAS_STATUS(DT_NODELABEL(lpi2c1), okay) \ - || DT_NODE_HAS_STATUS(DT_NODELABEL(lpi2c2), okay)) + (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpi2c1)) \ + || DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpi2c2))) /* Configure LPI2C0102 using SYS_PLL3_DIV2_CLK */ rootCfg.mux = kCLOCK_LPI2C0102_ClockRoot_MuxSysPll3Div2; rootCfg.div = 4; @@ -225,8 +225,8 @@ static ALWAYS_INLINE void clock_init(void) #endif #if defined(CONFIG_I2C_MCUX_LPI2C) && \ - (DT_NODE_HAS_STATUS(DT_NODELABEL(lpi2c3), okay) \ - || DT_NODE_HAS_STATUS(DT_NODELABEL(lpi2c4), okay)) + (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpi2c3)) \ + || DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpi2c4))) /* Configure LPI2C0304 using SYS_PLL3_DIV2_CLK */ rootCfg.mux = kCLOCK_LPI2C0304_ClockRoot_MuxSysPll3Div2; rootCfg.div = 4; @@ -234,8 +234,8 @@ static ALWAYS_INLINE void clock_init(void) #endif #if defined(CONFIG_I2C_MCUX_LPI2C) && \ - (DT_NODE_HAS_STATUS(DT_NODELABEL(lpi2c5), okay) \ - || DT_NODE_HAS_STATUS(DT_NODELABEL(lpi2c6), okay)) + (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpi2c5)) \ + || DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpi2c6))) /* Configure LPI2C0506 using SYS_PLL3_DIV2_CLK */ rootCfg.mux = kCLOCK_LPI2C0506_ClockRoot_MuxSysPll3Div2; rootCfg.div = 4; @@ -243,8 +243,8 @@ static ALWAYS_INLINE void clock_init(void) #endif #if defined(CONFIG_SPI_MCUX_LPSPI) && \ - (DT_NODE_HAS_STATUS(DT_NODELABEL(lpspi1), okay) \ - || DT_NODE_HAS_STATUS(DT_NODELABEL(lpspi2), okay)) + (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpspi1)) \ + || DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpspi2))) /* Configure LPSPI0102 using SYS_PLL3_PFD1_CLK */ rootCfg.mux = kCLOCK_LPSPI0102_ClockRoot_MuxSysPll3Pfd1; rootCfg.div = 2; @@ -253,28 +253,28 @@ static ALWAYS_INLINE void clock_init(void) #if defined(CONFIG_COUNTER_MCUX_GPT) -#if (DT_NODE_HAS_STATUS(DT_NODELABEL(gpt1), okay)) +#if (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpt1))) /* Configure GPT1 using SYS_PLL3_DIV2_CLK */ rootCfg.mux = kCLOCK_GPT1_ClockRoot_MuxSysPll3Div2; rootCfg.div = 1; CLOCK_SetRootClock(kCLOCK_Root_Gpt1, &rootCfg); -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpt1), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpt1)) */ -#if (DT_NODE_HAS_STATUS(DT_NODELABEL(gpt2), okay)) +#if (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpt2))) /* Configure GPT2 using SYS_PLL3_DIV2_CLK */ rootCfg.mux = kCLOCK_GPT2_ClockRoot_MuxSysPll3Div2; rootCfg.div = 1; CLOCK_SetRootClock(kCLOCK_Root_Gpt2, &rootCfg); -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpt2), okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gpt2)) */ #endif /* CONFIG_COUNTER_MCUX_GPT */ #ifdef CONFIG_MCUX_ACMP -#if (DT_NODE_HAS_STATUS(DT_NODELABEL(acmp1), okay) \ - || DT_NODE_HAS_STATUS(DT_NODELABEL(acmp2), okay) \ - || DT_NODE_HAS_STATUS(DT_NODELABEL(acmp3), okay) \ - || DT_NODE_HAS_STATUS(DT_NODELABEL(acmp4), okay)) +#if (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(acmp1)) \ + || DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(acmp2)) \ + || DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(acmp3)) \ + || DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(acmp4))) /* Configure ACMP using MuxSysPll3Out */ rootCfg.mux = kCLOCK_ACMP_ClockRoot_MuxSysPll3Out; rootCfg.div = 2; @@ -394,7 +394,7 @@ static ALWAYS_INLINE void trdc_enable_all_access(void) * @return 0 */ -static int imxrt_init(void) +void soc_early_init_hook(void) { /* Initialize system clock */ clock_init(); @@ -409,8 +409,6 @@ static int imxrt_init(void) #endif __ISB(); __DSB(); - - return 0; } #ifdef CONFIG_SOC_RESET_HOOK @@ -419,5 +417,3 @@ void soc_reset_hook(void) SystemInit(); } #endif - -SYS_INIT(imxrt_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/imxrt/imxrt11xx/soc.c b/soc/nxp/imxrt/imxrt11xx/soc.c index 7648052177be..10ae6866d136 100644 --- a/soc/nxp/imxrt/imxrt11xx/soc.c +++ b/soc/nxp/imxrt/imxrt11xx/soc.c @@ -409,7 +409,7 @@ static ALWAYS_INLINE void clock_init(void) #endif #if CONFIG_ETH_MCUX || CONFIG_ETH_NXP_ENET -#if DT_NODE_HAS_STATUS(DT_NODELABEL(enet), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(enet)) /* 50 MHz ENET clock */ rootCfg.mux = kCLOCK_ENET1_ClockRoot_MuxSysPll1Div2; rootCfg.div = 10; @@ -424,7 +424,7 @@ static ALWAYS_INLINE void clock_init(void) (IOMUXC_GPR_GPR4_ENET_REF_CLK_DIR(0x01U) | IOMUXC_GPR_GPR4_ENET_TX_CLK_SEL(0x1U)); #endif #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(enet1g), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(enet1g)) rootCfg.mux = kCLOCK_ENET2_ClockRoot_MuxSysPll1Div2; #if DT_ENUM_HAS_VALUE(DT_CHILD(DT_NODELABEL(enet1g), ethernet), phy_connection_type, rgmii) /* 125 MHz ENET1G clock */ @@ -491,13 +491,13 @@ static ALWAYS_INLINE void clock_init(void) #endif #ifdef CONFIG_CAN_MCUX_FLEXCAN -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexcan1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcan1)) /* Configure CAN1 using Osc48MDiv2 */ rootCfg.mux = kCLOCK_CAN1_ClockRoot_MuxOscRc48MDiv2; rootCfg.div = 1; CLOCK_SetRootClock(kCLOCK_Root_Can1, &rootCfg); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexcan3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcan3)) /* Configure CAN1 using Osc48MDiv2 */ rootCfg.mux = kCLOCK_CAN3_ClockRoot_MuxOscRc48MDiv2; rootCfg.div = 1; @@ -506,7 +506,7 @@ static ALWAYS_INLINE void clock_init(void) #endif #ifdef CONFIG_MCUX_ACMP -#if DT_NODE_HAS_STATUS(DT_NODELABEL(acmp1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(acmp1)) /* Configure ACMP1 using Osc48MDiv2*/ rootCfg.mux = kCLOCK_ACMP_ClockRoot_MuxOscRc48MDiv2; rootCfg.div = 1; @@ -532,28 +532,28 @@ static ALWAYS_INLINE void clock_init(void) CLOCK_SetRootClock(kCLOCK_Root_Gpt1, &rootCfg); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usb1), okay) && (CONFIG_USB_DC_NXP_EHCI || CONFIG_UDC_NXP_EHCI) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usb1)) && (CONFIG_USB_DC_NXP_EHCI || CONFIG_UDC_NXP_EHCI) CLOCK_EnableUsbhs0PhyPllClock( kCLOCK_Usb480M, DT_PROP_BY_PHANDLE(DT_NODELABEL(usb1), clocks, clock_frequency)); CLOCK_EnableUsbhs0Clock(kCLOCK_Usb480M, DT_PROP_BY_PHANDLE(DT_NODELABEL(usb1), clocks, clock_frequency)); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usb1), okay) && CONFIG_USB_DC_NXP_EHCI +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usb1)) && CONFIG_USB_DC_NXP_EHCI USB_EhciPhyInit(kUSB_ControllerEhci0, CPU_XTAL_CLK_HZ, &usbPhyConfig); #endif #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usb2), okay) && (CONFIG_USB_DC_NXP_EHCI || CONFIG_UDC_NXP_EHCI) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usb2)) && (CONFIG_USB_DC_NXP_EHCI || CONFIG_UDC_NXP_EHCI) CLOCK_EnableUsbhs1PhyPllClock( kCLOCK_Usb480M, DT_PROP_BY_PHANDLE(DT_NODELABEL(usb2), clocks, clock_frequency)); CLOCK_EnableUsbhs1Clock(kCLOCK_Usb480M, DT_PROP_BY_PHANDLE(DT_NODELABEL(usb2), clocks, clock_frequency)); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usb1), okay) && CONFIG_USB_DC_NXP_EHCI +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usb1)) && CONFIG_USB_DC_NXP_EHCI USB_EhciPhyInit(kUSB_ControllerEhci1, CPU_XTAL_CLK_HZ, &usbPhyConfig); #endif #endif #if CONFIG_IMX_USDHC -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usdhc1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usdhc1)) /* Configure USDHC1 using SysPll2Pfd2*/ rootCfg.mux = kCLOCK_USDHC1_ClockRoot_MuxSysPll2Pfd2; rootCfg.div = 2; @@ -561,7 +561,7 @@ static ALWAYS_INLINE void clock_init(void) CLOCK_EnableClock(kCLOCK_Usdhc1); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usdhc2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usdhc2)) /* Configure USDHC2 using SysPll2Pfd2*/ rootCfg.mux = kCLOCK_USDHC2_ClockRoot_MuxSysPll2Pfd2; rootCfg.div = 2; @@ -571,7 +571,7 @@ static ALWAYS_INLINE void clock_init(void) #endif #if !(DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_flash), nxp_imx_flexspi)) && \ - defined(CONFIG_MEMC_MCUX_FLEXSPI) && DT_NODE_HAS_STATUS(DT_NODELABEL(flexspi), okay) + defined(CONFIG_MEMC_MCUX_FLEXSPI) && DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexspi)) /* Configure FLEXSPI1 using OSC_RC_48M_DIV2 */ rootCfg.mux = kCLOCK_FLEXSPI1_ClockRoot_MuxOscRc48MDiv2; rootCfg.div = 1; diff --git a/soc/nxp/imxrt/imxrt5xx/Kconfig b/soc/nxp/imxrt/imxrt5xx/Kconfig index dcaf50b03b17..81ccd78df6ef 100644 --- a/soc/nxp/imxrt/imxrt5xx/Kconfig +++ b/soc/nxp/imxrt/imxrt5xx/Kconfig @@ -31,6 +31,7 @@ config SOC_MIMXRT595S_CM33 select HAS_MCUX_USDHC2 select HAS_MCUX_USB_LPCIP3511 select HAS_MCUX_CTIMER + select SOC_EARLY_INIT_HOOK config SOC_MIMXRT595S_F1 select XTENSA diff --git a/soc/nxp/imxrt/imxrt5xx/cm33/power.c b/soc/nxp/imxrt/imxrt5xx/cm33/power.c index 3599dcfa646c..30911cbb22db 100644 --- a/soc/nxp/imxrt/imxrt5xx/cm33/power.c +++ b/soc/nxp/imxrt/imxrt5xx/cm33/power.c @@ -61,10 +61,8 @@ void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id) } /* Initialize power system */ -static int rt5xx_power_init(void) +void rt5xx_power_init(void) { - int ret = 0; - /* This function is called to set vddcore low voltage detection * falling trip voltage, this is not impacting the voltage in anyway. */ @@ -75,7 +73,4 @@ static int rt5xx_power_init(void) POWER_UpdatePmicRecoveryTime(1); #endif - return ret; } - -SYS_INIT(rt5xx_power_init, PRE_KERNEL_2, 0); diff --git a/soc/nxp/imxrt/imxrt5xx/cm33/soc.c b/soc/nxp/imxrt/imxrt5xx/cm33/soc.c index c10b404ed486..5d99d069da92 100644 --- a/soc/nxp/imxrt/imxrt5xx/cm33/soc.c +++ b/soc/nxp/imxrt/imxrt5xx/cm33/soc.c @@ -351,7 +351,7 @@ void __weak rt5xx_clock_init(void) /* Switch CLKOUT to FRO_DIV2 */ CLOCK_AttachClk(kFRO_DIV2_to_CLKOUT); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usdhc0), okay) && CONFIG_IMX_USDHC +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usdhc0)) && CONFIG_IMX_USDHC /* Make sure USDHC ram buffer has been power up*/ POWER_DisablePD(kPDRUNCFG_APD_USDHC0_SRAM); POWER_DisablePD(kPDRUNCFG_PPD_USDHC0_SRAM); @@ -366,7 +366,7 @@ void __weak rt5xx_clock_init(void) RESET_PeripheralReset(kSDIO0_RST_SHIFT_RSTn); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(smartdma), okay) && CONFIG_DMA_MCUX_SMARTDMA +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(smartdma)) && CONFIG_DMA_MCUX_SMARTDMA /* Power up SMARTDMA ram */ POWER_DisablePD(kPDRUNCFG_APD_SMARTDMA_SRAM); POWER_DisablePD(kPDRUNCFG_PPD_SMARTDMA_SRAM); @@ -511,16 +511,16 @@ void __weak imxrt_deinit_display_interface(void) #endif +extern void rt5xx_power_init(void); + /** * * @brief Perform basic hardware initialization * * Initialize the interrupt controller device drivers. * Also initialize the timer device driver, if required. - * - * @return 0 */ -static int nxp_rt500_init(void) +void soc_early_init_hook(void) { /* Initialize clocks with tool generated code */ rt5xx_clock_init(); @@ -536,8 +536,8 @@ static int nxp_rt500_init(void) IOPCTL->PIO[1][15] = 0; IOPCTL->PIO[3][28] = 0; IOPCTL->PIO[3][29] = 0; +#ifdef CONFIG_PM + rt5xx_power_init(); +#endif - return 0; } - -SYS_INIT(nxp_rt500_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/imxrt/imxrt6xx/Kconfig b/soc/nxp/imxrt/imxrt6xx/Kconfig index b68855292e3e..831b8b1b1abd 100644 --- a/soc/nxp/imxrt/imxrt6xx/Kconfig +++ b/soc/nxp/imxrt/imxrt6xx/Kconfig @@ -30,6 +30,7 @@ config SOC_MIMXRT685S_CM33 select INIT_SYS_PLL select HAS_MCUX_USB_LPCIP3511 select HAS_MCUX_CTIMER + select SOC_EARLY_INIT_HOOK if SOC_SERIES_IMXRT6XX diff --git a/soc/nxp/imxrt/imxrt6xx/cm33/soc.c b/soc/nxp/imxrt/imxrt6xx/cm33/soc.c index d829558754e6..a81c8bc201ae 100644 --- a/soc/nxp/imxrt/imxrt6xx/cm33/soc.c +++ b/soc/nxp/imxrt/imxrt6xx/cm33/soc.c @@ -286,7 +286,7 @@ static ALWAYS_INLINE void clock_init(void) CLOCK_AttachClk(kNONE_to_WDT0_CLK); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usdhc0), okay) && CONFIG_IMX_USDHC +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usdhc0)) && CONFIG_IMX_USDHC /* Make sure USDHC ram buffer has been power up*/ POWER_DisablePD(kPDRUNCFG_APD_USDHC0_SRAM); POWER_DisablePD(kPDRUNCFG_PPD_USDHC0_SRAM); @@ -343,7 +343,7 @@ static ALWAYS_INLINE void clock_init(void) #endif /* CONFIG_SOC_MIMXRT685S_CM33 */ } -#if (DT_NODE_HAS_STATUS(DT_NODELABEL(usdhc0), okay) && CONFIG_IMX_USDHC) +#if (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usdhc0)) && CONFIG_IMX_USDHC) void imxrt_usdhc_pinmux(uint16_t nusdhc, bool init, uint32_t speed, uint32_t strength) { @@ -360,11 +360,9 @@ void imxrt_usdhc_dat3_pull(bool pullup) * * Initialize the interrupt controller device drivers. * Also initialize the timer device driver, if required. - * - * @return 0 */ -static int nxp_rt600_init(void) +void soc_early_init_hook(void) { /* Initialize clock */ clock_init(); @@ -372,8 +370,6 @@ static int nxp_rt600_init(void) #ifndef CONFIG_IMXRT6XX_CODE_CACHE CACHE64_DisableCache(CACHE64); #endif - - return 0; } #ifdef CONFIG_SOC_RESET_HOOK @@ -400,5 +396,3 @@ void soc_reset_hook(void) } #endif - -SYS_INIT(nxp_rt600_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/imxrt/imxrt6xx/cm33/soc.h b/soc/nxp/imxrt/imxrt6xx/cm33/soc.h index 356b0e5727c7..71e5d69544e2 100644 --- a/soc/nxp/imxrt/imxrt6xx/cm33/soc.h +++ b/soc/nxp/imxrt/imxrt6xx/cm33/soc.h @@ -85,8 +85,8 @@ extern "C" { #endif #if CONFIG_IMX_USDHC && \ - (DT_NODE_HAS_STATUS(DT_NODELABEL(usdhc0), okay) || \ - DT_NODE_HAS_STATUS(DT_NODELABEL(usdhc1), okay)) + (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usdhc0)) || \ + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usdhc1))) void imxrt_usdhc_pinmux(uint16_t nusdhc, bool init, uint32_t speed, uint32_t strength); diff --git a/soc/nxp/kinetis/k2x/Kconfig b/soc/nxp/kinetis/k2x/Kconfig index cf61f57132b9..f89d6c86b4cf 100644 --- a/soc/nxp/kinetis/k2x/Kconfig +++ b/soc/nxp/kinetis/k2x/Kconfig @@ -14,6 +14,7 @@ config SOC_SERIES_KINETIS_K2X select CPU_CORTEX_M_HAS_DWT select CLOCK_CONTROL select SOC_RESET_HOOK + select SOC_EARLY_INIT_HOOK config SOC_MK22F51212 select HAS_MCUX diff --git a/soc/nxp/kinetis/k2x/soc.c b/soc/nxp/kinetis/k2x/soc.c index 82aecf9b687b..e89526f55568 100644 --- a/soc/nxp/kinetis/k2x/soc.c +++ b/soc/nxp/kinetis/k2x/soc.c @@ -118,15 +118,13 @@ static ALWAYS_INLINE void clock_init(void) * @return 0 */ -static int fsl_frdm_k22f_init(void) +void soc_early_init_hook(void) { /* release I/O power hold to allow normal run state */ PMC->REGSC |= PMC_REGSC_ACKISO_MASK; /* Initialize PLL/system clock to 120 MHz */ clock_init(); - - return 0; } #ifdef CONFIG_SOC_RESET_HOOK @@ -137,5 +135,3 @@ void soc_reset_hook(void) } #endif /* CONFIG_SOC_RESET_HOOK */ - -SYS_INIT(fsl_frdm_k22f_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/kinetis/k6x/Kconfig b/soc/nxp/kinetis/k6x/Kconfig index 5ec9c9acf21c..af342ae30caf 100644 --- a/soc/nxp/kinetis/k6x/Kconfig +++ b/soc/nxp/kinetis/k6x/Kconfig @@ -11,6 +11,7 @@ config SOC_SERIES_KINETIS_K6X select HAS_MCUX_PIT select CLOCK_CONTROL select SOC_RESET_HOOK + select SOC_EARLY_INIT_HOOK config SOC_MK64F12 select HAS_MCUX diff --git a/soc/nxp/kinetis/k6x/soc.c b/soc/nxp/kinetis/k6x/soc.c index 41708af79548..32832dc8a0a2 100644 --- a/soc/nxp/kinetis/k6x/soc.c +++ b/soc/nxp/kinetis/k6x/soc.c @@ -101,7 +101,7 @@ static ALWAYS_INLINE void clock_init(void) CLOCK_SetSimConfig(&simConfig); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpuart0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpuart0)) CLOCK_SetLpuartClock(LPUART0SRC_OSCERCLK); #endif @@ -124,10 +124,9 @@ static ALWAYS_INLINE void clock_init(void) * Initialize the interrupt controller device drivers. * Also initialize the timer device driver, if required. * - * @return 0 */ -static int k6x_init(void) +void soc_early_init_hook(void) { #if !defined(CONFIG_ARM_MPU) uint32_t temp_reg; @@ -162,8 +161,6 @@ static int k6x_init(void) #endif /* Initialize PLL/system clock up to 180 MHz */ clock_init(); - - return 0; } #ifdef CONFIG_SOC_RESET_HOOK @@ -174,5 +171,3 @@ void soc_reset_hook(void) } #endif /* CONFIG_SOC_RESET_HOOK */ - -SYS_INIT(k6x_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/kinetis/k8x/Kconfig b/soc/nxp/kinetis/k8x/Kconfig index 649300c3dbad..bf30d20797e9 100644 --- a/soc/nxp/kinetis/k8x/Kconfig +++ b/soc/nxp/kinetis/k8x/Kconfig @@ -27,6 +27,7 @@ config SOC_SERIES_KINETIS_K8X select HAS_MCUX_RCM select HAS_MCUX_CACHE select SOC_RESET_HOOK + select SOC_EARLY_INIT_HOOK if SOC_SERIES_KINETIS_K8X diff --git a/soc/nxp/kinetis/k8x/soc.c b/soc/nxp/kinetis/k8x/soc.c index 19d6f2df3412..d338ad72a967 100644 --- a/soc/nxp/kinetis/k8x/soc.c +++ b/soc/nxp/kinetis/k8x/soc.c @@ -92,7 +92,7 @@ static ALWAYS_INLINE void clk_init(void) #endif } -static int k8x_init(void) +void soc_early_init_hook(void) { #if !defined(CONFIG_ARM_MPU) uint32_t temp_reg; @@ -116,8 +116,6 @@ static int k8x_init(void) /* Initialize system clocks and PLL */ clk_init(); - - return 0; } #ifdef CONFIG_SOC_RESET_HOOK @@ -128,5 +126,3 @@ void soc_reset_hook(void) } #endif /* CONFIG_SOC_RESET_HOOK */ - -SYS_INIT(k8x_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/kinetis/ke1xf/Kconfig b/soc/nxp/kinetis/ke1xf/Kconfig index a89888edaadb..b3cf86dd9356 100644 --- a/soc/nxp/kinetis/ke1xf/Kconfig +++ b/soc/nxp/kinetis/ke1xf/Kconfig @@ -30,6 +30,7 @@ config SOC_SERIES_KINETIS_KE1XF select HAS_MCUX_PWT select HAS_MCUX_RCM select SOC_RESET_HOOK + select SOC_EARLY_INIT_HOOK select HAS_PM config SOC_MKE16F16 diff --git a/soc/nxp/kinetis/ke1xf/soc.c b/soc/nxp/kinetis/ke1xf/soc.c index 7ada4249dfa4..35968f6acf0f 100644 --- a/soc/nxp/kinetis/ke1xf/soc.c +++ b/soc/nxp/kinetis/ke1xf/soc.c @@ -61,7 +61,7 @@ static const scg_sys_clk_config_t scg_sys_clk_config = { #endif }; -#if DT_NODE_HAS_STATUS(SCG_CLOCK_NODE(sosc_clk), okay) +#if DT_NODE_HAS_STATUS_OKAY(SCG_CLOCK_NODE(sosc_clk)) /* System Oscillator (SOSC) configuration */ ASSERT_ASYNC_CLK_DIV_VALID(SCG_CLOCK_DIV(soscdiv1_clk), "Invalid SCG SOSC divider 1 value"); @@ -155,7 +155,7 @@ static ALWAYS_INLINE void clk_init(void) }; scg_sys_clk_config_t current; -#if DT_NODE_HAS_STATUS(SCG_CLOCK_NODE(sosc_clk), okay) +#if DT_NODE_HAS_STATUS_OKAY(SCG_CLOCK_NODE(sosc_clk)) /* Optionally initialize system oscillator */ CLOCK_InitSysOsc(&scg_sosc_config); CLOCK_SetXtal0Freq(scg_sosc_config.freq); @@ -179,65 +179,65 @@ static ALWAYS_INLINE void clk_init(void) CLOCK_GetCurSysClkConfig(¤t); } while (current.src != scg_sys_clk_config.src); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpuart0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpuart0)) CLOCK_SetIpSrc(kCLOCK_Lpuart0, DT_CLOCKS_CELL(DT_NODELABEL(lpuart0), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpuart1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpuart1)) CLOCK_SetIpSrc(kCLOCK_Lpuart1, DT_CLOCKS_CELL(DT_NODELABEL(lpuart1), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpuart2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpuart2)) CLOCK_SetIpSrc(kCLOCK_Lpuart2, DT_CLOCKS_CELL(DT_NODELABEL(lpuart2), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpi2c0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpi2c0)) CLOCK_SetIpSrc(kCLOCK_Lpi2c0, DT_CLOCKS_CELL(DT_NODELABEL(lpi2c0), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpi2c1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpi2c1)) CLOCK_SetIpSrc(kCLOCK_Lpi2c1, DT_CLOCKS_CELL(DT_NODELABEL(lpi2c1), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpspi0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpspi0)) CLOCK_SetIpSrc(kCLOCK_Lpspi0, DT_CLOCKS_CELL(DT_NODELABEL(lpspi0), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpspi1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpspi1)) CLOCK_SetIpSrc(kCLOCK_Lpspi1, DT_CLOCKS_CELL(DT_NODELABEL(lpspi1), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(adc0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(adc0)) CLOCK_SetIpSrc(kCLOCK_Adc0, DT_CLOCKS_CELL(DT_NODELABEL(adc0), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(adc1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(adc1)) CLOCK_SetIpSrc(kCLOCK_Adc1, DT_CLOCKS_CELL(DT_NODELABEL(adc1), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(adc2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(adc2)) CLOCK_SetIpSrc(kCLOCK_Adc2, DT_CLOCKS_CELL(DT_NODELABEL(adc2), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ftm0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ftm0)) CLOCK_SetIpSrc(kCLOCK_Ftm0, DT_CLOCKS_CELL(DT_NODELABEL(ftm0), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ftm1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ftm1)) CLOCK_SetIpSrc(kCLOCK_Ftm1, DT_CLOCKS_CELL(DT_NODELABEL(ftm1), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ftm2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ftm2)) CLOCK_SetIpSrc(kCLOCK_Ftm2, DT_CLOCKS_CELL(DT_NODELABEL(ftm2), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(ftm3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ftm3)) CLOCK_SetIpSrc(kCLOCK_Ftm3, DT_CLOCKS_CELL(DT_NODELABEL(ftm3), ip_source)); #endif } -static int ke1xf_init(void) +void soc_early_init_hook(void) { #if !defined(CONFIG_ARM_MPU) @@ -264,8 +264,6 @@ static int ke1xf_init(void) /* SystemInit will have enabled the code cache. Disable it here */ L1CACHE_DisableCodeCache(); #endif - - return 0; } #ifdef CONFIG_SOC_RESET_HOOK @@ -314,5 +312,3 @@ void soc_reset_hook(void) } #endif /* CONFIG_SOC_RESET_HOOK */ - -SYS_INIT(ke1xf_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/kinetis/ke1xz/Kconfig b/soc/nxp/kinetis/ke1xz/Kconfig index 2563a2200411..f8e878cb13ae 100644 --- a/soc/nxp/kinetis/ke1xz/Kconfig +++ b/soc/nxp/kinetis/ke1xz/Kconfig @@ -13,3 +13,4 @@ config SOC_SERIES_KE1XZ select HAS_MCUX select HAS_PM select SOC_RESET_HOOK + select SOC_EARLY_INIT_HOOK diff --git a/soc/nxp/kinetis/ke1xz/soc.c b/soc/nxp/kinetis/ke1xz/soc.c index 38521bccc85a..0f8ad0de6aca 100644 --- a/soc/nxp/kinetis/ke1xz/soc.c +++ b/soc/nxp/kinetis/ke1xz/soc.c @@ -106,51 +106,49 @@ static ALWAYS_INLINE void clk_init(void) CLOCK_GetCurSysClkConfig(¤t); } while (current.src != scg_sys_clk_config.src); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpuart0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpuart0)) CLOCK_SetIpSrc(kCLOCK_Lpuart0, DT_CLOCKS_CELL(DT_NODELABEL(lpuart0), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpuart1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpuart1)) CLOCK_SetIpSrc(kCLOCK_Lpuart1, DT_CLOCKS_CELL(DT_NODELABEL(lpuart1), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpuart2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpuart2)) CLOCK_SetIpSrc(kCLOCK_Lpuart2, DT_CLOCKS_CELL(DT_NODELABEL(lpuart2), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpi2c0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpi2c0)) CLOCK_SetIpSrc(kCLOCK_Lpi2c0, DT_CLOCKS_CELL(DT_NODELABEL(lpi2c0), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpi2c1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpi2c1)) CLOCK_SetIpSrc(kCLOCK_Lpi2c1, DT_CLOCKS_CELL(DT_NODELABEL(lpi2c1), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(flexio), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexio)) CLOCK_SetIpSrc(kCLOCK_Flexio0, DT_CLOCKS_CELL(DT_NODELABEL(flexio), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpspi0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpspi0)) CLOCK_SetIpSrc(kCLOCK_Lpspi0, DT_CLOCKS_CELL(DT_NODELABEL(lpspi0), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpspi1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpspi1)) CLOCK_SetIpSrc(kCLOCK_Lpspi1, DT_CLOCKS_CELL(DT_NODELABEL(lpspi1), ip_source)); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(adc0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(adc0)) CLOCK_SetIpSrc(kCLOCK_Adc0, DT_CLOCKS_CELL(DT_NODELABEL(adc0), ip_source)); #endif } -static int ke1xz_init(void) +void soc_early_init_hook(void) { /* Initialize system clocks and PLL */ clk_init(); - - return 0; } #ifdef CONFIG_SOC_RESET_HOOK @@ -162,5 +160,3 @@ void soc_reset_hook(void) } #endif /* CONFIG_SOC_RESET_HOOK */ - -SYS_INIT(ke1xz_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/kinetis/kl2x/Kconfig b/soc/nxp/kinetis/kl2x/Kconfig index c2e5255e00a0..e545c2a68002 100644 --- a/soc/nxp/kinetis/kl2x/Kconfig +++ b/soc/nxp/kinetis/kl2x/Kconfig @@ -10,6 +10,7 @@ config SOC_SERIES_KINETIS_KL2X select CPU_CORTEX_M_HAS_VTOR select CLOCK_CONTROL select SOC_RESET_HOOK + select SOC_EARLY_INIT_HOOK config SOC_MKL25Z4 select CPU_CORTEX_M0PLUS diff --git a/soc/nxp/kinetis/kl2x/soc.c b/soc/nxp/kinetis/kl2x/soc.c index 9a525b2632c1..8ab125d4c7ce 100644 --- a/soc/nxp/kinetis/kl2x/soc.c +++ b/soc/nxp/kinetis/kl2x/soc.c @@ -70,7 +70,7 @@ static ALWAYS_INLINE void clock_init(void) CLOCK_SetInternalRefClkConfig(kMCG_IrclkEnable, kMCG_IrcSlow, 0); CLOCK_SetSimConfig(&simConfig); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(uart0)) CLOCK_SetLpsci0Clock(LPSCI0SRC_MCGFLLCLK); #endif #if CONFIG_USB_KINETIS || CONFIG_UDC_KINETIS @@ -79,12 +79,10 @@ static ALWAYS_INLINE void clock_init(void) #endif } -static int kl2x_init(void) +void soc_early_init_hook(void) { /* Initialize system clock to 48 MHz */ clock_init(); - - return 0; } #ifdef CONFIG_SOC_RESET_HOOK @@ -95,5 +93,3 @@ void soc_reset_hook(void) } #endif /* CONFIG_SOC_RESET_HOOK */ - -SYS_INIT(kl2x_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/kinetis/kv5x/Kconfig b/soc/nxp/kinetis/kv5x/Kconfig index 6c9cd6f34ef3..d4d977ce2126 100644 --- a/soc/nxp/kinetis/kv5x/Kconfig +++ b/soc/nxp/kinetis/kv5x/Kconfig @@ -22,3 +22,4 @@ config SOC_SERIES_KINETIS_KV5X select HAS_MCG select HAS_MCUX_RCM select SOC_RESET_HOOK + select SOC_EARLY_INIT_HOOK diff --git a/soc/nxp/kinetis/kv5x/soc.c b/soc/nxp/kinetis/kv5x/soc.c index 91c4823e4e22..cd5d4048c42c 100644 --- a/soc/nxp/kinetis/kv5x/soc.c +++ b/soc/nxp/kinetis/kv5x/soc.c @@ -78,7 +78,7 @@ static ALWAYS_INLINE void clk_init(void) CLOCK_SetSimConfig(&sim_config); } -static int kv5x_init(void) +void soc_early_init_hook(void) { /* release I/O power hold to allow normal run state */ PMC->REGSC |= PMC_REGSC_ACKISO_MASK; @@ -93,8 +93,6 @@ static int kv5x_init(void) sys_cache_instr_enable(); sys_cache_data_enable(); - - return 0; } #ifdef CONFIG_SOC_RESET_HOOK @@ -105,5 +103,3 @@ void soc_reset_hook(void) } #endif /* CONFIG_SOC_RESET_HOOK */ - -SYS_INIT(kv5x_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/kinetis/kwx/Kconfig b/soc/nxp/kinetis/kwx/Kconfig index 49a9f78c04bd..150de248d4e5 100644 --- a/soc/nxp/kinetis/kwx/Kconfig +++ b/soc/nxp/kinetis/kwx/Kconfig @@ -9,6 +9,7 @@ config SOC_SERIES_KINETIS_KWX select CPU_CORTEX_M_HAS_VTOR select CLOCK_CONTROL select SOC_RESET_HOOK + select SOC_EARLY_INIT_HOOK config SOC_MKW22D5 select CPU_CORTEX_M4 diff --git a/soc/nxp/kinetis/kwx/soc_kw2xd.c b/soc/nxp/kinetis/kwx/soc_kw2xd.c index 95e5a955acc4..c2fcddfa6ed0 100644 --- a/soc/nxp/kinetis/kwx/soc_kw2xd.c +++ b/soc/nxp/kinetis/kwx/soc_kw2xd.c @@ -147,15 +147,13 @@ static ALWAYS_INLINE void clock_init(void) * * @return 0 */ -static int kw2xd_init(void) +void soc_early_init_hook(void) { /* release I/O power hold to allow normal run state */ PMC->REGSC |= PMC_REGSC_ACKISO_MASK; /* Initialize PLL/system clock to 48 MHz */ clock_init(); - - return 0; } #ifdef CONFIG_SOC_RESET_HOOK @@ -166,5 +164,3 @@ void soc_reset_hook(void) } #endif /* CONFIG_SOC_RESET_HOOK */ - -SYS_INIT(kw2xd_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/kinetis/kwx/soc_kw4xz.c b/soc/nxp/kinetis/kwx/soc_kw4xz.c index a14fe28c165c..f6baedb07b76 100644 --- a/soc/nxp/kinetis/kwx/soc_kw4xz.c +++ b/soc/nxp/kinetis/kwx/soc_kw4xz.c @@ -67,24 +67,22 @@ static ALWAYS_INLINE void clock_init(void) CLOCK_SetSimConfig(&simConfig); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpuart0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpuart0)) CLOCK_SetLpuartClock(LPUART0SRC_OSCERCLK); #endif #if defined(CONFIG_PWM) && \ - (DT_NODE_HAS_STATUS(DT_NODELABEL(pwm0), okay) || \ - DT_NODE_HAS_STATUS(DT_NODELABEL(pwm1), okay) || \ - DT_NODE_HAS_STATUS(DT_NODELABEL(pwm2), okay)) + (DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm0)) || \ + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm1)) || \ + DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pwm2))) CLOCK_SetTpmClock(TPMSRC_MCGPLLCLK); #endif } -static int kwx_init(void) +void soc_early_init_hook(void) { /* Initialize system clock to 40 MHz */ clock_init(); - - return 0; } #ifdef CONFIG_SOC_RESET_HOOK @@ -95,5 +93,3 @@ void soc_reset_hook(void) } #endif /* CONFIG_SOC_RESET_HOOK */ - -SYS_INIT(kwx_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/lpc/lpc51u68/Kconfig b/soc/nxp/lpc/lpc51u68/Kconfig index 8a2436d12374..37c8231d7f65 100644 --- a/soc/nxp/lpc/lpc51u68/Kconfig +++ b/soc/nxp/lpc/lpc51u68/Kconfig @@ -16,6 +16,7 @@ config SOC_SERIES_LPC51U68 select CPU_CORTEX_M_HAS_SYSTICK select CPU_CORTEX_M_HAS_VTOR select SOC_RESET_HOOK + select SOC_EARLY_INIT_HOOK config SOC_LPC51U68 select CLOCK_CONTROL diff --git a/soc/nxp/lpc/lpc51u68/soc.c b/soc/nxp/lpc/lpc51u68/soc.c index b38b601baaa2..fd8f23800b33 100644 --- a/soc/nxp/lpc/lpc51u68/soc.c +++ b/soc/nxp/lpc/lpc51u68/soc.c @@ -11,7 +11,7 @@ #include #include -int soc_init(void) +void soc_early_init_hook(void) { POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); CLOCK_SetupFROClocking(12000000U); @@ -42,17 +42,11 @@ int soc_init(void) POWER_DisablePD(kPDRUNCFG_PD_VD7_ENA); POWER_DisablePD(kPDRUNCFG_PD_VREFP_SW); POWER_DisablePD(kPDRUNCFG_PD_TEMPS); - - return 0; } #ifdef CONFIG_SOC_RESET_HOOK - void soc_reset_hook(void) { SystemInit(); } - #endif /* CONFIG_SOC_RESET_HOOK */ - -SYS_INIT(soc_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/lpc/lpc55xxx/soc.c b/soc/nxp/lpc/lpc55xxx/soc.c index 233ab0d9d82d..1959b525e92e 100644 --- a/soc/nxp/lpc/lpc55xxx/soc.c +++ b/soc/nxp/lpc/lpc55xxx/soc.c @@ -193,7 +193,7 @@ static ALWAYS_INLINE void clock_init(void) CLOCK_AttachClk(kFRO12M_to_FLEXCOMM4); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(hs_lspi), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(hs_lspi)) /* Attach 12 MHz clock to HSLSPI */ CLOCK_AttachClk(kFRO_HF_DIV_to_HSLSPI); #endif diff --git a/soc/nxp/mcx/mcxc/Kconfig b/soc/nxp/mcx/mcxc/Kconfig index 02ed4233bc07..ff49d66ae656 100644 --- a/soc/nxp/mcx/mcxc/Kconfig +++ b/soc/nxp/mcx/mcxc/Kconfig @@ -16,6 +16,7 @@ config SOC_SERIES_MCXC select HAS_MCUX_LPUART select HAS_MCUX_LPI2C select HAS_MCUX_TPM + select SOC_EARLY_INIT_HOOK if SOC_SERIES_MCXC diff --git a/soc/nxp/mcx/mcxc/soc.c b/soc/nxp/mcx/mcxc/soc.c index a6d0d8bd9fdd..01b42984b313 100644 --- a/soc/nxp/mcx/mcxc/soc.c +++ b/soc/nxp/mcx/mcxc/soc.c @@ -88,15 +88,14 @@ static void clock_init(void) /* Set SystemCoreClock variable. */ SystemCoreClock = DT_PROP(DT_NODELABEL(cpu0), clock_frequency); /* Set LPUART0 clock source. */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpuart0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpuart0)) CLOCK_SetLpuart0Clock(LPUART_CLOCK_SEL(lpuart0)); #endif } -static int mcxc_init(void) +void soc_early_init_hook(void) { clock_init(); - return 0; } #ifdef CONFIG_SOC_RESET_HOOK @@ -107,5 +106,3 @@ void soc_reset_hook(void) } #endif /* CONFIG_SOC_RESET_HOOK */ - -SYS_INIT(mcxc_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/rw/Kconfig b/soc/nxp/rw/Kconfig index e67d0013721b..272d7073bfa9 100644 --- a/soc/nxp/rw/Kconfig +++ b/soc/nxp/rw/Kconfig @@ -17,6 +17,7 @@ config SOC_SERIES_RW6XX select HAS_MCUX_FLEXCOMM select HAS_MCUX_CACHE select HAS_PM + select SOC_EARLY_INIT_HOOK if SOC_SERIES_RW6XX diff --git a/soc/nxp/rw/power.c b/soc/nxp/rw/power.c index 2979d48ff5b2..f4176b6349cf 100644 --- a/soc/nxp/rw/power.c +++ b/soc/nxp/rw/power.c @@ -28,11 +28,11 @@ LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL); power_sleep_config_t slp_cfg; -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pin0), okay) || DT_NODE_HAS_STATUS(DT_NODELABEL(pin1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pin0)) || DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pin1)) pinctrl_soc_pin_t pin_cfg; #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pin0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pin0)) static void pin0_isr(const struct device *dev) { uint8_t level = ~(DT_ENUM_IDX(DT_NODELABEL(pin0), wakeup_level)) & 0x1; @@ -44,7 +44,7 @@ static void pin0_isr(const struct device *dev) } #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pin1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pin1)) static void pin1_isr(const struct device *dev) { uint8_t level = ~(DT_ENUM_IDX(DT_NODELABEL(pin1), wakeup_level)) & 0x1; @@ -61,7 +61,7 @@ __weak void pm_state_set(enum pm_state state, uint8_t substate_id) { ARG_UNUSED(substate_id); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pin0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pin0)) pin_cfg = IOMUX_GPIO_IDX(24) | IOMUX_TYPE(IOMUX_GPIO); pinctrl_configure_pins(&pin_cfg, 1, 0); POWER_ConfigWakeupPin(kPOWER_WakeupPin0, DT_ENUM_IDX(DT_NODELABEL(pin0), wakeup_level)); @@ -70,7 +70,7 @@ __weak void pm_state_set(enum pm_state state, uint8_t substate_id) EnableIRQ(DT_IRQN(DT_NODELABEL(pin0))); POWER_EnableWakeup(DT_IRQN(DT_NODELABEL(pin0))); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pin1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pin1)) pin_cfg = IOMUX_GPIO_IDX(25) | IOMUX_TYPE(IOMUX_GPIO); pinctrl_configure_pins(&pin_cfg, 1, 0); POWER_ConfigWakeupPin(kPOWER_WakeupPin1, DT_ENUM_IDX(DT_NODELABEL(pin1), wakeup_level)); @@ -109,7 +109,7 @@ __weak void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id) __enable_irq(); } -static int nxp_rw6xx_power_init(void) +void nxp_rw6xx_power_init(void) { uint32_t suspend_sleepconfig[5] = DT_PROP_OR(NODE_ID, deep_sleep_config, {}); @@ -119,7 +119,7 @@ static int nxp_rw6xx_power_init(void) slp_cfg.memPdCfg = suspend_sleepconfig[3]; slp_cfg.pm3BuckCfg = suspend_sleepconfig[4]; -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pin0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pin0)) /* PIN 0 uses GPIO0_24, confiure the pin as GPIO */ pin_cfg = IOMUX_GPIO_IDX(24) | IOMUX_TYPE(IOMUX_GPIO); pinctrl_configure_pins(&pin_cfg, 1, 0); @@ -131,7 +131,7 @@ static int nxp_rw6xx_power_init(void) NULL, 0); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pin1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pin1)) /* PIN 1 uses GPIO0_25, confiure the pin as GPIO */ pin_cfg = IOMUX_GPIO_IDX(25) | IOMUX_TYPE(IOMUX_GPIO); pinctrl_configure_pins(&pin_cfg, 1, 0); @@ -142,8 +142,4 @@ static int nxp_rw6xx_power_init(void) IRQ_CONNECT(DT_IRQN(DT_NODELABEL(pin1)), DT_IRQ(DT_NODELABEL(pin1), priority), pin1_isr, NULL, 0); #endif - - return 0; } - -SYS_INIT(nxp_rw6xx_power_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); diff --git a/soc/nxp/rw/soc.c b/soc/nxp/rw/soc.c index 8aa3d6f6deee..9d3b6c548f15 100644 --- a/soc/nxp/rw/soc.c +++ b/soc/nxp/rw/soc.c @@ -221,7 +221,7 @@ __ramfunc void clock_init(void) #endif #endif /* CONFIG_SPI */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(dmic0), okay) && CONFIG_AUDIO_DMIC_MCUX +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dmic0)) && CONFIG_AUDIO_DMIC_MCUX /* Clock DMIC from Audio PLL. PLL output is sourced from AVPLL * channel 1, which is clocked at 12.288 MHz. We can divide this * by 4 to achieve the desired DMIC bit clk of 3.072 MHz @@ -230,7 +230,7 @@ __ramfunc void clock_init(void) CLOCK_SetClkDiv(kCLOCK_DivDmicClk, 4); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(lcdic), okay) && CONFIG_MIPI_DBI_NXP_LCDIC +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lcdic)) && CONFIG_MIPI_DBI_NXP_LCDIC CLOCK_AttachClk(kMAIN_CLK_to_LCD_CLK); RESET_PeripheralReset(kLCDIC_RST_SHIFT_RSTn); #endif @@ -250,7 +250,7 @@ __ramfunc void clock_init(void) #endif #endif /* CONFIG_COUNTER_MCUX_CTIMER */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(usb_otg), okay) && CONFIG_USB_DC_NXP_EHCI +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(usb_otg)) && CONFIG_USB_DC_NXP_EHCI /* Enable system xtal from Analog */ SYSCTL2->ANA_GRP_CTRL |= SYSCTL2_ANA_GRP_CTRL_PU_AG_MASK; /* reset USB */ @@ -261,24 +261,23 @@ __ramfunc void clock_init(void) CLOCK_EnableUsbhsPhyClock(); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(enet), okay) && CONFIG_NET_L2_ETHERNET +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(enet)) && CONFIG_NET_L2_ETHERNET RESET_PeripheralReset(kENET_IPG_RST_SHIFT_RSTn); RESET_PeripheralReset(kENET_IPG_S_RST_SHIFT_RSTn); #endif } +extern void nxp_rw6xx_power_init(void); /** * * @brief Perform basic hardware initialization * * Initialize the interrupt controller device drivers. * Also initialize the timer device driver, if required. - * - * @return 0 */ -static int nxp_rw600_init(void) +void soc_early_init_hook(void) { #if (DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(wwdt), nxp_lpc_wwdt, okay)) POWER_EnableResetSource(kPOWER_ResetSourceWdt); @@ -290,7 +289,7 @@ static int nxp_rw600_init(void) #define PMU_RESET_CAUSES \ COND_CODE_0(IS_EMPTY(PMU_RESET_CAUSES_), (PMU_RESET_CAUSES_), (0)) #define WDT_RESET \ - COND_CODE_1(DT_NODE_HAS_STATUS(wwdt, okay), (kPOWER_ResetSourceWdt), (0)) + COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(wwdt), (kPOWER_ResetSourceWdt), (0)) #define RESET_CAUSES \ (PMU_RESET_CAUSES | WDT_RESET) #else @@ -305,8 +304,9 @@ static int nxp_rw600_init(void) #if defined(CONFIG_ADC_MCUX_GAU) || defined(CONFIG_DAC_MCUX_GAU) POWER_PowerOnGau(); #endif - - return 0; +#if CONFIG_PM + nxp_rw6xx_power_init(); +#endif } void soc_reset_hook(void) @@ -314,5 +314,3 @@ void soc_reset_hook(void) /* This is provided by the SDK */ SystemInit(); } - -SYS_INIT(nxp_rw600_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/s32/s32k1/Kconfig b/soc/nxp/s32/s32k1/Kconfig index 0883614c82bd..2bb3a2719046 100644 --- a/soc/nxp/s32/s32k1/Kconfig +++ b/soc/nxp/s32/s32k1/Kconfig @@ -19,6 +19,7 @@ config SOC_SERIES_S32K1 select HAS_MCUX_WDOG32 select HAS_MCUX_RTC select HAS_MCUX_ADC12 + select SOC_EARLY_INIT_HOOK config SOC_S32K116 select CPU_CORTEX_M0PLUS diff --git a/soc/nxp/s32/s32k1/soc.c b/soc/nxp/s32/s32k1/soc.c index 20a27eb13c0d..484838cf68c3 100644 --- a/soc/nxp/s32/s32k1/soc.c +++ b/soc/nxp/s32/s32k1/soc.c @@ -48,7 +48,7 @@ void z_arm_watchdog_init(void) } #endif /* CONFIG_WDOG_INIT */ -static int soc_init(void) +void soc_early_init_hook(void) { #if !defined(CONFIG_ARM_MPU) uint32_t tmp; @@ -71,8 +71,4 @@ static int soc_init(void) #endif OsIf_Init(NULL); - - return 0; } - -SYS_INIT(soc_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/s32/s32k3/Kconfig b/soc/nxp/s32/s32k3/Kconfig index fdf0bba26877..627898f7231a 100644 --- a/soc/nxp/s32/s32k3/Kconfig +++ b/soc/nxp/s32/s32k3/Kconfig @@ -22,6 +22,7 @@ config SOC_SERIES_S32K3 select HAS_MCUX_LPSPI select HAS_MCUX_CACHE select HAS_MCUX_EDMA + select SOC_EARLY_INIT_HOOK if SOC_SERIES_S32K3 diff --git a/soc/nxp/s32/s32k3/soc.c b/soc/nxp/s32/s32k3/soc.c index be822677189e..e2ecba3c6fbf 100644 --- a/soc/nxp/s32/s32k3/soc.c +++ b/soc/nxp/s32/s32k3/soc.c @@ -49,14 +49,10 @@ const struct ivt ivt_header __attribute__((section(".ivt_header"))) = { }; #endif /* CONFIG_XIP */ -static int soc_init(void) +void soc_early_init_hook(void) { sys_cache_instr_enable(); sys_cache_data_enable(); OsIf_Init(NULL); - - return 0; } - -SYS_INIT(soc_init, PRE_KERNEL_1, 0); diff --git a/soc/nxp/s32/s32ze/Kconfig b/soc/nxp/s32/s32ze/Kconfig index 8c9041a2fe3e..9ee9aaa1429c 100644 --- a/soc/nxp/s32/s32ze/Kconfig +++ b/soc/nxp/s32/s32ze/Kconfig @@ -18,6 +18,7 @@ config SOC_SERIES_S32ZE select HAS_MCUX_PIT select HAS_MCUX_FLEXCAN select HAS_MCUX_LPI2C + select SOC_EARLY_INIT_HOOK if SOC_SERIES_S32ZE diff --git a/soc/nxp/s32/s32ze/soc.c b/soc/nxp/s32/s32ze/soc.c index 801e0173ae34..da05a2085b7c 100644 --- a/soc/nxp/s32/s32ze/soc.c +++ b/soc/nxp/s32/s32ze/soc.c @@ -44,11 +44,7 @@ void soc_reset_hook(void) } } -static int soc_init(void) +void soc_early_init_hook(void) { OsIf_Init(NULL); - - return 0; } - -SYS_INIT(soc_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); diff --git a/soc/openisa/rv32m1/soc.c b/soc/openisa/rv32m1/soc.c index 95edf0c53832..0f41fc69ca6b 100644 --- a/soc/openisa/rv32m1/soc.c +++ b/soc/openisa/rv32m1/soc.c @@ -197,16 +197,16 @@ static void rv32m1_switch_to_sirc(void) */ static void rv32m1_setup_peripheral_clocks(void) { -#if DT_NODE_HAS_STATUS(DT_NODELABEL(tpm0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(tpm0)) CLOCK_SetIpSrc(kCLOCK_Tpm0, kCLOCK_IpSrcFircAsync); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(tpm1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(tpm1)) CLOCK_SetIpSrc(kCLOCK_Tpm1, kCLOCK_IpSrcFircAsync); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(tpm2), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(tpm2)) CLOCK_SetIpSrc(kCLOCK_Tpm2, kCLOCK_IpSrcFircAsync); #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(tpm3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(tpm3)) CLOCK_SetIpSrc(kCLOCK_Tpm3, kCLOCK_IpSrcFircAsync); #endif } diff --git a/soc/renesas/ra/ra4m1/soc.c b/soc/renesas/ra/ra4m1/soc.c index 7f021ba17fae..7d8f27449141 100644 --- a/soc/renesas/ra/ra4m1/soc.c +++ b/soc/renesas/ra/ra4m1/soc.c @@ -107,7 +107,7 @@ const struct opt_set_mem ops __attribute__((section(".opt_set_mem"))) = { .LVDAS = 0x1, /* Disable voltage monitor 0 following reset */ .VDSEL1 = 0x3, .RSVD2 = 0x3, - .HOCOEN = !DT_NODE_HAS_STATUS(DT_PATH(clocks, hoco), okay), + .HOCOEN = !DT_NODE_HAS_STATUS_OKAY(DT_PATH(clocks, hoco)), .RSVD3 = 0x7, .HOCOFRQ1 = OFS1_HOCO_FREQ, .RSVD4 = 0x1ffff, diff --git a/soc/renesas/smartbond/da1469x/power.c b/soc/renesas/smartbond/da1469x/power.c index 80a497acff54..fec9b5f6c622 100644 --- a/soc/renesas/smartbond/da1469x/power.c +++ b/soc/renesas/smartbond/da1469x/power.c @@ -48,7 +48,7 @@ void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id) static int renesas_da1469x_pm_init(void) { static const struct da1469x_sleep_config sleep_cfg = { - .enable_xtal_on_wakeup = DT_NODE_HAS_STATUS(DT_NODELABEL(xtal32m), okay), + .enable_xtal_on_wakeup = DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(xtal32m)), }; da1469x_sleep_config(&sleep_cfg); diff --git a/soc/snps/arc_iot/Kconfig b/soc/snps/arc_iot/Kconfig index 362d2d1ae716..0ea361d2325a 100644 --- a/soc/snps/arc_iot/Kconfig +++ b/soc/snps/arc_iot/Kconfig @@ -6,3 +6,4 @@ config SOC_ARC_IOT select ARC select CPU_HAS_MPU select CPU_HAS_FPU + select SOC_EARLY_INIT_HOOK diff --git a/soc/snps/arc_iot/soc.c b/soc/snps/arc_iot/soc.c index 832c6df5f51d..d42ed3f9d9c6 100644 --- a/soc/snps/arc_iot/soc.c +++ b/soc/snps/arc_iot/soc.c @@ -15,14 +15,7 @@ #define CPU_FREQ DT_PROP(DT_PATH(cpus, cpu_0), clock_frequency) -static int arc_iot_init(void) +void soc_early_init_hook(void) { - - if (arc_iot_pll_fout_config(CPU_FREQ / 1000000) < 0) { - return -1; - } - - return 0; + arc_iot_pll_fout_config(CPU_FREQ / 1000000); } - -SYS_INIT(arc_iot_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); diff --git a/soc/snps/emsk/Kconfig b/soc/snps/emsk/Kconfig index 88cdfe706711..014d5357f0af 100644 --- a/soc/snps/emsk/Kconfig +++ b/soc/snps/emsk/Kconfig @@ -4,12 +4,16 @@ config SOC_EMSK select ARC + select SOC_EARLY_INIT_HOOK config SOC_EMSK_EM7D select CPU_HAS_MPU + select SOC_EARLY_INIT_HOOK config SOC_EMSK_EM9D select CPU_HAS_FPU + select SOC_EARLY_INIT_HOOK config SOC_EMSK_EM11D select CPU_HAS_FPU + select SOC_EARLY_INIT_HOOK diff --git a/soc/snps/emsk/soc_config.c b/soc/snps/emsk/soc_config.c index adca19b683c0..5c18898ecd28 100644 --- a/soc/snps/emsk/soc_config.c +++ b/soc/snps/emsk/soc_config.c @@ -11,24 +11,20 @@ #ifdef CONFIG_UART_NS16550 -static int uart_ns16550_init(void) +void soc_early_init_hook(void) { /* On ARC EM Starter kit board, * send the UART the command to clear the interrupt */ -#if DT_NODE_HAS_STATUS(DT_INST(0, ns16550), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_INST(0, ns16550)) sys_write32(0, DT_REG_ADDR(DT_INST(0, ns16550))+0x4); sys_write32(0, DT_REG_ADDR(DT_INST(0, ns16550))+0x10); -#endif /* DT_NODE_HAS_STATUS(DT_INST(0, ns16550), okay) */ -#if DT_NODE_HAS_STATUS(DT_INST(1, ns16550), okay) +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_INST(0, ns16550)) */ +#if DT_NODE_HAS_STATUS_OKAY(DT_INST(1, ns16550)) sys_write32(0, DT_REG_ADDR(DT_INST(1, ns16550))+0x4); sys_write32(0, DT_REG_ADDR(DT_INST(1, ns16550))+0x10); -#endif /* DT_NODE_HAS_STATUS(DT_INST(1, ns16550), okay) */ - - return 0; +#endif /* DT_NODE_HAS_STATUS_OKAY(DT_INST(1, ns16550)) */ } -SYS_INIT(uart_ns16550_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); - #endif /* CONFIG_UART_NS16550 */ diff --git a/soc/st/stm32/stm32h7x/mpu_regions.c b/soc/st/stm32/stm32h7x/mpu_regions.c index 29825ad226a9..8582db607249 100644 --- a/soc/st/stm32/stm32h7x/mpu_regions.c +++ b/soc/st/stm32/stm32h7x/mpu_regions.c @@ -21,8 +21,8 @@ static const struct arm_mpu_region mpu_regions[] = { REGION_512K | MPU_RASR_XN_Msk | P_RW_U_NA_Msk) }), -#if DT_NODE_HAS_STATUS(DT_NODELABEL(mac), okay) -#if DT_NODE_HAS_STATUS(DT_NODELABEL(sram3), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(mac)) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(sram3)) MPU_REGION_ENTRY("SRAM3_ETH_BUF", DT_REG_ADDR(DT_NODELABEL(sram3)), REGION_RAM_NOCACHE_ATTR(REGION_16K)), diff --git a/soc/xlnx/zynq7000/xc7zxxx/soc.c b/soc/xlnx/zynq7000/xc7zxxx/soc.c index 37d30b02426a..c1dad84ff36e 100644 --- a/soc/xlnx/zynq7000/xc7zxxx/soc.c +++ b/soc/xlnx/zynq7000/xc7zxxx/soc.c @@ -39,13 +39,13 @@ static const struct arm_mmu_region mmu_regions[] = { /* ARM Arch timer, GIC are covered by the MPCore mapping */ /* GEMs */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gem0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gem0)) MMU_REGION_FLAT_ENTRY("gem0", DT_REG_ADDR(DT_NODELABEL(gem0)), DT_REG_SIZE(DT_NODELABEL(gem0)), MT_DEVICE | MATTR_SHARED | MPERM_R | MPERM_W), #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gem1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gem1)) MMU_REGION_FLAT_ENTRY("gem1", DT_REG_ADDR(DT_NODELABEL(gem1)), DT_REG_SIZE(DT_NODELABEL(gem1)), @@ -53,7 +53,7 @@ static const struct arm_mmu_region mmu_regions[] = { #endif /* GPIO controller */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(psgpio), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(psgpio)) MMU_REGION_FLAT_ENTRY("psgpio", DT_REG_ADDR(DT_NODELABEL(psgpio)), DT_REG_SIZE(DT_NODELABEL(psgpio)), @@ -106,7 +106,7 @@ void soc_reset_hook(void) sctlr &= ~SCTLR_A_Msk; __set_SCTLR(sctlr); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(slcr), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(slcr)) mm_reg_t addr = DT_REG_ADDR(DT_NODELABEL(slcr)); /* Unlock System Level Control Registers (SLCR) */ diff --git a/soc/xlnx/zynq7000/xc7zxxxs/soc.c b/soc/xlnx/zynq7000/xc7zxxxs/soc.c index a46d9a217843..982ee094e01f 100644 --- a/soc/xlnx/zynq7000/xc7zxxxs/soc.c +++ b/soc/xlnx/zynq7000/xc7zxxxs/soc.c @@ -39,13 +39,13 @@ static const struct arm_mmu_region mmu_regions[] = { /* ARM Arch timer, GIC are covered by the MPCore mapping */ /* GEMs */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gem0), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gem0)) MMU_REGION_FLAT_ENTRY("gem0", DT_REG_ADDR(DT_NODELABEL(gem0)), DT_REG_SIZE(DT_NODELABEL(gem0)), MT_DEVICE | MATTR_SHARED | MPERM_R | MPERM_W), #endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(gem1), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(gem1)) MMU_REGION_FLAT_ENTRY("gem1", DT_REG_ADDR(DT_NODELABEL(gem1)), DT_REG_SIZE(DT_NODELABEL(gem1)), @@ -53,7 +53,7 @@ static const struct arm_mmu_region mmu_regions[] = { #endif /* GPIO controller */ -#if DT_NODE_HAS_STATUS(DT_NODELABEL(psgpio), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(psgpio)) MMU_REGION_FLAT_ENTRY("psgpio", DT_REG_ADDR(DT_NODELABEL(psgpio)), DT_REG_SIZE(DT_NODELABEL(psgpio)), @@ -106,7 +106,7 @@ void soc_reset_hook(void) sctlr &= ~SCTLR_A_Msk; __set_SCTLR(sctlr); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(slcr), okay) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(slcr)) mm_reg_t addr = DT_REG_ADDR(DT_NODELABEL(slcr)); /* Unlock System Level Control Registers (SLCR) */ diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_fem.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_fem.h index b9ada56b5ab2..a80de9f85e54 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_fem.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_fem.h @@ -17,9 +17,9 @@ #if DT_NODE_HAS_PROP(DT_NODELABEL(radio), fem) #define FEM_NODE DT_PHANDLE(DT_NODELABEL(radio), fem) -#if DT_NODE_HAS_STATUS(FEM_NODE, okay) +#if DT_NODE_HAS_STATUS_OKAY(FEM_NODE) #define HAL_RADIO_HAVE_FEM -#endif /* DT_NODE_HAS_STATUS(FEM_NODE, okay) */ +#endif /* DT_NODE_HAS_STATUS_OKAY(FEM_NODE) */ #endif /* DT_NODE_HAS_PROP(DT_NODELABEL(radio), fem)) */ /* Does FEM_NODE have a particular DT compatible? */ diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index 4710f24e90cd..bf3dd13cce9a 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -343,6 +343,17 @@ config BT_CONN_PARAM_ANY min and max connection intervals in order to verify whether the desired parameters have been established in the connection. +config BT_CONN_CHECK_NULL_BEFORE_CREATE + bool "Check if *conn is NULL when creating a connection" + help + Enable this option to ensure that bt_conn_le_create and + bt_conn_le_create_synced return an error if *conn is not initialized + to NULL. This option is recommended to use to catch programming + errors where the application reuses the connection pointer of an + active connection object without dereferencing it. Without + dereferencing, the connection object stays alive which can lead to an + unpredictable behavior. + config BT_USER_PHY_UPDATE bool "User control of PHY Update Procedure" depends on BT_PHY_UPDATE @@ -661,9 +672,13 @@ config BT_BONDABLE bool "Bondable Mode" default y help - This option enables support for Bondable Mode. In this mode, - Bonding flag in AuthReq of SMP Pairing Request/Response will be set - indicating the support for this mode. + This option is the default value of the bonding flag for any ACL connection. + If the option is true, the default bonding flag is true. Or, the default + bonding flag is false. + After a connection is established, the bonding flag of the connection + can also be changed by calling `bt_conn_set_bondable()` if the configuration + `the bonding flag per-connection` (BT_BONDABLE_PER_CONNECTION) is + enabled. Please see the BT_BONDABLE_PER_CONNECTION configuration. config BT_BONDING_REQUIRED bool "Always require bonding" diff --git a/subsys/bluetooth/host/adv.c b/subsys/bluetooth/host/adv.c index 8420daea603f..2191effefbae 100644 --- a/subsys/bluetooth/host/adv.c +++ b/subsys/bluetooth/host/adv.c @@ -662,7 +662,7 @@ static int hci_set_ad_ext(struct bt_le_ext_adv *adv, uint16_t hci_op, } if (total_len_bytes > bt_dev.le.max_adv_data_len) { - LOG_WRN("adv or scan rsp data too large (%d > max %d)", total_len_bytes, + LOG_WRN("adv or scan rsp data too large (%zu > max %u)", total_len_bytes, bt_dev.le.max_adv_data_len); return -EDOM; } diff --git a/subsys/bluetooth/host/att.c b/subsys/bluetooth/host/att.c index 7af47a6a3b8d..f5bca16d8d23 100644 --- a/subsys/bluetooth/host/att.c +++ b/subsys/bluetooth/host/att.c @@ -3150,9 +3150,10 @@ static void att_timeout(struct k_work *work) struct k_work_delayable *dwork = k_work_delayable_from_work(work); struct bt_att_chan *chan = CONTAINER_OF(dwork, struct bt_att_chan, timeout_work); + int err; bt_addr_le_to_str(bt_conn_get_dst(chan->att->conn), addr, sizeof(addr)); - LOG_ERR("ATT Timeout for device %s", addr); + LOG_ERR("ATT Timeout for device %s. Disconnecting...", addr); /* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part F] page 480: * @@ -3163,6 +3164,16 @@ static void att_timeout(struct k_work *work) * target device on this ATT Bearer. */ bt_att_disconnected(&chan->chan.chan); + + /* The timeout state is local and can block new ATT operations, but does not affect the + * remote side. Disconnecting the GATT connection upon ATT timeout simplifies error handling + * for developers. This reduces rare failure conditions to a common one, allowing developers + * to handle unexpected disconnections without needing special cases for ATT timeouts. + */ + err = bt_conn_disconnect(chan->chan.chan.conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); + if (err) { + LOG_ERR("Disconnecting failed (err %d)", err); + } } static struct bt_att_chan *att_get_fixed_chan(struct bt_conn *conn) diff --git a/subsys/bluetooth/host/att_internal.h b/subsys/bluetooth/host/att_internal.h index 7898dcedb748..6eec4c5496e1 100644 --- a/subsys/bluetooth/host/att_internal.h +++ b/subsys/bluetooth/host/att_internal.h @@ -10,7 +10,8 @@ #define BT_EATT_PSM 0x27 #define BT_ATT_DEFAULT_LE_MTU 23 -#define BT_ATT_TIMEOUT K_SECONDS(30) +#define BT_ATT_TIMEOUT_SEC 30 +#define BT_ATT_TIMEOUT K_SECONDS(BT_ATT_TIMEOUT_SEC) /* Local ATT Rx MTU * diff --git a/subsys/bluetooth/host/buf.c b/subsys/bluetooth/host/buf.c index 2e6394884817..2ce2477ff05e 100644 --- a/subsys/bluetooth/host/buf.c +++ b/subsys/bluetooth/host/buf.c @@ -158,7 +158,7 @@ struct net_buf *bt_buf_make_view(struct net_buf *view, __ASSERT_NO_MSG(!bt_buf_has_view(parent)); - LOG_DBG("make-view %p viewsize %u meta %p", view, len, meta); + LOG_DBG("make-view %p viewsize %zu meta %p", view, len, meta); net_buf_simple_clone(&parent->b, &view->b); view->size = net_buf_headroom(parent) + len; diff --git a/subsys/bluetooth/host/classic/l2cap_br.c b/subsys/bluetooth/host/classic/l2cap_br.c index 523cce4600b5..4c1461c7f04a 100644 --- a/subsys/bluetooth/host/classic/l2cap_br.c +++ b/subsys/bluetooth/host/classic/l2cap_br.c @@ -786,6 +786,13 @@ l2cap_br_conn_security(struct bt_l2cap_chan *chan, const uint16_t psm) * since service/profile requires that. */ if (check == 0) { + /* + * General Bonding refers to the process of performing bonding + * during connection setup or channel establishment procedures + * as a precursor to accessing a service. + * For current case, it is dedicated bonding. + */ + atomic_set_bit(chan->conn->flags, BT_CONN_BR_GENERAL_BONDING); return L2CAP_CONN_SECURITY_PENDING; } diff --git a/subsys/bluetooth/host/classic/rfcomm.c b/subsys/bluetooth/host/classic/rfcomm.c index 21ccba25e7ef..f8742bff3678 100644 --- a/subsys/bluetooth/host/classic/rfcomm.c +++ b/subsys/bluetooth/host/classic/rfcomm.c @@ -829,6 +829,13 @@ static enum security_result rfcomm_dlc_security(struct bt_rfcomm_dlc *dlc) } if (!bt_conn_set_security(conn, dlc->required_sec_level)) { + /* + * General Bonding refers to the process of performing bonding + * during connection setup or channel establishment procedures + * as a precursor to accessing a service. + * For current case, it is dedicated bonding. + */ + atomic_set_bit(conn->flags, BT_CONN_BR_GENERAL_BONDING); /* If Security elevation is initiated or in progress */ return RFCOMM_SECURITY_PENDING; } diff --git a/subsys/bluetooth/host/classic/ssp.c b/subsys/bluetooth/host/classic/ssp.c index 72ac72624a76..41a42f829f33 100644 --- a/subsys/bluetooth/host/classic/ssp.c +++ b/subsys/bluetooth/host/classic/ssp.c @@ -666,9 +666,17 @@ void bt_hci_io_capa_req(struct net_buf *buf) */ if (atomic_test_bit(conn->flags, BT_CONN_BR_PAIRING_INITIATOR)) { if (get_io_capa() != BT_IO_NO_INPUT_OUTPUT) { - auth = BT_HCI_DEDICATED_BONDING_MITM; + if (atomic_test_bit(conn->flags, BT_CONN_BR_GENERAL_BONDING)) { + auth = BT_HCI_GENERAL_BONDING_MITM; + } else { + auth = BT_HCI_DEDICATED_BONDING_MITM; + } } else { - auth = BT_HCI_DEDICATED_BONDING; + if (atomic_test_bit(conn->flags, BT_CONN_BR_GENERAL_BONDING)) { + auth = BT_HCI_GENERAL_BONDING; + } else { + auth = BT_HCI_DEDICATED_BONDING; + } } } else { auth = ssp_get_auth(conn); diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 5e853d57be16..9797337000aa 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -160,7 +160,7 @@ static struct net_buf *get_data_frag(struct net_buf *outside, size_t winsize) window = bt_buf_make_view(window, outside, winsize, &get_frag_md(window)->view_meta); - LOG_DBG("get-acl-frag: outside %p window %p size %d", outside, window, winsize); + LOG_DBG("get-acl-frag: outside %p window %p size %zu", outside, window, winsize); return window; } @@ -665,7 +665,7 @@ static int send_buf(struct bt_conn *conn, struct net_buf *buf, return -EIO; } - LOG_DBG("conn %p buf %p len %u buf->len %u cb %p ud %p", + LOG_DBG("conn %p buf %p len %zu buf->len %u cb %p ud %p", conn, buf, len, buf->len, cb, ud); /* Acquire the right to send 1 packet to the controller */ @@ -2633,6 +2633,7 @@ static void reset_pairing(struct bt_conn *conn) atomic_clear_bit(conn->flags, BT_CONN_BR_PAIRING); atomic_clear_bit(conn->flags, BT_CONN_BR_PAIRING_INITIATOR); atomic_clear_bit(conn->flags, BT_CONN_BR_LEGACY_SECURE); + atomic_clear_bit(conn->flags, BT_CONN_BR_GENERAL_BONDING); } #endif /* CONFIG_BT_CLASSIC */ @@ -3728,6 +3729,23 @@ int bt_conn_le_create(const bt_addr_le_t *peer, const struct bt_conn_le_create_p struct bt_conn *conn; int err; + CHECKIF(ret_conn == NULL) { + return -EINVAL; + } + + CHECKIF(*ret_conn != NULL) { + /* This rule helps application developers prevent leaks of connection references. If + * a bt_conn variable is not null, it presumably holds a reference and must not be + * overwritten. To avoid this warning, initialize the variables to null, and set + * them to null when moving the reference. + */ + LOG_WRN("*conn should be unreferenced and initialized to NULL"); + + if (IS_ENABLED(CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE)) { + return -EINVAL; + } + } + err = conn_le_create_common_checks(peer, conn_param); if (err) { return err; @@ -3787,6 +3805,23 @@ int bt_conn_le_create_synced(const struct bt_le_ext_adv *adv, struct bt_conn *conn; int err; + CHECKIF(ret_conn == NULL) { + return -EINVAL; + } + + CHECKIF(*ret_conn != NULL) { + /* This rule helps application developers prevent leaks of connection references. If + * a bt_conn variable is not null, it presumably holds a reference and must not be + * overwritten. To avoid this warning, initialize the variables to null, and set + * them to null when moving the reference. + */ + LOG_WRN("*conn should be unreferenced and initialized to NULL"); + + if (IS_ENABLED(CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE)) { + return -EINVAL; + } + } + err = conn_le_create_common_checks(synced_param->peer, conn_param); if (err) { return err; diff --git a/subsys/bluetooth/host/conn_internal.h b/subsys/bluetooth/host/conn_internal.h index 6b6c97b19026..f5e747febdd8 100644 --- a/subsys/bluetooth/host/conn_internal.h +++ b/subsys/bluetooth/host/conn_internal.h @@ -60,6 +60,7 @@ enum { BT_CONN_USER, /* user I/O when pairing */ BT_CONN_BR_PAIRING, /* BR connection in pairing context */ BT_CONN_BR_NOBOND, /* SSP no bond pairing tracker */ + BT_CONN_BR_GENERAL_BONDING, /* BR general bonding */ BT_CONN_BR_PAIRING_INITIATOR, /* local host starts authentication */ BT_CONN_CLEANUP, /* Disconnected, pending cleanup */ BT_CONN_AUTO_INIT_PROCEDURES_DONE, /* Auto-initiated procedures have run */ diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index 8747eae47917..1e3850fd5911 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -717,6 +717,10 @@ static void cancel_data_ready(struct bt_l2cap_le_chan *le_chan) int bt_l2cap_send_pdu(struct bt_l2cap_le_chan *le_chan, struct net_buf *pdu, bt_conn_tx_cb_t cb, void *user_data) { + if (!le_chan->chan.conn || le_chan->chan.conn->state != BT_CONN_CONNECTED) { + return -ENOTCONN; + } + /* Allow for an additional buffer reference if callback is provided. This can be used to * extend lifetime of the net buffer until the data transmission is confirmed by ACK of the * remote. @@ -937,7 +941,7 @@ struct net_buf *l2cap_data_pull(struct bt_conn *conn, struct bt_l2cap_hdr *hdr; uint16_t pdu_len = get_pdu_len(lechan, pdu); - LOG_DBG("Adding L2CAP PDU header: buf %p chan %p len %zu / %zu", + LOG_DBG("Adding L2CAP PDU header: buf %p chan %p len %u / %u", pdu, lechan, pdu_len, pdu->len); LOG_HEXDUMP_DBG(pdu->data, pdu->len, "PDU payload"); diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 1971f185f956..24ace96809d7 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -2639,6 +2639,11 @@ void bt_set_bondable(bool enable) bondable = enable; } +bool bt_get_bondable(void) +{ + return bondable; +} + void bt_le_oob_set_sc_flag(bool enable) { sc_oobd_present = enable; diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index b08f67835e1b..7b904f6262fd 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -76,6 +76,8 @@ static struct bt_conn_auth_info_cb auth_info_cb; */ #define HCI_CMD_MAX_PARAM 65 +#define DEFAULT_SCAN_TIMEOUT_SEC 10 + #if defined(CONFIG_BT_BROADCASTER) enum { SHELL_ADV_OPT_CONNECTABLE, @@ -218,9 +220,31 @@ static struct bt_auto_connect { bool addr_set; bool connect_name; } auto_connect; -#endif +#endif /* CONFIG_BT_CENTRAL */ #if defined(CONFIG_BT_OBSERVER) +static void active_scan_timeout(struct k_work *work) +{ + int err; + + shell_print(ctx_shell, "Scan timeout"); + + err = bt_le_scan_stop(); + if (err) { + shell_error(ctx_shell, "Failed to stop scan (err %d)", err); + } + +#if defined(CONFIG_BT_CENTRAL) + if (auto_connect.connect_name) { + auto_connect.connect_name = false; + /* "name" is what would be in argv[0] normally */ + cmd_scan_filter_clear_name(ctx_shell, 1, (char *[]){ "name" }); + } +#endif /* CONFIG_BT_CENTRAL */ +} + +static K_WORK_DELAYABLE_DEFINE(active_scan_timeout_work, active_scan_timeout); + static struct bt_scan_filter { char name[NAME_LEN]; bool name_set; @@ -591,14 +615,6 @@ static void scan_recv(const struct bt_le_scan_recv_info *info, struct net_buf_si static void scan_timeout(void) { shell_print(ctx_shell, "Scan timeout"); - -#if defined(CONFIG_BT_CENTRAL) - if (auto_connect.connect_name) { - auto_connect.connect_name = false; - /* "name" is what would be in argv[0] normally */ - cmd_scan_filter_clear_name(ctx_shell, 1, (char *[]){ "name" }); - } -#endif /* CONFIG_BT_CENTRAL */ } #endif /* CONFIG_BT_OBSERVER */ @@ -1602,7 +1618,7 @@ static int cmd_active_scan_on(const struct shell *sh, uint32_t options, .options = BT_LE_SCAN_OPT_NONE, .interval = BT_GAP_SCAN_FAST_INTERVAL, .window = BT_GAP_SCAN_FAST_WINDOW, - .timeout = timeout, }; + .timeout = 0, }; param.options |= options; @@ -1615,6 +1631,11 @@ static int cmd_active_scan_on(const struct shell *sh, uint32_t options, shell_print(sh, "Bluetooth active scan enabled"); } + if (timeout != 0) { + /* Schedule the k_work to act as a timeout */ + (void)k_work_reschedule(&active_scan_timeout_work, K_SECONDS(timeout)); + } + return 0; } @@ -1647,6 +1668,9 @@ static int cmd_scan_off(const struct shell *sh) { int err; + /* Cancel the potentially pending scan timeout work */ + (void)k_work_cancel_delayable(&active_scan_timeout_work); + err = bt_le_scan_stop(); if (err) { shell_error(sh, "Stopping scanning failed (err %d)", err); @@ -3327,13 +3351,12 @@ static int cmd_auto_conn(const struct shell *sh, size_t argc, char *argv[]) static int cmd_connect_le_name(const struct shell *sh, size_t argc, char *argv[]) { - const uint16_t timeout_seconds = 10; const struct bt_le_scan_param param = { .type = BT_LE_SCAN_TYPE_ACTIVE, .options = BT_LE_SCAN_OPT_NONE, .interval = BT_GAP_SCAN_FAST_INTERVAL, .window = BT_GAP_SCAN_FAST_WINDOW, - .timeout = timeout_seconds * 100, /* 10ms units */ + .timeout = 0, }; int err; @@ -3359,6 +3382,9 @@ static int cmd_connect_le_name(const struct shell *sh, size_t argc, char *argv[] /* Set boolean to tell the scan callback to connect to this name */ auto_connect.connect_name = true; + /* Schedule the k_work to act as a timeout */ + (void)k_work_reschedule(&active_scan_timeout_work, K_SECONDS(DEFAULT_SCAN_TIMEOUT_SEC)); + return 0; } #endif /* CONFIG_BT_CENTRAL */ diff --git a/subsys/dfu/boot/mcuboot_shell.c b/subsys/dfu/boot/mcuboot_shell.c index be4e558713f1..e167bc1e39b8 100644 --- a/subsys/dfu/boot/mcuboot_shell.c +++ b/subsys/dfu/boot/mcuboot_shell.c @@ -20,6 +20,16 @@ #endif #endif +#if USE_PARTITION_MANAGER +#include + +#ifdef CONFIG_NCS_IS_VARIANT_IMAGE +#define ACTIVE_IMAGE_ID PM_MCUBOOT_SECONDARY_ID +#else +#define ACTIVE_IMAGE_ID PM_MCUBOOT_PRIMARY_ID +#endif +#endif + struct area_desc { const char *name; unsigned int id; @@ -93,6 +103,35 @@ static int cmd_mcuboot_erase(const struct shell *sh, size_t argc, id = strtoul(argv[1], NULL, 0); /* Check if this is the parent (MCUboot) or own slot and if so, deny the request */ +#if USE_PARTITION_MANAGER +#ifdef PM_MCUBOOT_ID + if (id == PM_MCUBOOT_ID || id == PM_MCUBOOT_PAD_ID) { + shell_error(sh, "Cannot erase boot partition"); + return -EACCES; + } +#endif + +#ifdef PM_APP_ID + if (id == PM_APP_ID) { + shell_error(sh, "Cannot erase this area"); + return -EACCES; + } +#endif + +#ifdef PM_MCUBOOT_PRIMARY_APP_ID + if (id == PM_MCUBOOT_PRIMARY_APP_ID) { + shell_error(sh, "Cannot erase this area"); + return -EACCES; + } +#endif + +#ifdef ACTIVE_IMAGE_ID + if (id == ACTIVE_IMAGE_ID) { + shell_error(sh, "Cannot erase active partitions"); + return -EACCES; + } +#endif +#else #if FIXED_PARTITION_EXISTS(boot_partition) if (id == FIXED_PARTITION_ID(boot_partition)) { shell_error(sh, "Cannot erase boot partition"); @@ -105,6 +144,7 @@ static int cmd_mcuboot_erase(const struct shell *sh, size_t argc, shell_error(sh, "Cannot erase active partitions"); return -EACCES; } +#endif #endif err = boot_erase_img_bank(id); diff --git a/subsys/fs/zms/Kconfig b/subsys/fs/zms/Kconfig index c9514608da88..a2b060dfb4bb 100644 --- a/subsys/fs/zms/Kconfig +++ b/subsys/fs/zms/Kconfig @@ -1,9 +1,9 @@ -#Zephyr Memory Storage ZMS - #Copyright (c) 2024 BayLibre SAS #SPDX-License-Identifier: Apache-2.0 +#Zephyr Memory Storage ZMS + config ZMS bool "Zephyr Memory Storage" select CRC @@ -34,20 +34,19 @@ config ZMS_DATA_CRC help Enables DATA CRC -config ZMS_CUSTOM_BLOCK_SIZE - bool "Custom buffer size used by ZMS for reads and writes" - default n +config ZMS_CUSTOMIZE_BLOCK_SIZE + bool "Customize the size of the buffer used internally for reads and writes" help - ZMS uses internal buffers to read/write and compare stored data. - Increasing the size of these buffers should be done carefully in order to not + ZMS uses an internal buffer to read/write and compare stored data. + Increasing the size of this buffer should be done carefully in order to not overflow the stack. Increasing this buffer means as well that ZMS could work with storage devices that have larger write-block-size which decreases ZMS performance -config ZMS_MAX_BLOCK_SIZE +config ZMS_CUSTOM_BLOCK_SIZE int "ZMS internal buffer size" default 32 - depends on ZMS_CUSTOM_BLOCK_SIZE + depends on ZMS_CUSTOMIZE_BLOCK_SIZE help Changes the internal buffer size of ZMS diff --git a/subsys/fs/zms/zms.c b/subsys/fs/zms/zms.c index 839c079f923d..f0f22c597356 100644 --- a/subsys/fs/zms/zms.c +++ b/subsys/fs/zms/zms.c @@ -1,8 +1,8 @@ -/* ZMS: Zephyr Memory Storage - * - * Copyright (c) 2024 BayLibre SAS +/* Copyright (c) 2024 BayLibre SAS * * SPDX-License-Identifier: Apache-2.0 + * + * ZMS: Zephyr Memory Storage */ #include @@ -87,8 +87,10 @@ static inline size_t zms_lookup_cache_pos(uint32_t id) static int zms_lookup_cache_rebuild(struct zms_fs *fs) { - int rc, previous_sector_num = ZMS_INVALID_SECTOR_NUM; - uint64_t addr, ate_addr; + int rc; + int previous_sector_num = ZMS_INVALID_SECTOR_NUM; + uint64_t addr; + uint64_t ate_addr; uint64_t *cache_entry; uint8_t current_cycle; struct zms_ate ate; @@ -155,6 +157,19 @@ static inline off_t zms_addr_to_offset(struct zms_fs *fs, uint64_t addr) return fs->offset + (fs->sector_size * SECTOR_NUM(addr)) + SECTOR_OFFSET(addr); } +/* Helper to round down len to the closest multiple of write_block_size */ +static inline size_t zms_round_down_write_block_size(struct zms_fs *fs, size_t len) +{ + return len & ~(fs->flash_parameters->write_block_size - 1U); +} + +/* Helper to round up len to multiple of write_block_size */ +static inline size_t zms_round_up_write_block_size(struct zms_fs *fs, size_t len) +{ + return (len + (fs->flash_parameters->write_block_size - 1U)) & + ~(fs->flash_parameters->write_block_size - 1U); +} + /* zms_al_size returns size aligned to fs->write_block_size */ static inline size_t zms_al_size(struct zms_fs *fs, size_t len) { @@ -163,7 +178,8 @@ static inline size_t zms_al_size(struct zms_fs *fs, size_t len) if (write_block_size <= 1U) { return len; } - return (len + (write_block_size - 1U)) & ~(write_block_size - 1U); + + return zms_round_up_write_block_size(fs, len); } /* Helper to get empty ATE address */ @@ -194,7 +210,7 @@ static int zms_flash_al_wrt(struct zms_fs *fs, uint64_t addr, const void *data, offset = zms_addr_to_offset(fs, addr); - blen = len & ~(fs->flash_parameters->write_block_size - 1U); + blen = zms_round_down_write_block_size(fs, len); if (blen > 0) { rc = flash_write(fs->flash_device, offset, data8, blen); if (rc) { @@ -276,10 +292,11 @@ static int zms_flash_block_cmp(struct zms_fs *fs, uint64_t addr, const void *dat { const uint8_t *data8 = (const uint8_t *)data; int rc; - size_t bytes_to_cmp, block_size; + size_t bytes_to_cmp; + size_t block_size; uint8_t buf[ZMS_BLOCK_SIZE]; - block_size = ZMS_BLOCK_SIZE & ~(fs->flash_parameters->write_block_size - 1U); + block_size = zms_round_down_write_block_size(fs, ZMS_BLOCK_SIZE); while (len) { bytes_to_cmp = MIN(block_size, len); @@ -305,10 +322,11 @@ static int zms_flash_block_cmp(struct zms_fs *fs, uint64_t addr, const void *dat static int zms_flash_cmp_const(struct zms_fs *fs, uint64_t addr, uint8_t value, size_t len) { int rc; - size_t bytes_to_cmp, block_size; + size_t bytes_to_cmp; + size_t block_size; uint8_t cmp[ZMS_BLOCK_SIZE]; - block_size = ZMS_BLOCK_SIZE & ~(fs->flash_parameters->write_block_size - 1U); + block_size = zms_round_down_write_block_size(fs, ZMS_BLOCK_SIZE); (void)memset(cmp, value, block_size); while (len) { @@ -329,10 +347,11 @@ static int zms_flash_cmp_const(struct zms_fs *fs, uint64_t addr, uint8_t value, static int zms_flash_block_move(struct zms_fs *fs, uint64_t addr, size_t len) { int rc; - size_t bytes_to_copy, block_size; + size_t bytes_to_copy; + size_t block_size; uint8_t buf[ZMS_BLOCK_SIZE]; - block_size = ZMS_BLOCK_SIZE & ~(fs->flash_parameters->write_block_size - 1U); + block_size = zms_round_down_write_block_size(fs, ZMS_BLOCK_SIZE); while (len) { bytes_to_copy = MIN(block_size, len); @@ -416,17 +435,17 @@ static int zms_ate_crc8_check(const struct zms_ate *entry) return 1; } -/* zms_ate_valid validates an ate: - * return 1 if crc8 and cycle_cnt valid, - * 0 otherwise +/* zms_ate_valid validates an ate in the current sector by checking if the ate crc is valid + * and its cycle cnt matches the cycle cnt of the active sector + * + * return 1 if ATE is valid, + * 0 otherwise + * + * see: zms_ate_valid_different_sector */ static int zms_ate_valid(struct zms_fs *fs, const struct zms_ate *entry) { - if ((fs->sector_cycle != entry->cycle_cnt) || zms_ate_crc8_check(entry)) { - return 0; - } - - return 1; + return zms_ate_valid_different_sector(fs, entry, fs->sector_cycle); } /* zms_ate_valid_different_sector validates an ate that is in a different @@ -467,10 +486,11 @@ static inline int zms_get_cycle_on_sector_change(struct zms_fs *fs, uint64_t add return 0; } -/* zms_close_ate_valid validates an sector close ate: a valid sector close ate: - * - valid ate - * - len = 0 and id = ZMS_HEAD_ID - * - offset points to location at ate multiple from sector size +/* zms_close_ate_valid validates a sector close ate. + * A valid sector close ate should be: + * - a valid ate + * - with len = 0 and id = ZMS_HEAD_ID + * - and offset points to location at ate multiple from sector size * return true if valid, false otherwise */ static bool zms_close_ate_valid(struct zms_fs *fs, const struct zms_ate *entry) @@ -479,9 +499,10 @@ static bool zms_close_ate_valid(struct zms_fs *fs, const struct zms_ate *entry) (entry->id == ZMS_HEAD_ID) && !((fs->sector_size - entry->offset) % fs->ate_size)); } -/* zms_empty_ate_valid validates an sector empty ate: a valid sector empty ate: - * - valid ate - * - len = 0xffff and id = 0xffffffff +/* zms_empty_ate_valid validates an sector empty ate. + * A valid sector empty ate should be: + * - a valid ate + * - with len = 0xffff and id = 0xffffffff * return true if valid, false otherwise */ static bool zms_empty_ate_valid(struct zms_fs *fs, const struct zms_ate *entry) @@ -576,7 +597,8 @@ static int zms_flash_write_entry(struct zms_fs *fs, uint32_t id, const void *dat */ static int zms_recover_last_ate(struct zms_fs *fs, uint64_t *addr, uint64_t *data_wra) { - uint64_t data_end_addr, ate_end_addr; + uint64_t data_end_addr; + uint64_t ate_end_addr; struct zms_ate end_ate; int rc; @@ -614,7 +636,8 @@ static int zms_recover_last_ate(struct zms_fs *fs, uint64_t *addr, uint64_t *dat static int zms_compute_prev_addr(struct zms_fs *fs, uint64_t *addr) { int sec_closed; - struct zms_ate empty_ate, close_ate; + struct zms_ate empty_ate; + struct zms_ate close_ate; *addr += fs->ate_size; if ((SECTOR_OFFSET(*addr)) != (fs->sector_size - 2 * fs->ate_size)) { @@ -677,7 +700,8 @@ static void zms_sector_advance(struct zms_fs *fs, uint64_t *addr) static int zms_sector_close(struct zms_fs *fs) { int rc; - struct zms_ate close_ate, garbage_ate; + struct zms_ate close_ate; + struct zms_ate garbage_ate; close_ate.id = ZMS_HEAD_ID; close_ate.len = 0U; @@ -851,7 +875,8 @@ static int zms_find_ate_with_id(struct zms_fs *fs, uint32_t id, uint64_t start_a { int rc; int previous_sector_num = ZMS_INVALID_SECTOR_NUM; - uint64_t wlk_prev_addr, wlk_addr; + uint64_t wlk_prev_addr; + uint64_t wlk_addr; int prev_found = 0; struct zms_ate wlk_ate; uint8_t current_cycle; @@ -893,9 +918,19 @@ static int zms_find_ate_with_id(struct zms_fs *fs, uint32_t id, uint64_t start_a */ static int zms_gc(struct zms_fs *fs) { - int rc, sec_closed; - struct zms_ate close_ate, gc_ate, wlk_ate, empty_ate; - uint64_t sec_addr, gc_addr, gc_prev_addr, wlk_addr, wlk_prev_addr, data_addr, stop_addr; + int rc; + int sec_closed; + struct zms_ate close_ate; + struct zms_ate gc_ate; + struct zms_ate wlk_ate; + struct zms_ate empty_ate; + uint64_t sec_addr; + uint64_t gc_addr; + uint64_t gc_prev_addr; + uint64_t wlk_addr; + uint64_t wlk_prev_addr; + uint64_t data_addr; + uint64_t stop_addr; uint8_t previous_cycle = 0; rc = zms_get_sector_cycle(fs, fs->ate_wra, &fs->sector_cycle); @@ -1016,17 +1051,12 @@ static int zms_gc(struct zms_fs *fs) /* restore the previous sector_cycle */ fs->sector_cycle = previous_cycle; - /* Make it possible to detect that gc has finished by writing a - * gc done ate to the sector. In the field we might have zms systems - * that do not have sufficient space to add this ate, so for these - * situations avoid adding the gc done ate. + /* Write a GC_done ATE to mark the end of this operation */ - if (fs->ate_wra >= (fs->data_wra + fs->ate_size)) { - rc = zms_add_gc_done_ate(fs); - if (rc) { - return rc; - } + rc = zms_add_gc_done_ate(fs); + if (rc) { + return rc; } /* Erase the GC'ed sector when needed */ @@ -1077,14 +1107,16 @@ int zms_clear(struct zms_fs *fs) static int zms_init(struct zms_fs *fs) { - int rc, sec_closed; - struct zms_ate last_ate, first_ate, close_ate, empty_ate; - /* Initialize addr to 0 for the case fs->sector_count == 0. This - * should never happen as this is verified in zms_mount() but both - * Coverity and GCC believe the contrary. - */ - uint64_t addr = 0U, data_wra = 0U; - uint32_t i, closed_sectors = 0; + int rc; + int sec_closed; + struct zms_ate last_ate; + struct zms_ate first_ate; + struct zms_ate close_ate; + struct zms_ate empty_ate; + uint64_t addr = 0U; + uint64_t data_wra = 0U; + uint32_t i; + uint32_t closed_sectors = 0; bool zms_magic_exist = false; k_mutex_lock(&fs->zms_lock, K_FOREVER); @@ -1335,7 +1367,6 @@ static int zms_init(struct zms_fs *fs) int zms_mount(struct zms_fs *fs) { - int rc; struct flash_pages_info info; size_t write_block_size; @@ -1349,7 +1380,7 @@ int zms_mount(struct zms_fs *fs) } fs->ate_size = zms_al_size(fs, sizeof(struct zms_ate)); - write_block_size = flash_get_write_block_size(fs->flash_device); + write_block_size = fs->flash_parameters->write_block_size; /* check that the write block size is supported */ if (write_block_size > ZMS_BLOCK_SIZE || write_block_size == 0) { @@ -1407,8 +1438,10 @@ ssize_t zms_write(struct zms_fs *fs, uint32_t id, const void *data, size_t len) int rc; size_t data_size; struct zms_ate wlk_ate; - uint64_t wlk_addr, rd_addr; - uint32_t gc_count, required_space = 0U; /* no space, appropriate for delete ate */ + uint64_t wlk_addr; + uint64_t rd_addr; + uint32_t gc_count; + uint32_t required_space = 0U; /* no space, appropriate for delete ate */ int prev_found = 0; if (!fs->ready) { @@ -1548,8 +1581,11 @@ int zms_delete(struct zms_fs *fs, uint32_t id) ssize_t zms_read_hist(struct zms_fs *fs, uint32_t id, void *data, size_t len, uint32_t cnt) { - int rc, prev_found = 0; - uint64_t wlk_addr, rd_addr = 0, wlk_prev_addr = 0; + int rc; + int prev_found = 0; + uint64_t wlk_addr; + uint64_t rd_addr = 0; + uint64_t wlk_prev_addr = 0; uint32_t cnt_his; struct zms_ate wlk_ate; #ifdef CONFIG_ZMS_DATA_CRC @@ -1664,12 +1700,22 @@ ssize_t zms_get_data_length(struct zms_fs *fs, uint32_t id) ssize_t zms_calc_free_space(struct zms_fs *fs) { - - int rc, previous_sector_num = ZMS_INVALID_SECTOR_NUM, prev_found = 0, sec_closed; - struct zms_ate step_ate, wlk_ate, empty_ate, close_ate; - uint64_t step_addr, wlk_addr, step_prev_addr, wlk_prev_addr, data_wra = 0U; + int rc; + int previous_sector_num = ZMS_INVALID_SECTOR_NUM; + int prev_found = 0; + int sec_closed; + struct zms_ate step_ate; + struct zms_ate wlk_ate; + struct zms_ate empty_ate; + struct zms_ate close_ate; + uint64_t step_addr; + uint64_t wlk_addr; + uint64_t step_prev_addr; + uint64_t wlk_prev_addr; + uint64_t data_wra = 0U; uint8_t current_cycle; ssize_t free_space = 0; + const uint32_t second_to_last_offset = (2 * fs->ate_size); if (!fs->ready) { LOG_ERR("zms not initialized"); @@ -1733,9 +1779,8 @@ ssize_t zms_calc_free_space(struct zms_fs *fs) /* Let's look now for special cases where some sectors have only ATEs with * small data size. */ - const uint32_t second_to_last_offset = (2 * fs->ate_size); - for (uint32_t i = 0; i < fs->sector_count; i++) { + for (int i = 0; i < fs->sector_count; i++) { step_addr = zms_close_ate_addr(fs, ((uint64_t)i << ADDR_SECT_SHIFT)); /* verify if the sector is closed */ @@ -1768,7 +1813,7 @@ ssize_t zms_calc_free_space(struct zms_fs *fs) return free_space; } -size_t zms_sector_max_data_size(struct zms_fs *fs) +size_t zms_active_sector_free_space(struct zms_fs *fs) { if (!fs->ready) { LOG_ERR("ZMS not initialized"); diff --git a/subsys/fs/zms/zms_priv.h b/subsys/fs/zms/zms_priv.h index 6594048ea0f4..428ff6babca8 100644 --- a/subsys/fs/zms/zms_priv.h +++ b/subsys/fs/zms/zms_priv.h @@ -1,9 +1,10 @@ -/* ZMS: Zephyr Memory Storage - * - * Copyright (c) 2024 BayLibre SAS +/* Copyright (c) 2024 BayLibre SAS * * SPDX-License-Identifier: Apache-2.0 + * + * ZMS: Zephyr Memory Storage */ + #ifndef __ZMS_PRIV_H_ #define __ZMS_PRIV_H_ @@ -23,8 +24,8 @@ extern "C" { #define SECTOR_NUM(x) FIELD_GET(ADDR_SECT_MASK, x) #define SECTOR_OFFSET(x) FIELD_GET(ADDR_OFFS_MASK, x) -#if defined(CONFIG_ZMS_CUSTOM_BLOCK_SIZE) -#define ZMS_BLOCK_SIZE CONFIG_ZMS_MAX_BLOCK_SIZE +#if defined(CONFIG_ZMS_CUSTOMIZE_BLOCK_SIZE) +#define ZMS_BLOCK_SIZE CONFIG_ZMS_CUSTOM_BLOCK_SIZE #else #define ZMS_BLOCK_SIZE 32 #endif @@ -46,8 +47,8 @@ extern "C" { struct zms_ate { uint8_t crc8; /* crc8 check of the entry */ uint8_t cycle_cnt; /* cycle counter for non erasable devices */ - uint32_t id; /* data id */ uint16_t len; /* data len within sector */ + uint32_t id; /* data id */ union { uint8_t data[8]; /* used to store small size data */ struct { diff --git a/subsys/ipc/ipc_service/backends/ipc_icbmsg.c b/subsys/ipc/ipc_service/backends/ipc_icbmsg.c index 9fd7752999f8..927950dd50aa 100644 --- a/subsys/ipc/ipc_service/backends/ipc_icbmsg.c +++ b/subsys/ipc/ipc_service/backends/ipc_icbmsg.c @@ -1434,11 +1434,11 @@ const static struct ipc_service_backend backend_ops = { }; \ BUILD_ASSERT(IS_POWER_OF_TWO(GET_CACHE_ALIGNMENT(i)), \ "This module supports only power of two cache alignment"); \ - BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, tx, rx) > GET_CACHE_ALIGNMENT(i)) && \ + BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, tx, rx) >= GET_CACHE_ALIGNMENT(i)) && \ (GET_BLOCK_SIZE_INST(i, tx, rx) < \ GET_MEM_SIZE_INST(i, tx)), \ "TX region is too small for provided number of blocks"); \ - BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, rx, tx) > GET_CACHE_ALIGNMENT(i)) && \ + BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, rx, tx) >= GET_CACHE_ALIGNMENT(i)) && \ (GET_BLOCK_SIZE_INST(i, rx, tx) < \ GET_MEM_SIZE_INST(i, rx)), \ "RX region is too small for provided number of blocks"); \ diff --git a/subsys/logging/frontends/Kconfig b/subsys/logging/frontends/Kconfig index c232eb7354ad..4d6d85e3e883 100644 --- a/subsys/logging/frontends/Kconfig +++ b/subsys/logging/frontends/Kconfig @@ -46,8 +46,9 @@ config LOG_FRONTEND_STMESP_DICT config LOG_FRONTEND_STMESP_FSC bool "Send fully self-contained messages" - select LOG_MSG_APPEND_RO_STRING_LOC if (!NRF_ETR && !SOC_NRF54H20_CPUPPR && \ - !SOC_NRF54H20_CPUFLPR) + select LOG_MSG_APPEND_RO_STRING_LOC if !(NRF_ETR || \ + SOC_NRF54H20_CPUPPR || SOC_NRF54H20_ENGB_CPUPPR || \ + SOC_NRF54H20_CPUFLPR || SOC_NRF54H20_ENGB_CPUFLPR) config LOG_FRONTEND_STMESP_FLUSH_COUNT int "Number of flushing words" diff --git a/subsys/net/ip/Kconfig b/subsys/net/ip/Kconfig index cb08b3846ca4..f8c215b4fc3d 100644 --- a/subsys/net/ip/Kconfig +++ b/subsys/net/ip/Kconfig @@ -663,7 +663,7 @@ config NET_BUF_TX_COUNT Each data buffer will occupy CONFIG_NET_BUF_DATA_SIZE + smallish header (sizeof(struct net_buf)) amount of data. -choice +choice NET_PKT_DATA_ALLOC_TYPE prompt "Network packet data allocator type" default NET_BUF_FIXED_DATA_SIZE help diff --git a/subsys/net/l2/wifi/CMakeLists.txt b/subsys/net/l2/wifi/CMakeLists.txt index bab445e82629..fc844e37ca2e 100644 --- a/subsys/net/l2/wifi/CMakeLists.txt +++ b/subsys/net/l2/wifi/CMakeLists.txt @@ -23,27 +23,49 @@ if (CONFIG_WIFI_NM) zephyr_iterable_section(NAME wifi_nm_instance GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN}) endif() -# Wi-Fi Enterprise test certificates handling -set(gen_inc_dir ${ZEPHYR_BINARY_DIR}/misc/generated) -set(gen_dir ${gen_inc_dir}/wifi_enterprise_test_certs) - -# convert .pem files to array data at build time -zephyr_include_directories(${gen_inc_dir}) - -generate_inc_file_for_target( - app - ${ZEPHYR_BASE}/samples/net/wifi/test_certs/client.pem - ${gen_dir}/client.pem.inc - ) - -generate_inc_file_for_target( - app - ${ZEPHYR_BASE}/samples/net/wifi/test_certs/client-key.pem - ${gen_dir}/client-key.pem.inc - ) - -generate_inc_file_for_target( - app - ${ZEPHYR_BASE}/samples/net/wifi/test_certs/ca.pem - ${gen_dir}/ca.pem.inc - ) +if(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE) + # Wi-Fi Enterprise test certificates handling + set(gen_inc_dir ${ZEPHYR_BINARY_DIR}/misc/generated) + set(gen_dir ${gen_inc_dir}/wifi_enterprise_test_certs) + # Create output directory for test certs + file(MAKE_DIRECTORY ${gen_dir}) + + # convert .pem files to array data at build time + zephyr_include_directories(${gen_inc_dir}) + + generate_inc_file_for_target( + app + ${ZEPHYR_BASE}/samples/net/wifi/test_certs/client.pem + ${gen_dir}/client.pem.inc + ) + + generate_inc_file_for_target( + app + ${ZEPHYR_BASE}/samples/net/wifi/test_certs/client-key.pem + ${gen_dir}/client-key.pem.inc + ) + + generate_inc_file_for_target( + app + ${ZEPHYR_BASE}/samples/net/wifi/test_certs/ca.pem + ${gen_dir}/ca.pem.inc + ) + + generate_inc_file_for_target( + app + ${ZEPHYR_BASE}/samples/net/wifi/test_certs/client2.pem + ${gen_dir}/client2.pem.inc + ) + + generate_inc_file_for_target( + app + ${ZEPHYR_BASE}/samples/net/wifi/test_certs/client-key2.pem + ${gen_dir}/client-key2.pem.inc + ) + + generate_inc_file_for_target( + app + ${ZEPHYR_BASE}/samples/net/wifi/test_certs/ca2.pem + ${gen_dir}/ca2.pem.inc + ) +endif() diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index d676edd8f993..5974cde6a1a2 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -41,6 +41,8 @@ const char *wifi_security_txt(enum wifi_security_type security) return "WAPI"; case WIFI_SECURITY_TYPE_EAP_TLS: return "EAP"; + case WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL: + return "WPA/WPA2/WPA3 PSK"; case WIFI_SECURITY_TYPE_UNKNOWN: default: return "UNKNOWN"; @@ -240,6 +242,18 @@ const char *wifi_ps_wakeup_mode_txt(enum wifi_ps_wakeup_mode ps_wakeup_mode) } } +const char * const wifi_ps_exit_strategy_txt(enum wifi_ps_exit_strategy ps_exit_strategy) +{ + switch (ps_exit_strategy) { + case WIFI_PS_EXIT_EVERY_TIM: + return "Every TIM"; + case WIFI_PS_EXIT_CUSTOM_ALGO: + return "Custom algorithm"; + default: + return "UNKNOWN"; + } +} + static const struct wifi_mgmt_ops *const get_wifi_api(struct net_if *iface) { const struct device *dev = net_if_get_device(iface); @@ -570,6 +584,13 @@ static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface, case WIFI_PS_PARAM_WAKEUP_MODE: case WIFI_PS_PARAM_TIMEOUT: break; + case WIFI_PS_PARAM_EXIT_STRATEGY: + if (ps_params->exit_strategy > WIFI_PS_EXIT_MAX) { + ps_params->fail_reason = + WIFI_PS_PARAM_FAIL_INVALID_EXIT_STRATEGY; + return -EINVAL; + } + break; default: ps_params->fail_reason = WIFI_PS_PARAM_FAIL_OPERATION_NOT_SUPPORTED; @@ -813,6 +834,21 @@ static int wifi_get_connection_params(uint32_t mgmt_request, struct net_if *ifac NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_CONN_PARAMS, wifi_get_connection_params); +static int wifi_wps_config(uint32_t mgmt_request, struct net_if *iface, void *data, size_t len) +{ + const struct device *dev = net_if_get_device(iface); + const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface); + struct wifi_wps_config_params *params = data; + + if (wifi_mgmt_api == NULL || wifi_mgmt_api->wps_config == NULL) { + return -ENOTSUP; + } + + return wifi_mgmt_api->wps_config(dev, params); +} + +NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_WPS_CONFIG, wifi_wps_config); + static int wifi_set_rts_threshold(uint32_t mgmt_request, struct net_if *iface, void *data, size_t len) { diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 2dbb44de0aa8..d422abb5024c 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -32,15 +32,30 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE static const char ca_cert_test[] = { #include + '\0' }; static const char client_cert_test[] = { #include + '\0' }; static const char client_key_test[] = { #include + '\0' }; + +static const char ca_cert2_test[] = { + #include + '\0'}; + +static const char client_cert2_test[] = { + #include + '\0'}; + +static const char client_key2_test[] = { + #include + '\0'}; #endif #define WIFI_SHELL_MODULE "wifi" @@ -100,6 +115,12 @@ static int cmd_wifi_set_enterprise_creds(const struct shell *sh, struct net_if * params.client_cert_len = ARRAY_SIZE(client_cert_test); params.client_key = (uint8_t *)client_key_test; params.client_key_len = ARRAY_SIZE(client_key_test); + params.ca_cert2 = (uint8_t *)ca_cert2_test; + params.ca_cert2_len = ARRAY_SIZE(ca_cert2_test); + params.client_cert2 = (uint8_t *)client_cert2_test; + params.client_cert2_len = ARRAY_SIZE(client_cert2_test); + params.client_key2 = (uint8_t *)client_key2_test; + params.client_key2_len = ARRAY_SIZE(client_key2_test); if (net_mgmt(NET_REQUEST_WIFI_ENTERPRISE_CREDS, iface, ¶ms, sizeof(params))) { PR_WARNING("Set enterprise credentials failed\n"); @@ -125,16 +146,16 @@ static bool parse_number(const struct shell *sh, long *param, char *str, } if (*endptr != '\0') { - PR_ERROR("Invalid number: %s", str_tmp); + PR_ERROR("Invalid number: %s\n", str_tmp); return false; } if ((num) < (min) || (num) > (max)) { if (pname) { - PR_WARNING("%s value out of range: %s, (%ld-%ld)", + PR_WARNING("%s value out of range: %s, (%ld-%ld)\n", pname, str_tmp, min, max); } else { - PR_WARNING("Value out of range: %s, (%ld-%ld)", + PR_WARNING("Value out of range: %s, (%ld-%ld)\n", str_tmp, min, max); } return false; @@ -500,7 +521,26 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv {"channel", required_argument, 0, 'c'}, {"timeout", required_argument, 0, 't'}, {"anon-id", required_argument, 0, 'a'}, - {"key-passwd", required_argument, 0, 'K'}, + {"key1-pwd", required_argument, 0, 'K'}, + {"key2-pwd", required_argument, 0, 'K'}, + {"suiteb-type", required_argument, 0, 'S'}, + {"eap-version", required_argument, 0, 'V'}, + {"eap-id1", required_argument, 0, 'I'}, + {"eap-id2", required_argument, 0, 'I'}, + {"eap-id3", required_argument, 0, 'I'}, + {"eap-id4", required_argument, 0, 'I'}, + {"eap-id5", required_argument, 0, 'I'}, + {"eap-id6", required_argument, 0, 'I'}, + {"eap-id7", required_argument, 0, 'I'}, + {"eap-id8", required_argument, 0, 'I'}, + {"eap-pwd1", required_argument, 0, 'P'}, + {"eap-pwd2", required_argument, 0, 'P'}, + {"eap-pwd3", required_argument, 0, 'P'}, + {"eap-pwd4", required_argument, 0, 'P'}, + {"eap-pwd5", required_argument, 0, 'P'}, + {"eap-pwd6", required_argument, 0, 'P'}, + {"eap-pwd7", required_argument, 0, 'P'}, + {"eap-pwd8", required_argument, 0, 'P'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; char *endptr; @@ -516,14 +556,16 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv char bands_str[MAX_BANDS_STR_LEN] = {0}; size_t offset = 0; long channel; + int key_passwd_cnt = 0; /* Defaults */ params->band = WIFI_FREQ_BAND_UNKNOWN; params->channel = WIFI_CHANNEL_ANY; params->security = WIFI_SECURITY_TYPE_NONE; params->mfp = WIFI_MFP_OPTIONAL; + params->eap_ver = 1; - while ((opt = getopt_long(argc, argv, "s:p:k:w:b:c:m:t:a:K:h", + while ((opt = getopt_long(argc, argv, "s:p:k:e:w:b:c:m:t:a:K:S:V:I:P:h", long_options, &opt_index)) != -1) { state = getopt_state_get(); switch (opt) { @@ -584,7 +626,8 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv params->channel = channel; break; case 'b': - if (iface_mode == WIFI_MODE_INFRA) { + if (iface_mode == WIFI_MODE_INFRA || + iface_mode == WIFI_MODE_AP) { switch (atoi(state->optarg)) { case 2: params->band = WIFI_FREQ_BAND_2_4_GHZ; @@ -636,10 +679,54 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv } break; case 'K': - params->key_passwd = optarg; - params->key_passwd_length = strlen(params->key_passwd); - if (params->key_passwd_length > WIFI_ENT_PSWD_MAX_LEN) { - PR_WARNING("key_passwd too long (max %d characters)\n", + if (key_passwd_cnt >= 2) { + PR_WARNING("too many key_passwd (max 2 key_passwd)\n"); + return -EINVAL; + } + + if (key_passwd_cnt == 0) { + params->key_passwd = optarg; + params->key_passwd_length = strlen(params->key_passwd); + if (params->key_passwd_length > WIFI_ENT_PSWD_MAX_LEN) { + PR_WARNING("key_passwd too long (max %d characters)\n", + WIFI_ENT_PSWD_MAX_LEN); + return -EINVAL; + } + } else if (key_passwd_cnt == 1) { + params->key2_passwd = optarg; + params->key2_passwd_length = strlen(params->key2_passwd); + if (params->key2_passwd_length > WIFI_ENT_PSWD_MAX_LEN) { + PR_WARNING("key2_passwd too long (max %d characters)\n", + WIFI_ENT_PSWD_MAX_LEN); + return -EINVAL; + } + } + key_passwd_cnt++; + break; + case 'S': + params->suiteb_type = atoi(optarg); + break; + case 'V': + params->eap_ver = atoi(optarg); + if (params->eap_ver != 0U && params->eap_ver != 1U) { + PR_WARNING("eap_ver error %d\n", params->eap_ver); + return -EINVAL; + } + break; + case 'I': + params->eap_identity = optarg; + params->eap_id_length = strlen(params->eap_identity); + if (params->eap_id_length > WIFI_ENT_IDENTITY_MAX_LEN) { + PR_WARNING("eap identity too long (max %d characters)\n", + WIFI_ENT_IDENTITY_MAX_LEN); + return -EINVAL; + } + break; + case 'P': + params->eap_password = optarg; + params->eap_passwd_length = strlen(params->eap_password); + if (params->eap_passwd_length > WIFI_ENT_PSWD_MAX_LEN) { + PR_WARNING("eap password length too long (max %d characters)\n", WIFI_ENT_PSWD_MAX_LEN); return -EINVAL; } @@ -706,7 +793,12 @@ static int cmd_wifi_connect(const struct shell *sh, size_t argc, #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE /* Load the enterprise credentials if needed */ - if (cnx_params.security == WIFI_SECURITY_TYPE_EAP_TLS) { + if (cnx_params.security == WIFI_SECURITY_TYPE_EAP_TLS || + cnx_params.security == WIFI_SECURITY_TYPE_EAP_PEAP_MSCHAPV2 || + cnx_params.security == WIFI_SECURITY_TYPE_EAP_PEAP_GTC || + cnx_params.security == WIFI_SECURITY_TYPE_EAP_TTLS_MSCHAPV2 || + cnx_params.security == WIFI_SECURITY_TYPE_EAP_PEAP_TLS || + cnx_params.security == WIFI_SECURITY_TYPE_EAP_TLS_SHA256) { cmd_wifi_set_enterprise_creds(sh, iface); } #endif @@ -950,6 +1042,65 @@ static int cmd_wifi_status(const struct shell *sh, size_t argc, char *argv[]) return 0; } +static int cmd_wifi_ap_status(const struct shell *sh, size_t argc, char *argv[]) +{ + struct net_if *iface = net_if_get_wifi_sap(); + struct wifi_iface_status status = {0}; + uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; + + context.sh = sh; + + if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &status, + sizeof(struct wifi_iface_status))) { + PR_WARNING("Status request failed\n"); + + return -ENOEXEC; + } + + switch (status.state) { + case WIFI_HAPD_IFACE_UNINITIALIZED: + PR("State: %s\n", "HAPD_IFACE_UNINITIALIZED"); + return 0; + case WIFI_HAPD_IFACE_DISABLED: + PR("State: %s\n", "HAPD_IFACE_DISABLED"); + return 0; + case WIFI_HAPD_IFACE_COUNTRY_UPDATE: + PR("State: %s\n", "HAPD_IFACE_DISABLED"); + return 0; + case WIFI_HAPD_IFACE_ACS: + PR("State: %s\n", "HAPD_IFACE_DISABLED"); + return 0; + case WIFI_HAPD_IFACE_HT_SCAN: + PR("State: %s\n", "HAPD_IFACE_DISABLED"); + return 0; + case WIFI_HAPD_IFACE_DFS: + PR("State: %s\n", "HAPD_IFACE_DISABLED"); + break; + case WIFI_HAPD_IFACE_ENABLED: + break; + default: + return 0; + } + + PR("Interface Mode: %s\n", wifi_mode_txt(status.iface_mode)); + PR("Link Mode: %s\n", wifi_link_mode_txt(status.link_mode)); + PR("SSID: %.32s\n", status.ssid); + PR("BSSID: %s\n", net_sprint_ll_addr_buf(status.bssid, WIFI_MAC_ADDR_LEN, mac_string_buf, + sizeof(mac_string_buf))); + PR("Band: %s\n", wifi_band_txt(status.band)); + PR("Channel: %d\n", status.channel); + PR("Security: %s\n", wifi_security_txt(status.security)); + PR("MFP: %s\n", wifi_mfp_txt(status.mfp)); + if (status.iface_mode == WIFI_MODE_INFRA) { + PR("RSSI: %d\n", status.rssi); + } + PR("Beacon Interval: %d\n", status.beacon_interval); + PR("DTIM: %d\n", status.dtim_period); + PR("TWT: %s\n", status.twt_capable ? "Supported" : "Not supported"); + + return 0; +} + #if defined(CONFIG_NET_STATISTICS_WIFI) && \ defined(CONFIG_NET_STATISTICS_USER_API) static void print_wifi_stats(struct net_if *iface, struct net_stats_wifi *data, @@ -1062,6 +1213,9 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[]) PR("PS timeout: disabled\n"); } + shell_fprintf(sh, SHELL_NORMAL, "PS exit strategy: %s\n", + wifi_ps_exit_strategy_txt(config.ps_params.exit_strategy)); + if (config.num_twt_flows == 0) { PR("No TWT flows\n"); } else { @@ -1671,16 +1825,19 @@ static int cmd_wifi_btm_query(const struct shell *sh, size_t argc, char *argv[]) { struct net_if *iface = net_if_get_first_wifi(); uint8_t query_reason = 0; + long tmp = 0; context.sh = sh; - if (!parse_number(sh, (long *)&query_reason, argv[1], NULL, + if (!parse_number(sh, &tmp, argv[1], NULL, WIFI_BTM_QUERY_REASON_UNSPECIFIED, WIFI_BTM_QUERY_REASON_LEAVING_ESS)) { return -EINVAL; } + query_reason = tmp; + if (net_mgmt(NET_REQUEST_WIFI_BTM_QUERY, iface, &query_reason, sizeof(query_reason))) { - PR_WARNING("Setting BTM query Reason failed..Reason :%d\n", query_reason); + PR_WARNING("Setting BTM query Reason failed. Reason : %d\n", query_reason); return -ENOEXEC; } @@ -1690,6 +1847,57 @@ static int cmd_wifi_btm_query(const struct shell *sh, size_t argc, char *argv[]) } #endif +static int cmd_wifi_wps_pbc(const struct shell *sh, size_t argc, char *argv[]) +{ + struct net_if *iface = net_if_get_first_wifi(); + struct wifi_wps_config_params params = {0}; + + context.sh = sh; + + if (argc == 1) { + params.oper = WIFI_WPS_PBC; + } else { + shell_help(sh); + return -ENOEXEC; + } + + if (net_mgmt(NET_REQUEST_WIFI_WPS_CONFIG, iface, ¶ms, sizeof(params))) { + PR_WARNING("Start wps pbc connection failed\n"); + return -ENOEXEC; + } + + return 0; +} + +static int cmd_wifi_wps_pin(const struct shell *sh, size_t argc, char *argv[]) +{ + struct net_if *iface = net_if_get_first_wifi(); + struct wifi_wps_config_params params = {0}; + + context.sh = sh; + + if (argc == 1) { + params.oper = WIFI_WPS_PIN_GET; + } else if (argc == 2) { + params.oper = WIFI_WPS_PIN_SET; + strncpy(params.pin, argv[1], WIFI_WPS_PIN_MAX_LEN); + } else { + shell_help(sh); + return -ENOEXEC; + } + + if (net_mgmt(NET_REQUEST_WIFI_WPS_CONFIG, iface, ¶ms, sizeof(params))) { + PR_WARNING("Start wps pin connection failed\n"); + return -ENOEXEC; + } + + if (params.oper == WIFI_WPS_PIN_GET) { + PR("WPS PIN is: %s\n", params.pin); + } + + return 0; +} + static int cmd_wifi_ps_wakeup_mode(const struct shell *sh, size_t argc, char *argv[]) { struct net_if *iface = net_if_get_first_wifi(); @@ -1777,6 +1985,40 @@ static int cmd_wifi_set_rts_threshold(const struct shell *sh, size_t argc, char return 0; } +static int cmd_wifi_ps_exit_strategy(const struct shell *sh, size_t argc, + char *argv[]) +{ + struct net_if *iface = net_if_get_first_wifi(); + struct wifi_ps_params params = { 0 }; + + context.sh = sh; + + if (!strncmp(argv[1], "tim", 3)) { + params.exit_strategy = WIFI_PS_EXIT_EVERY_TIM; + } else if (!strncmp(argv[1], "custom", 6)) { + params.exit_strategy = WIFI_PS_EXIT_CUSTOM_ALGO; + } else { + shell_fprintf(sh, SHELL_WARNING, "Invalid argument\n"); + shell_fprintf(sh, SHELL_INFO, "Valid argument : / \n"); + return -ENOEXEC; + } + + params.type = WIFI_PS_PARAM_EXIT_STRATEGY; + + if (net_mgmt(NET_REQUEST_WIFI_PS, iface, ¶ms, sizeof(params))) { + shell_fprintf(sh, SHELL_WARNING, + "Setting PS exit strategy to %s failed..Reason :%s\n", + wifi_ps_exit_strategy_txt(params.exit_strategy), + wifi_ps_get_config_err_code_str(params.fail_reason)); + return -ENOEXEC; + } + + shell_fprintf(sh, SHELL_NORMAL, "%s\n", + wifi_ps_exit_strategy_txt(params.exit_strategy)); + + return 0; +} + void parse_mode_args_to_params(const struct shell *sh, int argc, char *argv[], struct wifi_mode_info *mode, bool *do_mode_oper) @@ -2580,24 +2822,27 @@ static int cmd_wifi_dpp_ap_qr_code(const struct shell *sh, size_t argc, char *ar static int cmd_wifi_dpp_ap_auth_init(const struct shell *sh, size_t argc, char *argv[]) { - int ret = 0; - struct net_if *iface = net_if_get_wifi_sap(); - struct wifi_dpp_params params = {0}; int opt; int opt_index = 0; struct getopt_state *state; - static struct option long_options[] = {{"peer", required_argument, 0, 'p'}, {0, 0, 0, 0}}; + static const struct option long_options[] = { + {"peer", required_argument, 0, 'p'}, + {0, 0, 0, 0}}; + int ret = 0; + struct net_if *iface = net_if_get_wifi_sap(); + struct wifi_dpp_params params = {0}; params.action = WIFI_DPP_AUTH_INIT; - while ((opt = getopt_long(argc, argv, "p:", long_options, &opt_index)) != -1) { + while ((opt = getopt_long(argc, argv, "p:", + long_options, &opt_index)) != -1) { state = getopt_state_get(); switch (opt) { case 'p': - params.auth_init.peer = shell_strtol(optarg, 10, &ret); + params.auth_init.peer = shell_strtol(state->optarg, 10, &ret); break; default: - PR_ERROR("Invalid option %c\n", optopt); + PR_ERROR("Invalid option %c\n", state->optopt); return -EINVAL; } @@ -2656,43 +2901,41 @@ static int cmd_wifi_pmksa_flush(const struct shell *sh, size_t argc, char *argv[ return 0; } -SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, - SHELL_CMD_ARG(disable, NULL, - "Disable Access Point mode.\n", - cmd_wifi_ap_disable, - 1, 0), +SHELL_STATIC_SUBCMD_SET_CREATE( + wifi_cmd_ap, + SHELL_CMD_ARG(disable, NULL, "Disable Access Point mode.\n", cmd_wifi_ap_disable, 1, 0), SHELL_CMD_ARG(enable, NULL, - "-s --ssid=\n" - "-c --channel=\n" - "-p --passphrase= (valid only for secure SSIDs)\n" - "-k --key-mgmt= (valid only for secure SSIDs)\n" - "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP-TLS, 6:WEP\n" - "7: WPA-PSK, 11: DPP\n" - "-w --ieee-80211w= (optional: needs security type to be specified)\n" - "0:Disable, 1:Optional, 2:Required\n" - "-b --band= (2 -2.6GHz, 5 - 5Ghz, 6 - 6GHz)\n" - "-m --bssid=\n" - "-h --help (prints help)", - cmd_wifi_ap_enable, - 2, 13), - SHELL_CMD_ARG(stations, NULL, - "List stations connected to the AP", - cmd_wifi_ap_stations, - 1, 0), + "-s --ssid=\n" + "-c --channel=\n" + "-p --passphrase= (valid only for secure SSIDs)\n" + "-k --key-mgmt= (valid only for secure SSIDs)\n" + "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP-TLS, 6:WEP\n" + "7: WPA-PSK, 11: DPP\n" + "-w --ieee-80211w= (optional: needs security type to be specified)\n" + "0:Disable, 1:Optional, 2:Required\n" + "-b --band= (2 -2.6GHz, 5 - 5Ghz, 6 - 6GHz)\n" + "-m --bssid=\n" + "-h --help (prints help)", + cmd_wifi_ap_enable, 2, 13), + SHELL_CMD_ARG(stations, NULL, "List stations connected to the AP", cmd_wifi_ap_stations, 1, + 0), SHELL_CMD_ARG(disconnect, NULL, - "Disconnect a station from the AP\n" - "\n", - cmd_wifi_ap_sta_disconnect, - 2, 0), + "Disconnect a station from the AP\n" + "\n", + cmd_wifi_ap_sta_disconnect, 2, 0), SHELL_CMD_ARG(config, NULL, - "Configure AP parameters.\n" - "-i --max_inactivity=