17#include <nrf_rpc_os.h>
30#define NRF_RPC_PROTOCOL_VERSION 0
33#define NRF_RPC_ID_UNKNOWN 0xFF
36#define NRF_RPC_FLAGS_WAIT_ON_INIT 0x01
39#define NRF_RPC_FLAGS_INITIATOR 0x02
42#define NRF_RPC_FLAG_COND(_cond, _flag) ((_cond) ? (_flag) : 0UL)
82 size_t len,
void *handler_data);
118struct _nrf_rpc_decoder {
197#define NRF_RPC_GROUP_DEFINE_INTERNAL__(_name, _strid, _transport, _ack_handler, \
198 _ack_data, _err_handler, _bound_handler, \
199 _wait_on_init, _initiator) \
200 NRF_RPC_AUTO_ARR(NRF_RPC_CONCAT(_name, _cmd_array), \
201 "cmd_" NRF_RPC_STRINGIFY(_name)); \
202 NRF_RPC_AUTO_ARR(NRF_RPC_CONCAT(_name, _evt_array), \
203 "evt_" NRF_RPC_STRINGIFY(_name)); \
205 static struct nrf_rpc_group_data NRF_RPC_CONCAT(_name, _group_data) = { \
206 .src_group_id = NRF_RPC_ID_UNKNOWN, \
207 .dst_group_id = NRF_RPC_ID_UNKNOWN, \
208 .transport_initialized = false, \
211 NRF_RPC_AUTO_ARR_ITEM(const struct nrf_rpc_group, _name, "grp", \
213 .cmd_array = &NRF_RPC_CONCAT(_name, _cmd_array), \
214 .evt_array = &NRF_RPC_CONCAT(_name, _evt_array), \
215 .data = &NRF_RPC_CONCAT(_name, _group_data), \
216 .ack_handler = _ack_handler, \
217 .ack_handler_data = _ack_data, \
219 .transport = _transport, \
220 .err_handler = _err_handler, \
221 .bound_handler = _bound_handler, \
222 .flags = NRF_RPC_FLAG_COND(_wait_on_init, NRF_RPC_FLAGS_WAIT_ON_INIT) \
223 | NRF_RPC_FLAG_COND(_initiator, NRF_RPC_FLAGS_INITIATOR), \
241#define NRF_RPC_GROUP_DEFINE(_name, _strid, _transport, _ack_handler, _ack_data, \
243 NRF_RPC_GROUP_DEFINE_INTERNAL__(_name, _strid, _transport, _ack_handler, \
244 _ack_data, _err_handler, NULL, true, \
276#define NRF_RPC_GROUP_DEFINE_NOWAIT(_name, _strid, _transport, _ack_handler, \
277 _ack_data, _err_handler, _bound_handler, \
279 NRF_RPC_GROUP_DEFINE_INTERNAL__(_name, _strid, _transport, _ack_handler, \
280 _ack_data, _err_handler, _bound_handler, \
289#define NRF_RPC_GROUP_DECLARE(_name) \
290 extern const struct nrf_rpc_group _name
301#define NRF_RPC_CMD_DECODER(_group, _name, _cmd, _handler, _data) \
302 NRF_RPC_STATIC_ASSERT(_cmd <= 0xFE, "Command out of range"); \
303 NRF_RPC_AUTO_ARR_ITEM(const struct _nrf_rpc_decoder, \
304 NRF_RPC_CONCAT(_name, _cmd_dec), \
305 "cmd_" NRF_RPC_STRINGIFY(_group), \
306 NRF_RPC_STRINGIFY(_name)) = { \
308 .handler = _handler, \
309 .handler_data = _data, \
321#define NRF_RPC_EVT_DECODER(_group, _name, _evt, _handler, _data) \
322 NRF_RPC_STATIC_ASSERT(_evt <= 0xFE, "Event out of range"); \
323 NRF_RPC_AUTO_ARR_ITEM(const struct _nrf_rpc_decoder, \
324 NRF_RPC_CONCAT(_name, _evt_dec), \
325 "evt_" NRF_RPC_STRINGIFY(_group), \
326 NRF_RPC_STRINGIFY(_name)) = { \
328 .handler = _handler, \
329 .handler_data = _data, \
338#define NRF_RPC_GROUP_STATUS(_group) \
339 (_group.data->transport_initialized && (_group.data->dst_group_id != NRF_RPC_ID_UNKNOWN))
366 uint8_t *packet,
size_t len,
388 uint8_t cmd, uint8_t *packet,
size_t len,
389 const uint8_t **rsp_packet,
size_t *rsp_len);
409 uint8_t cmd, uint8_t *packet,
size_t len,
428 uint8_t cmd, uint8_t *packet,
430 const uint8_t **rsp_packet,
460 uint8_t *packet,
size_t len);
514 uint8_t packet_type);
519 uint8_t *packet,
size_t len,
522 int nrf_rpc_cmd_common(
const struct nrf_rpc_group *group, uint32_t cmd,
523 uint8_t *packet,
size_t len,
void *ptr1,
526 return nrf_rpc_cmd_common(group, cmd, packet, len, handler,
531 uint8_t cmd, uint8_t *packet,
size_t len,
532 const uint8_t **rsp_packet,
size_t *rsp_len)
534 int nrf_rpc_cmd_common(
const struct nrf_rpc_group *group, uint32_t cmd,
535 uint8_t *packet,
size_t len,
void *ptr1,
538 return nrf_rpc_cmd_common(group, cmd | 0x10000, packet, len, rsp_packet,
543 uint8_t cmd, uint8_t *packet,
size_t len,
547 void nrf_rpc_cmd_common_no_err(
const struct nrf_rpc_group *group,
548 uint32_t cmd, uint8_t *packet,
549 size_t len,
void *ptr1,
void *ptr2);
551 nrf_rpc_cmd_common_no_err(group, cmd, packet, len, handler,
556 uint8_t cmd, uint8_t *packet,
558 const uint8_t **rsp_packet,
561 void nrf_rpc_cmd_common_no_err(
const struct nrf_rpc_group *group,
562 uint32_t cmd, uint8_t *packet,
563 size_t len,
void *ptr1,
void *ptr2);
565 nrf_rpc_cmd_common_no_err(group, cmd | 0x10000, packet, len, rsp_packet,
int nrf_rpc_rsp(const struct nrf_rpc_group *group, uint8_t *packet, size_t len)
Send a response.
void(* nrf_rpc_err_handler_t)(const struct nrf_rpc_err_report *report)
Callback to report error that cannot be returned by the API call.
Definition nrf_rpc.h:107
void nrf_rpc_rsp_no_err(const struct nrf_rpc_group *group, uint8_t *packet, size_t len)
Send a response and pass any error to an error handler.
void nrf_rpc_free_tx_buf(const struct nrf_rpc_group *group, uint8_t *buf)
Deallocates Tx buffer.
nrf_rpc_err_src
Error source.
Definition nrf_rpc.h:65
@ NRF_RPC_ERR_SRC_REMOTE
Error reported be the remote.
Definition nrf_rpc.h:68
@ NRF_RPC_ERR_SRC_RECV
Error during receiving.
Definition nrf_rpc.h:66
@ NRF_RPC_ERR_SRC_SEND
Error during sending.
Definition nrf_rpc.h:67
void(* nrf_rpc_ack_handler_t)(uint8_t id, void *handler_data)
Callback called when ACK was received.
Definition nrf_rpc.h:91
static void nrf_rpc_cmd_no_err(const struct nrf_rpc_group *group, uint8_t cmd, uint8_t *packet, size_t len, nrf_rpc_handler_t handler, void *handler_data)
Send a command, provide callback to handle response and pass any error to an error handler.
Definition nrf_rpc.h:542
int nrf_rpc_init(nrf_rpc_err_handler_t err_handler)
Initialize the nRF RPC.
static int nrf_rpc_cmd_rsp(const struct nrf_rpc_group *group, uint8_t cmd, uint8_t *packet, size_t len, const uint8_t **rsp_packet, size_t *rsp_len)
Send a command and get response as an output parameter.
Definition nrf_rpc.h:530
static int nrf_rpc_cmd(const struct nrf_rpc_group *group, uint8_t cmd, uint8_t *packet, size_t len, nrf_rpc_handler_t handler, void *handler_data)
Send a command and provide callback to handle response.
Definition nrf_rpc.h:518
void nrf_rpc_evt_no_err(const struct nrf_rpc_group *group, uint8_t evt, uint8_t *packet, size_t len)
Send an event and pass any error to an error handler.
void(* nrf_rpc_handler_t)(const struct nrf_rpc_group *group, const uint8_t *packet, size_t len, void *handler_data)
Callback that handles decoding of commands, events and responses.
Definition nrf_rpc.h:81
nrf_rpc_packet_type
Type of packet.
Definition nrf_rpc.h:52
@ NRF_RPC_PACKET_TYPE_ERR
Error report from remote.
Definition nrf_rpc.h:56
@ NRF_RPC_PACKET_TYPE_ACK
Event acknowledge.
Definition nrf_rpc.h:55
@ NRF_RPC_PACKET_TYPE_CMD
Command.
Definition nrf_rpc.h:58
@ NRF_RPC_PACKET_TYPE_INIT
Initialization packet.
Definition nrf_rpc.h:57
@ NRF_RPC_PACKET_TYPE_RSP
Response.
Definition nrf_rpc.h:54
@ NRF_RPC_PACKET_TYPE_EVT
Event.
Definition nrf_rpc.h:53
void(* nrf_rpc_group_bound_handler_t)(const struct nrf_rpc_group *group)
Callback called when the command group is bound.
Definition nrf_rpc.h:115
int nrf_rpc_evt(const struct nrf_rpc_group *group, uint8_t evt, uint8_t *packet, size_t len)
Send an event.
static void nrf_rpc_cmd_rsp_no_err(const struct nrf_rpc_group *group, uint8_t cmd, uint8_t *packet, size_t len, const uint8_t **rsp_packet, size_t *rsp_len)
Send a command, get response as an output parameter and pass any error to an error handler.
Definition nrf_rpc.h:555
void nrf_rpc_decoding_done(const struct nrf_rpc_group *group, const uint8_t *packet)
Indicate that decoding of the input packet is done.
void nrf_rpc_err(int code, enum nrf_rpc_err_src src, const struct nrf_rpc_group *group, uint8_t id, uint8_t packet_type)
Report an error to nRF RPC error handler.
void nrf_rpc_alloc_tx_buf(const struct nrf_rpc_group *group, uint8_t **buf, size_t len)
Allocates buffer for a packet.
int code
Error code.
Definition nrf_rpc.h:157
enum nrf_rpc_packet_type packet_type
Type of packet. Value may be outside defined enum values if packet is malformed.
Definition nrf_rpc.h:171
enum nrf_rpc_err_src src
Source of the error.
Definition nrf_rpc.h:163
const struct nrf_rpc_group * group
Group where the error occurred or NULL if it is unknown.
Definition nrf_rpc.h:160
uint8_t id
Command or event id or NRF_RPC_ID_UNKNOWN.
Definition nrf_rpc.h:166
Error report.
Definition nrf_rpc.h:154
uint8_t dst_group_id
Definition nrf_rpc.h:127
bool transport_initialized
Definition nrf_rpc.h:129
struct nrf_rpc_os_event decode_done_event
Definition nrf_rpc.h:128
uint8_t src_group_id
Definition nrf_rpc.h:126
Group data structure. It contains no constant group data.
Definition nrf_rpc.h:125
nrf_rpc_err_handler_t err_handler
Definition nrf_rpc.h:147
nrf_rpc_ack_handler_t ack_handler
Definition nrf_rpc.h:144
nrf_rpc_group_bound_handler_t bound_handler
Definition nrf_rpc.h:148
struct nrf_rpc_group_data * data
Definition nrf_rpc.h:142
void * ack_handler_data
Definition nrf_rpc.h:145
const uint32_t flags
Definition nrf_rpc.h:149
const void * cmd_array
Definition nrf_rpc.h:140
const struct nrf_rpc_tr * transport
Definition nrf_rpc.h:143
const char * strid
Definition nrf_rpc.h:146
const void * evt_array
Definition nrf_rpc.h:141
Defines a group of commands and events.
Definition nrf_rpc.h:139
nRF RPC transport structure.
Definition nrf_rpc_tr.h:92