ble_mesh: stack: fix the structure init order to meet C++ requirements

This commit is contained in:
InfiniteYuan 2022-08-16 17:48:04 +08:00 committed by YuanMingFu
parent 02312e6a31
commit d3290e761b
6 changed files with 1126 additions and 38 deletions

View File

@ -68,6 +68,14 @@ typedef uint8_t esp_ble_mesh_octet8_t[ESP_BLE_MESH_OCTET8_LEN];
#define ESP_BLE_MESH_KEY_PRIMARY 0x0000
#define ESP_BLE_MESH_KEY_ANY 0xFFFF
/*!< Internal macros used to initialize array members */
#define ESP_BLE_MESH_KEY_UNUSED_ELT_(IDX, _) ESP_BLE_MESH_KEY_UNUSED
#define ESP_BLE_MESH_ADDR_UNASSIGNED_ELT_(IDX, _) ESP_BLE_MESH_ADDR_UNASSIGNED
#define ESP_BLE_MESH_MODEL_KEYS_UNUSED \
{ LISTIFY(CONFIG_BLE_MESH_MODEL_KEY_COUNT, ESP_BLE_MESH_KEY_UNUSED_ELT_, (,)) }
#define ESP_BLE_MESH_MODEL_GROUPS_UNASSIGNED \
{ LISTIFY(CONFIG_BLE_MESH_MODEL_GROUP_COUNT, ESP_BLE_MESH_ADDR_UNASSIGNED_ELT_, (,)) }
/*!< Primary Network Key index */
#define ESP_BLE_MESH_NET_PRIMARY 0x000
@ -264,26 +272,24 @@ typedef enum {
#define ESP_BLE_MESH_SIG_MODEL(_id, _op, _pub, _user_data) \
{ \
.model_id = (_id), \
.op = _op, \
.keys = { [0 ... (CONFIG_BLE_MESH_MODEL_KEY_COUNT - 1)] = \
ESP_BLE_MESH_KEY_UNUSED }, \
.pub = _pub, \
.groups = { [0 ... (CONFIG_BLE_MESH_MODEL_GROUP_COUNT - 1)] = \
ESP_BLE_MESH_ADDR_UNASSIGNED }, \
.keys = ESP_BLE_MESH_MODEL_KEYS_UNUSED, \
.groups = ESP_BLE_MESH_MODEL_GROUPS_UNASSIGNED, \
.op = _op, \
.user_data = _user_data, \
}
/*!< This macro is associated with BLE_MESH_MODEL_VND_CB in mesh_access.h */
#define ESP_BLE_MESH_VENDOR_MODEL(_company, _id, _op, _pub, _user_data) \
{ \
.vnd.company_id = (_company), \
.vnd.model_id = (_id), \
.op = _op, \
.vnd = { \
.company_id = (_company), \
.model_id = (_id), \
}, \
.pub = _pub, \
.keys = { [0 ... (CONFIG_BLE_MESH_MODEL_KEY_COUNT - 1)] = \
ESP_BLE_MESH_KEY_UNUSED }, \
.groups = { [0 ... (CONFIG_BLE_MESH_MODEL_GROUP_COUNT - 1)] = \
ESP_BLE_MESH_ADDR_UNASSIGNED }, \
.keys = ESP_BLE_MESH_MODEL_KEYS_UNUSED, \
.groups = ESP_BLE_MESH_MODEL_GROUPS_UNASSIGNED, \
.op = _op, \
.user_data = _user_data, \
}
@ -302,8 +308,8 @@ typedef enum {
{ \
.location = (_loc), \
.sig_model_count = ARRAY_SIZE(_mods), \
.sig_models = (_mods), \
.vnd_model_count = ARRAY_SIZE(_vnd_mods), \
.sig_models = (_mods), \
.vnd_models = (_vnd_mods), \
}
@ -416,8 +422,8 @@ typedef struct {
#define ESP_BLE_MESH_MODEL_PUB_DEFINE(_name, _msg_len, _role) \
NET_BUF_SIMPLE_DEFINE_STATIC(bt_mesh_pub_msg_##_name, _msg_len); \
static esp_ble_mesh_model_pub_t _name = { \
.update = (uint32_t)NULL, \
.msg = &bt_mesh_pub_msg_##_name, \
.update = (uint32_t)NULL, \
.dev_role = _role, \
}

View File

@ -840,22 +840,22 @@ struct net_buf_pool {
#if defined(CONFIG_BLE_MESH_NET_BUF_POOL_USAGE)
#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _destroy) \
{ \
.alloc = _alloc, \
.__bufs = (struct net_buf *)_bufs, \
.buf_count = _count, \
.uninit_count = _count, \
.avail_count = _count, \
.destroy = _destroy, \
.name = STRINGIFY(_pool), \
.destroy = _destroy, \
.alloc = _alloc, \
.__bufs = (struct net_buf *)_bufs, \
}
#else
#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _destroy) \
{ \
.alloc = _alloc, \
.__bufs = (struct net_buf *)_bufs, \
.buf_count = _count, \
.uninit_count = _count, \
.destroy = _destroy, \
.alloc = _alloc, \
.__bufs = (struct net_buf *)_bufs, \
}
#endif /* CONFIG_BLE_MESH_NET_BUF_POOL_USAGE */

View File

@ -17,6 +17,7 @@
#include <stddef.h>
#include "esp_bit_defs.h"
#include "mesh_types.h"
#include "mesh_utils_loops.h"
#ifdef __cplusplus
extern "C" {
@ -180,6 +181,40 @@ extern "C" {
*/
#define Z_IS_ENABLED3(ignore_this, val, ...) val
/* Used to remove brackets from around a single argument. */
#define __DEBRACKET(...) __VA_ARGS__
#define UTIL_CAT(a, ...) UTIL_PRIMITIVE_CAT(a, __VA_ARGS__)
#define UTIL_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__
/**
* @brief Generates a sequence of code with configurable separator.
*
* Example:
*
* #define FOO(i, _) MY_PWM ## i
* { LISTIFY(PWM_COUNT, FOO, (,)) }
*
* The above two lines expand to:
*
* { MY_PWM0 , MY_PWM1 }
*
* @param LEN The length of the sequence. Must be an integer literal less
* than 255.
* @param F A macro function that accepts at least two arguments:
* <tt>F(i, ...)</tt>. @p F is called repeatedly in the expansion.
* Its first argument @p i is the index in the sequence, and
* the variable list of arguments passed to LISTIFY are passed
* through to @p F.
*
* @param sep Separator (e.g. comma or semicolon). Must be in parentheses;
* this is required to enable providing a comma as separator.
*
* @note Calling LISTIFY with undefined arguments has undefined
* behavior.
*/
#define LISTIFY(LEN, F, sep, ...) UTIL_CAT(Z_UTIL_LISTIFY_, LEN)(F, sep, __VA_ARGS__)
const char *bt_hex(const void *buf, size_t len);
void mem_rcopy(uint8_t *dst, uint8_t const *src, uint16_t len);

File diff suppressed because it is too large Load Diff

View File

@ -50,8 +50,8 @@ extern "C" {
{ \
.loc = (_loc), \
.model_count = ARRAY_SIZE(_mods), \
.models = (_mods), \
.vnd_model_count = ARRAY_SIZE(_vnd_mods), \
.models = (_mods), \
.vnd_models = (_vnd_mods), \
}
@ -255,14 +255,12 @@ struct bt_mesh_model_op {
#define BLE_MESH_MODEL_CB(_id, _op, _pub, _user_data, _cb) \
{ \
.id = (_id), \
.op = (_op), \
.keys = { [0 ... (CONFIG_BLE_MESH_MODEL_KEY_COUNT - 1)] = \
BLE_MESH_KEY_UNUSED }, \
.pub = (_pub), \
.groups = { [0 ... (CONFIG_BLE_MESH_MODEL_GROUP_COUNT - 1)] = \
BLE_MESH_ADDR_UNASSIGNED }, \
.user_data = (_user_data), \
.keys = ESP_BLE_MESH_MODEL_KEYS_UNUSED, \
.groups = ESP_BLE_MESH_MODEL_GROUPS_UNASSIGNED, \
.op = (_op), \
.cb = (_cb), \
.user_data = (_user_data), \
}
/** @def BLE_MESH_MODEL_VND_CB
@ -280,14 +278,12 @@ struct bt_mesh_model_op {
{ \
.vnd.company = (_company), \
.vnd.id = (_id), \
.op = (_op), \
.pub = (_pub), \
.keys = { [0 ... (CONFIG_BLE_MESH_MODEL_KEY_COUNT - 1)] = \
BLE_MESH_KEY_UNUSED }, \
.groups = { [0 ... (CONFIG_BLE_MESH_MODEL_GROUP_COUNT - 1)] = \
BLE_MESH_ADDR_UNASSIGNED }, \
.user_data = (_user_data), \
.keys = ESP_BLE_MESH_MODEL_KEYS_UNUSED, \
.groups = ESP_BLE_MESH_MODEL_GROUPS_UNASSIGNED, \
.op = (_op), \
.cb = (_cb), \
.user_data = (_user_data), \
}
/** @def BLE_MESH_TRANSMIT
@ -419,8 +415,8 @@ struct bt_mesh_model_pub {
#define BLE_MESH_MODEL_PUB_DEFINE(_name, _update, _msg_len) \
NET_BUF_SIMPLE_DEFINE_STATIC(bt_mesh_pub_msg_##_name, _msg_len); \
static struct bt_mesh_model_pub _name = { \
.update = _update, \
.msg = &bt_mesh_pub_msg_##_name, \
.update = _update, \
}
/** Model callback functions. */

View File

@ -573,9 +573,9 @@ struct bt_mesh_gatt_attr {
#define BLE_MESH_GATT_PRIMARY_SERVICE(_service) \
{ \
.uuid = BLE_MESH_UUID_GATT_PRIMARY, \
.perm = BLE_MESH_GATT_PERM_READ, \
.read = bt_mesh_gatts_attr_read_service, \
.user_data = _service, \
.perm = BLE_MESH_GATT_PERM_READ, \
}
/** @def BLE_MESH_GATT_SECONDARY_SERVICE
@ -588,9 +588,9 @@ struct bt_mesh_gatt_attr {
#define BLE_MESH_GATT_SECONDARY_SERVICE(_service) \
{ \
.uuid = BLE_MESH_UUID_GATT_SECONDARY, \
.perm = BLE_MESH_GATT_PERM_READ, \
.read = bt_mesh_gatts_attr_read_service, \
.user_data = _service, \
.perm = BLE_MESH_GATT_PERM_READ, \
}
/** @def BLE_MESH_GATT_INCLUDE_SERVICE
@ -603,9 +603,9 @@ struct bt_mesh_gatt_attr {
#define BLE_MESH_GATT_INCLUDE_SERVICE(_service_incl) \
{ \
.uuid = BLE_MESH_UUID_GATT_INCLUDE, \
.perm = BLE_MESH_GATT_PERM_READ, \
.read = bt_mesh_gatts_attr_read_included, \
.user_data = _service_incl, \
.perm = BLE_MESH_GATT_PERM_READ, \
}
/** @def BLE_MESH_GATT_CHARACTERISTIC
@ -619,10 +619,10 @@ struct bt_mesh_gatt_attr {
#define BLE_MESH_GATT_CHARACTERISTIC(_uuid, _props) \
{ \
.uuid = BLE_MESH_UUID_GATT_CHRC, \
.perm = BLE_MESH_GATT_PERM_READ, \
.read = bt_mesh_gatts_attr_read_chrc, \
.user_data = (&(struct bt_mesh_gatt_char) { .uuid = _uuid, \
.properties = _props, }), \
.perm = BLE_MESH_GATT_PERM_READ, \
}
/** @def BLE_MESH_GATT_DESCRIPTOR
@ -639,10 +639,10 @@ struct bt_mesh_gatt_attr {
#define BLE_MESH_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _value) \
{ \
.uuid = _uuid, \
.perm = _perm, \
.read = _read, \
.write = _write, \
.user_data = _value, \
.perm = _perm, \
}
/** @def BLE_MESH_GATT_SERVICE