nrfxlib API 2.7.99
Loading...
Searching...
No Matches
nrf_rpc_common.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_COMMON_H_
8#define _NRF_RPC_COMMON_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
25#define __NRF_RPC_CONCAT(_x, _y) _x ## _y
26
40#define NRF_RPC_CONCAT(_x, _y) \
41 __NRF_RPC_CONCAT(_x, _y)
42
46#define __NRF_RPC_STRINGIFY(_x) #_x
47
58#define NRF_RPC_STRINGIFY(_x) \
59 __NRF_RPC_STRINGIFY(_x)
60
70#define NRF_RPC_CONTAINER_OF(_ptr, _type, _field_name) \
71 ((_type *)(((uint8_t *)_ptr) - offsetof(_type, _field_name)))
72
73#ifdef __GNUC__
74#define __NRF_RPC_STATIC_ASSERT(_expr, _msg) \
75 _Static_assert(_expr, _msg)
76#else
77#define __NRF_RPC_STATIC_ASSERT(_expr, _msg) \
78 extern char (*_ignore(void))
79#endif /* __GNUC__ */
80
87#define NRF_RPC_STATIC_ASSERT(_expr, _msg) \
88 __NRF_RPC_STATIC_ASSERT(_expr, _msg)
89
90#if defined(__ASSERT)
91#define __NRF_RPC_ASSERT(_expr) __ASSERT(_expr, "nRF RPC assertion failed")
92#else
93#include <assert.h>
94#define __NRF_RPC_ASSERT assert
95#endif
96
101#define NRF_RPC_ASSERT(_expr) \
102 __NRF_RPC_ASSERT(_expr)
103
111#define NRF_RPC_AUTO_ARR(_name, _array_key) \
112 const uint8_t NRF_RPC_CONCAT(_name, _auto_arr_end) __used \
113 __attribute__((__section__(".nrf_rpc." _array_key ".c"))); \
114 const uint8_t *const _name __used \
115 __attribute__((__section__(".nrf_rpc." _array_key ".a"))) = \
116 &NRF_RPC_CONCAT(_name, _auto_arr_end)
117
125#define NRF_RPC_AUTO_ARR_ITEM(_type, _name, _array_key, _item_key) \
126 _type _name __used \
127 __attribute__((__section__(".nrf_rpc." _array_key ".b." _item_key)))
128
138#define NRF_RPC_AUTO_ARR_FOR(_it, _var, _array_ptr, _type) \
139 (_var) = (_type *)((const uint8_t *const *)(_array_ptr) + 1); \
140 (const uint8_t *const)_var < \
141 *(const uint8_t *const *)(_array_ptr); \
142 (_var) = (_type *)(_var) + 1, (void)_it
143
150#define NRF_RPC_AUTO_ARR_GET(_array_ptr, _index, _type) \
151 (((_type *)((const uint8_t *const *)(_array_ptr) + 1))[_index])
152
157#ifdef __cplusplus
158}
159#endif
160
161#endif /* _NRF_RPC_COMMON_H_ */