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 {
220#define NRF_RPC_GROUP_DEFINE_INTERNAL__(_name, _strid, _transport, _ack_handler, \
221 _ack_data, _err_handler, _bound_handler, \
222 _wait_on_init, _initiator) \
223 NRF_RPC_AUTO_ARR(NRF_RPC_CONCAT(_name, _cmd_array), \
224 "cmd_" NRF_RPC_STRINGIFY(_name)); \
225 NRF_RPC_AUTO_ARR(NRF_RPC_CONCAT(_name, _evt_array), \
226 "evt_" NRF_RPC_STRINGIFY(_name)); \
228 static struct nrf_rpc_group_data NRF_RPC_CONCAT(_name, _group_data) = { \
229 .src_group_id = NRF_RPC_ID_UNKNOWN, \
230 .dst_group_id = NRF_RPC_ID_UNKNOWN, \
231 .transport_initialized = false, \
234 NRF_RPC_AUTO_ARR_ITEM(const struct nrf_rpc_group, _name, "grp", \
236 .cmd_array = &NRF_RPC_CONCAT(_name, _cmd_array), \
237 .evt_array = &NRF_RPC_CONCAT(_name, _evt_array), \
238 .data = &NRF_RPC_CONCAT(_name, _group_data), \
239 .ack_handler = _ack_handler, \
240 .ack_handler_data = _ack_data, \
242 .transport = _transport, \
243 .err_handler = _err_handler, \
244 .bound_handler = _bound_handler, \
245 .flags = NRF_RPC_FLAG_COND(_wait_on_init, NRF_RPC_FLAGS_WAIT_ON_INIT) \
246 | NRF_RPC_FLAG_COND(_initiator, NRF_RPC_FLAGS_INITIATOR), \
264#define NRF_RPC_GROUP_DEFINE(_name, _strid, _transport, _ack_handler, _ack_data, _err_handler) \
265 NRF_RPC_GROUP_DEFINE_INTERNAL__(_name, _strid, _transport, _ack_handler, _ack_data, \
266 _err_handler, NULL, \
267 IS_ENABLED(CONFIG_NRF_RPC_GROUP_DEFAULT_WAIT_ON_INIT), \
268 IS_ENABLED(CONFIG_NRF_RPC_GROUP_DEFAULT_INITIATOR))
299#define NRF_RPC_GROUP_DEFINE_NOWAIT(_name, _strid, _transport, _ack_handler, \
300 _ack_data, _err_handler, _bound_handler, \
302 NRF_RPC_GROUP_DEFINE_INTERNAL__(_name, _strid, _transport, _ack_handler, \
303 _ack_data, _err_handler, _bound_handler, \
312#define NRF_RPC_GROUP_DECLARE(_name) \
313 extern const struct nrf_rpc_group _name
324#define NRF_RPC_CMD_DECODER(_group, _name, _cmd, _handler, _data) \
325 NRF_RPC_STATIC_ASSERT(_cmd <= 0xFE, "Command out of range"); \
326 NRF_RPC_AUTO_ARR_ITEM(const struct _nrf_rpc_decoder, \
327 NRF_RPC_CONCAT(_name, _cmd_dec), \
328 "cmd_" NRF_RPC_STRINGIFY(_group), \
329 NRF_RPC_STRINGIFY(_name)) = { \
331 .handler = _handler, \
332 .handler_data = _data, \
344#define NRF_RPC_EVT_DECODER(_group, _name, _evt, _handler, _data) \
345 NRF_RPC_STATIC_ASSERT(_evt <= 0xFE, "Event out of range"); \
346 NRF_RPC_AUTO_ARR_ITEM(const struct _nrf_rpc_decoder, \
347 NRF_RPC_CONCAT(_name, _evt_dec), \
348 "evt_" NRF_RPC_STRINGIFY(_group), \
349 NRF_RPC_STRINGIFY(_name)) = { \
351 .handler = _handler, \
352 .handler_data = _data, \
361#define NRF_RPC_GROUP_STATUS(_group) \
362 (_group.data->transport_initialized && (_group.data->dst_group_id != NRF_RPC_ID_UNKNOWN))
503 size_t len,
const uint8_t **rsp_packet,
size_t *rsp_len);
540 uint8_t *packet,
size_t len,
const uint8_t **rsp_packet,
570 uint8_t *packet,
size_t len);
624 uint8_t packet_type);
642 uint8_t packet_type,
const char *file,
int line,
const char *func);
644#ifdef CONFIG_NRF_RPC_DETAILED_ERROR_REPORTING
645#define nrf_rpc_err(_code, _src, _group, _id, _packet_type) \
646 nrf_rpc_err_impl(_code, _src, _group, _id, _packet_type, __FILE__, __LINE__, __func__)
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.
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.
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.
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
int nrf_rpc_bind(void)
Binds the nRF RPC groups.
void nrf_rpc_unbind(void)
Unbinds the nRF RPC groups.
void nrf_rpc_set_bound_handler(nrf_rpc_group_bound_handler_t bound_handler)
Register a global bound handler.
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_stop(bool cleanup)
Temporarily suspend all RPC communication.
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
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.
int nrf_rpc_setup(nrf_rpc_err_handler_t err_handler, nrf_rpc_group_bound_handler_t bound_handler)
Initialize the nRF RPC internal state.
void(* nrf_rpc_ack_handler_t)(uint8_t id, void *handler_data)
Callback called when ACK was received.
Definition nrf_rpc.h:91
void nrf_rpc_resume(void)
resumes RPC communication
void nrf_rpc_err_impl(int code, enum nrf_rpc_err_src src, const struct nrf_rpc_group *group, uint8_t id, uint8_t packet_type, const char *file, int line, const char *func)
Report an error to nRF RPC error handler.
int nrf_rpc_init(nrf_rpc_err_handler_t err_handler)
Initialize the nRF RPC.
void nrf_rpc_register_cleanup_handler(struct nrf_rpc_cleanup_handler *handler)
Registers the cleanup handler.
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.
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.
void(* handler)(void *context)
Handler to the cleanup function invoked on the call to nrf_rpc_stop.
Definition nrf_rpc.h:188
struct nrf_rpc_cleanup_handler * next
Pointer to the next element in the list. Managed automatically by the nrf_rpc.
Definition nrf_rpc.h:194
void * context
Custom context passed as the function parameter.
Definition nrf_rpc.h:191
Cleanup procedure list element.
Definition nrf_rpc.h:186
int code
Error code.
Definition nrf_rpc.h:157
const char * file
File where the error was reported.
Definition nrf_rpc.h:174
const char * func
Function where the error was reported.
Definition nrf_rpc.h:180
int line
Line number where the error was reported.
Definition nrf_rpc.h:177
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