1 /*
2 * Copyright (c) 2017 Oticon A/S
3 * Copyright (c) 2023 Nordic Semiconductor ASA
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7 #include <stdbool.h>
8 #include <stdlib.h>
9 #include "bs_tracing.h"
10 #include "bstests.h"
11 #include "bs_cmd_line.h"
12 #include "bs_dynargs.h"
13 #include "posix_native_task.h"
14 #include "nsi_tracing.h"
15 #include "nsi_main.h"
16 #include "nsi_cpu_ctrl.h"
17
18 static const char exe_name[] = "nrf_bsim options:";
19
20 static char *testid;
21 static bool cpu_autostart;
22
cmd_testid_found(char * argv,int offset)23 static void cmd_testid_found(char *argv, int offset)
24 {
25 bst_set_testapp_mode(testid);
26 }
27
cmd_testlist_found(char * argv,int offset)28 static void cmd_testlist_found(char *argv, int offset)
29 {
30 bst_print_testslist();
31 nsi_exit(0);
32 }
33
cmd_autostart_found(char * argv,int offset)34 static void cmd_autostart_found(char *argv, int offset)
35 {
36 nsi_cpu_set_auto_start(CONFIG_NATIVE_SIMULATOR_MCU_N, cpu_autostart);
37 }
38
nrfbsim_register_args(void)39 static void nrfbsim_register_args(void)
40 {
41 static bs_args_struct_t args_struct_toadd[] = {
42 {
43 .option = "cpu" STRINGIFY(CONFIG_NATIVE_SIMULATOR_MCU_N) "_testid",
44 .name = "testid",
45 .type = 's',
46 .dest = (void *)&testid,
47 .call_when_found = cmd_testid_found,
48 .descript = "Which of the bs tests shall be run. Run -testslist for more info"
49 },
50 {
51 .is_switch = true,
52 .option = "cpu" STRINGIFY(CONFIG_NATIVE_SIMULATOR_MCU_N) "_testslist",
53 .type = 'b',
54 .call_when_found = cmd_testlist_found,
55 .descript = "Print information about the available bs application tests"
56 },
57 #if (CONFIG_NATIVE_SIMULATOR_MCU_N == CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX)
58 {
59 .option = "testid",
60 .name = "testid",
61 .type = 's',
62 .dest = (void *)&testid,
63 .call_when_found = cmd_testid_found,
64 .descript = "Alias of cpu" STRINGIFY(CONFIG_NATIVE_SIMULATOR_MCU_N) "_testid"
65 },
66 {
67 .is_switch = true,
68 .option = "testslist",
69 .type = 'b',
70 .call_when_found = cmd_testlist_found,
71 .descript = "Alias of cpu" STRINGIFY(CONFIG_NATIVE_SIMULATOR_MCU_N) "_testslist"
72 },
73 #endif
74 {
75 .option = "cpu" STRINGIFY(CONFIG_NATIVE_SIMULATOR_MCU_N) "_autostart",
76 .name = "autostart",
77 .type = 'b',
78 .dest = (void *)&cpu_autostart,
79 .call_when_found = cmd_autostart_found,
80 .descript = "Automatically start CPU" STRINGIFY(CONFIG_NATIVE_SIMULATOR_MCU_N)
81 },
82 ARG_TABLE_ENDMARKER
83 };
84
85 bs_add_extra_dynargs(args_struct_toadd);
86 bs_args_override_exe_name((char *)exe_name);
87 }
88
89 NATIVE_TASK(nrfbsim_register_args, PRE_BOOT_1, 100);
90