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

Nrf rpc sm_ipt backend #525

Closed
Closed
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
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2019 - 2020 Nordic Semiconductor
# Copyright (c) 2019 - 2021 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
Expand All @@ -19,3 +19,4 @@ add_subdirectory_ifdef(CONFIG_BT softdevice_controller)
add_subdirectory_ifdef(CONFIG_NET_L2_OPENTHREAD openthread)
add_subdirectory_ifdef(CONFIG_NRF_RPC nrf_rpc)
add_subdirectory_ifdef(CONFIG_ZIGBEE zboss)
add_subdirectory_ifdef(CONFIG_SM_IPT sm_ipt)
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ doc/* @b-gent
/zboss/ @tomchy
/zephyr/ @carlescufi
/nrf_rpc/ @doki-nordic @KAGA164
/sm_ipt/ @doki-nordic
3 changes: 2 additions & 1 deletion Kconfig.nrfxlib
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2019 - 2020 Nordic Semiconductor
# Copyright (c) 2019 - 2021 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
Expand All @@ -13,6 +13,7 @@ rsource "crypto/Kconfig"
rsource "nrf_security/Kconfig"
rsource "softdevice_controller/Kconfig"
rsource "nrf_rpc/Kconfig"
rsource "sm_ipt/Kconfig"
rsource "zboss/Kconfig"
rsource "openthread/Kconfig"
rsource "nrf_802154/zephyr/Kconfig.nrfxlib"
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ Refer to their respective documentation for more information.
nrf_rpc/README
softdevice_controller/README
zboss/README
sm_ipt/README
3 changes: 2 additions & 1 deletion nrf_rpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
zephyr_include_directories(include)

zephyr_library()
zephyr_library_sources(nrf_rpc.c)

zephyr_library_sources_ifdef(CONFIG_NRF_RPC_CBOR nrf_rpc_cbor.c)
zephyr_library_sources_ifdef(CONFIG_NRF_RPC_TR_SHMEM sm_ipt_backend.c)
zephyr_library_sources(nrf_rpc.c)

zephyr_linker_sources(SECTIONS nrf_rpc.ld)
7 changes: 7 additions & 0 deletions nrf_rpc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ config NRF_RPC_TR_RPMSG
help
If enabled selects RPMsg as a transport layer for nRF PRC.

config NRF_RPC_TR_SHMEM
bool "nRF RPC over shared memory"
select SM_IPT
help
If enabled selects SM_IPT as a transport layer for nRF PRC.
It requires additional API implemented in nrf_rpc_os.h file.

Copy link
Contributor

Choose a reason for hiding this comment

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

We are using SM IPT module, so we can use its name instead of just shared memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

config NRF_RPC_TR_CUSTOM
bool "User provided transport layer"
help
Expand Down
22 changes: 22 additions & 0 deletions nrf_rpc/include/nrf_rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,20 @@ extern "C" {
/* Internal definition used in the macros. */
#define _NRF_RPC_HEADER_SIZE 4

#ifndef NRF_RPC_TR_MAX_HEADER_SIZE
#define NRF_RPC_TR_MAX_HEADER_SIZE 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't define them here. Transport header file is responsible for defining it.
The same for NRF_RPC_TR_AUTO_FREE_RX_BUF.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is ifdef def, so if transport have not defined anything the values of macros are set to default.

#endif

#ifndef NRF_RPC_TR_AUTO_FREE_RX_BUF
#define NRF_RPC_TR_AUTO_FREE_RX_BUF 0
#endif

/** @brief Special value to indicate that ID is unknown or irrelevant. */
#define NRF_RPC_ID_UNKNOWN 0xFF

/** @brief Special value to indicate that ID is unknown or irrelevant. */
#define NRF_RPC_MAX_ALLOC_SIZE 0x70000000

/* Forward declaration. */
struct nrf_rpc_err_report;

Expand Down Expand Up @@ -230,9 +241,20 @@ struct nrf_rpc_err_report {
* a newly allocated packet buffer.
* @param[in] _len Requested length of the packet.
*/
/* If nrf_rpc_tr_alloc_tx_buf is a macro, put it directly,
* because it may allocate memory on stack.
*/
#ifdef nrf_rpc_tr_alloc_tx_buf
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it is better to explain this #ifdef, because it is not obvious.

/* If nrf_rpc_tr_alloc_tx_buf is a macro, put it directly, because it may allocate memory on stack. */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment added

#define NRF_RPC_ALLOC(_packet, _len) \
nrf_rpc_tr_alloc_tx_buf(&(_packet), _NRF_RPC_HEADER_SIZE + (_len)); \
*(uint8_t **)&(_packet) += _NRF_RPC_HEADER_SIZE
#else
#define NRF_RPC_ALLOC(_packet, _len) \
do { \
extern uint8_t *_nrf_rpc_alloc(size_t len); \
(_packet) = _nrf_rpc_alloc(_len); \
} while (0)
#endif

/** @brief Deallocate memory for a packet.
*
Expand Down
5 changes: 5 additions & 0 deletions nrf_rpc/include/nrf_rpc_cbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,14 @@ struct nrf_rpc_cbor_rsp_ctx {
* resources to encode and send a packet.
* @param[in] _len Requested length of the packet.
*/
#ifdef nrf_rpc_tr_alloc_tx_buf
#define NRF_RPC_CBOR_ALLOC(_ctx, _len) \
NRF_RPC_ALLOC((_ctx).out_packet, (_len) + 1); \
_nrf_rpc_cbor_prepare((struct nrf_rpc_cbor_ctx *)(&(_ctx)), (_len) + 1)
#else
#define NRF_RPC_CBOR_ALLOC(_ctx, _len) \
_nrf_rpc_cbor_prepare((struct nrf_rpc_cbor_ctx *)(&(_ctx)), (_len) + 1)
#endif

/** @brief Deallocate memory for a packet.
*
Expand Down
6 changes: 5 additions & 1 deletion nrf_rpc/include/nrf_rpc_tr.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Nordic Semiconductor ASA
* Copyright (c) 2020-2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
Expand All @@ -11,6 +11,10 @@

#include <nrf_rpc_rpmsg.h>

#elif defined(CONFIG_NRF_RPC_TR_SHMEM)

#include <sm_ipt_backend.h>

#elif defined(CONFIG_NRF_RPC_TR_CUSTOM)

#include CONFIG_NRF_RPC_TR_CUSTOM_INCLUDE
Expand Down
47 changes: 47 additions & 0 deletions nrf_rpc/include/sm_ipt_backend.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef SM_IPT_BACKEND_H
#define SM_IPT_BACKEND_H

#include <sm_ipt.h>

#ifdef __cplusplus
extern "C" {
#endif

extern struct sm_ipt_ctx sm_ipt_context;

static inline int nrf_rpc_tr_init(sm_ipt_receive_handler_t callback)
{
return sm_ipt_init(&sm_ipt_context, callback);
}

static inline void nrf_rpc_tr_free_rx_buf(const uint8_t *packet)
{
sm_ipt_free_rx_buf(&sm_ipt_context, packet);
}

static inline void nrf_rpc_tr_alloc_tx_buf(uint8_t **buf, size_t len)
{
sm_ipt_alloc_tx_buf(&sm_ipt_context, buf, len);
}

static inline void nrf_rpc_tr_free_tx_buf(uint8_t *buf)
{
sm_ipt_free_tx_buf(&sm_ipt_context, buf);
}

static inline int nrf_rpc_tr_send(uint8_t *buf, size_t len)
{
return sm_ipt_send(&sm_ipt_context, buf, len);
}

#ifdef __cplusplus
}
#endif

#endif
17 changes: 16 additions & 1 deletion nrf_rpc/nrf_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ static void receive_handler(const uint8_t *packet, size_t len)
}

NRF_RPC_DBG("Received %d bytes packet from %d to %d, type 0x%02X, "
"cmd/evt/cnt 0x%02X, grp %d (%s)", len, hdr.src, hdr.dst,
"cmd/evt/cnt 0x%02X, grp %d (%s)", (int)len, hdr.src, hdr.dst,
hdr.type, hdr.id, hdr.group_id,
(group != NULL) ? group->strid : "unknown");

Expand Down Expand Up @@ -801,3 +801,18 @@ void nrf_rpc_err(int code, enum nrf_rpc_err_src src,
global_err_handler(&report);
}
}

#ifndef nrf_rpc_tr_alloc_tx_buf

uint8_t *_nrf_rpc_alloc(size_t len)
{
uint8_t *packet;

NRF_RPC_ASSERT(len < NRF_RPC_MAX_ALLOC_SIZE);

nrf_rpc_tr_alloc_tx_buf(&packet, _NRF_RPC_HEADER_SIZE + len);

return &packet[_NRF_RPC_HEADER_SIZE];
Copy link
Contributor

Choose a reason for hiding this comment

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

Blank line before return ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

}

#endif
3 changes: 3 additions & 0 deletions nrf_rpc/nrf_rpc_cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ void _nrf_rpc_cbor_proxy_handler(const uint8_t *packet, size_t len,

void _nrf_rpc_cbor_prepare(struct nrf_rpc_cbor_ctx *ctx, size_t len)
{
#ifndef nrf_rpc_tr_alloc_tx_buf
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this defined ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Transport layer provides this function (nrf_rpc_tr.h). Here it is as a template (*_tmpl.h)

NRF_RPC_ALLOC(ctx->out_packet, len + 1);
#endif
cbor_buf_writer_init(&ctx->writer, ctx->out_packet, len);
cbor_encoder_init(&ctx->encoder, &ctx->writer.enc, 0);
}
9 changes: 9 additions & 0 deletions nrf_rpc/sm_ipt_backend.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include "sm_ipt_backend.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Add copyright comment at the beginning of a file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


struct sm_ipt_ctx sm_ipt_context;
1 change: 1 addition & 0 deletions nrf_rpc/template/nrf_rpc_os_tmpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef void (*nrf_rpc_os_work_t)(const uint8_t *data, size_t len);
*
* @param callback Work callback that will be called when something was send
* to a thread pool.
* @param user_data Data pointer passed to ipm device callbacks
*
* @return 0 on success or negative error code.
*/
Expand Down
2 changes: 1 addition & 1 deletion nrf_rpc/template/nrf_rpc_tr_tmpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ int nrf_rpc_tr_send(uint8_t *buf, size_t len);
* @}
*/

#endif /* TRANS_RPMSG_H_ */
#endif /* NRF_RPC_TR_TMPL_H_ */
11 changes: 11 additions & 0 deletions sm_ipt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Copyright (c) 2021 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

zephyr_include_directories(include)

zephyr_library()

zephyr_library_sources(sm_ipt.c)
42 changes: 42 additions & 0 deletions sm_ipt/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# Copyright (c) 2021 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menuconfig SM_IPT
bool "Shared memory Inter-Processor Transport"
help
Enable Shared memory Inter-Processor Transport library

if SM_IPT

choice
prompt "Shared memory blocks"
default SM_IPT_NUM_BLOCKS_32

config SM_IPT_NUM_BLOCKS_32
bool "32"
help
Selects 32 shared memory blocks per single input or output channel.

config SM_IPT_NUM_BLOCKS_64
bool "64"
help
Selects 64 shared memory blocks per single input or output channel.
This will increase allocatable memory granularity, but it will have
some impact on performance and code size.

endchoice

config SM_IPT_PRIMARY
bool "Primary role"
help
One side must have primary role (this option selected) and the other
side must have secondary role. Shared memory layout depends on this configuration.

module = SM_IPT
module-str = SM IPT
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"

endif # SM_IPT
16 changes: 16 additions & 0 deletions sm_ipt/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.. _sm_ipt:

Shared Memory Inter-Processor Transport library (SM IPT)
########################################################

SM IPT is a inter-processor transport library for |NCS| enabling inter-processor communication on Nordic Semiconductor SoCs.
The library is RTOS-agnostic and provides porting templates.

It is designed to be used with as a transport layer, or standalone.

.. toctree::
:maxdepth: 2
:caption: Subpages:

doc/usage
doc/api
17 changes: 17 additions & 0 deletions sm_ipt/doc/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. _sm_ipt_api:

API documentation
#################

.. contents::
:local:
:depth: 2

.. _sm_ipt_api_documentation:

SM IPT
------

.. doxygengroup:: sm_ipt
:project: nrfxlib
:members:
3 changes: 3 additions & 0 deletions sm_ipt/doc/img/architecture.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading