-
Notifications
You must be signed in to change notification settings - Fork 317
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
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 |
---|---|---|
|
@@ -34,3 +34,4 @@ doc/* @b-gent | |
/zboss/ @tomchy | ||
/zephyr/ @carlescufi | ||
/nrf_rpc/ @doki-nordic @KAGA164 | ||
/sm_ipt/ @doki-nordic |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
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. Don't define them here. Transport header file is responsible for defining it. 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. 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; | ||
|
||
|
@@ -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 | ||
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. Maybe it is better to explain this /* If nrf_rpc_tr_alloc_tx_buf is a macro, put it directly, because it may allocate memory on stack. */ 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. 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. | ||
* | ||
|
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
|
||
|
@@ -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]; | ||
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. Blank line before return ? 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. Added |
||
} | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
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. Where is this defined ? 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. 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); | ||
} |
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" | ||
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. Add copyright comment at the beginning of a file. 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. Done |
||
|
||
struct sm_ipt_ctx sm_ipt_context; |
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) |
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 |
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 |
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: |
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.
We are using SM IPT module, so we can use its name instead of just
shared memory
.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.
Done