From 8b9920fd7705cb69375c855577efec7202fe3e96 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 1 Jul 2019 17:33:08 +0300 Subject: [PATCH] Bluetooth: GATT: Make use of Z_STRUCT_SECTION_ITERABLE This makes use of Z_STRUCT_SECTION_ITERABLE to define static service sections. Signed-off-by: Luiz Augusto von Dentz --- include/bluetooth/gatt.h | 3 +-- include/linker/common-rom.ld | 6 +++--- subsys/bluetooth/host/gatt.c | 19 +++++-------------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/include/bluetooth/gatt.h b/include/bluetooth/gatt.h index 0cff8f8a34d..a04c43b5e43 100644 --- a/include/bluetooth/gatt.h +++ b/include/bluetooth/gatt.h @@ -443,8 +443,7 @@ ssize_t bt_gatt_attr_read_service(struct bt_conn *conn, */ #define BT_GATT_SERVICE_DEFINE(_name, ...) \ const struct bt_gatt_attr attr_##_name[] = { __VA_ARGS__ }; \ - const struct bt_gatt_service_static _name __aligned(4) \ - __in_section(_bt_services, static, _name) = \ + const Z_STRUCT_SECTION_ITERABLE(bt_gatt_service_static, _name) =\ BT_GATT_SERVICE(attr_##_name) /** @def BT_GATT_SERVICE diff --git a/include/linker/common-rom.ld b/include/linker/common-rom.ld index 352e76545fe..914a079a7ec 100644 --- a/include/linker/common-rom.ld +++ b/include/linker/common-rom.ld @@ -94,9 +94,9 @@ SECTION_DATA_PROLOGUE(_bt_services_area,,SUBALIGN(4)) { - _bt_services_start = .; - KEEP(*(SORT_BY_NAME("._bt_services.static.*"))) - _bt_services_end = .; + _bt_gatt_service_static_list_start = .; + KEEP(*(SORT_BY_NAME("._bt_gatt_service_static.static.*"))) + _bt_gatt_service_static_list_end = .; } GROUP_LINK_IN(ROMABLE_REGION) #if defined(CONFIG_SETTINGS) diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index ad33607ce57..3ad4156577a 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -50,9 +50,6 @@ #define DB_HASH_TIMEOUT K_MSEC(10) -/* Linker-defined symbols bound to the bt_gatt_service_static structs */ -extern const struct bt_gatt_service_static _bt_services_start[]; -extern const struct bt_gatt_service_static _bt_services_end[]; static u16_t last_static_handle; /* Persistent storage format for GATT CCC */ @@ -734,13 +731,11 @@ static void ccc_delayed_store(struct k_work *work) void bt_gatt_init(void) { - const struct bt_gatt_service_static *svc; - if (!atomic_cas(&init, 0, 1)) { return; } - for (svc = _bt_services_start; svc < _bt_services_end; svc++) { + Z_STRUCT_SECTION_FOREACH(bt_gatt_service_static, svc) { last_static_handle += svc->attr_count; } @@ -933,11 +928,9 @@ static u8_t get_service_handles(const struct bt_gatt_attr *attr, static u16_t find_static_attr(const struct bt_gatt_attr *attr) { - const struct bt_gatt_service_static *static_svc; - u16_t handle; + u16_t handle = 1; - for (static_svc = _bt_services_start, handle = 1; - static_svc < _bt_services_end; static_svc++) { + Z_STRUCT_SECTION_FOREACH(bt_gatt_service_static, static_svc) { for (int i = 0; i < static_svc->attr_count; i++, handle++) { if (attr == &static_svc->attrs[i]) { return handle; @@ -1088,11 +1081,9 @@ void bt_gatt_foreach_attr_type(u16_t start_handle, u16_t end_handle, } if (start_handle <= last_static_handle) { - const struct bt_gatt_service_static *static_svc; - u16_t handle; + u16_t handle = 1; - for (static_svc = _bt_services_start, handle = 1; - static_svc < _bt_services_end; static_svc++) { + Z_STRUCT_SECTION_FOREACH(bt_gatt_service_static, static_svc) { /* Skip ahead if start is not within service handles */ if (handle + static_svc->attr_count < start_handle) { handle += static_svc->attr_count;