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.*/
8285static 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. */
8995static void (* * rx_timeout_cb )(void );
9096
9197static volatile bool cancel_request ;
9298static 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
115113static 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-
364362static 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+
625629static 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
728736static 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
859868void 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+
10291051int 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