Browse Source

boards native bsim: Provide control of disconnection on exit

Allow either programatically from the test/code or from the command
line to chose if this executable exiting should terminate the
whole simulation, or if it should only disconnect the device.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
pull/90168/head
Alberto Escolar Piedras 2 months ago committed by Benjamin Cabé
parent
commit
5c9c3497ed
  1. 22
      boards/native/nrf_bsim/common/bsim_control.h
  2. 40
      boards/native/nrf_bsim/common/runner_hooks.c

22
boards/native/nrf_bsim/common/bsim_control.h

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef BOARDS_NATIVE_BSIM_COMMON_BSIM_CONTROL_H
#define BOARDS_NATIVE_BSIM_COMMON_BSIM_CONTROL_H
#include <stdint.h>
#include "bsim_args_runner.h"
#ifdef __cplusplus
extern "C" {
#endif
void bsim_set_terminate_on_exit(bool terminate);
#ifdef __cplusplus
}
#endif
#endif /* BOARDS_NATIVE_BSIM_COMMON_BSIM_CONTROL_H */

40
boards/native/nrf_bsim/common/runner_hooks.c

@ -16,6 +16,20 @@ @@ -16,6 +16,20 @@
#include "NRF_HWLowL.h"
#include "bsim_args_runner.h"
static bool bsim_disconnect_on_exit;
/*
* Control what will happen to the overall simulation when this executable exists.
* If <terminate> is true (default behavior) the Phy will be told to end the simulation
* when this executable exits.
* If <terminate> is false, this device will just disconnect, but let the simulation continue
* otherwise.
*/
void bsim_set_terminate_on_exit(bool terminate)
{
bsim_disconnect_on_exit = !terminate;
}
static uint8_t main_clean_up_trace_wrap(void)
{
return nsi_exit_inner(0);
@ -40,9 +54,33 @@ NSI_TASK(open_dumps, PRE_BOOT_2, 500); @@ -40,9 +54,33 @@ NSI_TASK(open_dumps, PRE_BOOT_2, 500);
static void exit_hooks(void)
{
hwll_terminate_simulation();
if (bsim_disconnect_on_exit) {
hwll_disconnect_phy();
} else {
hwll_terminate_simulation();
}
bs_dump_files_close_all();
bs_clean_back_channels();
}
NSI_TASK(exit_hooks, ON_EXIT_PRE, 500);
static void exit_control_args(void)
{
static bs_args_struct_t args_struct_toadd[] = {
{
.option = "disconnect_on_exit",
.type = 'b',
.name = "term",
.dest = (void *)&bsim_disconnect_on_exit,
.descript = "If set to 1, on exit only disconnect this device from the Phy and let "
"the simulation continue. Otherwise (default) on exit terminate the "
"whole simulation."
},
ARG_TABLE_ENDMARKER
};
bs_add_extra_dynargs(args_struct_toadd);
}
NSI_TASK(exit_control_args, PRE_BOOT_1, 10);

Loading…
Cancel
Save