From 5efe751240e4ed14cc30565ff7bc6e68440210fc Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 12 Sep 2024 11:20:06 +0200 Subject: [PATCH] boards native: Add function to remap embedded address Add a function which can be used to remap embedded device address, into addresses which can be used in the simulated native boards. For the nrf_bsim boards we provide an actual implementation. For other boards, we provide an optional dummy version which does nothing. It is up to each board implementation to decide if they want to provide one or use the dummy. Signed-off-by: Alberto Escolar Piedras --- boards/native/nrf_bsim/CMakeLists.txt | 1 + boards/native/nrf_bsim/native_remap.c | 12 ++++++++++++ soc/native/inf_clock/CMakeLists.txt | 1 + soc/native/inf_clock/native_remap.c | 16 ++++++++++++++++ soc/native/inf_clock/soc.h | 15 +++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 boards/native/nrf_bsim/native_remap.c create mode 100644 soc/native/inf_clock/native_remap.c 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/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