diff --git a/boards/native/nrf_bsim/CMakeLists.txt b/boards/native/nrf_bsim/CMakeLists.txt index d55a52e1a53..6aeb3f01634 100644 --- a/boards/native/nrf_bsim/CMakeLists.txt +++ b/boards/native/nrf_bsim/CMakeLists.txt @@ -24,6 +24,7 @@ zephyr_library_sources( cpu_wait.c argparse.c nsi_if.c + native_remap.c soc/nrfx_coredep.c common/bstests_entry.c common/cmsis/cmsis.c diff --git a/boards/native/nrf_bsim/native_remap.c b/boards/native/nrf_bsim/native_remap.c new file mode 100644 index 00000000000..d8b756a9576 --- /dev/null +++ b/boards/native/nrf_bsim/native_remap.c @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include "NHW_misc.h" + +bool native_emb_addr_remap(void **addr) +{ + return nhw_convert_RAM_addr(addr); +} diff --git a/include/zephyr/ipc/pbuf.h b/include/zephyr/ipc/pbuf.h index 0be5bd5185c..8783cdbbf14 100644 --- a/include/zephyr/ipc/pbuf.h +++ b/include/zephyr/ipc/pbuf.h @@ -35,6 +35,13 @@ extern "C" { */ #define _PBUF_MIN_DATA_LEN ROUND_UP(PBUF_PACKET_LEN_SZ + 1 + _PBUF_IDX_SIZE, _PBUF_IDX_SIZE) +#if defined(CONFIG_ARCH_POSIX) +/* For the native simulated boards we need to modify some pointers at init */ +#define PBUF_MAYBE_CONST +#else +#define PBUF_MAYBE_CONST const +#endif + /** @brief Control block of packet buffer. * * The structure contains configuration data. @@ -87,9 +94,9 @@ struct pbuf_data { * written in a way to protect the data from being corrupted. */ struct pbuf { - const struct pbuf_cfg *const cfg; /* Configuration of the - * buffer. - */ + PBUF_MAYBE_CONST struct pbuf_cfg *const cfg; /* Configuration of the + * buffer. + */ struct pbuf_data data; /* Data used to read and write * to the buffer */ @@ -144,17 +151,32 @@ struct pbuf { "Misaligned memory."); \ BUILD_ASSERT(size >= (MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE + \ _PBUF_MIN_DATA_LEN), "Insufficient size."); \ - \ - static const struct pbuf_cfg cfg_##name = \ + static PBUF_MAYBE_CONST struct pbuf_cfg cfg_##name = \ PBUF_CFG_INIT(mem_addr, size, dcache_align); \ static struct pbuf name = { \ .cfg = &cfg_##name, \ } /** - * @brief Initialize the packet buffer. + * @brief Initialize the Tx packet buffer. + * + * This function initializes the Tx packet buffer based on provided configuration. + * If the configuration is incorrect, the function will return error. + * + * It is recommended to use PBUF_DEFINE macro for build time initialization. + * + * @param pb Pointer to the packed buffer containing + * configuration and data. Configuration has to be + * fixed before the initialization. + * @retval 0 on success. + * @retval -EINVAL when the input parameter is incorrect. + */ +int pbuf_tx_init(struct pbuf *pb); + +/** + * @brief Initialize the Rx packet buffer. * - * This function initializes the packet buffer based on provided configuration. + * This function initializes the Rx packet buffer. * If the configuration is incorrect, the function will return error. * * It is recommended to use PBUF_DEFINE macro for build time initialization. @@ -165,7 +187,7 @@ struct pbuf { * @retval 0 on success. * @retval -EINVAL when the input parameter is incorrect. */ -int pbuf_init(struct pbuf *pb); +int pbuf_rx_init(struct pbuf *pb); /** * @brief Write specified amount of data to the packet buffer. diff --git a/samples/subsys/ipc/ipc_service/icmsg/CMakeLists.txt b/samples/subsys/ipc/ipc_service/icmsg/CMakeLists.txt index 725fd707174..e9e246b02fa 100644 --- a/samples/subsys/ipc/ipc_service/icmsg/CMakeLists.txt +++ b/samples/subsys/ipc/ipc_service/icmsg/CMakeLists.txt @@ -9,6 +9,7 @@ cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) if(NOT CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP AND + NOT CONFIG_BOARD_NRF5340BSIM_NRF5340_CPUAPP AND NOT CONFIG_BOARD_STM32H747I_DISCO AND NOT CONFIG_BOARD_NRF54L15PDK_NRF54L15_CPUAPP) message(FATAL_ERROR "${BOARD} is not supported for this sample") diff --git a/samples/subsys/ipc/ipc_service/icmsg/Kconfig.sysbuild b/samples/subsys/ipc/ipc_service/icmsg/Kconfig.sysbuild index 9a2c85d065d..41b892aba6a 100644 --- a/samples/subsys/ipc/ipc_service/icmsg/Kconfig.sysbuild +++ b/samples/subsys/ipc/ipc_service/icmsg/Kconfig.sysbuild @@ -7,5 +7,6 @@ source "share/sysbuild/Kconfig" config REMOTE_BOARD string default "nrf5340dk/nrf5340/cpunet" if $(BOARD) = "nrf5340dk" + default "nrf5340bsim/nrf5340/cpunet" if $(BOARD) = "nrf5340bsim" default "nrf54l15pdk/nrf54l15/cpuflpr" if $(BOARD) = "nrf54l15pdk" default "stm32h747i_disco/stm32h747xx/m4" if $(BOARD) = "stm32h747i_disco" diff --git a/samples/subsys/ipc/ipc_service/icmsg/boards/nrf5340bsim_nrf5340_cpuapp.overlay b/samples/subsys/ipc/ipc_service/icmsg/boards/nrf5340bsim_nrf5340_cpuapp.overlay new file mode 100644 index 00000000000..53c9b68afe7 --- /dev/null +++ b/samples/subsys/ipc/ipc_service/icmsg/boards/nrf5340bsim_nrf5340_cpuapp.overlay @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "nrf5340dk_nrf5340_cpuapp.overlay" diff --git a/samples/subsys/ipc/ipc_service/icmsg/remote/boards/nrf5340bsim_nrf5340_cpunet.overlay b/samples/subsys/ipc/ipc_service/icmsg/remote/boards/nrf5340bsim_nrf5340_cpunet.overlay new file mode 100644 index 00000000000..c5194cf93cd --- /dev/null +++ b/samples/subsys/ipc/ipc_service/icmsg/remote/boards/nrf5340bsim_nrf5340_cpunet.overlay @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "nrf5340dk_nrf5340_cpunet.overlay" diff --git a/samples/subsys/ipc/ipc_service/icmsg/sample.yaml b/samples/subsys/ipc/ipc_service/icmsg/sample.yaml index b981c1b8215..321ed3398ed 100644 --- a/samples/subsys/ipc/ipc_service/icmsg/sample.yaml +++ b/samples/subsys/ipc/ipc_service/icmsg/sample.yaml @@ -2,9 +2,12 @@ sample: name: IPC Service example integration (icmsg backend) tests: sample.ipc.icmsg: - platform_allow: nrf5340dk/nrf5340/cpuapp + platform_allow: + - nrf5340dk/nrf5340/cpuapp + - nrf5340bsim/nrf5340/cpuapp integration_platforms: - nrf5340dk/nrf5340/cpuapp + - nrf5340bsim/nrf5340/cpuapp tags: ipc sysbuild: true harness: console diff --git a/samples/subsys/ipc/ipc_service/icmsg/sysbuild.cmake b/samples/subsys/ipc/ipc_service/icmsg/sysbuild.cmake index b1f0947aff7..305c85cc3eb 100644 --- a/samples/subsys/ipc/ipc_service/icmsg/sysbuild.cmake +++ b/samples/subsys/ipc/ipc_service/icmsg/sysbuild.cmake @@ -12,3 +12,6 @@ ExternalZephyrProject_Add( SOURCE_DIR ${APP_DIR}/remote BOARD ${SB_CONFIG_REMOTE_BOARD} ) + +native_simulator_set_child_images(${DEFAULT_IMAGE} remote) +native_simulator_set_final_executable(${DEFAULT_IMAGE}) diff --git a/samples/subsys/ipc/ipc_service/multi_endpoint/CMakeLists.txt b/samples/subsys/ipc/ipc_service/multi_endpoint/CMakeLists.txt index c167dd5375b..fca156d9fe2 100644 --- a/samples/subsys/ipc/ipc_service/multi_endpoint/CMakeLists.txt +++ b/samples/subsys/ipc/ipc_service/multi_endpoint/CMakeLists.txt @@ -8,7 +8,8 @@ cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -if(NOT CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP) +if(NOT CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP AND + NOT CONFIG_BOARD_NRF5340BSIM_NRF5340_CPUAPP ) message(FATAL_ERROR "${BOARD} is not supported for this sample") endif() diff --git a/samples/subsys/ipc/ipc_service/multi_endpoint/Kconfig.sysbuild b/samples/subsys/ipc/ipc_service/multi_endpoint/Kconfig.sysbuild index d0849e37dde..5e4c6d497cf 100644 --- a/samples/subsys/ipc/ipc_service/multi_endpoint/Kconfig.sysbuild +++ b/samples/subsys/ipc/ipc_service/multi_endpoint/Kconfig.sysbuild @@ -7,3 +7,4 @@ source "share/sysbuild/Kconfig" config NET_CORE_BOARD string default "nrf5340dk/nrf5340/cpunet" if $(BOARD) = "nrf5340dk" + default "nrf5340bsim/nrf5340/cpunet" if $(BOARD) = "nrf5340bsim" diff --git a/samples/subsys/ipc/ipc_service/multi_endpoint/boards/nrf5340bsim_nrf5340_cpuapp.overlay b/samples/subsys/ipc/ipc_service/multi_endpoint/boards/nrf5340bsim_nrf5340_cpuapp.overlay new file mode 100644 index 00000000000..53c9b68afe7 --- /dev/null +++ b/samples/subsys/ipc/ipc_service/multi_endpoint/boards/nrf5340bsim_nrf5340_cpuapp.overlay @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "nrf5340dk_nrf5340_cpuapp.overlay" diff --git a/samples/subsys/ipc/ipc_service/multi_endpoint/remote/boards/nrf5340bsim_nrf5340_cpunet.overlay b/samples/subsys/ipc/ipc_service/multi_endpoint/remote/boards/nrf5340bsim_nrf5340_cpunet.overlay new file mode 100644 index 00000000000..c5194cf93cd --- /dev/null +++ b/samples/subsys/ipc/ipc_service/multi_endpoint/remote/boards/nrf5340bsim_nrf5340_cpunet.overlay @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "nrf5340dk_nrf5340_cpunet.overlay" diff --git a/samples/subsys/ipc/ipc_service/multi_endpoint/sample.yaml b/samples/subsys/ipc/ipc_service/multi_endpoint/sample.yaml index b05c8f001f2..f808c95252e 100644 --- a/samples/subsys/ipc/ipc_service/multi_endpoint/sample.yaml +++ b/samples/subsys/ipc/ipc_service/multi_endpoint/sample.yaml @@ -14,15 +14,21 @@ common: - "IPC-service HOST \\[INST 1\\] demo ended\\." tests: sample.ipc.multi_endpoint: - platform_allow: nrf5340dk/nrf5340/cpuapp + platform_allow: + - nrf5340dk/nrf5340/cpuapp + - nrf5340bsim/nrf5340/cpuapp integration_platforms: - nrf5340dk/nrf5340/cpuapp + - nrf5340bsim/nrf5340/cpuapp tags: ipc sysbuild: true sample.ipc.multi_endpoint.icbmsg: - platform_allow: nrf5340dk/nrf5340/cpuapp + platform_allow: + - nrf5340dk/nrf5340/cpuapp + - nrf5340bsim/nrf5340/cpuapp integration_platforms: - nrf5340dk/nrf5340/cpuapp + - nrf5340bsim/nrf5340/cpuapp tags: ipc sysbuild: true extra_args: diff --git a/samples/subsys/ipc/ipc_service/multi_endpoint/sysbuild.cmake b/samples/subsys/ipc/ipc_service/multi_endpoint/sysbuild.cmake index d0d79b8f240..9117870be8a 100644 --- a/samples/subsys/ipc/ipc_service/multi_endpoint/sysbuild.cmake +++ b/samples/subsys/ipc/ipc_service/multi_endpoint/sysbuild.cmake @@ -12,3 +12,6 @@ ExternalZephyrProject_Add( SOURCE_DIR ${APP_DIR}/remote BOARD ${SB_CONFIG_NET_CORE_BOARD} ) + +native_simulator_set_child_images(${DEFAULT_IMAGE} remote) +native_simulator_set_final_executable(${DEFAULT_IMAGE}) diff --git a/samples/subsys/ipc/ipc_service/static_vrings/CMakeLists.txt b/samples/subsys/ipc/ipc_service/static_vrings/CMakeLists.txt index 4deb07c4789..588bfe71dd0 100644 --- a/samples/subsys/ipc/ipc_service/static_vrings/CMakeLists.txt +++ b/samples/subsys/ipc/ipc_service/static_vrings/CMakeLists.txt @@ -12,6 +12,7 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/../remote/zephyr) if(NOT (CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP OR + CONFIG_BOARD_NRF5340BSIM_NRF5340_CPUAPP OR CONFIG_BOARD_LPCXPRESSO55S69_LPC55S69_CPU0 OR CONFIG_BOARD_MIMXRT1160_EVK_MIMXRT1166_CM7 OR CONFIG_BOARD_MIMXRT1170_EVK_MIMXRT1176_CM7 diff --git a/samples/subsys/ipc/ipc_service/static_vrings/Kconfig.sysbuild b/samples/subsys/ipc/ipc_service/static_vrings/Kconfig.sysbuild index a1214db3284..4f9caa82501 100644 --- a/samples/subsys/ipc/ipc_service/static_vrings/Kconfig.sysbuild +++ b/samples/subsys/ipc/ipc_service/static_vrings/Kconfig.sysbuild @@ -8,6 +8,7 @@ source "share/sysbuild/Kconfig" config NET_CORE_BOARD string default "nrf5340dk/nrf5340/cpunet" if $(BOARD) = "nrf5340dk" + default "nrf5340bsim/nrf5340/cpunet" if $(BOARD) = "nrf5340bsim" default "lpcxpresso55s69/lpc55s69/cpu1" if $(BOARD) = "lpcxpresso55s69" default "mimxrt1160_evk/mimxrt1166/cm4" if $(BOARD) = "mimxrt1160_evk" default "mimxrt1170_evk/mimxrt1176/cm4" if $(BOARD) = "mimxrt1170_evk" diff --git a/samples/subsys/ipc/ipc_service/static_vrings/boards/nrf5340bsim_nrf5340_cpuapp.overlay b/samples/subsys/ipc/ipc_service/static_vrings/boards/nrf5340bsim_nrf5340_cpuapp.overlay new file mode 100644 index 00000000000..53c9b68afe7 --- /dev/null +++ b/samples/subsys/ipc/ipc_service/static_vrings/boards/nrf5340bsim_nrf5340_cpuapp.overlay @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "nrf5340dk_nrf5340_cpuapp.overlay" diff --git a/samples/subsys/ipc/ipc_service/static_vrings/remote/boards/nrf5340bsim_nrf5340_cpunet.overlay b/samples/subsys/ipc/ipc_service/static_vrings/remote/boards/nrf5340bsim_nrf5340_cpunet.overlay new file mode 100644 index 00000000000..57176705564 --- /dev/null +++ b/samples/subsys/ipc/ipc_service/static_vrings/remote/boards/nrf5340bsim_nrf5340_cpunet.overlay @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "nrf5340dk_nrf5340_cpunet.overlay" diff --git a/samples/subsys/ipc/ipc_service/static_vrings/sample.yaml b/samples/subsys/ipc/ipc_service/static_vrings/sample.yaml index 911b3624e44..d15df7b803e 100644 --- a/samples/subsys/ipc/ipc_service/static_vrings/sample.yaml +++ b/samples/subsys/ipc/ipc_service/static_vrings/sample.yaml @@ -4,12 +4,14 @@ tests: sample.ipc.static_vrings: platform_allow: - nrf5340dk/nrf5340/cpuapp + - nrf5340bsim/nrf5340/cpuapp - lpcxpresso55s69/lpc55s69/cpu0 - mimxrt1160_evk/mimxrt1166/cm7 - mimxrt1170_evk/mimxrt1176/cm7 - mimxrt1170_evk@B/mimxrt1176/cm7 integration_platforms: - nrf5340dk/nrf5340/cpuapp + - nrf5340bsim/nrf5340/cpuapp tags: ipc sysbuild: true harness: console diff --git a/samples/subsys/ipc/ipc_service/static_vrings/sysbuild.cmake b/samples/subsys/ipc/ipc_service/static_vrings/sysbuild.cmake index 2e99a95d3c3..cf5de9dd941 100644 --- a/samples/subsys/ipc/ipc_service/static_vrings/sysbuild.cmake +++ b/samples/subsys/ipc/ipc_service/static_vrings/sysbuild.cmake @@ -21,3 +21,6 @@ ExternalZephyrProject_Add( # remote core's build, such as the output image's LMA add_dependencies(${DEFAULT_IMAGE} ${REMOTE_APP}) sysbuild_add_dependencies(CONFIGURE ${DEFAULT_IMAGE} ${REMOTE_APP}) + +native_simulator_set_child_images(${DEFAULT_IMAGE} remote) +native_simulator_set_final_executable(${DEFAULT_IMAGE}) diff --git a/soc/native/inf_clock/CMakeLists.txt b/soc/native/inf_clock/CMakeLists.txt index 7f9d09b2c34..494ea4de774 100644 --- a/soc/native/inf_clock/CMakeLists.txt +++ b/soc/native/inf_clock/CMakeLists.txt @@ -8,6 +8,7 @@ zephyr_library_compile_definitions(NO_POSIX_CHEATS) zephyr_library_sources( soc.c native_tasks.c + native_remap.c ) zephyr_library_include_directories( diff --git a/soc/native/inf_clock/native_remap.c b/soc/native/inf_clock/native_remap.c new file mode 100644 index 00000000000..4aa6bd1129e --- /dev/null +++ b/soc/native/inf_clock/native_remap.c @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include + +/** + * Dummy version which does nothing + * Boards which do not have a better implementation can use this + */ +__weak bool native_emb_addr_remap(void **addr) +{ + return false; +} diff --git a/soc/native/inf_clock/soc.h b/soc/native/inf_clock/soc.h index 36d54ac3f72..c7de6c22802 100644 --- a/soc/native/inf_clock/soc.h +++ b/soc/native/inf_clock/soc.h @@ -7,6 +7,7 @@ #ifndef _POSIX_SOC_INF_CLOCK_SOC_H #define _POSIX_SOC_INF_CLOCK_SOC_H +#include #include #include "board_soc.h" #include "posix_soc.h" @@ -18,6 +19,20 @@ extern "C" { void posix_soc_clean_up(void); +/** + * Remap an embedded device address, into an address which can be used in the simulated native + * board. + * + * If the provided address is not in a range known to this function it will not be modified and the + * function will return false. + * Otherwise the provided address pointer will be modified, and true returned. + * + * Note: The SOC provides a dummy version of this function which does nothing, + * so all boards will have an implementation. + * It is optional for boards to provide one if desired. + */ +bool native_emb_addr_remap(void **addr); + #ifdef __cplusplus } #endif diff --git a/subsys/ipc/ipc_service/backends/ipc_icbmsg.c b/subsys/ipc/ipc_service/backends/ipc_icbmsg.c index 70c4c4c362f..9fd7752999f 100644 --- a/subsys/ipc/ipc_service/backends/ipc_icbmsg.c +++ b/subsys/ipc/ipc_service/backends/ipc_icbmsg.c @@ -87,6 +87,13 @@ #include #include +#if defined(CONFIG_ARCH_POSIX) +#include +#define MAYBE_CONST +#else +#define MAYBE_CONST const +#endif + LOG_MODULE_REGISTER(ipc_icbmsg, CONFIG_IPC_SERVICE_BACKEND_ICBMSG_LOG_LEVEL); @@ -1238,12 +1245,17 @@ static int release_rx_buffer(const struct device *instance, void *token, void *d */ static int backend_init(const struct device *instance) { - const struct icbmsg_config *conf = instance->config; + MAYBE_CONST struct icbmsg_config *conf = (struct icbmsg_config *)instance->config; struct backend_data *dev_data = instance->data; #ifdef CONFIG_MULTITHREADING static K_THREAD_STACK_DEFINE(ep_bound_work_q_stack, EP_BOUND_WORK_Q_STACK_SIZE); static bool is_work_q_started; +#if defined(CONFIG_ARCH_POSIX) + native_emb_addr_remap((void **)&conf->tx.blocks_ptr); + native_emb_addr_remap((void **)&conf->rx.blocks_ptr); +#endif + if (!is_work_q_started) { k_work_queue_init(&ep_bound_work_q); k_work_queue_start(&ep_bound_work_q, ep_bound_work_q_stack, @@ -1401,7 +1413,7 @@ const static struct ipc_service_backend backend_ops = { .rx_pb = &rx_icbmsg_pb_##i, \ } \ }; \ - static const struct icbmsg_config backend_config_##i = \ + static MAYBE_CONST struct icbmsg_config backend_config_##i = \ { \ .control_config = { \ .mbox_tx = MBOX_DT_SPEC_INST_GET(i, tx), \ diff --git a/subsys/ipc/ipc_service/lib/icmsg.c b/subsys/ipc/ipc_service/lib/icmsg.c index e73bdaaa723..9de8a99ad58 100644 --- a/subsys/ipc/ipc_service/lib/icmsg.c +++ b/subsys/ipc/ipc_service/lib/icmsg.c @@ -270,16 +270,14 @@ int icmsg_open(const struct icmsg_config_t *conf, k_mutex_init(&dev_data->tx_lock); #endif - int ret = pbuf_init(dev_data->tx_pb); + int ret = pbuf_tx_init(dev_data->tx_pb); if (ret < 0) { __ASSERT(false, "Incorrect configuration"); return ret; } - /* Initialize local copies of rx_pb. */ - dev_data->rx_pb->data.wr_idx = 0; - dev_data->rx_pb->data.rd_idx = 0; + (void)pbuf_rx_init(dev_data->rx_pb); ret = pbuf_write(dev_data->tx_pb, magic, sizeof(magic)); diff --git a/subsys/ipc/ipc_service/lib/icmsg_me.c b/subsys/ipc/ipc_service/lib/icmsg_me.c index b4d384e6bb0..8606b56161e 100644 --- a/subsys/ipc/ipc_service/lib/icmsg_me.c +++ b/subsys/ipc/ipc_service/lib/icmsg_me.c @@ -4,6 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L + #include #include diff --git a/subsys/ipc/ipc_service/lib/pbuf.c b/subsys/ipc/ipc_service/lib/pbuf.c index 1164f814ca0..c744946f4ca 100644 --- a/subsys/ipc/ipc_service/lib/pbuf.c +++ b/subsys/ipc/ipc_service/lib/pbuf.c @@ -11,6 +11,10 @@ #include #include +#if defined(CONFIG_ARCH_POSIX) +#include +#endif + /* Helper funciton for getting numer of bytes being written to the bufer. */ static uint32_t idx_occupied(uint32_t len, uint32_t wr_idx, uint32_t rd_idx) { @@ -54,11 +58,23 @@ static int validate_cfg(const struct pbuf_cfg *cfg) return 0; } -int pbuf_init(struct pbuf *pb) +#if defined(CONFIG_ARCH_POSIX) +void pbuf_native_addr_remap(struct pbuf *pb) +{ + native_emb_addr_remap((void **)&pb->cfg->rd_idx_loc); + native_emb_addr_remap((void **)&pb->cfg->wr_idx_loc); + native_emb_addr_remap((void **)&pb->cfg->data_loc); +} +#endif + +int pbuf_tx_init(struct pbuf *pb) { if (validate_cfg(pb->cfg) != 0) { return -EINVAL; } +#if defined(CONFIG_ARCH_POSIX) + pbuf_native_addr_remap(pb); +#endif /* Initialize local copy of indexes. */ pb->data.wr_idx = 0; @@ -77,6 +93,22 @@ int pbuf_init(struct pbuf *pb) return 0; } +int pbuf_rx_init(struct pbuf *pb) +{ + if (validate_cfg(pb->cfg) != 0) { + return -EINVAL; + } +#if defined(CONFIG_ARCH_POSIX) + pbuf_native_addr_remap(pb); +#endif + + /* Initialize local copy of indexes. */ + pb->data.wr_idx = 0; + pb->data.rd_idx = 0; + + return 0; +} + int pbuf_write(struct pbuf *pb, const char *data, uint16_t len) { if (pb == NULL || len == 0 || data == NULL) { diff --git a/tests/subsys/ipc/pbuf/src/main.c b/tests/subsys/ipc/pbuf/src/main.c index d4bbb9db4fe..4af9da68c47 100644 --- a/tests/subsys/ipc/pbuf/src/main.c +++ b/tests/subsys/ipc/pbuf/src/main.c @@ -48,7 +48,7 @@ ZTEST(test_pbuf, test_rw) * order to avoid clang complains about memory_area not being constant * expression. */ - static const struct pbuf_cfg cfg = PBUF_CFG_INIT(memory_area, MEM_AREA_SZ, 0); + static PBUF_MAYBE_CONST struct pbuf_cfg cfg = PBUF_CFG_INIT(memory_area, MEM_AREA_SZ, 0); static struct pbuf pb = { .cfg = &cfg, @@ -58,7 +58,7 @@ ZTEST(test_pbuf, test_rw) write_buf[i] = i+1; } - zassert_equal(pbuf_init(&pb), 0); + zassert_equal(pbuf_tx_init(&pb), 0); /* Write MSGA_SZ bytes packet. */ ret = pbuf_write(&pb, write_buf, MSGA_SZ); @@ -115,9 +115,9 @@ ZTEST(test_pbuf, test_retcodes) * order to avoid clang complains about memory_area not being constant * expression. */ - static const struct pbuf_cfg cfg0 = PBUF_CFG_INIT(memory_area, MEM_AREA_SZ, 32); - static const struct pbuf_cfg cfg1 = PBUF_CFG_INIT(memory_area, MEM_AREA_SZ, 0); - static const struct pbuf_cfg cfg2 = PBUF_CFG_INIT(memory_area, 20, 4); + static PBUF_MAYBE_CONST struct pbuf_cfg cfg0 = PBUF_CFG_INIT(memory_area, MEM_AREA_SZ, 32); + static PBUF_MAYBE_CONST struct pbuf_cfg cfg1 = PBUF_CFG_INIT(memory_area, MEM_AREA_SZ, 0); + static PBUF_MAYBE_CONST struct pbuf_cfg cfg2 = PBUF_CFG_INIT(memory_area, 20, 4); static struct pbuf pb0 = { .cfg = &cfg0, @@ -132,9 +132,9 @@ ZTEST(test_pbuf, test_retcodes) }; /* Initialize buffers. */ - zassert_equal(pbuf_init(&pb0), 0); - zassert_equal(pbuf_init(&pb1), 0); - zassert_equal(pbuf_init(&pb2), 0); + zassert_equal(pbuf_tx_init(&pb0), 0); + zassert_equal(pbuf_tx_init(&pb1), 0); + zassert_equal(pbuf_tx_init(&pb2), 0); print_pbuf_info(&pb0); print_pbuf_info(&pb1); @@ -268,13 +268,13 @@ ZTEST(test_pbuf, test_stress) * order to avoid clang complains about buffer not being constant * expression. */ - static const struct pbuf_cfg cfg = PBUF_CFG_INIT(buffer, MEM_AREA_SZ, 4); + static PBUF_MAYBE_CONST struct pbuf_cfg cfg = PBUF_CFG_INIT(buffer, MEM_AREA_SZ, 4); static struct pbuf pb = { .cfg = &cfg, }; - zassert_equal(pbuf_init(&pb), 0); + zassert_equal(pbuf_tx_init(&pb), 0); ctx.pbuf = &pb; ctx.wr_cnt = 0; ctx.rd_cnt = 0; diff --git a/west.yml b/west.yml index ee8ed5eaae5..7e3291d2123 100644 --- a/west.yml +++ b/west.yml @@ -300,7 +300,7 @@ manifest: groups: - tools - name: nrf_hw_models - revision: d2a119a9c7600ce06033a794de042e0ad9a38702 + revision: bf8e45bd1f870e49cc15392e045c28d54ea12285 path: modules/bsim_hw_models/nrf_hw_models - name: open-amp revision: b735edbc739ad59156eb55bb8ce2583d74537719