-
Notifications
You must be signed in to change notification settings - Fork 8.4k
net: openthread: Host-Processor support #47256
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # OpenThread Host options | ||
|
|
||
| # Copyright (c) 2022, Basalte bv | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| menuconfig IEEE802154_OPENTHREAD_HOST_SPINEL | ||
| bool "OpenThread Spinel driver" | ||
| depends on NET_L2_OPENTHREAD | ||
|
|
||
| if IEEE802154_OPENTHREAD_HOST_SPINEL | ||
|
|
||
| config IEEE802154_OPENTHREAD_HOST_SPINEL_DRV_NAME | ||
| string "OpenThread Spinel Driver's name" | ||
| default "IEEE802154_ot_spinel" | ||
| help | ||
| This option sets the driver name | ||
|
|
||
| endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| /* | ||
| * Copyright (c) 2022, Basalte bv | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /** | ||
| * @file | ||
| * Dummy IEEE 802.15.4 interface driver. This is meant for network connectivity between | ||
| * a host and an RCP radio. | ||
| */ | ||
|
|
||
| #define LOG_MODULE_NAME ot_spinel | ||
| #define LOG_LEVEL CONFIG_NET_OPENTHREAD_HOST_LOG_LEVEL | ||
|
|
||
| #include <zephyr/logging/log.h> | ||
| LOG_MODULE_REGISTER(LOG_MODULE_NAME); | ||
|
|
||
| #include <zephyr/kernel.h> | ||
|
|
||
| #include <stdbool.h> | ||
| #include <stddef.h> | ||
| #include <openthread/platform/radio.h> | ||
| #include <zephyr/net/openthread.h> | ||
| #include <zephyr/net/ieee802154_radio.h> | ||
|
|
||
| struct ot_spinel_context { | ||
| struct net_if *iface; | ||
| struct openthread_context *ot_context; | ||
| }; | ||
|
|
||
| static void ot_spinel_iface_init(struct net_if *iface) | ||
| { | ||
| struct ot_spinel_context *ctx = net_if_get_device(iface)->data; | ||
| otExtAddress eui64; | ||
|
|
||
| ctx->iface = iface; | ||
|
|
||
| ieee802154_init(iface); | ||
|
|
||
| ctx->ot_context = net_if_l2_data(iface); | ||
|
|
||
| otPlatRadioGetIeeeEui64(ctx->ot_context->instance, eui64.m8); | ||
| net_if_set_link_addr(iface, eui64.m8, OT_EXT_ADDRESS_SIZE, NET_LINK_IEEE802154); | ||
| } | ||
|
|
||
| static enum ieee802154_hw_caps ot_spinel_get_capabilities(const struct device *dev) | ||
| { | ||
| ARG_UNUSED(dev); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int ot_spinel_cca(const struct device *dev) | ||
| { | ||
| ARG_UNUSED(dev); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int ot_spinel_set_channel(const struct device *dev, uint16_t channel) | ||
| { | ||
| ARG_UNUSED(dev); | ||
| ARG_UNUSED(channel); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int ot_spinel_filter(const struct device *dev, | ||
| bool set, | ||
| enum ieee802154_filter_type type, | ||
| const struct ieee802154_filter *filter) | ||
| { | ||
| ARG_UNUSED(dev); | ||
| ARG_UNUSED(set); | ||
| ARG_UNUSED(type); | ||
| ARG_UNUSED(filter); | ||
|
|
||
| return -ENOTSUP; | ||
| } | ||
|
|
||
| static int ot_spinel_set_txpower(const struct device *dev, int16_t dbm) | ||
| { | ||
| ARG_UNUSED(dev); | ||
| ARG_UNUSED(dbm); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int ot_spinel_tx(const struct device *dev, | ||
| enum ieee802154_tx_mode mode, | ||
| struct net_pkt *pkt, | ||
| struct net_buf *frag) | ||
| { | ||
| ARG_UNUSED(dev); | ||
| ARG_UNUSED(mode); | ||
| ARG_UNUSED(pkt); | ||
| ARG_UNUSED(frag); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int ot_spinel_start(const struct device *dev) | ||
| { | ||
| ARG_UNUSED(dev); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int ot_spinel_stop(const struct device *dev) | ||
| { | ||
| ARG_UNUSED(dev); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int ot_spinel_configure(const struct device *dev, | ||
| enum ieee802154_config_type type, | ||
| const struct ieee802154_config *config) | ||
| { | ||
| ARG_UNUSED(dev); | ||
| ARG_UNUSED(type); | ||
| ARG_UNUSED(config); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int ot_spinel_init(const struct device *dev) | ||
| { | ||
| ARG_UNUSED(dev); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static struct ot_spinel_context ot_spinel_context_data; | ||
|
|
||
| static struct ieee802154_radio_api ot_spinel_if_api = { | ||
| .iface_api.init = ot_spinel_iface_init, | ||
|
|
||
| .get_capabilities = ot_spinel_get_capabilities, | ||
| .cca = ot_spinel_cca, | ||
| .set_channel = ot_spinel_set_channel, | ||
| .filter = ot_spinel_filter, | ||
| .set_txpower = ot_spinel_set_txpower, | ||
| .tx = ot_spinel_tx, | ||
| .start = ot_spinel_start, | ||
| .stop = ot_spinel_stop, | ||
| .configure = ot_spinel_configure, | ||
| }; | ||
|
|
||
| #define ot_spinel_MTU 1280 | ||
|
|
||
| NET_DEVICE_INIT(ot_spinel, CONFIG_IEEE802154_OPENTHREAD_HOST_SPINEL_DRV_NAME, | ||
| ot_spinel_init, NULL, &ot_spinel_context_data, NULL, | ||
| CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &ot_spinel_if_api, | ||
| OPENTHREAD_L2, NET_L2_GET_CTX_TYPE(OPENTHREAD_L2), | ||
| ot_spinel_MTU); | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,42 @@ | ||||||
| # Copyright (c) 2022, Basalte bv | ||||||
| # SPDX-License-Identifier: Apache-2.0 | ||||||
|
|
||||||
| description: Virtual device to communicate with RCP using Spinel | ||||||
|
|
||||||
| compatible: "google,openthread-spinel" | ||||||
|
|
||||||
| include: spi-device.yaml | ||||||
|
|
||||||
| properties: | ||||||
| irq-gpios: | ||||||
| type: phandle-array | ||||||
| required: false | ||||||
| description: Interrupt pin | ||||||
|
|
||||||
| Optional interript pin asserted by the RCP | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| radio device on data ready. | ||||||
|
|
||||||
| reset-gpios: | ||||||
| type: phandle-array | ||||||
| required: false | ||||||
| description: RESET pin | ||||||
|
|
||||||
| The RESET pin of the RCP radio device. | ||||||
|
|
||||||
| reset-time: | ||||||
| type: int | ||||||
| required: false | ||||||
| default: 1 | ||||||
| description: The duration (in ms) for the RCP radio reset. | ||||||
|
|
||||||
| startup-time: | ||||||
| type: int | ||||||
| required: false | ||||||
| default: 0 | ||||||
| description: The duration (in ms) for the RCP radio startup. | ||||||
|
|
||||||
| cs-delay: | ||||||
| type: int | ||||||
| required: false | ||||||
| default: 0 | ||||||
| description: The delay (in ms) for the RCP radio chip select. | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -377,6 +377,11 @@ if(CONFIG_OPENTHREAD_COPROCESSOR_VENDOR_HOOK_SOURCE) | |
| set(OT_NCP_VENDOR_HOOK_SOURCE ${CONFIG_OPENTHREAD_COPROCESSOR_VENDOR_HOOK_SOURCE} CACHE STRING "NCP vendor hook source file name" FORCE) | ||
| endif() | ||
|
|
||
| if(CONFIG_OPENTHREAD_HOSTPROCESSOR_SPINEL_RCP_RESTORATION_MAX_COUNT) | ||
| set(OT_RCP_RESTORATION_MAX_COUNT | ||
| "${CONFIG_OPENTHREAD_HOSTPROCESSOR_SPINEL_RCP_RESTORATION_MAX_COUNT}" CACHE STRING "set max RCP restoration count" FORCE) | ||
| endif() | ||
|
|
||
| # Zephyr logging options | ||
|
|
||
| if(CONFIG_LOG_BACKEND_SPINEL) | ||
|
|
@@ -457,7 +462,7 @@ if(CONFIG_OPENTHREAD_COPROCESSOR_RCP) | |
| list(APPEND ot_libs openthread-rcp) | ||
| endif() | ||
|
|
||
| if(CONFIG_OPENTHREAD_COPROCESSOR_NCP) | ||
| if(CONFIG_OPENTHREAD_COPROCESSOR_NCP OR CONFIG_OPENTHREAD_HOSTPROCESSOR) | ||
| if(CONFIG_OPENTHREAD_FTD) | ||
| list(APPEND ot_libs openthread-ncp-ftd) | ||
| elseif(CONFIG_OPENTHREAD_MTD) | ||
|
|
@@ -481,6 +486,23 @@ if(CONFIG_OPENTHREAD_SETTINGS_RAM) | |
| list(APPEND ot_libs openthread-platform-utils-static) | ||
| endif() | ||
|
|
||
| if(CONFIG_OPENTHREAD_HOSTPROCESSOR) | ||
| # Inject our platform spinel implementation | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you elaborate on why is it needed to inject those sources into OT libs, why can't it end up in the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The OpenThread build system has private compile definitions for each library. This was the easiest way to make sure exactly the same definitions are set. |
||
| set(ot_host_sources ${ZEPHYR_BASE}/subsys/net/lib/openthread/platform/radio_spinel.cpp) | ||
|
|
||
| if(CONFIG_OPENTHREAD_HOSTPROCESSOR_SPI) | ||
| list(APPEND ot_host_sources ${ZEPHYR_BASE}/subsys/net/lib/openthread/platform/spi_interface.cpp) | ||
| endif() | ||
|
|
||
| if(CONFIG_OPENTHREAD_FTD) | ||
| target_sources(openthread-ncp-ftd PRIVATE ${ot_host_sources}) | ||
| elseif(CONFIG_OPENTHREAD_MTD) | ||
| target_sources(openthread-ncp-mtd PRIVATE ${ot_host_sources}) | ||
| endif() | ||
|
|
||
| list(APPEND ot_libs openthread-platform) | ||
| endif() | ||
|
|
||
| zephyr_link_libraries(${ot_libs}) | ||
|
|
||
| endif() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are those dummy-implementations even needed, couldn't they be just NULL pointers? Noone should actaully call them as the radio layer for OT gets a custom implementation for this configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure how to add this file, but if the API isn't called from other subsystems, I can leave them as
NULL. Isn't some shell command able to call these?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK they're not.