-
Notifications
You must be signed in to change notification settings - Fork 8.4k
OpenThread HDLC RCP communication support #75986
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
Merged
nashif
merged 7 commits into
zephyrproject-rtos:main
from
nxp-upstream:feature_openthread_hdlc_rcp
Nov 27, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b82a397
drivers: openthread: nxp: Add a HDLC RCP communication
JA-NXP 397ccbd
modules: openthread: Add of spinel hdlc rcp host interface
JA-NXP 4d54e04
net: openthread: Adapt OpenThread to support RCP interface
JA-NXP 730f3f2
samples: net: sockets: Add OT RCP config for echo client, server
JA-NXP e3c1bc0
boards: nxp: frdm_rw612: add flash partitions
JA-NXP 4ff7095
west.yml: hal_nxp update from upstream
JA-NXP 05aaaa5
doc: LICENSING: Add BSD-3-clause for OpenThread files
dleach02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| zephyr_library() | ||
|
|
||
| zephyr_library_sources_ifdef(CONFIG_HDLC_RCP_IF_NXP hdlc_rcp_if_nxp.c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Configuration options for HDLC RCP communication Interface | ||
|
|
||
| # Copyright (c) 2024 NXP | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # | ||
| # HDLC communication Interface used by Zephyr running Openthread RCP host | ||
| # | ||
|
|
||
| menuconfig HDLC_RCP_IF | ||
| bool "HDLC interface for a Zephyr Openthread RCP host" | ||
| depends on NET_L2_OPENTHREAD && !OPENTHREAD_COPROCESSOR | ||
|
|
||
| if HDLC_RCP_IF | ||
|
|
||
| source "drivers/hdlc_rcp_if/Kconfig.nxp" | ||
|
|
||
| config HDLC_RCP_IF_DRV_NAME | ||
| string "HDLC RCP Interface Driver's name" | ||
| default "hdlc_rcp_if" | ||
| help | ||
| This option sets the driver name | ||
|
|
||
| module = HDLC_RCP_IF_DRIVER | ||
| module-str = HDLC driver for Openthread RCP host | ||
| module-help = Sets log level for Openthread HDLC RCP host interface Device Drivers. | ||
| source "subsys/logging/Kconfig.template.log_config" | ||
|
|
||
| endif # HDLC_RCP_IF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Configuration options for NXP HDLC RCP communication Interface | ||
|
|
||
| # Copyright (c) 2024 NXP | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # | ||
| # HDLC communication Interface used by Zephyr running Openthread RCP host | ||
| # | ||
|
|
||
| config HDLC_RCP_IF_NXP | ||
| bool "NXP HDLC interface for Zephyr Openthread RCP host" | ||
| default y | ||
| depends on DT_HAS_NXP_HDLC_RCP_IF_ENABLED |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| /* | ||
xavraz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * Copyright (c) 2024, NXP | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /** | ||
| * @file | ||
| * IEEE 802.15.4 HDLC RCP interface. This is meant for network connectivity | ||
| * between a host and a RCP radio device. | ||
| */ | ||
|
|
||
| /* -------------------------------------------------------------------------- */ | ||
| /* Includes */ | ||
| /* -------------------------------------------------------------------------- */ | ||
| #include <fwk_platform_hdlc.h> | ||
| #include <fwk_platform_ot.h> | ||
| #include <openthread/platform/radio.h> | ||
| #include <stdbool.h> | ||
| #include <stddef.h> | ||
| #include <zephyr/init.h> | ||
| #include <zephyr/logging/log.h> | ||
| #include <zephyr/net/hdlc_rcp_if/hdlc_rcp_if.h> | ||
| #include <zephyr/net/ieee802154_radio.h> | ||
| #include <zephyr/net/openthread.h> | ||
|
|
||
| /* -------------------------------------------------------------------------- */ | ||
| /* Definitions */ | ||
| /* -------------------------------------------------------------------------- */ | ||
|
|
||
| #define DT_DRV_COMPAT nxp_hdlc_rcp_if | ||
|
|
||
| #define LOG_MODULE_NAME hdlc_rcp_if_nxp | ||
| #define LOG_LEVEL CONFIG_HDLC_RCP_IF_DRIVER_LOG_LEVEL | ||
| LOG_MODULE_REGISTER(LOG_MODULE_NAME); | ||
|
|
||
| #define HDLC_RCP_IF_IRQ_N DT_INST_IRQ_BY_NAME(0, hdlc_rcp_if_int, irq) | ||
| #define HDLC_RCP_IF_IRQ_P DT_INST_IRQ_BY_NAME(0, hdlc_rcp_if_int, priority) | ||
| #define HDLC_RCP_IF_WAKEUP_IRQ_N DT_INST_IRQ_BY_NAME(0, wakeup_int, irq) | ||
| #define HDLC_RCP_IF_WAKEUP_IRQ_P DT_INST_IRQ_BY_NAME(0, wakeup_int, priority) | ||
|
|
||
| struct ot_hdlc_rcp_context { | ||
| struct net_if *iface; | ||
| struct openthread_context *ot_context; | ||
| }; | ||
|
|
||
| /* -------------------------------------------------------------------------- */ | ||
| /* Private prototypes */ | ||
| /* -------------------------------------------------------------------------- */ | ||
| extern int32_t hdlc_rcp_if_handler(void); | ||
| extern int32_t hdlc_rcp_if_wakeup_done_handler(void); | ||
|
|
||
| /* -------------------------------------------------------------------------- */ | ||
| /* Private functions */ | ||
| /* -------------------------------------------------------------------------- */ | ||
|
|
||
| static void hdlc_iface_init(struct net_if *iface) | ||
| { | ||
| struct ot_hdlc_rcp_context *ctx = net_if_get_device(iface)->data; | ||
| otExtAddress eui64; | ||
|
|
||
| /* HDLC RCP interface Interrupt */ | ||
| IRQ_CONNECT(HDLC_RCP_IF_IRQ_N, HDLC_RCP_IF_IRQ_P, hdlc_rcp_if_handler, 0, 0); | ||
| irq_enable(HDLC_RCP_IF_IRQ_N); | ||
|
|
||
| /* Wake up done interrupt */ | ||
| IRQ_CONNECT(HDLC_RCP_IF_WAKEUP_IRQ_N, HDLC_RCP_IF_WAKEUP_IRQ_P, | ||
| hdlc_rcp_if_wakeup_done_handler, 0, 0); | ||
| irq_enable(HDLC_RCP_IF_WAKEUP_IRQ_N); | ||
|
|
||
| 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 int hdlc_register_rx_cb(hdlc_rx_callback_t hdlc_rx_callback, void *param) | ||
| { | ||
| int ret = 0; | ||
|
|
||
| ret = PLATFORM_InitHdlcInterface(hdlc_rx_callback, param); | ||
| if (ret < 0) { | ||
| LOG_ERR("HDLC RX callback registration failed"); | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| static int hdlc_send(const uint8_t *frame, uint16_t length) | ||
| { | ||
| int ret = 0; | ||
|
|
||
| ret = PLATFORM_SendHdlcMessage((uint8_t *)frame, length); | ||
| if (ret < 0) { | ||
| LOG_ERR("HDLC send frame failed"); | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| static int hdlc_deinit(void) | ||
| { | ||
| int ret = 0; | ||
|
|
||
| ret = PLATFORM_TerminateHdlcInterface(); | ||
| if (ret < 0) { | ||
| LOG_ERR("Failed to shutdown OpenThread controller"); | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| static const struct hdlc_api nxp_hdlc_api = { | ||
| .iface_api.init = hdlc_iface_init, | ||
| .register_rx_cb = hdlc_register_rx_cb, | ||
| .send = hdlc_send, | ||
| .deinit = hdlc_deinit, | ||
| }; | ||
|
|
||
| #define L2_CTX_TYPE NET_L2_GET_CTX_TYPE(OPENTHREAD_L2) | ||
|
|
||
| #define MTU 1280 | ||
|
|
||
| NET_DEVICE_DT_INST_DEFINE(0, NULL, /* Initialization Function */ | ||
| NULL, /* No PM API support */ | ||
| NULL, /* No context data */ | ||
| NULL, /* Configuration info */ | ||
| CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, /* Initial priority */ | ||
| &nxp_hdlc_api, /* API interface functions */ | ||
| OPENTHREAD_L2, /* Openthread L2 */ | ||
| NET_L2_GET_CTX_TYPE(OPENTHREAD_L2), /* Openthread L2 context type */ | ||
| MTU); /* MTU size */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Copyright (c) 2024, NXP | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| description: NXP HDLC RCP interface node | ||
|
|
||
| compatible: "nxp,hdlc-rcp-if" | ||
|
|
||
| include: base.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * Copyright (c) 2024, NXP | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /** | ||
| * @file | ||
| * @brief Public APIs of HDLC RCP communication Interface | ||
| * | ||
| * This file provide the HDLC APIs to be used by an RCP host | ||
| */ | ||
|
|
||
| #include <zephyr/sys/util.h> | ||
| #include <zephyr/net/net_if.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief OT RCP HDLC RX callback function. | ||
| * | ||
| * @note This function is called in the radio spinel HDLC level | ||
| */ | ||
| typedef void (*hdlc_rx_callback_t)(uint8_t *data, uint16_t len, void *param); | ||
|
|
||
| /** HDLC interface configuration data. */ | ||
| struct hdlc_api { | ||
| /** | ||
| * @brief HDLC interface API | ||
| */ | ||
| struct net_if_api iface_api; | ||
|
|
||
| /** | ||
| * @brief Register the Spinel HDLC RX callback. | ||
| * | ||
| * @param hdlc_rx_callback pointer to the spinel HDLC RX callback | ||
| * @param param pointer to the spinel HDLC interface | ||
| * | ||
| * @retval 0 The callback was successfully registered. | ||
| * @retval -EIO The callback could not be registered. | ||
| */ | ||
| int (*register_rx_cb)(hdlc_rx_callback_t hdlc_rx_callback, void *param); | ||
|
|
||
| /** | ||
| * @brief Transmit a HDLC frame | ||
| * | ||
| * | ||
| * @param frame pointer to the HDLC frame to be transmitted. | ||
| * @param length length of the HDLC frame to be transmitted. | ||
|
|
||
| * @retval 0 The frame was successfully sent. | ||
| * @retval -EIO The frame could not be sent due to some unspecified | ||
| * interface error (e.g. the interface being busy). | ||
| */ | ||
| int (*send)(const uint8_t *frame, uint16_t length); | ||
|
|
||
| /** | ||
| * @brief Deinitialize the device. | ||
| * | ||
| * @param none | ||
| * | ||
| * @retval 0 The interface was successfully stopped. | ||
| * @retval -EIO The interface could not be stopped. | ||
| */ | ||
| int (*deinit)(void); | ||
| }; | ||
|
|
||
| /* Make sure that the interface API is properly setup inside | ||
| * HDLC interface API struct (it is the first one). | ||
| */ | ||
| BUILD_ASSERT(offsetof(struct hdlc_api, iface_api) == 0); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why do we need to use middleware that again translates to UART/SPI? There is already UART and SPI abstraction in zephyr.
I once opened a PoC PR to support over a generic SPI interface: #47256
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.
Since for our RW612 board we don't use SPI/UART for RCP however we use a custom interface for inter cpu communication. So we are thinking to create a generic driver interface for HDLC in order to map any interface type.