Skip to content

Commit 728faee

Browse files
samples: peripheral: added new command to control channel sequence
we see value in being able to run a custom sweep in the tx_with_sleep mode where not all channels are used, or even where the sequence isn't a strictly rising sweep. added a new command that allows users to configure if they want a custom sweep sequence with a custom amount of channels in the sweep. also added a new command to print out this channel sequence so that users can verify that it is configured correctly and check initial array configuration. Signed-off-by: Thomas Johansen <thomas.johansen@nordicsemi.no>
1 parent e267d1a commit 728faee

3 files changed

Lines changed: 98 additions & 23 deletions

File tree

samples/peripheral/radio_test/src/radio_cmd.c

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -672,11 +672,9 @@ static int cmd_tx_sweep_with_sleep_start(const struct shell *shell, size_t argc,
672672
memset(&test_config, 0, sizeof(test_config));
673673
test_config.type = TX_SWEEP_WITH_SLEEP;
674674
test_config.mode = config.mode;
675-
test_config.params.tx_sweep_duty_cycle.channel_index_start = 0;
676-
test_config.params.tx_sweep_duty_cycle.channel_index_end = 71;
677-
test_config.params.tx_sweep_duty_cycle.t_tx_us = config.t_tx_us;
678-
test_config.params.tx_sweep_duty_cycle.t_sleep_us = config.t_sleep_us;
679-
test_config.params.tx_sweep_duty_cycle.txpower = config.txpower;
675+
test_config.params.tx_sweep_with_sleep.t_tx_us = config.t_tx_us;
676+
test_config.params.tx_sweep_with_sleep.t_sleep_us = config.t_sleep_us;
677+
test_config.params.tx_sweep_with_sleep.txpower = config.txpower;
680678

681679
radio_test_start(&test_config);
682680

@@ -686,6 +684,58 @@ static int cmd_tx_sweep_with_sleep_start(const struct shell *shell, size_t argc,
686684
return 0;
687685
}
688686

687+
static int cmd_set_channel_sequence(const struct shell *shell, size_t argc,
688+
char **argv)
689+
{
690+
if (argc == 1) {
691+
shell_help(shell);
692+
return SHELL_CMD_HELP_PRINTED;
693+
}
694+
695+
uint8_t sequence_length = argc - 1;
696+
697+
if (sequence_length > 80) {
698+
shell_error(shell, "Too many channels in array, %i is larger than 80",
699+
sequence_length);
700+
}
701+
702+
for (uint8_t i = 0; i < sequence_length; i++) {
703+
int channel = atoi(argv[i + 1]);
704+
705+
if (channel > 80 || channel < 0) {
706+
shell_error(shell, "Channel number %i with value %i is out of range. "
707+
"Allowed range for channels is 0 to 80", i,
708+
channel);
709+
return -EINVAL;
710+
}
711+
}
712+
713+
struct radio_test_channel_sequence *channel_sequence = radio_test_channel_sequence_get();
714+
715+
channel_sequence->sequence_length = sequence_length;
716+
for (uint8_t i = 0; i < sequence_length; i++) {
717+
uint8_t channel = atoi(argv[i + 1]);
718+
719+
channel_sequence->sequence_array[i] = channel;
720+
}
721+
return 0;
722+
}
723+
724+
static int cmd_print_channel_sequence(const struct shell *shell, size_t argc, char **argv)
725+
{
726+
struct radio_test_channel_sequence *channel_sequence = radio_test_channel_sequence_get();
727+
728+
shell_print(shell, "Channel Sequence length: %i", channel_sequence->sequence_length);
729+
shell_fprintf_normal(shell, "Channel Sequence: [%i", channel_sequence->sequence_array[0]);
730+
731+
for (uint8_t i = 1; i < channel_sequence->sequence_length; i++) {
732+
shell_fprintf_normal(shell, ", %i", channel_sequence->sequence_array[i]);
733+
}
734+
735+
shell_print(shell, "]");
736+
return 0;
737+
}
738+
689739
static int cmd_rx_start(const struct shell *shell, size_t argc, char **argv)
690740
{
691741
if (test_in_progress) {
@@ -1530,6 +1580,13 @@ SHELL_CMD_REGISTER(start_tx_sweep_with_sleep, NULL,
15301580
"Start TX sweep with sleep cycle, "
15311581
"<tx_time> (us) <sleep_time> (us)",
15321582
cmd_tx_sweep_with_sleep_start);
1583+
SHELL_CMD_REGISTER(set_channel_sequence, NULL,
1584+
"Set a custom hopping sequence for TX "
1585+
"<sequence_of_up_to_80_channels>",
1586+
cmd_set_channel_sequence);
1587+
SHELL_CMD_REGISTER(print_channel_sequence, NULL,
1588+
"Print the custom hopping sequence for TX.",
1589+
cmd_print_channel_sequence);
15331590
SHELL_CMD_REGISTER(start_rx, NULL, "Start RX", cmd_rx_start);
15341591
SHELL_CMD_REGISTER(print_rx, NULL, "Print RX payload", cmd_print_payload);
15351592
#if defined(TOGGLE_DCDC_HELP)

samples/peripheral/radio_test/src/radio_test.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,13 @@ static uint32_t rx_packet_cnt;
108108
static uint8_t current_channel;
109109

110110
/* Radio TX Sweep with sleep channel array */
111-
const static uint8_t channel_array[72] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
111+
static struct radio_test_channel_sequence channel_sequence = {
112+
.sequence_length = 72,
113+
.sequence_array = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
112114
17, 18, 19, 20, 21, 22, 23, 24, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
113115
42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
114-
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78};
116+
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78}
117+
};
115118

116119
/* Timer used for channel sweeps and tx with duty cycle. */
117120
static nrfx_timer_t timer =
@@ -1142,9 +1145,9 @@ void radio_test_start(const struct radio_test_config *config)
11421145
config->params.modulated_tx_duty_cycle.duty_cycle);
11431146
break;
11441147
case TX_SWEEP_WITH_SLEEP:
1145-
radio_tx_sweep_with_sleep(config->params.tx_sweep_duty_cycle.txpower,
1146-
config->params.tx_sweep_duty_cycle.t_tx_us,
1147-
config->params.tx_sweep_duty_cycle.t_sleep_us);
1148+
radio_tx_sweep_with_sleep(config->params.tx_sweep_with_sleep.txpower,
1149+
config->params.tx_sweep_with_sleep.t_tx_us,
1150+
config->params.tx_sweep_with_sleep.t_sleep_us);
11481151
break;
11491152
}
11501153

@@ -1273,14 +1276,14 @@ static void timer_handler(nrf_timer_event_t event_type, void *context)
12731276
sweep_processing = true;
12741277

12751278
/* disable radio after tone */
1276-
radio_unmodulated_tx_carrier_radio_setup(NRF_RADIO_MODE_BLE_1MBIT,
1277-
config->params.tx_sweep_duty_cycle.txpower,
1278-
channel_array[current_channel],
1279-
false);
1279+
radio_unmodulated_tx_carrier_radio_setup(
1280+
NRF_RADIO_MODE_BLE_1MBIT,
1281+
config->params.tx_sweep_with_sleep.txpower,
1282+
channel_sequence.sequence_array[current_channel], false);
12801283

12811284
/* set up next channel */
1282-
channel_start = config->params.tx_sweep_duty_cycle.channel_index_start;
1283-
channel_end = config->params.tx_sweep_duty_cycle.channel_index_end;
1285+
channel_start = 0;
1286+
channel_end = channel_sequence.sequence_length - 1;
12841287
} else {
12851288
printk("Unexpected test type: %d\n", config->type);
12861289
return;
@@ -1404,3 +1407,8 @@ int radio_test_init(struct radio_test_config *config)
14041407

14051408
return 0;
14061409
}
1410+
1411+
struct radio_test_channel_sequence *radio_test_channel_sequence_get(void)
1412+
{
1413+
return &channel_sequence;
1414+
}

samples/peripheral/radio_test/src/radio_test.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,12 @@ struct radio_test_config {
181181
/** Radio output power. */
182182
int8_t txpower;
183183

184-
/** Radio start channel index. */
185-
uint8_t channel_index_start;
186-
187-
/** Radio end channel index. */
188-
uint8_t channel_index_end;
189-
190184
/** Radio transmission time in us. */
191185
uint16_t t_tx_us;
192186

193187
/** Radio sleep time in us. */
194188
uint16_t t_sleep_us;
195-
} tx_sweep_duty_cycle;
189+
} tx_sweep_with_sleep;
196190
} params;
197191

198192
#if CONFIG_FEM
@@ -216,6 +210,15 @@ struct radio_rx_stats {
216210
uint32_t packet_cnt;
217211
};
218212

213+
/**@brief Configurable sequence for TX with sleep. */
214+
struct radio_test_channel_sequence {
215+
/** Length of configurable sequence. */
216+
uint8_t sequence_length;
217+
218+
/** Configurable sequence contents. */
219+
uint8_t sequence_array[80];
220+
};
221+
219222
/**
220223
* @brief Function for initializing the Radio Test module.
221224
*
@@ -254,4 +257,11 @@ void radio_rx_stats_get(struct radio_rx_stats *rx_stats);
254257
*/
255258
void toggle_dcdc_state(uint8_t dcdc_state);
256259

260+
/**
261+
* @brief Function for getting the radio_test_channel_sequence for the TX sweep with sleep.
262+
*
263+
* @return Pointer to the static channel_sequence in the radio_test
264+
*/
265+
struct radio_test_channel_sequence *radio_test_channel_sequence_get(void);
266+
257267
#endif /* RADIO_TEST_H_ */

0 commit comments

Comments
 (0)