Skip to content
Merged
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
26 changes: 26 additions & 0 deletions boards/nxp/frdm_rw612/frdm_rw612.dts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,32 @@
erase-block-size = <4096>;
write-block-size = <1>;
spi-max-frequency = <104000000>;

partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 DT_SIZE_K(128)>;
};
/* The MCUBoot swap-move algorithm uses the last 2 sectors
* of the primary slot0 for swap status and move.
*/
slot0_partition: partition@20000 {
label = "image-0";
reg = <0x00020000 (DT_SIZE_M(3) + DT_SIZE_K(2 * 4))>;
};
slot1_partition: partition@323000 {
label = "image-1";
reg = <0x00323000 DT_SIZE_M(3)>;
};
storage_partition: partition@623000 {
label = "storage";
reg = <0x00623000 (DT_SIZE_M(58) - DT_SIZE_K(136))>;
};
};
};
aps6404l: aps6404l@2 {
compatible = "nxp,imx-flexspi-aps6404l";
Expand Down
8 changes: 8 additions & 0 deletions doc/LICENSING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ licensing in this document.
*Origin:* ThreadX

*Licensing:* `MIT License`_

.. _BSD-3-clause:
https://opensource.org/license/bsd-3-clause

*modules/openthread/platform/{hdlc_interface.cpp,hdlc_interface.hpp,radio_spinel.cpp}*
*Origin:* OpenThread

*Licensing:* `BSD-3-clause`_
1 change: 1 addition & 0 deletions drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ add_subdirectory_ifdef(CONFIG_FUEL_GAUGE fuel_gauge)
add_subdirectory_ifdef(CONFIG_GNSS gnss)
add_subdirectory_ifdef(CONFIG_GPIO gpio)
add_subdirectory_ifdef(CONFIG_HAPTICS haptics)
add_subdirectory_ifdef(CONFIG_HDLC_RCP_IF hdlc_rcp_if)
add_subdirectory_ifdef(CONFIG_HWINFO hwinfo)
add_subdirectory_ifdef(CONFIG_HWSPINLOCK hwspinlock)
add_subdirectory_ifdef(CONFIG_I2C i2c)
Expand Down
1 change: 1 addition & 0 deletions drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ source "drivers/fuel_gauge/Kconfig"
source "drivers/gnss/Kconfig"
source "drivers/gpio/Kconfig"
source "drivers/haptics/Kconfig"
source "drivers/hdlc_rcp_if/Kconfig"
source "drivers/hwinfo/Kconfig"
source "drivers/hwspinlock/Kconfig"
source "drivers/i2c/Kconfig"
Expand Down
5 changes: 5 additions & 0 deletions drivers/hdlc_rcp_if/CMakeLists.txt
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)
29 changes: 29 additions & 0 deletions drivers/hdlc_rcp_if/Kconfig
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
13 changes: 13 additions & 0 deletions drivers/hdlc_rcp_if/Kconfig.nxp
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
136 changes: 136 additions & 0 deletions drivers/hdlc_rcp_if/hdlc_rcp_if_nxp.c
Copy link
Contributor

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
Contributor

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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* 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 */
9 changes: 9 additions & 0 deletions dts/arm/nxp/nxp_rw6xx_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
chosen {
zephyr,entropy = &trng;
zephyr,bt-hci = &hci;
zephyr,hdlc-rcp-if = &hdlc_rcp_if;
};

cpus {
Expand Down Expand Up @@ -521,6 +522,14 @@
interrupt-names = "hci_int", "wakeup_int";
};

hdlc_rcp_if: hdlc_rcp_if {
compatible = "nxp,hdlc-rcp-if";
/* first index is the hdlc_rcp_if interrupt */
/* the second is the wake up done interrupt */
interrupts = <90 2>, <82 2>;
interrupt-names = "hdlc_rcp_if_int", "wakeup_int";
};

enet: enet@138000 {
compatible = "nxp,enet";
reg = <0x138000 0x700>;
Expand Down
8 changes: 8 additions & 0 deletions dts/bindings/hdlc_rcp_if/nxp,hdlc-rcp-if.yaml
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
77 changes: 77 additions & 0 deletions include/zephyr/net/hdlc_rcp_if/hdlc_rcp_if.h
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
11 changes: 11 additions & 0 deletions modules/openthread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@ list(APPEND ot_libs openthread-mtd)
endif()
endif()

if(CONFIG_HDLC_RCP_IF)
list(APPEND ot_libs
ot-config
openthread-platform
openthread-radio-spinel
openthread-spinel-ncp
openthread-url
openthread-hdlc
)
endif()

if(CONFIG_OPENTHREAD_SETTINGS_RAM)
target_compile_options(openthread-platform-utils PRIVATE
$<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_OPTIONS>
Expand Down
8 changes: 8 additions & 0 deletions modules/openthread/platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ zephyr_library_sources(
entropy.c
misc.c
platform.c
)

zephyr_library_sources_ifndef(CONFIG_HDLC_RCP_IF
radio.c
spi.c
)

zephyr_library_sources_ifdef(CONFIG_HDLC_RCP_IF
radio_spinel.cpp
hdlc_interface.cpp
)

zephyr_library_sources_ifdef(CONFIG_OPENTHREAD_BLE_TCAT ble.c)
zephyr_library_sources_ifdef(CONFIG_OPENTHREAD_DIAG diag.c)
zephyr_library_sources_ifdef(CONFIG_OPENTHREAD_COPROCESSOR uart.c)
Expand Down
Loading
Loading