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

OpenThread HDLC RCP communication support #75986

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

xavraz
Copy link

@xavraz xavraz commented Jul 17, 2024

This PR adds support to an RCP design, the core of OpenThread lives on the host processor connected to an RCP radio controller over a HDLC interface.

  • OpenThread HDLC RCP communication added with its hdlc_api interface APIs and a NXP driver
  • Add of spinel hdlc rcp interface for an OpenThread rcp host
  • Adapt openthread.c file to support RCP interface

Tested on a board using NXP's RW612 component.

Copy link

Hello @xavraz, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@canisLupus1313
Copy link
Contributor

@xavraz thanks for your contribution.
It seems that You have included some of the Openthread files in the Zephyr code. I would say would be better to include form openthread module.
More over I don't think that C++ code is accepted in zephyr core.

Also, can you explain what is the purpose of this PR? The RCP architecture is supported in zephyr.

@xavraz
Copy link
Author

xavraz commented Jul 18, 2024

@canisLupus1313, thank you for your comment.

OT-RCP Architecture

This PR corresponds to an ot-rcp host support. The existing support in Zephyr is for an ot-rcp device, as follows :
https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.7.1/nrf/ug_thread_architectures.html#thread-architectures-designs-cp-rcp.
This means Zephyr supports only a radio coprocessor associated with a host processor.

Zephyr code

Concerning your question "included some of the Openthread files in the Zephyr code."
openthread\platform\radio_spinel.cpp and spinel_hdlc.cpp files are interfaces :

  1. radio_spinel.cpp
    Interface between net\l2\openthread HOST layer and the spinel driver from the openthread library.
    zephyr\subsys\net\l2\openthread\openthread.c (not in modules\lib\openthread)

    zephyr\modules\openthread\platform\radio_spinel.cpp

    modules\lib\openthread\src\lib\spinel\spinel_driver.cpp

  2. spinel_hdlc.cpp
    Interface between the spinel driver from the openthread library and the HDLC interface.
    modules\lib\openthread\src\lib\spinel\spinel_driver.cpp

    zephyr\modules\openthread\platform\spinel_hdlc.cpp

    zephyr\drivers\hdlc_rcp_if\hdlc_rcp_if_nxp.c

C++ code in Zephyr

There are already few files in zephyr directory as follows for example

    • zephyr\modules\thrift\src\thrift\transport\TSSLSocket.cpp
    • zephyr\modules\thrift\src\thrift\server\TServerFramework.cpp

Copy link
Contributor

@rlubos rlubos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modules/openthread/platform/radio_spinel.cpp Show resolved Hide resolved
modules/openthread/platform/platform_spinel.c Outdated Show resolved Hide resolved
modules/openthread/platform/platform.h Outdated Show resolved Hide resolved
# Openthead HDLC RCP communication Interface configuration options
# Copyright 2024 NXP
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BSD license should be changed to Apache-2.0

Copy link
Author

@xavraz xavraz Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change the licences following all your comments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that you can only change the license if you are the author. If you took the code from somewhere else, then you need to use the original license.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canisLupus1313 commented 2 days ago
@xavraz thanks for your contribution.
It seems that You have included some of the Openthread files in the Zephyr code. I would say would be better to include form openthread module.

Concerning the OpenThread files included in the Zephyr code, this has been done to ensure the compatibility if the OpenThread library version is modified. This permits to go back to an older OpenThread version. Otherwise, if the source code is set in modules\lib\openthread\src\xxx, then, it is not possible to go back to an older OpenThread version.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

${ZEPHYR_BASE}/arch/arm/include
${ZEPHYR_BASE}/../modules/lib/openthread/src
${ZEPHYR_BASE}/../modules/lib/openthread/src/core
${ZEPHYR_BASE}/../modules/lib/openthread/third_party/mbedtls/repo/include
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zephyr is using it's own mbed TLS: https://github.com/zephyrproject-rtos/mbedtls not exactly same as the on in OT.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

Comment on lines 49 to 53
#define OT_PLAT_DBG_LEVEL_NONE 0
#define OT_PLAT_DBG_LEVEL_ERR 1
#define OT_PLAT_DBG_LEVEL_WARNING 2
#define OT_PLAT_DBG_LEVEL_INFO 3
#define OT_PLAT_DBG_LEVEL_DEBUG 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you defining those?
It should be possible to reuse logging from https://docs.zephyrproject.org/latest/services/logging/index.html

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

@canisLupus1313
Copy link
Contributor

@canisLupus1313, thank you for your comment.

OT-RCP Architecture

This PR corresponds to an ot-rcp host support. The existing support in Zephyr is for an ot-rcp device, as follows : https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.7.1/nrf/ug_thread_architectures.html#thread-architectures-designs-cp-rcp. This means Zephyr supports only a radio coprocessor associated with a host processor.

Zephyr code

Concerning your question "included some of the Openthread files in the Zephyr code." openthread\platform\radio_spinel.cpp and spinel_hdlc.cpp files are interfaces :

  1. radio_spinel.cpp
    Interface between net\l2\openthread HOST layer and the spinel driver from the openthread library.
    zephyr\subsys\net\l2\openthread\openthread.c (not in modules\lib\openthread)

    zephyr\modules\openthread\platform\radio_spinel.cpp

    modules\lib\openthread\src\lib\spinel\spinel_driver.cpp
  2. spinel_hdlc.cpp
    Interface between the spinel driver from the openthread library and the HDLC interface.
    modules\lib\openthread\src\lib\spinel\spinel_driver.cpp

    zephyr\modules\openthread\platform\spinel_hdlc.cpp

    zephyr\drivers\hdlc_rcp_if\hdlc_rcp_if_nxp.c

C++ code in Zephyr

There are already few files in zephyr directory as follows for example

• zephyr\modules\thrift\src\thrift\transport\TSSLSocket.cpp
• zephyr\modules\thrift\src\thrift\server\TServerFramework.cpp

@xavraz Thanks for clarification.
The idea of what You are trying to do seems great. I'm wondering if the parts of code corresponding to the Spinel interface wouldn't fit more into OT repository than zephyr's. Then You chould just provide the Platform API for sending the data. and altering integration in openthread.c as you have already done. Have You considered that?

drivers/hdlc_rcp_if/Kconfig Outdated Show resolved Hide resolved
drivers/hdlc_rcp_if/Kconfig.nxp Outdated Show resolved Hide resolved
modules/openthread/platform/spinel_hdlc.cpp Outdated Show resolved Hide resolved
modules/openthread/platform/platform_spinel.c Outdated Show resolved Hide resolved
modules/openthread/platform/spinel_hdlc.hpp Outdated Show resolved Hide resolved
@JA-NXP
Copy link

JA-NXP commented Oct 16, 2024

I didn't changed the settings_nvs.c file so I don't know why I have this error:
image

@JA-NXP JA-NXP force-pushed the feature_openthread_hdlc_rcp branch from 678cee7 to a492241 Compare October 16, 2024 09:23
@rlubos
Copy link
Contributor

rlubos commented Oct 16, 2024

@JA-NXP Settings subsys will fetch the storage partition info from device tree, and it seems that storage_partition is not defined for frdm_rw612, hence the error. rd_rw612_bga doesn't seem to have this problem:

storage_partition: partition@623000 {

Copy link
Collaborator

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

Copy link

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.

@zephyrbot
Copy link
Collaborator

zephyrbot commented Oct 17, 2024

The following west manifest projects have been modified in this Pull Request:

Name Old Revision New Revision Diff
hal_nxp zephyrproject-rtos/hal_nxp@4a4741f (master) zephyrproject-rtos/hal_nxp#453 zephyrproject-rtos/hal_nxp#453/files

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@JA-NXP JA-NXP force-pushed the feature_openthread_hdlc_rcp branch from 7f6b72f to bd0e312 Compare October 17, 2024 12:38
@dleach02 dleach02 force-pushed the feature_openthread_hdlc_rcp branch 2 times, most recently from f5e1f04 to 20acadd Compare October 21, 2024 16:27
@dleach02
Copy link
Member

#79882 updated the TSC ticket with TSC notes. There is a specific question on why we need to pull the particular files in.

rlubos
rlubos previously approved these changes Oct 31, 2024
hdlc_api = (struct hdlc_api *)radio_dev->api;
if (!hdlc_api) {
otLogDebgPlat("Radio device initialization failed");
assert(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you mixing zephyr's __ASSERT macros with these assert calls?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree & resolved

return ret;
}

static struct hdlc_api hdlc_api = {.iface_api.init = hdlc_iface_init,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use a name that is the same as the struct type, also this should be const.

I wonder why compliance doesn't complain here?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree & resolved

Comment on lines 359 to 360
(void)buffer;
(void)len;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use some macro here, OT_UNUSED_VARIABLE or maybe even prefer ARG_UNUSED?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree & resolved

status = PLATFORM_InitHdlcInterface(hdlc_rx_callback, param);
if (status < 0) {
LOG_ERR("HDLC RX callback registration failed");
ret = EIO;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error return values are typically negative.

Also I don't think the do {} while (false); makes sense here.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree & resolved

@JA-NXP JA-NXP force-pushed the feature_openthread_hdlc_rcp branch 2 times, most recently from 28d957b to c22284e Compare November 5, 2024 14:47
return ret;
}

static struct hdlc_api nxp_hdlc_api = {.iface_api.init = hdlc_iface_init,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static struct hdlc_api nxp_hdlc_api = {.iface_api.init = hdlc_iface_init,
static const struct hdlc_api nxp_hdlc_api = {.iface_api.init = hdlc_iface_init,

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Comment on lines 117 to 120
static 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};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a trailing comma so it gets formatted with only 1 indentation.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to know. Resolved.

@JA-NXP JA-NXP force-pushed the feature_openthread_hdlc_rcp branch 2 times, most recently from 4844f76 to 1afb64b Compare November 5, 2024 16:53
Add a HDLC RCP communication with its hdlc_api interface APIs
and a NXP driver.

Signed-off-by: Jamel Arbi <[email protected]>
Add a spinel support to an RCP design, the core of OpenThread lives on the
host processor connected to an RCP radio controller over a HDLC interface.

Signed-off-by: Jamel Arbi <[email protected]>
Adapt the openthread.c file to support the host RCP interface.

Signed-off-by: Jamel Arbi <[email protected]>
Add OT RCP config for NXP RW612 platform

Signed-off-by: Jamel Arbi <[email protected]>
Add flash partirions for NXP FRDM RW612 board

Signed-off-by: Jamel Arbi <[email protected]>
Update hal_nxp to include Openthread RCP changes

Signed-off-by: Jamel Arbi <[email protected]>
@JA-NXP JA-NXP force-pushed the feature_openthread_hdlc_rcp branch from 1afb64b to f51d525 Compare November 5, 2024 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Networking area: OpenThread area: Samples Samples area: Sockets Networking sockets DNM This PR should not be merged (Do Not Merge) manifest manifest-hal_nxp platform: NXP Drivers NXP Semiconductors, drivers platform: NXP NXP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants