Skip to content

Commit 8d44d12

Browse files
committed
[nrf fromlist] net: openthread: cache radio_api->get_capabilities
The capabilities returned by radio_api->get_capabilities do not change. The result is cached in a variable to improve performance. Upstream PR: zephyrproject-rtos/zephyr#79919 Signed-off-by: Andrzej Kuroś <[email protected]>
1 parent 93175d0 commit 8d44d12

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

modules/openthread/platform/radio.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ static struct ieee802154_radio_api *radio_api;
104104

105105
/* Get the default tx output power from Kconfig */
106106
static int8_t tx_power = CONFIG_OPENTHREAD_DEFAULT_TX_POWER;
107-
static uint16_t channel;
108107
static bool promiscuous;
108+
static uint16_t channel;
109+
static enum ieee802154_hw_caps radio_caps;
109110

110111
static uint16_t energy_detection_time;
111112
static uint8_t energy_detection_channel;
@@ -368,8 +369,9 @@ void platformRadioInit(void)
368369
OT_WORKER_PRIORITY, NULL);
369370
k_thread_name_set(&ot_work_q.thread, "ot_radio_workq");
370371

371-
if ((radio_api->get_capabilities(radio_dev) &
372-
IEEE802154_HW_TX_RX_ACK) != IEEE802154_HW_TX_RX_ACK) {
372+
radio_caps = radio_api->get_capabilities(radio_dev);
373+
374+
if ((radio_caps & IEEE802154_HW_TX_RX_ACK) != IEEE802154_HW_TX_RX_ACK) {
373375
LOG_ERR("Only radios with automatic ack handling "
374376
"are currently supported");
375377
k_panic();
@@ -415,7 +417,7 @@ void transmit_message(struct k_work *tx_job)
415417
sTransmitFrame.mInfo.mTxInfo.mIsSecurityProcessed);
416418
net_pkt_set_ieee802154_mac_hdr_rdy(tx_pkt, sTransmitFrame.mInfo.mTxInfo.mIsHeaderUpdated);
417419

418-
if ((radio_api->get_capabilities(radio_dev) & IEEE802154_HW_TXTIME) &&
420+
if ((radio_caps & IEEE802154_HW_TXTIME) &&
419421
(sTransmitFrame.mInfo.mTxInfo.mTxDelay != 0)) {
420422
#if defined(CONFIG_NET_PKT_TXTIME)
421423
uint32_t tx_at = sTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime +
@@ -425,7 +427,7 @@ void transmit_message(struct k_work *tx_job)
425427
tx_err =
426428
radio_api->tx(radio_dev, IEEE802154_TX_MODE_TXTIME_CCA, tx_pkt, tx_payload);
427429
} else if (sTransmitFrame.mInfo.mTxInfo.mCsmaCaEnabled) {
428-
if (radio_api->get_capabilities(radio_dev) & IEEE802154_HW_CSMA) {
430+
if (radio_caps & IEEE802154_HW_CSMA) {
429431
tx_err = radio_api->tx(radio_dev, IEEE802154_TX_MODE_CSMA_CA, tx_pkt,
430432
tx_payload);
431433
} else {
@@ -662,7 +664,7 @@ void platformRadioProcess(otInstance *aInstance)
662664
reset_pending_event(PENDING_EVENT_TX_DONE);
663665

664666
if (sState == OT_RADIO_STATE_TRANSMIT ||
665-
radio_api->get_capabilities(radio_dev) & IEEE802154_HW_SLEEP_TO_TX) {
667+
(radio_caps & IEEE802154_HW_SLEEP_TO_TX)) {
666668
sState = OT_RADIO_STATE_RECEIVE;
667669
handle_tx_done(aInstance);
668670
}
@@ -848,10 +850,6 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aPacket)
848850

849851
__ASSERT_NO_MSG(aPacket == &sTransmitFrame);
850852

851-
enum ieee802154_hw_caps radio_caps;
852-
853-
radio_caps = radio_api->get_capabilities(radio_dev);
854-
855853
if ((sState == OT_RADIO_STATE_RECEIVE) || (radio_caps & IEEE802154_HW_SLEEP_TO_TX)) {
856854
if (run_tx_task(aInstance) == 0) {
857855
error = OT_ERROR_NONE;
@@ -880,11 +878,8 @@ int8_t otPlatRadioGetRssi(otInstance *aInstance)
880878
int8_t ret_rssi = INT8_MAX;
881879
int error = 0;
882880
const uint16_t detection_time = 1;
883-
enum ieee802154_hw_caps radio_caps;
884881
ARG_UNUSED(aInstance);
885882

886-
radio_caps = radio_api->get_capabilities(radio_dev);
887-
888883
if (!(radio_caps & IEEE802154_HW_ENERGY_SCAN)) {
889884
/*
890885
* TODO: No API in Zephyr to get the RSSI
@@ -913,13 +908,10 @@ otRadioCaps otPlatRadioGetCaps(otInstance *aInstance)
913908
{
914909
otRadioCaps caps = OT_RADIO_CAPS_NONE;
915910

916-
enum ieee802154_hw_caps radio_caps;
917911
ARG_UNUSED(aInstance);
918912
__ASSERT(radio_api,
919913
"platformRadioInit needs to be called prior to otPlatRadioGetCaps");
920914

921-
radio_caps = radio_api->get_capabilities(radio_dev);
922-
923915
if (radio_caps & IEEE802154_HW_ENERGY_SCAN) {
924916
caps |= OT_RADIO_CAPS_ENERGY_SCAN;
925917
}

0 commit comments

Comments
 (0)