From 35c0b77304d3dcc3d80329ae70e11f6c17de4a1f Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Wed, 9 Sep 2020 15:57:34 +0530 Subject: [PATCH] Bluetooth: controller: Add interface to get ULL ref count Add a static inline interface to get ULL context reference count. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/ll_sw/lll.h | 4 +++- subsys/bluetooth/controller/ll_sw/ull.c | 6 +++--- subsys/bluetooth/controller/ll_sw/ull_adv.c | 2 +- subsys/bluetooth/controller/ll_sw/ull_internal.h | 5 +++++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/lll.h b/subsys/bluetooth/controller/ll_sw/lll.h index 13e4b8c4a92..c8a720748b4 100644 --- a/subsys/bluetooth/controller/ll_sw/lll.h +++ b/subsys/bluetooth/controller/ll_sw/lll.h @@ -111,7 +111,9 @@ struct evt_hdr { }; struct ull_hdr { - uint8_t ref; /* Number of ongoing (between Prepare and Done) events */ + uint8_t volatile ref; /* Number of ongoing (between Prepare and Done) + * events + */ void (*disabled_cb)(void *param); void *disabled_param; }; diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index b35daee2394..cac617b5339 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -1133,7 +1133,7 @@ int ull_disable(void *lll) hdr->disabled_param = &sem; hdr->disabled_cb = disabled_cb; - if (!hdr->ref) { + if (!ull_ref_get(hdr)) { return ULL_STATUS_SUCCESS; } @@ -1857,11 +1857,11 @@ static inline void rx_demux_event_done(memq_link_t *link, } /* Decrement prepare reference */ - LL_ASSERT(ull_hdr->ref); + LL_ASSERT(ull_ref_get(ull_hdr)); ull_ref_dec(ull_hdr); /* If disable initiated, signal the semaphore */ - if (!ull_hdr->ref && ull_hdr->disabled_cb) { + if (!ull_ref_get(ull_hdr) && ull_hdr->disabled_cb) { ull_hdr->disabled_cb(ull_hdr->disabled_param); } } diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv.c b/subsys/bluetooth/controller/ll_sw/ull_adv.c index 0e60384feb9..7cbb8412259 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv.c @@ -1675,7 +1675,7 @@ static void ticker_op_stop_cb(uint32_t status, void *param) adv = param; hdr = &adv->ull; mfy.param = &adv->lll; - if (hdr->ref) { + if (ull_ref_get(hdr)) { LL_ASSERT(!hdr->disabled_cb); hdr->disabled_param = mfy.param; hdr->disabled_cb = disabled_cb; diff --git a/subsys/bluetooth/controller/ll_sw/ull_internal.h b/subsys/bluetooth/controller/ll_sw/ull_internal.h index c061ad88e9d..a0cf45ea228 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_internal.h +++ b/subsys/bluetooth/controller/ll_sw/ull_internal.h @@ -4,6 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +static inline uint8_t ull_ref_get(struct ull_hdr *hdr) +{ + return hdr->ref; +} + static inline uint8_t ull_ref_inc(struct ull_hdr *hdr) { return ++hdr->ref;