From 5c796a960b15edb30a1b36dd7205697fbb234bfe Mon Sep 17 00:00:00 2001 From: Lingao Meng Date: Tue, 23 Nov 2021 14:27:31 +0800 Subject: [PATCH] Bluetooth: Mesh: Replace macro as inline Use inline function ins of macro. Signed-off-by: Lingao Meng --- subsys/bluetooth/mesh/adv_ext.c | 34 +++++++++++++++++++++------------ subsys/bluetooth/mesh/cfg.c | 2 +- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 285e9e72081..78eaf6a91ae 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -71,9 +71,6 @@ static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_relay[CONFIG_BT_MESH_RELAY_A .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), } }; -#define BT_MESH_RELAY_ADV_INS (adv_relay) -#else /* !CONFIG_BT_MESH_RELAY_ADV_SETS */ -#define BT_MESH_RELAY_ADV_INS (&adv_main) #endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ #if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) @@ -82,18 +79,31 @@ static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_gatt) = { .tag = BT_MESH_PROXY_ADV, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; -#define BT_MESH_ADV_EXT_GATT_SEPARATE_INS (&adv_gatt) -#elif defined(CONFIG_BT_MESH_GATT_SERVER) +#else /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ #define BT_MESH_ADV_COUNT (1 + CONFIG_BT_MESH_RELAY_ADV_SETS) -#define BT_MESH_ADV_EXT_GATT_SEPARATE_INS (&adv_main) -#else /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ -#define BT_MESH_ADV_COUNT (1 + CONFIG_BT_MESH_RELAY_ADV_SETS) -#define BT_MESH_ADV_EXT_GATT_SEPARATE_INS (struct bt_mesh_ext_adv)NULL #endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ BUILD_ASSERT(CONFIG_BT_EXT_ADV_MAX_ADV_SET >= BT_MESH_ADV_COUNT, "Insufficient adv instances"); +static inline struct bt_mesh_ext_adv *relay_adv_get(void) +{ +#if CONFIG_BT_MESH_RELAY_ADV_SETS + return adv_relay; +#else /* !CONFIG_BT_MESH_RELAY_ADV_SETS */ + return &adv_main; +#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ +} + +static inline struct bt_mesh_ext_adv *gatt_adv_get(void) +{ +#if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) + return &adv_gatt; +#else /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ + return &adv_main; +#endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ +} + static int adv_start(struct bt_mesh_ext_adv *adv, const struct bt_le_adv_param *param, struct bt_le_ext_adv_start_param *start, @@ -251,7 +261,7 @@ static bool schedule_send(struct bt_mesh_ext_adv *adv) void bt_mesh_adv_gatt_update(void) { - (void)schedule_send(BT_MESH_ADV_EXT_GATT_SEPARATE_INS); + (void)schedule_send(gatt_adv_get()); } void bt_mesh_adv_buf_local_ready(void) @@ -327,7 +337,7 @@ static void adv_sent(struct bt_le_ext_adv *instance, static void connected(struct bt_le_ext_adv *instance, struct bt_le_ext_adv_connected_info *info) { - struct bt_mesh_ext_adv *adv = BT_MESH_ADV_EXT_GATT_SEPARATE_INS; + struct bt_mesh_ext_adv *adv = gatt_adv_get(); if (atomic_test_and_clear_bit(adv->flags, ADV_FLAG_PROXY)) { atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); @@ -369,7 +379,7 @@ int bt_mesh_adv_gatt_start(const struct bt_le_adv_param *param, const struct bt_data *ad, size_t ad_len, const struct bt_data *sd, size_t sd_len) { - struct bt_mesh_ext_adv *adv = BT_MESH_ADV_EXT_GATT_SEPARATE_INS; + struct bt_mesh_ext_adv *adv = gatt_adv_get(); struct bt_le_ext_adv_start_param start = { /* Timeout is set in 10 ms steps, with 0 indicating "forever" */ .timeout = (duration == SYS_FOREVER_MS) ? 0 : (duration / 10), diff --git a/subsys/bluetooth/mesh/cfg.c b/subsys/bluetooth/mesh/cfg.c index d751f9d2332..f34effc533b 100644 --- a/subsys/bluetooth/mesh/cfg.c +++ b/subsys/bluetooth/mesh/cfg.c @@ -102,7 +102,7 @@ int bt_mesh_gatt_proxy_set(enum bt_mesh_feat_state gatt_proxy) if (gatt_proxy == BT_MESH_FEATURE_DISABLED && !bt_mesh_subnet_find(node_id_is_running, NULL)) { - bt_mesh_adv_update(); + bt_mesh_adv_gatt_update(); } bt_mesh_hb_feature_changed(BT_MESH_FEAT_PROXY);