Skip to content

Commit 9845a12

Browse files
committed
samples: radio_test: share channel index for TX sleep sweeps
Use channel_sequence.current_index when stepping both TX sweep with sleep variants. Signed-off-by: Aleksandr Mirlenko <aleksandr.mirlenko@nordicsemi.no>
1 parent 54a8d02 commit 9845a12

1 file changed

Lines changed: 26 additions & 20 deletions

File tree

samples/peripheral/radio_test/src/radio_test.c

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ static nrfx_timer_t timer =
194194

195195
static bool sweep_processing;
196196

197+
/* First COMPARE0 runs before the first COMPARE4 TX; skip increment so index 0 is used first. */
198+
static bool tx_sweep_with_sleep_first_cc0;
199+
197200
/* Total payload size */
198201
static uint16_t total_payload_size;
199202

@@ -1198,7 +1201,8 @@ static void radio_tx_sweep_with_sleep(int8_t txpower, uint16_t t_tx_us, uint16_t
11981201
radio_disable();
11991202
const uint32_t total_time_per_channel_us = t_tx_us + t_sleep_us;
12001203

1201-
current_channel = 0;
1204+
channel_sequence.current_index = 0;
1205+
tx_sweep_with_sleep_first_cc0 = true;
12021206

12031207
nrfx_timer_disable(&timer);
12041208
nrf_timer_shorts_disable(timer.p_reg, ~0);
@@ -1369,6 +1373,18 @@ static void rx_timeout_work_handler(struct k_work *work)
13691373
}
13701374
}
13711375

1376+
static void increment_channel_index_and_reshuffle_on_wrap(void)
1377+
{
1378+
channel_sequence.current_index =
1379+
(channel_sequence.current_index + 1) % channel_sequence.length;
1380+
1381+
if (channel_sequence.hopping_mode == CHANNEL_HOP_RANDOM_FISHER_YATES &&
1382+
channel_sequence.current_index == 0) {
1383+
radio_disable();
1384+
shuffle_channel_sequence();
1385+
}
1386+
}
1387+
13721388
static void timer_handler(nrf_timer_event_t event_type, void *context)
13731389
{
13741390
const struct radio_test_config *config =
@@ -1399,15 +1415,16 @@ static void timer_handler(nrf_timer_event_t event_type, void *context)
13991415

14001416
sweep_processing = true;
14011417

1402-
/* disable radio after tone */
1418+
if (tx_sweep_with_sleep_first_cc0) {
1419+
tx_sweep_with_sleep_first_cc0 = false;
1420+
} else {
1421+
increment_channel_index_and_reshuffle_on_wrap();
1422+
}
1423+
14031424
radio_unmodulated_tx_carrier_radio_setup(
14041425
NRF_RADIO_MODE_BLE_1MBIT,
14051426
config->params.tx_sweep_with_sleep.txpower,
1406-
active_channel_sequence()[current_channel], false);
1407-
1408-
/* set up next channel */
1409-
channel_start = 0;
1410-
channel_end = channel_sequence.length - 1;
1427+
active_channel_sequence()[channel_sequence.current_index], false);
14111428
} else if (config->type == TX_SWEEP_WITH_SLEEP_MODULATED) {
14121429

14131430
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_DISABLE);
@@ -1416,15 +1433,9 @@ static void timer_handler(nrf_timer_event_t event_type, void *context)
14161433
}
14171434
nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_DISABLED);
14181435
nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_READY);
1419-
channel_sequence.current_index =
1420-
(channel_sequence.current_index + 1) % channel_sequence.length;
1421-
1422-
if (channel_sequence.hopping_mode == CHANNEL_HOP_RANDOM_FISHER_YATES &&
1423-
channel_sequence.current_index == 0) {
1424-
shuffle_channel_sequence();
1425-
}
1426-
14271436
nrf_radio_event_clear(NRF_RADIO, RADIO_TEST_EVENT_END);
1437+
1438+
increment_channel_index_and_reshuffle_on_wrap();
14281439
radio_channel_set(
14291440
config->mode,
14301441
active_channel_sequence()[channel_sequence.current_index]);
@@ -1438,11 +1449,6 @@ static void timer_handler(nrf_timer_event_t event_type, void *context)
14381449
current_channel++;
14391450
if (current_channel > channel_end) {
14401451
current_channel = channel_start;
1441-
1442-
if (channel_sequence.hopping_mode == CHANNEL_HOP_RANDOM_FISHER_YATES &&
1443-
config->type == TX_SWEEP_WITH_SLEEP) {
1444-
shuffle_channel_sequence();
1445-
}
14461452
}
14471453
#if NRF_ERRATA_STATIC_CHECK(54H, 216)
14481454
} else if (event_type == NRF_TIMER_EVENT_COMPARE7) { /* HMPAN-216 errata */

0 commit comments

Comments
 (0)