Skip to content

Commit ae5914c

Browse files
Jędrzej Ciupisnordicjm
authored andcommitted
[nrf fromtree] drivers: ieee802154: nrf5: support raw mode
When CONFIG_IEEE802154_RAW_MODE is set there is no network interface that could provide pointer to the device the interface is running on top of. The current implementation of nRF5 ieee802154 driver implicitly assumes that such an interface is always present, which leads to crashes when raw mode is enabled. This commit adds support for IEEE802154_RAW_MODE in nRF5 ieee802154 driver by latching pointer to the ieee802154 device on initialization if needed so that it doesn't have to be retrieved using the network interface in run-time. Signed-off-by: Jędrzej Ciupis <[email protected]> (cherry picked from commit 0bad09c)
1 parent 2ac74ca commit ae5914c

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

drivers/ieee802154/ieee802154_nrf5.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ struct nrf5_802154_config {
5757
};
5858

5959
static struct nrf5_802154_data nrf5_data;
60+
#if defined(CONFIG_IEEE802154_RAW_MODE)
61+
static const struct device *nrf5_dev;
62+
#endif
6063

6164
#define ACK_REQUEST_BYTE 1
6265
#define ACK_REQUEST_BIT (1 << 5)
@@ -98,6 +101,15 @@ static struct nrf5_802154_data nrf5_data;
98101
#define IEEE802154_NRF5_VENDOR_OUI (uint32_t)0xF4CE36
99102
#endif
100103

104+
static inline const struct device *nrf5_get_device(void)
105+
{
106+
#if defined(CONFIG_IEEE802154_RAW_MODE)
107+
return nrf5_dev;
108+
#else
109+
return net_if_get_device(nrf5_data.iface);
110+
#endif
111+
}
112+
101113
static void nrf5_get_eui64(uint8_t *mac)
102114
{
103115
uint64_t factoryAddress;
@@ -736,6 +748,9 @@ static int nrf5_init(const struct device *dev)
736748
{
737749
const struct nrf5_802154_config *nrf5_radio_cfg = NRF5_802154_CFG(dev);
738750
struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev);
751+
#if defined(CONFIG_IEEE802154_RAW_MODE)
752+
nrf5_dev = dev;
753+
#endif
739754

740755
k_fifo_init(&nrf5_radio->rx_fifo);
741756
k_sem_init(&nrf5_radio->tx_wait, 0, 1);
@@ -1016,7 +1031,7 @@ void nrf_802154_received_timestamp_raw(uint8_t *data, int8_t power, uint8_t lqi,
10161031

10171032
void nrf_802154_receive_failed(nrf_802154_rx_error_t error, uint32_t id)
10181033
{
1019-
const struct device *dev = net_if_get_device(nrf5_data.iface);
1034+
const struct device *dev = nrf5_get_device();
10201035

10211036
#if defined(CONFIG_IEEE802154_CSL_ENDPOINT)
10221037
if (id == DRX_SLOT_RX) {
@@ -1133,7 +1148,7 @@ void nrf_802154_energy_detected(const nrf_802154_energy_detected_t *result)
11331148
energy_scan_done_cb_t callback = nrf5_data.energy_scan_done;
11341149

11351150
nrf5_data.energy_scan_done = NULL;
1136-
callback(net_if_get_device(nrf5_data.iface), result->ed_dbm);
1151+
callback(nrf5_get_device(), result->ed_dbm);
11371152
}
11381153
}
11391154

@@ -1143,7 +1158,7 @@ void nrf_802154_energy_detection_failed(nrf_802154_ed_error_t error)
11431158
energy_scan_done_cb_t callback = nrf5_data.energy_scan_done;
11441159

11451160
nrf5_data.energy_scan_done = NULL;
1146-
callback(net_if_get_device(nrf5_data.iface), SHRT_MAX);
1161+
callback(nrf5_get_device(), SHRT_MAX);
11471162
}
11481163
}
11491164

0 commit comments

Comments
 (0)