Skip to content

Commit 44351f9

Browse files
samples: radio_test: adding new test mode for tx sweep
the current TX sweep command in the radio test uses a near 100% duty cycle. Adding a new version of the TX sweep command that allows us to set a TX time and a "wait" time to use controlled duty cycles. Signed-off-by: Thomas Johansen <thomas.johansen@nordicsemi.no>
1 parent 6daeae1 commit 44351f9

3 files changed

Lines changed: 151 additions & 4 deletions

File tree

samples/peripheral/radio_test/src/radio_cmd.c

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"Toggle DC/DC state regardless of state value"
3232
#endif
3333

34-
3534
/* Radio parameter configuration. */
3635
static struct radio_param_config {
3736
/** Radio transmission pattern. */
@@ -55,6 +54,12 @@ static struct radio_param_config {
5554
/** Duty cycle. */
5655
uint32_t duty_cycle;
5756

57+
/** Radio transmission time in us */
58+
uint16_t t_tx_us;
59+
60+
/** Radio sleep time in us */
61+
uint16_t t_sleep_us;
62+
5863
/**
5964
* Number of packets to be received.
6065
* Set to zero for continuous RX.
@@ -73,6 +78,8 @@ static struct radio_param_config {
7378
.channel_end = 80,
7479
.delay_ms = 10,
7580
.duty_cycle = 50,
81+
.t_tx_us = 80,
82+
.t_sleep_us = 160,
7683
#if CONFIG_FEM
7784
.fem.tx_power_control = FEM_USE_DEFAULT_TX_POWER_CONTROL
7885
#endif /* CONFIG_FEM */
@@ -630,6 +637,60 @@ static int cmd_tx_sweep_start(const struct shell *shell, size_t argc,
630637
return 0;
631638
}
632639

640+
static int cmd_tx_sweep_with_sleep_start(const struct shell *shell, size_t argc,
641+
char **argv)
642+
{
643+
if (argc == 1) {
644+
shell_help(shell);
645+
return SHELL_CMD_HELP_PRINTED;
646+
}
647+
648+
if (argc != 3 && argc != 1) {
649+
shell_error(shell, "%s: bad parameters count", argv[0]);
650+
return -EINVAL;
651+
}
652+
653+
if (argc == 3) {
654+
uint8_t tx_time = atoi(argv[1]);
655+
uint8_t sleep_time = atoi(argv[2]);
656+
657+
const uint8_t min_tx_time_us = 20;
658+
const uint8_t min_sleep_time_us = 80;
659+
660+
if (sleep_time < min_sleep_time_us) {
661+
shell_error(shell,
662+
"Too short sleep time: %ius.\nNeeds to be at least: %ius",
663+
sleep_time, min_sleep_time_us);
664+
return -EINVAL;
665+
}
666+
667+
if (tx_time < min_tx_time_us) {
668+
shell_error(shell, "Too short tx time: %ius.\nNeeds to be at least: %ius",
669+
tx_time, min_tx_time_us);
670+
return -EINVAL;
671+
}
672+
673+
config.t_tx_us = tx_time;
674+
config.t_sleep_us = sleep_time;
675+
}
676+
677+
memset(&test_config, 0, sizeof(test_config));
678+
test_config.type = TX_SWEEP_WITH_DUTY_CYCLE;
679+
test_config.mode = config.mode;
680+
test_config.params.tx_sweep_duty_cycle.channel_index_start = 0;
681+
test_config.params.tx_sweep_duty_cycle.channel_index_end = 71;
682+
test_config.params.tx_sweep_duty_cycle.t_tx_us = config.t_tx_us;
683+
test_config.params.tx_sweep_duty_cycle.t_sleep_us = config.t_sleep_us;
684+
test_config.params.tx_sweep_duty_cycle.txpower = config.txpower;
685+
686+
radio_test_start(&test_config);
687+
688+
test_in_progress = true;
689+
690+
shell_print(shell, "TX sweep with duty cycle");
691+
return 0;
692+
}
693+
633694
static int cmd_rx_start(const struct shell *shell, size_t argc, char **argv)
634695
{
635696
if (test_in_progress) {
@@ -1470,6 +1531,10 @@ SHELL_CMD_REGISTER(parameters_print, NULL,
14701531
cmd_print);
14711532
SHELL_CMD_REGISTER(start_rx_sweep, NULL, "Start RX sweep", cmd_rx_sweep_start);
14721533
SHELL_CMD_REGISTER(start_tx_sweep, NULL, "Start TX sweep", cmd_tx_sweep_start);
1534+
SHELL_CMD_REGISTER(start_tx_sweep_with_sleep, NULL,
1535+
"Start TX sweep with sleep cycle, "
1536+
"<tx_time> (us) <sleep_time> (us)",
1537+
cmd_tx_sweep_with_sleep_start);
14731538
SHELL_CMD_REGISTER(start_rx, NULL, "Start RX", cmd_rx_start);
14741539
SHELL_CMD_REGISTER(print_rx, NULL, "Print RX payload", cmd_print_payload);
14751540
#if defined(TOGGLE_DCDC_HELP)

samples/peripheral/radio_test/src/radio_test.c

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,17 @@
8484
#define TIMER_CC1_MOD_TX_DUTY NRF_TIMER_CC_CHANNEL1
8585
#define TIMER_CC2_FEM_0 NRF_TIMER_CC_CHANNEL2
8686
#define TIMER_CC3_FEM_1 NRF_TIMER_CC_CHANNEL3
87+
#define TIMER_CC4_SWEEP_DUTY NRF_TIMER_CC_CHANNEL4
8788
#if NRF54H_ERRATA_216_PRESENT
8889
#define TIMER_CC7_ERRATA216 NRF_TIMER_CC_CHANNEL7
8990
#endif /* NRF54H_ERRATA_216_PRESENT */
9091

9192
/* RX timeout counted from the last packet received. */
9293
#define RX_PACKET_TIMEOUT_MS 100
9394

95+
/* Ram-up time for radio when using fast ramp. */
96+
#define RADIO_RAMP_UP_FAST_US 40
97+
9498
/* Buffer for the radio TX packet */
9599
static uint8_t tx_packet[RADIO_MAX_PAYLOAD_LEN];
96100
/* Buffer for the radio RX packet. */
@@ -103,6 +107,12 @@ static uint32_t rx_packet_cnt;
103107
/* Radio current channel (frequency). */
104108
static uint8_t current_channel;
105109

110+
/* Radio Sweep with duty-cycle channel array */
111+
const static uint8_t channel_array[72] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
112+
17, 18, 19, 20, 21, 22, 23, 24, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
113+
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};
115+
106116
/* Timer used for channel sweeps and tx with duty cycle. */
107117
static nrfx_timer_t timer =
108118
NRFX_TIMER_INSTANCE(NRF_TIMER_INST_GET(RADIO_TEST_TIMER_INSTANCE));
@@ -850,24 +860,31 @@ static void radio_mode_set(NRF_RADIO_Type *reg, nrf_radio_mode_t mode)
850860
mltpan_6(mode);
851861
}
852862

853-
static void radio_unmodulated_tx_carrier(uint8_t mode, int8_t txpower, uint8_t channel)
863+
static void radio_unmodulated_tx_carrier_radio_setup(uint8_t mode, int8_t txpower, uint8_t channel,
864+
bool start_ready_short_enable)
854865
{
855866
radio_disable();
856867

857868
radio_mode_set(NRF_RADIO, mode);
858-
nrf_radio_shorts_enable(NRF_RADIO, NRF_RADIO_SHORT_READY_START_MASK);
859869
radio_power_set(mode, channel, txpower);
860-
861870
radio_channel_set(mode, channel);
862871

872+
if (start_ready_short_enable) {
873+
nrf_radio_shorts_enable(NRF_RADIO, NRF_RADIO_SHORT_READY_START_MASK);
874+
}
875+
863876
#if CONFIG_FEM
864877
(void)fem_configure(false, mode, &fem);
865878
#else
866879
if (sweep_processing) {
867880
radio_ppi_config(false);
868881
}
869882
#endif /* CONFIG_FEM */
883+
}
870884

885+
static void radio_unmodulated_tx_carrier(uint8_t mode, int8_t txpower, uint8_t channel)
886+
{
887+
radio_unmodulated_tx_carrier_radio_setup(mode, txpower, channel, true);
871888
radio_start(false, sweep_processing);
872889
}
873890

@@ -1052,6 +1069,31 @@ static void radio_modulated_tx_carrier_duty_cycle(uint8_t mode, int8_t txpower,
10521069
irq_unlock(key);
10531070
}
10541071

1072+
static void radio_tx_sweep_with_sleep(int8_t txpower, uint16_t t_tx_us, uint16_t t_sleep_us)
1073+
{
1074+
radio_disable();
1075+
const uint32_t total_time_per_channel_us = t_tx_us + t_sleep_us;
1076+
1077+
current_channel = 0;
1078+
1079+
nrfx_timer_disable(&timer);
1080+
nrf_timer_shorts_disable(timer.p_reg, ~0);
1081+
nrf_timer_int_disable(timer.p_reg, ~0);
1082+
1083+
nrfx_timer_compare(&timer,
1084+
TIMER_CC0_SWEEP_DWELL,
1085+
nrfx_timer_us_to_ticks(&timer, t_tx_us + RADIO_RAMP_UP_FAST_US),
1086+
true);
1087+
1088+
nrfx_timer_extended_compare(&timer,
1089+
TIMER_CC4_SWEEP_DUTY,
1090+
nrfx_timer_us_to_ticks(&timer, total_time_per_channel_us),
1091+
NRF_TIMER_SHORT_COMPARE4_CLEAR_MASK,
1092+
true);
1093+
1094+
nrfx_timer_enable(&timer);
1095+
}
1096+
10551097
void radio_test_start(const struct radio_test_config *config)
10561098
{
10571099
#if CONFIG_FEM
@@ -1099,6 +1141,11 @@ void radio_test_start(const struct radio_test_config *config)
10991141
config->params.modulated_tx_duty_cycle.pattern,
11001142
config->params.modulated_tx_duty_cycle.duty_cycle);
11011143
break;
1144+
case TX_SWEEP_WITH_DUTY_CYCLE:
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+
break;
11021149
}
11031150

11041151
test_is_running = true;
@@ -1221,6 +1268,19 @@ static void timer_handler(nrf_timer_event_t event_type, void *context)
12211268

12221269
channel_start = config->params.rx_sweep.channel_start;
12231270
channel_end = config->params.rx_sweep.channel_end;
1271+
} else if (config->type == TX_SWEEP_WITH_DUTY_CYCLE) {
1272+
1273+
sweep_processing = true;
1274+
1275+
/* 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);
1280+
1281+
/* 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;
12241284
} else {
12251285
printk("Unexpected test type: %d\n", config->type);
12261286
return;
@@ -1236,6 +1296,8 @@ static void timer_handler(nrf_timer_event_t event_type, void *context)
12361296
} else if (event_type == NRF_TIMER_EVENT_COMPARE7) { /* HMPAN-216 errata */
12371297
errata_216_release();
12381298
#endif /* NRF54H_ERRATA_216_PRESENT */
1299+
} else if (event_type == NRF_TIMER_EVENT_COMPARE4) {
1300+
radio_start(false, true);
12391301
} else {
12401302
/* Do nothing */
12411303
}

samples/peripheral/radio_test/src/radio_test.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ enum radio_test_mode {
6767

6868
/** Duty-cycled modulated TX carrier. */
6969
MODULATED_TX_DUTY_CYCLE,
70+
71+
/** TX carrier sweep with unmodulated carrier wave */
72+
TX_SWEEP_WITH_DUTY_CYCLE,
7073
};
7174

7275
/**@brief Radio test front-end module (FEM) configuration */
@@ -173,6 +176,23 @@ struct radio_test_config {
173176
/** Duty cycle. */
174177
uint32_t duty_cycle;
175178
} modulated_tx_duty_cycle;
179+
180+
struct {
181+
/** Radio output power. */
182+
int8_t txpower;
183+
184+
/** Radio start channel (frequency). */
185+
uint8_t channel_index_start;
186+
187+
/** Radio end channel (frequency). */
188+
uint8_t channel_index_end;
189+
190+
/** Radio transmission time in us */
191+
uint16_t t_tx_us;
192+
193+
/** Radio sleep time in us */
194+
uint16_t t_sleep_us;
195+
} tx_sweep_duty_cycle;
176196
} params;
177197

178198
#if CONFIG_FEM

0 commit comments

Comments
 (0)