From f67c2895941e318875421ff069e2263ee9ca4e57 Mon Sep 17 00:00:00 2001 From: Andrzej Kuros Date: Tue, 20 Aug 2024 11:20:04 +0200 Subject: [PATCH] nrf_802154: exclude ant div code for non-nRF52 series The experimental feature Antenna Diversity works only with nRF52 series. The code is excluded by the macro NRF_802154_ANTENNA_DIVERSITY to save some flash in nRF53 series devices. Signed-off-by: Andrzej Kuros --- nrf_802154/driver/include/nrf_802154.h | 3 +++ nrf_802154/driver/include/nrf_802154_config.h | 13 ++++++++++ nrf_802154/driver/src/nrf_802154.c | 2 ++ nrf_802154/driver/src/nrf_802154_core.c | 24 +++++++++++++++++++ nrf_802154/driver/src/nrf_802154_trx.c | 8 +++++++ .../include/host/nrf_802154_config.h | 13 ++++++++++ 6 files changed, 63 insertions(+) diff --git a/nrf_802154/driver/include/nrf_802154.h b/nrf_802154/driver/include/nrf_802154.h index af7ddb8bc0..7beb39d9f7 100644 --- a/nrf_802154/driver/include/nrf_802154.h +++ b/nrf_802154/driver/include/nrf_802154.h @@ -165,6 +165,7 @@ void nrf_802154_tx_power_set(int8_t power); */ int8_t nrf_802154_tx_power_get(void); +#if NRF_802154_ANTENNA_DIVERSITY /** * @brief Sets the antenna diversity rx mode. * @@ -325,6 +326,8 @@ bool nrf_802154_antenna_diversity_init(void); */ void nrf_802154_antenna_diversity_timer_irq_handler(void); +#endif /* NRF_802154_ANTENNA_DIVERSITY */ + /** * @brief Gets the current time. * diff --git a/nrf_802154/driver/include/nrf_802154_config.h b/nrf_802154/driver/include/nrf_802154_config.h index ceba7e2bbd..bb9ef7bd00 100644 --- a/nrf_802154/driver/include/nrf_802154_config.h +++ b/nrf_802154/driver/include/nrf_802154_config.h @@ -525,6 +525,19 @@ extern "C" { #define NRF_802154_CARRIER_FUNCTIONS_ENABLED 1 #endif +/** + * @def NRF_802154_ANTENNA_DIVERSITY + * + * Enables experimental Antenna Diversity feature. + */ +#ifndef NRF_802154_ANTENNA_DIVERSITY +#if defined(NRF52_SERIES) +#define NRF_802154_ANTENNA_DIVERSITY 1 +#else +#define NRF_802154_ANTENNA_DIVERSITY 0 +#endif +#endif + /** *@} **/ diff --git a/nrf_802154/driver/src/nrf_802154.c b/nrf_802154/driver/src/nrf_802154.c index 42e1e165e5..18780da9f4 100644 --- a/nrf_802154/driver/src/nrf_802154.c +++ b/nrf_802154/driver/src/nrf_802154.c @@ -282,6 +282,7 @@ void nrf_802154_deinit(void) #endif } +#if NRF_802154_ANTENNA_DIVERSITY bool nrf_802154_antenna_diversity_rx_mode_set(nrf_802154_sl_ant_div_mode_t mode) { bool result = false; @@ -392,6 +393,7 @@ void nrf_802154_antenna_diversity_timer_irq_handler(void) nrf_802154_sl_ant_div_timer_irq_handle(); #endif } +#endif /* NRF_802154_ANTENNA_DIVERSITY */ nrf_802154_state_t nrf_802154_state_get(void) { diff --git a/nrf_802154/driver/src/nrf_802154_core.c b/nrf_802154/driver/src/nrf_802154_core.c index c118d68de4..10c532a7ed 100644 --- a/nrf_802154/driver/src/nrf_802154_core.c +++ b/nrf_802154/driver/src/nrf_802154_core.c @@ -426,8 +426,12 @@ static bool timeslot_is_granted(void) static bool antenna_diversity_is_enabled(void) { +#if NRF_802154_ANTENNA_DIVERSITY return (NRF_802154_SL_ANT_DIV_MODE_DISABLED != nrf_802154_sl_ant_div_cfg_mode_get(NRF_802154_SL_ANT_DIV_OP_RX)); +#else + return false; +#endif } /*************************************************************************************************** @@ -793,8 +797,10 @@ static bool current_operation_terminate(nrf_802154_term_t term_lvl, m_rx_prestarted_trig_count = 0; (void)nrf_802154_sl_timer_remove(&m_rx_prestarted_timer); +#if NRF_802154_ANTENNA_DIVERSITY /* Notify antenna diversity module that RX has been aborted. */ nrf_802154_sl_ant_div_rx_aborted_notify(); +#endif /* We might have boosted preconditions (to support coex) above level * normally requested for current state by request_preconditions_for_state(m_state). @@ -803,10 +809,12 @@ static bool current_operation_terminate(nrf_802154_term_t term_lvl, request_preconditions_for_state(m_state); } +#if NRF_802154_ANTENNA_DIVERSITY if (m_state == RADIO_STATE_ED) { nrf_802154_sl_ant_div_energy_detection_aborted_notify(); } +#endif if (notify) { @@ -1067,9 +1075,11 @@ static void ed_init(void) uint32_t trx_ed_count = 0U; +#if NRF_802154_ANTENNA_DIVERSITY // Notify antenna diversity about energy detection request. Antenna diversity state // will be updated, and m_ed_time_left reduced accordingly. nrf_802154_sl_ant_div_energy_detection_requested_notify(&m_ed_time_left); +#endif if (!ed_iter_setup(&m_ed_time_left, &trx_ed_count)) { @@ -1468,7 +1478,9 @@ static void on_rx_prestarted_timeout(nrf_802154_sl_timer_t * p_timer) nrf_802154_critical_section_forcefully_enter(); +#if NRF_802154_ANTENNA_DIVERSITY nrf_802154_sl_ant_div_rx_preamble_timeout_notify(); +#endif do { @@ -1490,7 +1502,9 @@ static void on_rx_prestarted_timeout(nrf_802154_sl_timer_t * p_timer) if (nrf_802154_sl_time64_is_in_future(now, m_rx_prestarted_timer.trigger_time)) { m_rx_prestarted_trig_count = 1; +#if NRF_802154_ANTENNA_DIVERSITY nrf_802154_sl_ant_div_rx_preamble_detected_notify(); +#endif break; } } @@ -1514,6 +1528,7 @@ void nrf_802154_trx_receive_frame_prestarted(void) { nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW); +#if NRF_802154_ANTENNA_DIVERSITY if (!antenna_diversity_is_enabled()) { // Only assert if notifications mask would not allow for calling this function. @@ -1524,6 +1539,7 @@ void nrf_802154_trx_receive_frame_prestarted(void) { // Antenna diversity uses this function for detecting possible preamble on air. } +#endif assert(m_state == RADIO_STATE_RX); @@ -1531,7 +1547,9 @@ void nrf_802154_trx_receive_frame_prestarted(void) nrf_802154_stat_counter_increment(received_energy_events); #endif +#if NRF_802154_ANTENNA_DIVERSITY nrf_802154_sl_ant_div_rx_preamble_detected_notify(); +#endif // Antenna diversity module should be notified if framestart doesn't come. bool rx_timeout_should_be_started = antenna_diversity_is_enabled(); @@ -1601,6 +1619,7 @@ void nrf_802154_trx_receive_frame_started(void) break; } +#if NRF_802154_ANTENNA_DIVERSITY if (antenna_diversity_is_enabled()) { // If antenna diversity is enabled, rx_prestarted_timer would be started even @@ -1609,6 +1628,7 @@ void nrf_802154_trx_receive_frame_started(void) (void)nrf_802154_sl_timer_remove(&m_rx_prestarted_timer); nrf_802154_sl_ant_div_rx_frame_started_notify(); } +#endif nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW); } @@ -1875,7 +1895,9 @@ void nrf_802154_trx_receive_frame_received(void) nrf_802154_stat_timestamp_write(last_rx_end_timestamp, ts); #endif +#if NRF_802154_ANTENNA_DIVERSITY nrf_802154_sl_ant_div_rx_frame_received_notify(); +#endif bool send_ack = false; @@ -2297,10 +2319,12 @@ void nrf_802154_trx_energy_detection_finished(uint8_t ed_sample) * Operation will be resumed in next timeslot */ } } +#if NRF_802154_ANTENNA_DIVERSITY else if (nrf_802154_sl_ant_div_energy_detection_finished_notify()) { ed_init(); } +#endif else { nrf_802154_trx_channel_set(nrf_802154_pib_channel_get()); diff --git a/nrf_802154/driver/src/nrf_802154_trx.c b/nrf_802154/driver/src/nrf_802154_trx.c index f5511a1613..3370cb652c 100644 --- a/nrf_802154/driver/src/nrf_802154_trx.c +++ b/nrf_802154/driver/src/nrf_802154_trx.c @@ -803,6 +803,7 @@ void nrf_802154_trx_disable(void) nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW); } +#if NRF_802154_ANTENNA_DIVERSITY static void rx_automatic_antenna_handle(void) { switch (m_trx_state) @@ -828,7 +829,9 @@ static void rx_automatic_antenna_handle(void) break; } } +#endif +#if NRF_802154_ANTENNA_DIVERSITY /** * Updates the antenna for reception, according to antenna diversity configuration. */ @@ -860,7 +863,9 @@ static void rx_antenna_update(void) assert(result); (void)result; } +#endif +#if NRF_802154_ANTENNA_DIVERSITY /** * Updates the antenna for transmission, according to antenna diversity configuration. * @@ -895,9 +900,11 @@ static void tx_antenna_update(void) assert(false); } } +#endif void nrf_802154_trx_antenna_update(void) { +#if NRF_802154_ANTENNA_DIVERSITY assert(m_trx_state != TRX_STATE_DISABLED); switch (m_trx_state) @@ -923,6 +930,7 @@ void nrf_802154_trx_antenna_update(void) /* Intentionally empty */ break; } +#endif } void nrf_802154_trx_channel_set(uint8_t channel) diff --git a/nrf_802154/serialization/include/host/nrf_802154_config.h b/nrf_802154/serialization/include/host/nrf_802154_config.h index a8beb20373..31cae93f7f 100644 --- a/nrf_802154/serialization/include/host/nrf_802154_config.h +++ b/nrf_802154/serialization/include/host/nrf_802154_config.h @@ -143,6 +143,19 @@ extern "C" { #define NRF_802154_TEST_MODES_ENABLED 0 #endif +/** + * @def NRF_802154_ANTENNA_DIVERSITY + * + * Enables experimental Antenna Diversity feature. + */ +#ifndef NRF_802154_ANTENNA_DIVERSITY +#if defined(NRF52_SERIES) +#define NRF_802154_ANTENNA_DIVERSITY 1 +#else +#define NRF_802154_ANTENNA_DIVERSITY 0 +#endif +#endif + #ifdef __cplusplus } #endif