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 <luiz.von.dentz@intel.com>
This commit is contained in:
parent
a1e25b91ff
commit
8b9920fd77
3 changed files with 9 additions and 19 deletions
|
@ -443,8 +443,7 @@ ssize_t bt_gatt_attr_read_service(struct bt_conn *conn,
|
||||||
*/
|
*/
|
||||||
#define BT_GATT_SERVICE_DEFINE(_name, ...) \
|
#define BT_GATT_SERVICE_DEFINE(_name, ...) \
|
||||||
const struct bt_gatt_attr attr_##_name[] = { __VA_ARGS__ }; \
|
const struct bt_gatt_attr attr_##_name[] = { __VA_ARGS__ }; \
|
||||||
const struct bt_gatt_service_static _name __aligned(4) \
|
const Z_STRUCT_SECTION_ITERABLE(bt_gatt_service_static, _name) =\
|
||||||
__in_section(_bt_services, static, _name) = \
|
|
||||||
BT_GATT_SERVICE(attr_##_name)
|
BT_GATT_SERVICE(attr_##_name)
|
||||||
|
|
||||||
/** @def BT_GATT_SERVICE
|
/** @def BT_GATT_SERVICE
|
||||||
|
|
|
@ -94,9 +94,9 @@
|
||||||
|
|
||||||
SECTION_DATA_PROLOGUE(_bt_services_area,,SUBALIGN(4))
|
SECTION_DATA_PROLOGUE(_bt_services_area,,SUBALIGN(4))
|
||||||
{
|
{
|
||||||
_bt_services_start = .;
|
_bt_gatt_service_static_list_start = .;
|
||||||
KEEP(*(SORT_BY_NAME("._bt_services.static.*")))
|
KEEP(*(SORT_BY_NAME("._bt_gatt_service_static.static.*")))
|
||||||
_bt_services_end = .;
|
_bt_gatt_service_static_list_end = .;
|
||||||
} GROUP_LINK_IN(ROMABLE_REGION)
|
} GROUP_LINK_IN(ROMABLE_REGION)
|
||||||
|
|
||||||
#if defined(CONFIG_SETTINGS)
|
#if defined(CONFIG_SETTINGS)
|
||||||
|
|
|
@ -50,9 +50,6 @@
|
||||||
|
|
||||||
#define DB_HASH_TIMEOUT K_MSEC(10)
|
#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;
|
static u16_t last_static_handle;
|
||||||
|
|
||||||
/* Persistent storage format for GATT CCC */
|
/* Persistent storage format for GATT CCC */
|
||||||
|
@ -734,13 +731,11 @@ static void ccc_delayed_store(struct k_work *work)
|
||||||
|
|
||||||
void bt_gatt_init(void)
|
void bt_gatt_init(void)
|
||||||
{
|
{
|
||||||
const struct bt_gatt_service_static *svc;
|
|
||||||
|
|
||||||
if (!atomic_cas(&init, 0, 1)) {
|
if (!atomic_cas(&init, 0, 1)) {
|
||||||
return;
|
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;
|
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)
|
static u16_t find_static_attr(const struct bt_gatt_attr *attr)
|
||||||
{
|
{
|
||||||
const struct bt_gatt_service_static *static_svc;
|
u16_t handle = 1;
|
||||||
u16_t handle;
|
|
||||||
|
|
||||||
for (static_svc = _bt_services_start, handle = 1;
|
Z_STRUCT_SECTION_FOREACH(bt_gatt_service_static, static_svc) {
|
||||||
static_svc < _bt_services_end; static_svc++) {
|
|
||||||
for (int i = 0; i < static_svc->attr_count; i++, handle++) {
|
for (int i = 0; i < static_svc->attr_count; i++, handle++) {
|
||||||
if (attr == &static_svc->attrs[i]) {
|
if (attr == &static_svc->attrs[i]) {
|
||||||
return handle;
|
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) {
|
if (start_handle <= last_static_handle) {
|
||||||
const struct bt_gatt_service_static *static_svc;
|
u16_t handle = 1;
|
||||||
u16_t handle;
|
|
||||||
|
|
||||||
for (static_svc = _bt_services_start, handle = 1;
|
Z_STRUCT_SECTION_FOREACH(bt_gatt_service_static, static_svc) {
|
||||||
static_svc < _bt_services_end; static_svc++) {
|
|
||||||
/* Skip ahead if start is not within service handles */
|
/* Skip ahead if start is not within service handles */
|
||||||
if (handle + static_svc->attr_count < start_handle) {
|
if (handle + static_svc->attr_count < start_handle) {
|
||||||
handle += static_svc->attr_count;
|
handle += static_svc->attr_count;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue