nrfxlib API 3.3.99
Loading...
Searching...
No Matches
nrf_rpc_cbor.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef _NRF_RPC_CBOR_H_
8#define _NRF_RPC_CBOR_H_
9
10#include <stdint.h>
11#include <stdbool.h>
12#include <stddef.h>
13
14#include <zcbor_common.h>
15#include <zcbor_decode.h>
16#include <zcbor_encode.h>
17
18#include <nrf_rpc.h>
19
20/* Max ZCBOR states: 2 means that no backups are available but we can use constant state
21 * to enable stop_on_error.
22 */
23#define NRF_RPC_ZCBOR_STATES (2 + CONFIG_NRF_RPC_ZCBOR_BACKUPS)
24
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37struct nrf_rpc_cbor_ctx;
38
45typedef void (*nrf_rpc_cbor_handler_t)(const struct nrf_rpc_group *group,
46 struct nrf_rpc_cbor_ctx *ctx, void *handler_data);
47
48/* Structure used internally to define TinCBOR command or event decoder. */
49struct _nrf_rpc_cbor_decoder {
51 void *handler_data;
52};
53
60 zcbor_state_t zs[NRF_RPC_ZCBOR_STATES];
61 union {
62 uint8_t *out_packet;
63 const uint8_t *in_packet;
64 };
65};
66
76#define NRF_RPC_CBOR_CMD_DECODER(_group, _name, _cmd, _handler, _data) \
77 static const \
78 struct _nrf_rpc_cbor_decoder NRF_RPC_CONCAT(_name, _cbor_data) = { \
79 .handler = _handler, \
80 .handler_data = _data, \
81 }; \
82 NRF_RPC_CMD_DECODER(_group, _name, _cmd, _nrf_rpc_cbor_proxy_handler, \
83 (void *)&NRF_RPC_CONCAT(_name, _cbor_data))
84
94#define NRF_RPC_CBOR_EVT_DECODER(_group, _name, _evt, _handler, _data) \
95 static const \
96 struct _nrf_rpc_cbor_decoder NRF_RPC_CONCAT(_name, _cbor_data) = { \
97 .handler = _handler, \
98 .handler_data = _data, \
99 }; \
100 NRF_RPC_EVT_DECODER(_group, _name, _evt, _nrf_rpc_cbor_proxy_handler, \
101 (void *)&NRF_RPC_CONCAT(_name, _cbor_data))
102
116#define NRF_RPC_CBOR_ALLOC(_group, _ctx, _len) \
117 do { \
118 nrf_rpc_alloc_tx_buf(_group, &((_ctx).out_packet), (_len) + 1); \
119 _nrf_rpc_cbor_prepare((struct nrf_rpc_cbor_ctx *)(&(_ctx)), (_len) + 1); \
120 } while (0)
121
130#define NRF_RPC_CBOR_DISCARD(_group, _ctx) \
131 nrf_rpc_free_tx_buf(_group, (_ctx).out_packet)
132
140
154int nrf_rpc_cbor_cmd(const struct nrf_rpc_group *group, uint8_t cmd,
155 struct nrf_rpc_cbor_ctx *ctx,
156 nrf_rpc_cbor_handler_t handler, void *handler_data);
157
172int nrf_rpc_cbor_cmd_rsp(const struct nrf_rpc_group *group, uint8_t cmd,
173 struct nrf_rpc_cbor_ctx *ctx);
174
190void nrf_rpc_cbor_cmd_no_err(const struct nrf_rpc_group *group, uint8_t cmd,
191 struct nrf_rpc_cbor_ctx *ctx,
193 void *handler_data);
194
195void nrf_rpc_cbor_cmd_no_err_impl(const struct nrf_rpc_group *group, uint8_t cmd,
196 struct nrf_rpc_cbor_ctx *ctx,
198 void *handler_data, const char *file, int line, const char *func);
199
200#ifdef CONFIG_NRF_RPC_DETAILED_ERROR_REPORTING
201#define nrf_rpc_cbor_cmd_no_err(_group, _cmd, _ctx, _handler, _handler_data) \
202 nrf_rpc_cbor_cmd_no_err_impl(_group, _cmd, _ctx, _handler, _handler_data, __FILE__, __LINE__, __func__)
203#endif
204
216 uint8_t cmd, struct nrf_rpc_cbor_ctx *ctx);
217
219 uint8_t cmd, struct nrf_rpc_cbor_ctx *ctx,
220 const char *file, int line, const char *func);
221
222#ifdef CONFIG_NRF_RPC_DETAILED_ERROR_REPORTING
223#define nrf_rpc_cbor_cmd_rsp_no_err(_group, _cmd, _ctx) \
224 nrf_rpc_cbor_cmd_rsp_no_err_impl(_group, _cmd, _ctx, __FILE__, __LINE__, __func__)
225#endif
226
236int nrf_rpc_cbor_evt(const struct nrf_rpc_group *group, uint8_t evt,
237 struct nrf_rpc_cbor_ctx *ctx);
238
249void nrf_rpc_cbor_evt_no_err(const struct nrf_rpc_group *group, uint8_t evt,
250 struct nrf_rpc_cbor_ctx *ctx);
251
252void nrf_rpc_cbor_evt_no_err_impl(const struct nrf_rpc_group *group, uint8_t evt,
253 struct nrf_rpc_cbor_ctx *ctx,
254 const char *file, int line, const char *func);
255
256#ifdef CONFIG_NRF_RPC_DETAILED_ERROR_REPORTING
257#define nrf_rpc_cbor_evt_no_err(_group, _evt, _ctx) \
258 nrf_rpc_cbor_evt_no_err_impl(_group, _evt, _ctx, __FILE__, __LINE__, __func__)
259#endif
260
269int nrf_rpc_cbor_rsp(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx);
270
280void nrf_rpc_cbor_rsp_no_err(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx);
281
282void nrf_rpc_cbor_rsp_no_err_impl(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
283 const char *file, int line, const char *func);
284
285#ifdef CONFIG_NRF_RPC_DETAILED_ERROR_REPORTING
286#define nrf_rpc_cbor_rsp_no_err(_group, _ctx) \
287 nrf_rpc_cbor_rsp_no_err_impl(_group, _ctx, __FILE__, __LINE__, __func__)
288#endif
289
302void nrf_rpc_cbor_decoding_done(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx);
303
304/* Functions used internally by the macros, not intended to be used directly. */
305void _nrf_rpc_cbor_prepare(struct nrf_rpc_cbor_ctx *ctx, size_t len);
306void _nrf_rpc_cbor_proxy_handler(const struct nrf_rpc_group *group, const uint8_t *packet,
307 size_t len, void *handler_data);
308
313#ifdef __cplusplus
314}
315#endif
316
317#endif /* _NRF_RPC_CBOR_H_ */
void nrf_rpc_cbor_decoding_done(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx)
Indicate that decoding of the input packet is done.
int nrf_rpc_cbor_cmd_rsp(const struct nrf_rpc_group *group, uint8_t cmd, struct nrf_rpc_cbor_ctx *ctx)
Send a command and get response as an output parameter.
void nrf_rpc_cbor_cmd_rsp_no_err_impl(const struct nrf_rpc_group *group, uint8_t cmd, struct nrf_rpc_cbor_ctx *ctx, const char *file, int line, const char *func)
int nrf_rpc_cbor_rsp(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx)
Send a response.
void nrf_rpc_cbor_rsp_no_err_impl(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx, const char *file, int line, const char *func)
void nrf_rpc_cbor_evt_no_err_impl(const struct nrf_rpc_group *group, uint8_t evt, struct nrf_rpc_cbor_ctx *ctx, const char *file, int line, const char *func)
void nrf_rpc_cbor_cmd_no_err_impl(const struct nrf_rpc_group *group, uint8_t cmd, struct nrf_rpc_cbor_ctx *ctx, nrf_rpc_cbor_handler_t handler, void *handler_data, const char *file, int line, const char *func)
void nrf_rpc_cbor_evt_no_err(const struct nrf_rpc_group *group, uint8_t evt, struct nrf_rpc_cbor_ctx *ctx)
Send an event and pass any error to an error handler.
bool nrf_rpc_cbor_is_alloc(struct nrf_rpc_cbor_ctx *ctx)
Check that the memory for a packet has been allocated.
int nrf_rpc_cbor_evt(const struct nrf_rpc_group *group, uint8_t evt, struct nrf_rpc_cbor_ctx *ctx)
Send an event.
void(* nrf_rpc_cbor_handler_t)(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
Callback that handles decoding of commands, events and responses.
Definition nrf_rpc_cbor.h:45
void nrf_rpc_cbor_cmd_no_err(const struct nrf_rpc_group *group, uint8_t cmd, struct nrf_rpc_cbor_ctx *ctx, nrf_rpc_cbor_handler_t handler, void *handler_data)
Send a command, provide callback to handle response and pass any error to an error handler.
void nrf_rpc_cbor_cmd_rsp_no_err(const struct nrf_rpc_group *group, uint8_t cmd, struct nrf_rpc_cbor_ctx *ctx)
Send a command, get response as an output parameter and pass any error to an error handler.
void nrf_rpc_cbor_rsp_no_err(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx)
Send a response and pass any error to an error handler.
int nrf_rpc_cbor_cmd(const struct nrf_rpc_group *group, uint8_t cmd, struct nrf_rpc_cbor_ctx *ctx, nrf_rpc_cbor_handler_t handler, void *handler_data)
Send a command and provide callback to handle response.
#define NRF_RPC_ZCBOR_STATES
Definition nrf_rpc_cbor.h:23
const uint8_t * in_packet
Definition nrf_rpc_cbor.h:63
uint8_t * out_packet
Definition nrf_rpc_cbor.h:62
zcbor_state_t zs[(2+CONFIG_NRF_RPC_ZCBOR_BACKUPS)]
Definition nrf_rpc_cbor.h:60
Context for encoding and sending commands, events and responses.
Definition nrf_rpc_cbor.h:59
Defines a group of commands and events.
Definition nrf_rpc.h:139