Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr openthread #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions drivers/ieee802154/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@ zephyr_sources_ifdef(CONFIG_IEEE802154_KW41Z ieee802154_kw41z.c)
zephyr_sources_ifdef(CONFIG_IEEE802154_UPIPE ieee802154_uart_pipe.c)
zephyr_sources_ifdef(CONFIG_IEEE802154_MCR20A ieee802154_mcr20a.c)
zephyr_sources_ifdef(CONFIG_IEEE802154_NRF5 ieee802154_nrf5.c)
zephyr_sources_ifdef(CONFIG_IEEE802154_NRF5_RAW ieee802154_nrf5.c)

if(CONFIG_NET_L2_OPENTHREAD)
# This driver calls DEVICE_INIT with the context of openthread. The
# context of openthread is defined in one of OpenThread's header
# files so we need express that this driver depends on OpenThread
# being downloaded to make sure that we don't build this driver
# before all of it's header file dependencies are met.
add_dependencies(${ZEPHYR_CURRENT_LIBRARY} ot)
endif()
2 changes: 1 addition & 1 deletion drivers/ieee802154/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
menuconfig IEEE802154
bool "IEEE 802.15.4 drivers options"
default n
default y if NET_L2_IEEE802154
default y if NET_L2_IEEE802154 || NET_L2_OPENTHREAD

if IEEE802154

Expand Down
18 changes: 17 additions & 1 deletion drivers/ieee802154/ieee802154_nrf5.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include <net/net_if.h>
#include <net/net_pkt.h>

#if defined(CONFIG_NET_L2_OPENTHREAD)
#include <net/openthread.h>
#endif

#include <misc/byteorder.h>
#include <string.h>
#include <random/rand32.h>
Expand Down Expand Up @@ -90,7 +94,8 @@ static void nrf5_rx_thread(void *arg1, void *arg2, void *arg3)
* The last 2 bytes contain LQI or FCS, depending if
* automatic CRC handling is enabled or not, respectively.
*/
if (IS_ENABLED(CONFIG_IEEE802154_RAW_MODE)) {
if (IS_ENABLED(CONFIG_IEEE802154_RAW_MODE) ||
IS_ENABLED(CONFIG_NET_L2_OPENTHREAD)) {
pkt_len = nrf5_radio->rx_psdu[0];
} else {
pkt_len = nrf5_radio->rx_psdu[0] - NRF5_FCS_LENGTH;
Expand Down Expand Up @@ -428,6 +433,17 @@ DEVICE_AND_API_INIT(nrf5_154_radio, CONFIG_IEEE802154_NRF5_DRV_NAME,
nrf5_init, &nrf5_data, &nrf5_radio_cfg,
POST_KERNEL, CONFIG_IEEE802154_NRF5_INIT_PRIO,
&nrf5_radio_api);
#elif defined(CONFIG_NET_L2_OPENTHREAD)
NET_DEVICE_INIT(nrf5_154_radio, CONFIG_IEEE802154_NRF5_DRV_NAME,
nrf5_init, &nrf5_data, &nrf5_radio_cfg,
CONFIG_IEEE802154_NRF5_INIT_PRIO,
&nrf5_radio_api, OPENTHREAD_L2,
NET_L2_GET_CTX_TYPE(OPENTHREAD_L2), 1280);

NET_STACK_INFO_ADDR(RX, nrf5_154_radio,
CONFIG_IEEE802154_NRF5_RX_STACK_SIZE,
CONFIG_IEEE802154_NRF5_RX_STACK_SIZE,
nrf5_data.rx_stack, 0);
#else
NET_DEVICE_INIT(nrf5_154_radio, CONFIG_IEEE802154_NRF5_DRV_NAME,
nrf5_init, &nrf5_data, &nrf5_radio_cfg,
Expand Down
5 changes: 5 additions & 0 deletions include/net/net_l2.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ NET_L2_DECLARE_PUBLIC(BLUETOOTH_L2);
NET_L2_DECLARE_PUBLIC(OFFLOAD_IP);
#endif /* CONFIG_NET_OFFLOAD */

#ifdef CONFIG_NET_L2_OPENTHREAD
#define OPENTHREAD_L2 OPENTHREAD
NET_L2_DECLARE_PUBLIC(OPENTHREAD_L2);
#endif /* CONFIG_NET_L2_OPENTHREAD */

extern struct net_l2 __net_l2_end[];

#define NET_L2_INIT(_name, _recv_fn, _send_fn, _reserve_fn, _enable_fn) \
Expand Down
4 changes: 2 additions & 2 deletions include/net/net_pkt.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ struct net_pkt {
#endif /* CONFIG_NET_IPV6_FRAGMENT */
#endif /* CONFIG_NET_IPV6 */

#if defined(CONFIG_NET_L2_IEEE802154) || defined(CONFIG_IEEE802154_RAW_MODE)
#if defined(CONFIG_IEEE802154) || defined(CONFIG_IEEE802154_RAW_MODE)
u8_t ieee802154_rssi; /* Received Signal Strength Indication */
u8_t ieee802154_lqi; /* Link Quality Indicator */
#endif
Expand Down Expand Up @@ -426,7 +426,7 @@ static inline void net_pkt_ll_swap(struct net_pkt *pkt)
net_pkt_ll_dst(pkt)->addr = addr;
}

#if defined(CONFIG_NET_L2_IEEE802154) || defined(CONFIG_IEEE802154_RAW_MODE)
#if defined(CONFIG_IEEE802154) || defined(CONFIG_IEEE802154_RAW_MODE)
static inline u8_t net_pkt_ieee802154_rssi(struct net_pkt *pkt)
{
return pkt->ieee802154_rssi;
Expand Down
39 changes: 39 additions & 0 deletions include/net/openthread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2017 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef __NET_OPENTHREAD_H_
#define __NET_OPENTHREAD_H_

#include <kernel.h>

#include <net/net_if.h>

#include <openthread/openthread.h>

#ifdef __cplusplus
extern "C" {
#endif

struct pkt_list_elem {
struct net_pkt *pkt;
};

struct openthread_context {
otInstance *instance;
struct net_if *iface;
u16_t pkt_list_in_idx;
u16_t pkt_list_out_idx;
u8_t pkt_list_full;
struct pkt_list_elem pkt_list[CONFIG_OPENTHREAD_PKT_LIST_SIZE];
};

#define OPENTHREAD_L2_CTX_TYPE struct openthread_context

#ifdef __cplusplus
}
#endif

#endif /* __NET_OPENTHREAD_H_ */
49 changes: 49 additions & 0 deletions samples/net/echo_client/prj_nrf52840_ot.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
CONFIG_CPLUSPLUS=y

CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000

CONFIG_BT=n

CONFIG_NETWORKING=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_ENTROPY_NRF5_RNG=y

CONFIG_NET_PKT_RX_COUNT=50
CONFIG_NET_PKT_TX_COUNT=50
CONFIG_NET_BUF_RX_COUNT=50
CONFIG_NET_BUF_TX_COUNT=50

CONFIG_NET_TX_STACK_SIZE=2048
CONFIG_NET_RX_STACK_SIZE=3072

CONFIG_NET_IPV4=n
CONFIG_NET_IPV6=y
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=10
CONFIG_NET_IPV6_NBR_CACHE=n
CONFIG_NET_IPV6_MLD=n

CONFIG_REBOOT=y

CONFIG_NET_LOG=y
CONFIG_SYS_LOG_SHOW_COLOR=y
CONFIG_PRINTK=y

CONFIG_UART_INTERRUPT_DRIVEN=y

CONFIG_FLASH=y
CONFIG_SOC_FLASH_NRF5=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

CONFIG_NET_L2_OPENTHREAD=y
CONFIG_OPENTHREAD_L2_DEBUG=y
CONFIG_OPENTHREAD_L2_LOG_LEVEL_INFO=y
CONFIG_OPENTHREAD_CHANNEL=13
CONFIG_IEEE802154_NRF5=y

CONFIG_NET_APP=y
CONFIG_NET_APP_NEED_IPV6=y
CONFIG_NET_APP_CLIENT=y
CONFIG_NET_APP_SETTINGS=y
CONFIG_NET_APP_MY_IPV6_ADDR="fdde:ad00:beef::1"
CONFIG_NET_APP_PEER_IPV6_ADDR="fdde:ad00:beef::2"
49 changes: 49 additions & 0 deletions samples/net/echo_server/prj_nrf52840_ot.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
CONFIG_CPLUSPLUS=y

CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000

CONFIG_BT=n

CONFIG_NETWORKING=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_ENTROPY_NRF5_RNG=y

CONFIG_NET_PKT_RX_COUNT=50
CONFIG_NET_PKT_TX_COUNT=50
CONFIG_NET_BUF_RX_COUNT=50
CONFIG_NET_BUF_TX_COUNT=50

CONFIG_NET_TX_STACK_SIZE=2048
CONFIG_NET_RX_STACK_SIZE=3072

CONFIG_NET_IPV4=n
CONFIG_NET_IPV6=y
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=10
CONFIG_NET_IPV6_NBR_CACHE=n
CONFIG_NET_IPV6_MLD=n

CONFIG_REBOOT=y

CONFIG_NET_LOG=y
CONFIG_SYS_LOG_SHOW_COLOR=y
CONFIG_PRINTK=y

CONFIG_UART_INTERRUPT_DRIVEN=y

CONFIG_FLASH=y
CONFIG_SOC_FLASH_NRF5=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

CONFIG_IEEE802154_NRF5=y
CONFIG_NET_L2_OPENTHREAD=y
CONFIG_OPENTHREAD_L2_DEBUG=y
CONFIG_OPENTHREAD_L2_LOG_LEVEL_INFO=y
CONFIG_OPENTHREAD_CHANNEL=13

CONFIG_NET_APP=y
CONFIG_NET_APP_NEED_IPV6=y
CONFIG_NET_APP_SERVER=y
CONFIG_NET_APP_SETTINGS=y
CONFIG_NET_APP_MY_IPV6_ADDR="fdde:ad00:beef::2"
CONFIG_NET_APP_PEER_IPV6_ADDR="fdde:ad00:beef::1"
4 changes: 4 additions & 0 deletions subsys/net/ip/l2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ endif()
if(CONFIG_NET_L2_IEEE802154)
add_subdirectory(ieee802154)
endif()

if(CONFIG_NET_L2_OPENTHREAD)
add_subdirectory(openthread)
endif()
2 changes: 2 additions & 0 deletions subsys/net/ip/l2/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,6 @@ config NET_DEBUG_ARP
help
Enables core ARP code part to output debug messages

source "subsys/net/ip/l2/openthread/Kconfig"

endmenu
14 changes: 14 additions & 0 deletions subsys/net/ip/l2/openthread/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
zephyr_library_named(subsys__net__ip__l2__openthread)
zephyr_library_include_directories(. ../..)
zephyr_library_compile_definitions_ifdef(
CONFIG_NEWLIB_LIBC __LINUX_ERRNO_EXTENSIONS__
)

zephyr_library_sources(
openthread.c
openthread_utils.c
)

add_dependencies(subsys__net__ip__l2__openthread
ot
)
Loading