Skip to content

Commit 5c9c349

Browse files
aescolarkartben
authored andcommitted
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>
1 parent 2673aa9 commit 5c9c349

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef BOARDS_NATIVE_BSIM_COMMON_BSIM_CONTROL_H
7+
#define BOARDS_NATIVE_BSIM_COMMON_BSIM_CONTROL_H
8+
9+
#include <stdint.h>
10+
#include "bsim_args_runner.h"
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
void bsim_set_terminate_on_exit(bool terminate);
17+
18+
#ifdef __cplusplus
19+
}
20+
#endif
21+
22+
#endif /* BOARDS_NATIVE_BSIM_COMMON_BSIM_CONTROL_H */

boards/native/nrf_bsim/common/runner_hooks.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@
1616
#include "NRF_HWLowL.h"
1717
#include "bsim_args_runner.h"
1818

19+
static bool bsim_disconnect_on_exit;
20+
21+
/*
22+
* Control what will happen to the overall simulation when this executable exists.
23+
* If <terminate> is true (default behavior) the Phy will be told to end the simulation
24+
* when this executable exits.
25+
* If <terminate> is false, this device will just disconnect, but let the simulation continue
26+
* otherwise.
27+
*/
28+
void bsim_set_terminate_on_exit(bool terminate)
29+
{
30+
bsim_disconnect_on_exit = !terminate;
31+
}
32+
1933
static uint8_t main_clean_up_trace_wrap(void)
2034
{
2135
return nsi_exit_inner(0);
@@ -40,9 +54,33 @@ NSI_TASK(open_dumps, PRE_BOOT_2, 500);
4054

4155
static void exit_hooks(void)
4256
{
43-
hwll_terminate_simulation();
57+
if (bsim_disconnect_on_exit) {
58+
hwll_disconnect_phy();
59+
} else {
60+
hwll_terminate_simulation();
61+
}
4462
bs_dump_files_close_all();
4563
bs_clean_back_channels();
4664
}
4765

4866
NSI_TASK(exit_hooks, ON_EXIT_PRE, 500);
67+
68+
static void exit_control_args(void)
69+
{
70+
static bs_args_struct_t args_struct_toadd[] = {
71+
{
72+
.option = "disconnect_on_exit",
73+
.type = 'b',
74+
.name = "term",
75+
.dest = (void *)&bsim_disconnect_on_exit,
76+
.descript = "If set to 1, on exit only disconnect this device from the Phy and let "
77+
"the simulation continue. Otherwise (default) on exit terminate the "
78+
"whole simulation."
79+
},
80+
ARG_TABLE_ENDMARKER
81+
};
82+
83+
bs_add_extra_dynargs(args_struct_toadd);
84+
}
85+
86+
NSI_TASK(exit_control_args, PRE_BOOT_1, 10);

0 commit comments

Comments
 (0)