Commit 780b1285 authored by Eduardo Montoya's avatar Eduardo Montoya Committed by Carles Cufi
Browse files

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: default avatarEduardo Montoya <eduardo.montoya@nordicsemi.no>
Signed-off-by: default avatarJędrzej Ciupis <jedrzej.ciupis@nordicsemi.no>
parent 5767998d
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -254,6 +254,8 @@ static int nrf5_cca(const struct device *dev)
{
	struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev);

	nrf_802154_channel_set(nrf5_data.channel);

	if (!nrf_802154_cca()) {
		LOG_DBG("CCA failed");
		return -EBUSY;
@@ -279,7 +281,7 @@ static int nrf5_set_channel(const struct device *dev, uint16_t channel)
		return channel < 11 ? -ENOTSUP : -EINVAL;
	}

	nrf_802154_channel_set(channel);
	nrf5_data.channel = channel;

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

	ARG_UNUSED(dev);

	nrf_802154_channel_set(nrf5_data.channel);

	if (nrf5_data.energy_scan_done == NULL) {
		nrf5_data.energy_scan_done = done_cb;

@@ -457,6 +461,10 @@ static bool nrf5_tx_immediate(struct net_pkt *pkt, uint8_t *payload, bool cca)
			.use_metadata_value = true,
			.power = nrf5_data.txpwr,
		},
		.tx_channel = {
			.use_metadata_value = true,
			.channel = nrf5_data.channel,
		},
	};

	return nrf_802154_transmit_raw(payload, &metadata);
@@ -474,6 +482,10 @@ static bool nrf5_tx_csma_ca(struct net_pkt *pkt, uint8_t *payload)
			.use_metadata_value = true,
			.power = nrf5_data.txpwr,
		},
		.tx_channel = {
			.use_metadata_value = true,
			.channel = nrf5_data.channel,
		},
	};

	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,
			.dynamic_data_is_set = net_pkt_ieee802154_mac_hdr_rdy(pkt),
		},
		.cca = cca,
		.channel = nrf_802154_channel_get(),
		.channel = nrf5_data.channel,
		.tx_power = {
			.use_metadata_value = true,
			.power = nrf5_data.txpwr,
@@ -655,6 +667,7 @@ static int nrf5_start(const struct device *dev)
	ARG_UNUSED(dev);

	nrf_802154_tx_power_set(nrf5_data.txpwr);
	nrf_802154_channel_set(nrf5_data.channel);

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

	nrf_802154_tx_power_set(nrf5_data.txpwr);
	nrf_802154_channel_set(nrf5_data.channel);

	if (!nrf_802154_continuous_carrier()) {
		LOG_ERR("Failed to enter continuous carrier state");
+3 −0
Original line number Diff line number Diff line
@@ -100,6 +100,9 @@ struct nrf5_802154_data {
	/* The TX power in dBm. */
	int8_t txpwr;

	/* The radio channel. */
	uint8_t channel;

#if defined(CONFIG_NRF_802154_SER_HOST) && defined(CONFIG_IEEE802154_CSL_ENDPOINT)
	/* The last configured value of CSL period in units of 10 symbols. */
	uint32_t csl_period;