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 <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
Alberto Escolar Piedras 2024-09-12 11:20:06 +02:00 committed by Anas Nashif
parent 942fa67a45
commit 5efe751240
5 changed files with 45 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,12 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdbool.h>
#include "NHW_misc.h"
bool native_emb_addr_remap(void **addr)
{
return nhw_convert_RAM_addr(addr);
}

View File

@ -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(

View File

@ -0,0 +1,16 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdbool.h>
#include <zephyr/toolchain.h>
/**
* 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;
}

View File

@ -7,6 +7,7 @@
#ifndef _POSIX_SOC_INF_CLOCK_SOC_H
#define _POSIX_SOC_INF_CLOCK_SOC_H
#include <stdbool.h>
#include <zephyr/toolchain.h>
#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