Skip to content

Commit 780b128

Browse files
edmontcarlescufi
authored andcommitted
drivers: ieee802154: nrf: cache radio channel
Cache configured radio channel and apply them only when a relevant radio task is requested. This allows to configure the channel in the transmit metadata, thus avoiding unneeded `nrf_802154` API calls in some scenarios. Signed-off-by: Eduardo Montoya <[email protected]> Signed-off-by: Jędrzej Ciupis <[email protected]>
1 parent 5767998 commit 780b128

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

drivers/ieee802154/ieee802154_nrf5.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ static int nrf5_cca(const struct device *dev)
254254
{
255255
struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev);
256256

257+
nrf_802154_channel_set(nrf5_data.channel);
258+
257259
if (!nrf_802154_cca()) {
258260
LOG_DBG("CCA failed");
259261
return -EBUSY;
@@ -279,7 +281,7 @@ static int nrf5_set_channel(const struct device *dev, uint16_t channel)
279281
return channel < 11 ? -ENOTSUP : -EINVAL;
280282
}
281283

282-
nrf_802154_channel_set(channel);
284+
nrf5_data.channel = channel;
283285

284286
return 0;
285287
}
@@ -292,6 +294,8 @@ static int nrf5_energy_scan_start(const struct device *dev,
292294

293295
ARG_UNUSED(dev);
294296

297+
nrf_802154_channel_set(nrf5_data.channel);
298+
295299
if (nrf5_data.energy_scan_done == NULL) {
296300
nrf5_data.energy_scan_done = done_cb;
297301

@@ -457,6 +461,10 @@ static bool nrf5_tx_immediate(struct net_pkt *pkt, uint8_t *payload, bool cca)
457461
.use_metadata_value = true,
458462
.power = nrf5_data.txpwr,
459463
},
464+
.tx_channel = {
465+
.use_metadata_value = true,
466+
.channel = nrf5_data.channel,
467+
},
460468
};
461469

462470
return nrf_802154_transmit_raw(payload, &metadata);
@@ -474,6 +482,10 @@ static bool nrf5_tx_csma_ca(struct net_pkt *pkt, uint8_t *payload)
474482
.use_metadata_value = true,
475483
.power = nrf5_data.txpwr,
476484
},
485+
.tx_channel = {
486+
.use_metadata_value = true,
487+
.channel = nrf5_data.channel,
488+
},
477489
};
478490

479491
return nrf_802154_transmit_csma_ca_raw(payload, &metadata);
@@ -513,7 +525,7 @@ static bool nrf5_tx_at(struct nrf5_802154_data *nrf5_radio, struct net_pkt *pkt,
513525
.dynamic_data_is_set = net_pkt_ieee802154_mac_hdr_rdy(pkt),
514526
},
515527
.cca = cca,
516-
.channel = nrf_802154_channel_get(),
528+
.channel = nrf5_data.channel,
517529
.tx_power = {
518530
.use_metadata_value = true,
519531
.power = nrf5_data.txpwr,
@@ -655,6 +667,7 @@ static int nrf5_start(const struct device *dev)
655667
ARG_UNUSED(dev);
656668

657669
nrf_802154_tx_power_set(nrf5_data.txpwr);
670+
nrf_802154_channel_set(nrf5_data.channel);
658671

659672
if (!nrf_802154_receive()) {
660673
LOG_ERR("Failed to enter receive state");
@@ -699,6 +712,7 @@ static int nrf5_continuous_carrier(const struct device *dev)
699712
ARG_UNUSED(dev);
700713

701714
nrf_802154_tx_power_set(nrf5_data.txpwr);
715+
nrf_802154_channel_set(nrf5_data.channel);
702716

703717
if (!nrf_802154_continuous_carrier()) {
704718
LOG_ERR("Failed to enter continuous carrier state");

drivers/ieee802154/ieee802154_nrf5.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ struct nrf5_802154_data {
100100
/* The TX power in dBm. */
101101
int8_t txpwr;
102102

103+
/* The radio channel. */
104+
uint8_t channel;
105+
103106
#if defined(CONFIG_NRF_802154_SER_HOST) && defined(CONFIG_IEEE802154_CSL_ENDPOINT)
104107
/* The last configured value of CSL period in units of 10 symbols. */
105108
uint32_t csl_period;

0 commit comments

Comments
 (0)