Skip to content

Commit 1f17a20

Browse files
committed
samples: port radio_test to ncs-bm
changed the implementation of the sample to the subsystems and modules available in sdk-nrf-bm Signed-off-by: Ivan Iushkov <ivan.iushkov@nordicsemi.no>
1 parent f0221fb commit 1f17a20

5 files changed

Lines changed: 114 additions & 51 deletions

File tree

samples/peripherals/radio_test/prj.conf

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,26 @@
44
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
#
66

7-
CONFIG_CONSOLE_HANDLER=y
7+
# Logging
8+
CONFIG_LOG=y
9+
CONFIG_LOG_BACKEND_BM_UARTE=y
10+
11+
# Enabling SoftDevice is not strictly needed, though we are building with SoftDevice boards.
12+
CONFIG_SOFTDEVICE=y
13+
14+
# Shell
815
CONFIG_SHELL=y
16+
CONFIG_SHELL_BACKEND_BM_UARTE=y
917

10-
CONFIG_DYNAMIC_INTERRUPTS=y
18+
# Optional shell features
19+
CONFIG_SHELL_HELP=y
20+
CONFIG_SHELL_TAB=y
21+
CONFIG_SHELL_TAB_AUTOCOMPLETION=y
22+
CONFIG_SHELL_HISTORY=y
1123

24+
# HW used by radio_test
1225
CONFIG_NRFX_TIMER=y
1326
CONFIG_NRFX_GPPI=y
1427

15-
CONFIG_ENTROPY_GENERATOR=y
16-
CONFIG_NRF_SECURITY=y
17-
18-
CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE=1024
28+
# Use fake PRNG to reduce HW dependencies
29+
CONFIG_TEST_RANDOM_GENERATOR=y

samples/peripherals/radio_test/src/main.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include <zephyr/sys/printk.h>
88
#include <zephyr/drivers/clock_control.h>
99
#include <zephyr/drivers/clock_control/nrf_clock_control.h>
10-
#include <zephyr/pm/device_runtime.h>
10+
#include <zephyr/shell/shell.h>
11+
#include <bm/shell/backend_bm_uarte.h>
1112
#if defined(NRF54L15_XXAA)
1213
#include <hal/nrf_clock.h>
1314
#endif /* defined(NRF54L15_XXAA) */
@@ -23,9 +24,9 @@
2324
#include <hal/nrf_clock.h>
2425
#endif /* defined(NRF54LM20A_XXAA) */
2526

26-
/* Empty trim value */
27-
#define TRIM_VALUE_EMPTY 0xFFFFFFFF
27+
#include "radio_test.h"
2828

29+
#if defined(CONFIG_CLOCK_CONTROL_NRF)
2930
static void clock_init(void)
3031
{
3132
int err;
@@ -73,12 +74,28 @@ static void clock_init(void)
7374

7475
printk("Clock has started\n");
7576
}
77+
#endif /* defined(CONFIG_CLOCK_CONTROL_NRF) */
7678

7779
int main(void)
7880
{
81+
const struct shell *sh = shell_backend_bm_uarte_get_ptr();
82+
const struct shell_backend_config_flags cfg_flags =
83+
SHELL_DEFAULT_BACKEND_CONFIG_FLAGS;
84+
85+
shell_init(sh, NULL, cfg_flags, false, 0);
86+
shell_start(sh);
87+
7988
printk("Starting Radio Test sample\n");
8089

90+
#if defined(CONFIG_CLOCK_CONTROL_NRF)
8191
clock_init();
92+
#endif
93+
94+
while (true) {
95+
shell_process(sh);
96+
radio_test_process();
97+
k_busy_wait(10000);
98+
}
8299

83100
return 0;
84101
}

samples/peripherals/radio_test/src/radio_cmd.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ static struct radio_param_config {
5454
* Set to zero for continuous RX.
5555
*/
5656
uint32_t rx_packets_num;
57-
5857
} config = {
5958
.tx_pattern = TRANSMIT_PATTERN_RANDOM,
6059
.mode = NRF_RADIO_MODE_BLE_1MBIT,
@@ -248,7 +247,6 @@ static void rx_end(void)
248247
return;
249248
}
250249

251-
252250
printk("\n");
253251
printk("Received number of packets: %d\n", recv_pkt);
254252
printk("Required number of packets: %d\n", req_pkt);
@@ -1122,7 +1120,6 @@ static int cmd_print_payload(const struct shell *shell, size_t argc,
11221120
return 0;
11231121
}
11241122

1125-
11261123
SHELL_STATIC_SUBCMD_SET_CREATE(sub_output_power,
11271124
#if defined(RADIO_TXPOWER_TXPOWER_Pos10dBm)
11281125
SHELL_CMD(pos10dBm, NULL, "TX power: +10 dBm", cmd_pos10dbm),
@@ -1225,7 +1222,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(sub_transmit_pattern,
12251222
SHELL_SUBCMD_SET_END
12261223
);
12271224

1228-
12291225
SHELL_CMD_REGISTER(start_channel, NULL,
12301226
"Start channel for the sweep or the channel for"
12311227
" the constant carrier (in MHz as difference from 2400 MHz) <channel>",
@@ -1249,6 +1245,7 @@ SHELL_CMD_REGISTER(output_power,
12491245
&sub_output_power,
12501246
"Output power set <sub_cmd>",
12511247
cmd_output_power_set);
1248+
12521249
SHELL_CMD_REGISTER(transmit_pattern,
12531250
&sub_transmit_pattern,
12541251
"Set the transmission pattern",
@@ -1269,8 +1266,6 @@ SHELL_CMD_REGISTER(toggle_dcdc_state, NULL, TOGGLE_DCDC_HELP, cmd_toggle_dc);
12691266

12701267
static int radio_cmd_init(void)
12711268
{
1272-
1273-
12741269
return radio_test_init(&test_config);
12751270
}
12761271

samples/peripherals/radio_test/src/radio_test.c

Lines changed: 68 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
#include <string.h>
1010
#include <inttypes.h>
1111

12+
#if !defined(CONFIG_SOC_SERIES_NRF54L)
1213
#include <hal/nrf_power.h>
14+
#endif /* !defined(CONFIG_SOC_SERIES_NRF54L) */
1315

1416
#include <nrfx_timer.h>
1517
#include <zephyr/kernel.h>
1618
#include <zephyr/random/random.h>
1719

1820
#include <hal/nrf_egu.h>
1921
#include <helpers/nrfx_gppi.h>
22+
#include <bm/bm_irq.h>
2023

2124
/* IEEE 802.15.4 default frequency. */
2225
#define IEEE_DEFAULT_FREQ (5)
@@ -81,36 +84,31 @@ static nrfx_gppi_handle_t ppi_radio_start;
8184
/* PPI endpoint status.*/
8285
static atomic_t endpoint_state;
8386

84-
/* Work element used to handle the end of packet reception. */
85-
static void rx_timeout_work_handler(struct k_work *work);
86-
K_WORK_DELAYABLE_DEFINE(rx_timeout_work, rx_timeout_work_handler);
87+
/* RX timeout state for bare-metal polling */
88+
#define RX_TIMEOUT_INACTIVE 0
89+
#define RX_TIMEOUT_IMMEDIATE 1
90+
#define RX_TIMEOUT_DELAYED 2
91+
static volatile int rx_timeout_state;
92+
static volatile int64_t rx_timeout_deadline;
8793

8894
/* Pointer to rx timeout callback function. */
8995
static void (**rx_timeout_cb)(void);
9096

9197
static volatile bool cancel_request;
9298
static volatile bool test_is_running;
9399

100+
/* Stored config pointer for ISR context access */
101+
static const struct radio_test_config *radio_test_cfg_ptr;
94102

95-
/**
96-
* @brief Send errata HMPAN-216 on request signal to SysCtrl
97-
*
98-
* Also ensure RADIO is not started within 40 us after the signal is triggered,
99-
* so execution is blocked until then by a semaphore.
100-
*
101-
* @return 0 if successful, otherwise a negative error code
102-
*/
103-
104-
/**
105-
* @brief Send errata HMPAN-216 off request signal to SysCtrl
106-
*
107-
* @return 0 if successful, otherwise a negative error code
108-
*/
109-
110-
/**
111-
* @brief Return to code execution after the required delay for errata HMPAN-216 has elapsed.
112-
*/
113-
103+
static void rx_timeout_schedule(int32_t delay_ms)
104+
{
105+
if (delay_ms == 0) {
106+
rx_timeout_state = RX_TIMEOUT_IMMEDIATE;
107+
} else {
108+
rx_timeout_deadline = k_uptime_get() + delay_ms;
109+
rx_timeout_state = RX_TIMEOUT_DELAYED;
110+
}
111+
}
114112

115113
static uint16_t channel_to_frequency(nrf_radio_mode_t mode, uint8_t channel)
116114
{
@@ -295,7 +293,8 @@ static void radio_power_set(nrf_radio_mode_t mode, uint8_t channel, int8_t power
295293
int8_t output_power = power;
296294
int8_t radio_power = power;
297295

298-
296+
ARG_UNUSED(mode);
297+
ARG_UNUSED(channel);
299298

300299
nrf_radio_txpower_set(NRF_RADIO, dbm_to_nrf_radio_txpower(radio_power));
301300

@@ -360,7 +359,6 @@ static void radio_ppi_tx_reconfigure(void)
360359
nrfx_gppi_conn_enable(ppi_radio_start);
361360
}
362361

363-
364362
static void radio_start(bool rx, bool force_egu)
365363
{
366364
if (force_egu) {
@@ -383,7 +381,12 @@ static void radio_config(nrf_radio_mode_t mode, enum transmit_pattern pattern)
383381
nrf_radio_packet_conf_t packet_conf;
384382

385383
/* Set fast ramp-up time. */
384+
#if defined(CONFIG_SOC_SERIES_NRF54H) || defined(CONFIG_SOC_SERIES_NRF54L) || \
385+
defined(CONFIG_SOC_SERIES_NRF71)
386386
nrf_radio_fast_ramp_up_enable_set(NRF_RADIO, true);
387+
#else
388+
nrf_radio_modecnf0_set(NRF_RADIO, true, RADIO_MODECNF0_DTX_Center);
389+
#endif /* defined(CONFIG_SOC_SERIES_NRF54H) || defined(CONFIG_SOC_SERIES_NRF54L) */
387390

388391
/* Disable CRC. */
389392
nrf_radio_crc_configure(NRF_RADIO, RADIO_CRCCNF_LEN_Disabled,
@@ -622,6 +625,7 @@ static void mltpan_6(nrf_radio_mode_t mode)
622625
ARG_UNUSED(mode);
623626
#endif /* defined(NRF54L_SERIES) && CONFIG_HAS_HW_NRF_RADIO_IEEE802154 */
624627
}
628+
625629
static void radio_mode_set(NRF_RADIO_Type *reg, nrf_radio_mode_t mode)
626630
{
627631
nrf_radio_mode_set(reg, mode);
@@ -638,6 +642,9 @@ static void radio_unmodulated_tx_carrier(uint8_t mode, int8_t txpower, uint8_t c
638642

639643
radio_channel_set(mode, channel);
640644

645+
if (sweep_processing) {
646+
radio_ppi_config(false);
647+
}
641648

642649
radio_start(false, sweep_processing);
643650
}
@@ -693,8 +700,6 @@ static void radio_modulated_tx_carrier(uint8_t mode, int8_t txpower, uint8_t cha
693700

694701
tx_packet_cnt = 0;
695702

696-
697-
698703
radio_start(false, false);
699704
}
700705

@@ -717,19 +722,21 @@ static void radio_rx(uint8_t mode, uint8_t channel, enum transmit_pattern patter
717722

718723
nrf_radio_int_enable(NRF_RADIO, NRF_RADIO_INT_CRCOK_MASK);
719724

725+
if (sweep_processing) {
726+
radio_ppi_config(true);
727+
}
720728

721729
radio_start(true, sweep_processing);
722730

723731
if (rx_packet_num > 0) {
724-
k_work_reschedule(&rx_timeout_work, K_SECONDS(CONFIG_RADIO_TEST_RX_TIMEOUT));
732+
rx_timeout_schedule(CONFIG_RADIO_TEST_RX_TIMEOUT * 1000);
725733
}
726734
}
727735

728736
static void radio_sweep_start(uint8_t channel, uint32_t delay_ms)
729737
{
730738
current_channel = channel;
731739

732-
733740
nrfx_timer_disable(&timer);
734741
nrf_timer_shorts_disable(timer.p_reg, ~0);
735742
nrf_timer_int_disable(timer.p_reg, ~0);
@@ -782,6 +789,7 @@ static void radio_modulated_tx_carrier_duty_cycle(uint8_t mode, int8_t txpower,
782789
/* We let the TIMER start the radio transmission again. */
783790
nrfx_timer_disable(&timer);
784791

792+
radio_ppi_config(false);
785793

786794
nrf_timer_shorts_disable(timer.p_reg, ~0);
787795
nrf_timer_int_disable(timer.p_reg, ~0);
@@ -854,6 +862,7 @@ static void cancel(void)
854862
endpoints_clear();
855863
radio_disable();
856864

865+
rx_timeout_state = RX_TIMEOUT_INACTIVE;
857866
}
858867

859868
void radio_test_cancel(enum radio_test_mode type)
@@ -913,7 +922,7 @@ void toggle_dcdc_state(uint8_t dcdc_state)
913922
}
914923
#endif /* NRF_POWER_HAS_DCDCEN_VDDH || NRF_POWER_HAS_DCDCEN */
915924

916-
static void rx_timeout_work_handler(struct k_work *work)
925+
static void rx_timeout_handle(void)
917926
{
918927
radio_disable();
919928
if (rx_timeout_cb != NULL && *rx_timeout_cb != NULL) {
@@ -985,6 +994,7 @@ void on_radio_end(const struct radio_test_config *config)
985994
if (tx_packet_cnt == config->params.modulated_tx.packets_num &&
986995
config->type == MODULATED_TX) {
987996
radio_disable();
997+
988998
config->params.modulated_tx.cb();
989999
} else if (cancel_request) {
9901000
cancel();
@@ -1004,9 +1014,9 @@ void radio_handler(const void *context)
10041014
rx_packet_cnt++;
10051015
if (config->params.rx.packets_num) {
10061016
if (rx_packet_cnt == config->params.rx.packets_num) {
1007-
k_work_reschedule(&rx_timeout_work, K_NO_WAIT);
1017+
rx_timeout_schedule(0);
10081018
} else {
1009-
k_work_reschedule(&rx_timeout_work, K_MSEC(RX_PACKET_TIMEOUT_MS));
1019+
rx_timeout_schedule(RX_PACKET_TIMEOUT_MS);
10101020
}
10111021
}
10121022
}
@@ -1026,16 +1036,30 @@ void radio_handler(const void *context)
10261036
}
10271037
}
10281038

1039+
ISR_DIRECT_DECLARE(radio_test_timer_isr)
1040+
{
1041+
nrfx_timer_irq_handler(&timer);
1042+
return 1;
1043+
}
1044+
1045+
ISR_DIRECT_DECLARE(radio_test_radio_isr)
1046+
{
1047+
radio_handler(radio_test_cfg_ptr);
1048+
return 1;
1049+
}
1050+
10291051
int radio_test_init(struct radio_test_config *config)
10301052
{
10311053
int nrfx_err;
10321054
uint32_t rad_domain = nrfx_gppi_domain_id_get((uint32_t)NRF_RADIO);
10331055

1056+
radio_test_cfg_ptr = config;
1057+
10341058
timer_init(config);
1035-
IRQ_CONNECT(RADIO_TEST_TIMER_IRQn, IRQ_PRIO_LOWEST,
1036-
nrfx_timer_irq_handler, &timer, 0);
1059+
BM_IRQ_DIRECT_CONNECT(RADIO_TEST_TIMER_IRQn, 7, radio_test_timer_isr, 0);
1060+
irq_enable(RADIO_TEST_TIMER_IRQn);
10371061

1038-
irq_connect_dynamic(RADIO_TEST_RADIO_IRQn, IRQ_PRIO_LOWEST, radio_handler, config, 0);
1062+
BM_IRQ_DIRECT_CONNECT(RADIO_TEST_RADIO_IRQn, 7, radio_test_radio_isr, 0);
10391063
irq_enable(RADIO_TEST_RADIO_IRQn);
10401064

10411065
nrfx_err = nrfx_gppi_domain_conn_alloc(rad_domain, rad_domain, &ppi_radio_start);
@@ -1046,6 +1070,15 @@ int radio_test_init(struct radio_test_config *config)
10461070

10471071
rx_timeout_cb = &config->params.rx.cb;
10481072

1049-
10501073
return 0;
10511074
}
1075+
1076+
void radio_test_process(void)
1077+
{
1078+
if (rx_timeout_state == RX_TIMEOUT_IMMEDIATE ||
1079+
(rx_timeout_state == RX_TIMEOUT_DELAYED &&
1080+
k_uptime_get() >= rx_timeout_deadline)) {
1081+
rx_timeout_state = RX_TIMEOUT_INACTIVE;
1082+
rx_timeout_handle();
1083+
}
1084+
}

0 commit comments

Comments
 (0)