samples: nrf53_sync_rtc: Add support in nrf5340bsim

Add support for this sample in the simulated nrf5340

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
Alberto Escolar Piedras 2023-10-17 17:16:52 +02:00 committed by Carles Cufí
parent 9dabc55c3e
commit 851e5cdbe2
4 changed files with 34 additions and 3 deletions

View File

@ -9,6 +9,8 @@ set(NET_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/sync_rtc_net-prefix/src/sync_rtc_
if("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpuapp")
set(BOARD_REMOTE "nrf5340dk_nrf5340_cpunet")
elseif("${BOARD}" STREQUAL "nrf5340bsim_nrf5340_cpuapp")
set(BOARD_REMOTE "nrf5340bsim_nrf5340_cpunet")
else()
message(FATAL_ERROR "${BOARD} is not supported for this sample")
endif()
@ -22,6 +24,15 @@ enable_language(C ASM)
target_sources(app PRIVATE src/main.c)
set(EXTRA_CMAKE_ARGS "")
if("${BOARD}" STREQUAL "nrf5340bsim_nrf5340_cpuapp")
set(EXTRA_CMAKE_ARGS
"-DCONFIG_NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS=\"${CMAKE_BINARY_DIR}/zephyr/${KERNEL_ELF_NAME}\"")
message(NOTICE "\nFinal executable including both CPU's images will be:\n"
"${NET_ZEPHYR_DIR}/${KERNEL_EXE_NAME}\n")
endif()
include(ExternalProject)
ExternalProject_Add(
@ -31,7 +42,9 @@ ExternalProject_Add(
CMAKE_CACHE_ARGS -DBOARD:STRING=${BOARD_REMOTE}
CMAKE_CACHE_ARGS -DDTC_OVERLAY_FILE:STRING=${NET_DTC_OVERLAY_FILE}
CMAKE_CACHE_ARGS -DEXTRA_CONF_FILE:STRING=${NET_OVERLAY_CONF}
CMAKE_ARGS "${EXTRA_CMAKE_ARGS}"
BUILD_BYPRODUCTS "${NET_ZEPHYR_DIR}/${KERNEL_BIN_NAME}"
# NB: Do we need to pass on more CMake variables?
BUILD_ALWAYS True
DEPENDS ${logical_target_for_zephyr_elf}
)

View File

@ -5,7 +5,8 @@
cmake_minimum_required(VERSION 3.20.0)
if("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpunet")
if(("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpunet") OR
("${BOARD}" STREQUAL "nrf5340bsim_nrf5340_cpunet"))
message(INFO " ${BOARD} compile as slave in this sample")
else()
message(FATAL_ERROR "${BOARD} is not supported for this sample")

View File

@ -13,6 +13,13 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main);
#if (CONFIG_SOC_SERIES_BSIM_NRFXX)
extern uint32_t shared_cell_buffer;
static uint32_t shared_cell = (uintptr_t)&shared_cell_buffer;
#else
static uint32_t shared_cell = 0x20070000;
#endif
static void sync_callback(void)
{
int32_t offset = z_nrf_rtc_timer_nrf53net_offset_get();
@ -20,7 +27,6 @@ static void sync_callback(void)
__ASSERT(offset >= 0, "Synchronization should be completed");
uint32_t timestamp = sys_clock_tick_get_32() + offset;
uint32_t shared_cell = 0x20070000;
uint32_t app_timestamp = *(volatile uint32_t *)shared_cell;
LOG_INF("Local timestamp: %u, application core timestamp: %u",

View File

@ -11,11 +11,22 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main);
#if (CONFIG_SOC_SERIES_BSIM_NRFXX)
#include "nsi_cpu_if.h"
/* For simulation, we can define shared memory variables linkable from
* other MCUs just by using NATIVE_SIMULATOR_IF
*/
NATIVE_SIMULATOR_IF uint32_t shared_cell_buffer;
static uint32_t shared_cell = (uintptr_t)&shared_cell_buffer;
#else
static uint32_t shared_cell = 0x20070000;
#endif
static void timeout_handler(struct k_timer *timer)
{
nrf_ipc_task_t task = offsetof(NRF_IPC_Type, TASKS_SEND[2]);
uint32_t now = sys_clock_tick_get_32();
uint32_t shared_cell = 0x20070000;
*(volatile uint32_t *)shared_cell = now;
nrf_ipc_task_trigger(NRF_IPC, task);