Skip to content

Commit 3290781

Browse files
KaSrokaAnas Nashif
authored andcommitted
drivers: 15.4: nrf5: Add OpenThread support to 802.15.4 driver
Initially add support for OpenThread only for nRF 802.15.4 radio driver. Signed-off-by: Kamil Sroka <[email protected]>
1 parent bdfaf7f commit 3290781

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

drivers/ieee802154/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@ zephyr_sources_ifdef(CONFIG_IEEE802154_UPIPE ieee802154_uart_pipe.c)
44
zephyr_sources_ifdef(CONFIG_IEEE802154_MCR20A ieee802154_mcr20a.c)
55
zephyr_sources_ifdef(CONFIG_IEEE802154_NRF5 ieee802154_nrf5.c)
66
zephyr_sources_ifdef(CONFIG_IEEE802154_CC1200 ieee802154_cc1200.c)
7+
8+
if(CONFIG_NET_L2_OPENTHREAD)
9+
# This driver calls DEVICE_INIT with the context of openthread. The
10+
# context of openthread is defined in one of OpenThread's header
11+
# files so we need express that this driver depends on OpenThread
12+
# being downloaded to make sure that we don't build this driver
13+
# before all of it's header file dependencies are met.
14+
add_dependencies(${ZEPHYR_CURRENT_LIBRARY} ot)
15+
endif()

drivers/ieee802154/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
menuconfig IEEE802154
1313
bool "IEEE 802.15.4 drivers options"
1414
default n
15-
default y if NET_L2_IEEE802154
15+
default y if NET_L2_IEEE802154 || NET_L2_OPENTHREAD
1616

1717
if IEEE802154
1818

drivers/ieee802154/ieee802154_nrf5.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#include <net/net_if.h>
2222
#include <net/net_pkt.h>
2323

24+
#if defined(CONFIG_NET_L2_OPENTHREAD)
25+
#include <net/openthread.h>
26+
#endif
27+
2428
#include <misc/byteorder.h>
2529
#include <string.h>
2630
#include <random/rand32.h>
@@ -90,7 +94,9 @@ static void nrf5_rx_thread(void *arg1, void *arg2, void *arg3)
9094
* The last 2 bytes contain LQI or FCS, depending if
9195
* automatic CRC handling is enabled or not, respectively.
9296
*/
93-
if (IS_ENABLED(CONFIG_IEEE802154_RAW_MODE)) {
97+
if (IS_ENABLED(CONFIG_IEEE802154_RAW_MODE) ||
98+
IS_ENABLED(CONFIG_NET_L2_OPENTHREAD)) {
99+
94100
pkt_len = nrf5_radio->rx_psdu[0];
95101
} else {
96102
pkt_len = nrf5_radio->rx_psdu[0] - NRF5_FCS_LENGTH;
@@ -423,20 +429,30 @@ static struct ieee802154_radio_api nrf5_radio_api = {
423429
.tx = nrf5_tx,
424430
};
425431

426-
#if defined(CONFIG_IEEE802154_RAW_MODE)
427-
DEVICE_AND_API_INIT(nrf5_154_radio, CONFIG_IEEE802154_NRF5_DRV_NAME,
428-
nrf5_init, &nrf5_data, &nrf5_radio_cfg,
429-
POST_KERNEL, CONFIG_IEEE802154_NRF5_INIT_PRIO,
430-
&nrf5_radio_api);
431-
#else
432+
#if defined(CONFIG_NET_L2_IEEE802154)
433+
#define L2 IEEE802154_L2
434+
#define L2_CTX_TYPE NET_L2_GET_CTX_TYPE(IEEE802154_L2)
435+
#define MTU 125
436+
#elif defined(CONFIG_NET_L2_OPENTHREAD)
437+
#define L2 OPENTHREAD_L2
438+
#define L2_CTX_TYPE NET_L2_GET_CTX_TYPE(OPENTHREAD_L2)
439+
#define MTU 1280
440+
#endif
441+
442+
#if defined(CONFIG_NET_L2_IEEE802154) || defined(CONFIG_NET_L2_OPENTHREAD)
432443
NET_DEVICE_INIT(nrf5_154_radio, CONFIG_IEEE802154_NRF5_DRV_NAME,
433444
nrf5_init, &nrf5_data, &nrf5_radio_cfg,
434445
CONFIG_IEEE802154_NRF5_INIT_PRIO,
435-
&nrf5_radio_api, IEEE802154_L2,
436-
NET_L2_GET_CTX_TYPE(IEEE802154_L2), 125);
446+
&nrf5_radio_api, L2,
447+
L2_CTX_TYPE, MTU);
437448

438449
NET_STACK_INFO_ADDR(RX, nrf5_154_radio,
439450
CONFIG_IEEE802154_NRF5_RX_STACK_SIZE,
440451
CONFIG_IEEE802154_NRF5_RX_STACK_SIZE,
441452
nrf5_data.rx_stack, 0);
453+
#else
454+
DEVICE_AND_API_INIT(nrf5_154_radio, CONFIG_IEEE802154_NRF5_DRV_NAME,
455+
nrf5_init, &nrf5_data, &nrf5_radio_cfg,
456+
POST_KERNEL, CONFIG_IEEE802154_NRF5_INIT_PRIO,
457+
&nrf5_radio_api);
442458
#endif

0 commit comments

Comments
 (0)