From cfa668fd511162ac572e8c989cbd0fb4633a66ab Mon Sep 17 00:00:00 2001 From: Wolfgang Puffitsch Date: Mon, 15 Feb 2021 23:25:26 +0100 Subject: [PATCH] Bluetooth: controller: Restructure LLL include files Move LLL header files for all roles to common folder. Move vendor-specific content to internal header files, in particular ADV buffer handling. Define the vendor-specific type lll_adv_pdu in a separate header file lll_adv_pdu.h to avoid cyclic dependency when moving ADV buffer handling to internal header file. Make sure all internal header files are in vendor-specific folders. The goal is to have a more consistent structure for LLL header files and allow unconditional inclusion of non-internal LLL header files. Signed-off-by: Wolfgang Puffitsch --- subsys/bluetooth/controller/ll_sw/lll_adv.h | 120 +++++++++ .../ll_sw/{nordic/lll => }/lll_adv_aux.h | 0 .../ll_sw/{nordic/lll => }/lll_adv_sync.h | 0 .../ll_sw/{nordic/lll => }/lll_master.h | 0 .../ll_sw/{nordic/lll => }/lll_scan_aux.h | 0 .../ll_sw/{nordic/lll => }/lll_sched.h | 0 .../ll_sw/{nordic/lll => }/lll_slave.h | 0 .../controller/ll_sw/nordic/lll/lll_adv.h | 253 ------------------ .../ll_sw/nordic/lll/lll_adv_internal.h | 103 +++++++ .../controller/ll_sw/nordic/lll/lll_adv_pdu.h | 28 ++ .../ll_sw/{ => nordic/lll}/lll_df_internal.h | 0 .../controller/ll_sw/openisa/lll/lll_adv.h | 196 -------------- .../ll_sw/openisa/lll/lll_adv_internal.h | 80 ++++++ .../ll_sw/openisa/lll/lll_adv_pdu.h | 28 ++ .../controller/ll_sw/openisa/lll/lll_master.h | 9 - .../controller/ll_sw/openisa/lll/lll_scan.h | 51 ---- .../controller/ll_sw/openisa/lll/lll_slave.h | 9 - subsys/bluetooth/controller/ll_sw/ull_adv.c | 1 + .../bluetooth/controller/ll_sw/ull_filter.c | 1 + 19 files changed, 361 insertions(+), 518 deletions(-) create mode 100644 subsys/bluetooth/controller/ll_sw/lll_adv.h rename subsys/bluetooth/controller/ll_sw/{nordic/lll => }/lll_adv_aux.h (100%) rename subsys/bluetooth/controller/ll_sw/{nordic/lll => }/lll_adv_sync.h (100%) rename subsys/bluetooth/controller/ll_sw/{nordic/lll => }/lll_master.h (100%) rename subsys/bluetooth/controller/ll_sw/{nordic/lll => }/lll_scan_aux.h (100%) rename subsys/bluetooth/controller/ll_sw/{nordic/lll => }/lll_sched.h (100%) rename subsys/bluetooth/controller/ll_sw/{nordic/lll => }/lll_slave.h (100%) delete mode 100644 subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.h create mode 100644 subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_pdu.h rename subsys/bluetooth/controller/ll_sw/{ => nordic/lll}/lll_df_internal.h (100%) delete mode 100644 subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv.h create mode 100644 subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv_pdu.h delete mode 100644 subsys/bluetooth/controller/ll_sw/openisa/lll/lll_master.h delete mode 100644 subsys/bluetooth/controller/ll_sw/openisa/lll/lll_scan.h delete mode 100644 subsys/bluetooth/controller/ll_sw/openisa/lll/lll_slave.h diff --git a/subsys/bluetooth/controller/ll_sw/lll_adv.h b/subsys/bluetooth/controller/ll_sw/lll_adv.h new file mode 100644 index 00000000000..ada2a6906ce --- /dev/null +++ b/subsys/bluetooth/controller/ll_sw/lll_adv.h @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2017-2019 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#if defined(CONFIG_BT_CTLR_ADV_SET) +#define BT_CTLR_ADV_SET CONFIG_BT_CTLR_ADV_SET +#else /* CONFIG_BT_CTLR_ADV_SET */ +#define BT_CTLR_ADV_SET 1 +#endif /* CONFIG_BT_CTLR_ADV_SET */ + +#include "lll_adv_pdu.h" + +struct lll_adv_aux { + struct lll_hdr hdr; + struct lll_adv *adv; + + uint32_t ticks_offset; + + struct lll_adv_pdu data; + +#if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) + int8_t tx_pwr_lvl; +#endif /* CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ +}; + +struct lll_adv_iso { + struct lll_hdr hdr; +}; + +struct lll_adv_sync { + struct lll_hdr hdr; + struct lll_adv *adv; +#if defined(CONFIG_BT_CTLR_ADV_ISO) + struct lll_adv_iso *adv_iso; +#endif /* CONFIG_BT_CTLR_ADV_ISO */ + + uint8_t access_addr[4]; + uint8_t crc_init[3]; + + uint16_t latency_prepare; + uint16_t latency_event; + uint16_t event_counter; + + uint8_t data_chan_map[5]; + uint8_t data_chan_count:6; + uint16_t data_chan_id; + + uint32_t ticks_offset; + + struct lll_adv_pdu data; + +#if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) + int8_t tx_pwr_lvl; +#endif /* CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ + +#if IS_ENABLED(CONFIG_BT_CTLR_DF_ADV_CTE_TX) + /* This flag is used only by LLL. It holds information if CTE + * transmission was started by LLL. + */ + uint8_t cte_started:1; +#endif /* CONFIG_BT_CTLR_DF_ADV_CTE_TX */ +}; + +struct lll_adv { + struct lll_hdr hdr; + +#if defined(CONFIG_BT_PERIPHERAL) + /* NOTE: conn context has to be after lll_hdr */ + struct lll_conn *conn; + uint8_t is_hdcd:1; +#endif /* CONFIG_BT_PERIPHERAL */ + + uint8_t chan_map:3; + uint8_t chan_map_curr:3; + uint8_t filter_policy:2; + +#if defined(CONFIG_BT_CTLR_ADV_EXT) + uint8_t phy_p:3; + uint8_t phy_s:3; +#endif /* CONFIG_BT_CTLR_ADV_EXT */ + +#if defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) + uint8_t scan_req_notify:1; +#endif + +#if defined(CONFIG_BT_HCI_MESH_EXT) + uint8_t is_mesh:1; +#endif /* CONFIG_BT_HCI_MESH_EXT */ + +#if defined(CONFIG_BT_CTLR_PRIVACY) + uint8_t rl_idx; +#endif /* CONFIG_BT_CTLR_PRIVACY */ + + struct lll_adv_pdu adv_data; + struct lll_adv_pdu scan_rsp; + +#if defined(CONFIG_BT_CTLR_ADV_EXT) + struct lll_adv_aux *aux; + +#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) + struct lll_adv_sync *sync; +#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ +#endif /* CONFIG_BT_CTLR_ADV_EXT */ + +#if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) + int8_t tx_pwr_lvl; +#endif /* CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ + +#if defined(CONFIG_BT_CTLR_ADV_EXT) + struct node_rx_hdr *node_rx_adv_term; +#endif /* CONFIG_BT_CTLR_ADV_EXT */ +}; + +int lll_adv_init(void); +int lll_adv_reset(void); +void lll_adv_prepare(void *param); + +extern uint16_t ull_adv_lll_handle_get(struct lll_adv *lll); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.h b/subsys/bluetooth/controller/ll_sw/lll_adv_aux.h similarity index 100% rename from subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.h rename to subsys/bluetooth/controller/ll_sw/lll_adv_aux.h diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.h b/subsys/bluetooth/controller/ll_sw/lll_adv_sync.h similarity index 100% rename from subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.h rename to subsys/bluetooth/controller/ll_sw/lll_adv_sync.h diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_master.h b/subsys/bluetooth/controller/ll_sw/lll_master.h similarity index 100% rename from subsys/bluetooth/controller/ll_sw/nordic/lll/lll_master.h rename to subsys/bluetooth/controller/ll_sw/lll_master.h diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.h b/subsys/bluetooth/controller/ll_sw/lll_scan_aux.h similarity index 100% rename from subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.h rename to subsys/bluetooth/controller/ll_sw/lll_scan_aux.h diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sched.h b/subsys/bluetooth/controller/ll_sw/lll_sched.h similarity index 100% rename from subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sched.h rename to subsys/bluetooth/controller/ll_sw/lll_sched.h diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_slave.h b/subsys/bluetooth/controller/ll_sw/lll_slave.h similarity index 100% rename from subsys/bluetooth/controller/ll_sw/nordic/lll/lll_slave.h rename to subsys/bluetooth/controller/ll_sw/lll_slave.h diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.h b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.h deleted file mode 100644 index d30b09598ae..00000000000 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.h +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (c) 2017-2019 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#if defined(CONFIG_BT_CTLR_ADV_SET) -#define BT_CTLR_ADV_SET CONFIG_BT_CTLR_ADV_SET -#else /* CONFIG_BT_CTLR_ADV_SET */ -#define BT_CTLR_ADV_SET 1 -#endif /* CONFIG_BT_CTLR_ADV_SET */ - -/* Structure used to double buffer pointers of AD Data PDU buffer. - * The first and last members are used to make modification to AD data to be - * context safe. Thread always appends or updates the buffer pointed to - * the array element indexed by the member last. - * LLL in the ISR context, checks, traverses to the valid pointer indexed - * by the member first, such that the buffer is the latest committed by - * the thread context. - */ -struct lll_adv_pdu { - uint8_t volatile first; - uint8_t last; - uint8_t *pdu[DOUBLE_BUFFER_SIZE]; -#if IS_ENABLED(CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY) - /* This is a storage for LLL configuration that may be - * changed while LLL advertising role is started. - * Also it makes the configuration data to be in sync - * with extended advertising PDU e.g. CTE TX configuration - * and CTEInfo field. - */ - void *extra_data[DOUBLE_BUFFER_SIZE]; -#endif /* CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY */ -}; - -struct lll_adv_aux { - struct lll_hdr hdr; - struct lll_adv *adv; - - uint32_t ticks_offset; - - struct lll_adv_pdu data; - -#if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) - int8_t tx_pwr_lvl; -#endif /* CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ -}; - -struct lll_adv_iso { - struct lll_hdr hdr; -}; - -struct lll_adv_sync { - struct lll_hdr hdr; - struct lll_adv *adv; -#if defined(CONFIG_BT_CTLR_ADV_ISO) - struct lll_adv_iso *adv_iso; -#endif /* CONFIG_BT_CTLR_ADV_ISO */ - - uint8_t access_addr[4]; - uint8_t crc_init[3]; - - uint16_t latency_prepare; - uint16_t latency_event; - uint16_t event_counter; - - uint8_t data_chan_map[5]; - uint8_t data_chan_count:6; - uint16_t data_chan_id; - - uint32_t ticks_offset; - - struct lll_adv_pdu data; - -#if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) - int8_t tx_pwr_lvl; -#endif /* CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ - -#if IS_ENABLED(CONFIG_BT_CTLR_DF_ADV_CTE_TX) - /* This flag is used only by LLL. It holds information if CTE - * transmission was started by LLL. - */ - uint8_t cte_started:1; -#endif /* CONFIG_BT_CTLR_DF_ADV_CTE_TX */ -}; - -struct lll_adv { - struct lll_hdr hdr; - -#if defined(CONFIG_BT_PERIPHERAL) - /* NOTE: conn context has to be after lll_hdr */ - struct lll_conn *conn; - uint8_t is_hdcd:1; -#endif /* CONFIG_BT_PERIPHERAL */ - - uint8_t chan_map:3; - uint8_t chan_map_curr:3; - uint8_t filter_policy:2; - -#if defined(CONFIG_BT_CTLR_ADV_EXT) - uint8_t phy_p:3; - uint8_t phy_s:3; -#endif /* CONFIG_BT_CTLR_ADV_EXT */ - -#if defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) - uint8_t scan_req_notify:1; -#endif - -#if defined(CONFIG_BT_HCI_MESH_EXT) - uint8_t is_mesh:1; -#endif /* CONFIG_BT_HCI_MESH_EXT */ - -#if defined(CONFIG_BT_CTLR_PRIVACY) - uint8_t rl_idx; -#endif /* CONFIG_BT_CTLR_PRIVACY */ - - struct lll_adv_pdu adv_data; - struct lll_adv_pdu scan_rsp; - -#if defined(CONFIG_BT_CTLR_ADV_EXT) - struct lll_adv_aux *aux; - -#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) - struct lll_adv_sync *sync; -#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ -#endif /* CONFIG_BT_CTLR_ADV_EXT */ - -#if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) - int8_t tx_pwr_lvl; -#endif /* CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ - -#if defined(CONFIG_BT_CTLR_ADV_EXT) - struct node_rx_hdr *node_rx_adv_term; -#endif /* CONFIG_BT_CTLR_ADV_EXT */ -}; - -int lll_adv_init(void); -int lll_adv_reset(void); -int lll_adv_data_init(struct lll_adv_pdu *pdu); -int lll_adv_data_reset(struct lll_adv_pdu *pdu); -int lll_adv_data_release(struct lll_adv_pdu *pdu); -struct pdu_adv *lll_adv_pdu_alloc(struct lll_adv_pdu *pdu, uint8_t *idx); -void lll_adv_prepare(void *param); - -#if IS_ENABLED(CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY) -int lll_adv_and_extra_data_init(struct lll_adv_pdu *pdu); -int lll_adv_and_extra_data_release(struct lll_adv_pdu *pdu); -struct pdu_adv *lll_adv_pdu_and_extra_data_alloc(struct lll_adv_pdu *pdu, - void **extra_data, - uint8_t *idx); -struct pdu_adv *lll_adv_pdu_and_extra_data_latest_get(struct lll_adv_pdu *pdu, - void **extra_data, - uint8_t *is_modified); -#endif /* CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY */ - -static inline void lll_adv_pdu_enqueue(struct lll_adv_pdu *pdu, uint8_t idx) -{ - pdu->last = idx; -} - -static inline struct pdu_adv *lll_adv_data_alloc(struct lll_adv *lll, uint8_t *idx) -{ - return lll_adv_pdu_alloc(&lll->adv_data, idx); -} - -static inline void lll_adv_data_enqueue(struct lll_adv *lll, uint8_t idx) -{ - lll_adv_pdu_enqueue(&lll->adv_data, idx); -} - -static inline struct pdu_adv *lll_adv_data_peek(struct lll_adv *lll) -{ - return (void *)lll->adv_data.pdu[lll->adv_data.last]; -} - -static inline struct pdu_adv *lll_adv_scan_rsp_alloc(struct lll_adv *lll, - uint8_t *idx) -{ - return lll_adv_pdu_alloc(&lll->scan_rsp, idx); -} - -static inline void lll_adv_scan_rsp_enqueue(struct lll_adv *lll, uint8_t idx) -{ - lll_adv_pdu_enqueue(&lll->scan_rsp, idx); -} - -static inline struct pdu_adv *lll_adv_scan_rsp_peek(struct lll_adv *lll) -{ - return (void *)lll->scan_rsp.pdu[lll->scan_rsp.last]; -} - -#if defined(CONFIG_BT_CTLR_ADV_EXT) -static inline struct pdu_adv *lll_adv_aux_data_alloc(struct lll_adv_aux *lll, - uint8_t *idx) -{ - return lll_adv_pdu_alloc(&lll->data, idx); -} - -static inline void lll_adv_aux_data_enqueue(struct lll_adv_aux *lll, - uint8_t idx) -{ - lll_adv_pdu_enqueue(&lll->data, idx); -} - -static inline struct pdu_adv *lll_adv_aux_data_peek(struct lll_adv_aux *lll) -{ - return (void *)lll->data.pdu[lll->data.last]; -} - -#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) -static inline struct pdu_adv *lll_adv_sync_data_alloc(struct lll_adv_sync *lll, - void **extra_data, - uint8_t *idx) -{ -#if IS_ENABLED(CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY) - return lll_adv_pdu_and_extra_data_alloc(&lll->data, extra_data, idx); -#else - return lll_adv_pdu_alloc(&lll->data, idx); -#endif /* CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY */ -} - -static inline void lll_adv_sync_data_release(struct lll_adv_sync *lll) -{ -#if IS_ENABLED(CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY) - lll_adv_and_extra_data_release(&lll->data); -#else - lll_adv_data_release(&lll->data); -#endif /* CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY */ -} - -static inline void lll_adv_sync_data_enqueue(struct lll_adv_sync *lll, - uint8_t idx) -{ - lll_adv_pdu_enqueue(&lll->data, idx); -} - -static inline struct pdu_adv *lll_adv_sync_data_peek(struct lll_adv_sync *lll, - void **extra_data) -{ - uint8_t last = lll->data.last; - -#if IS_ENABLED(CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY) - if (extra_data) { - *extra_data = lll->data.extra_data[last]; - } -#endif /* CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY */ - - return (void *)lll->data.pdu[last]; -} -#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ -#endif /* CONFIG_BT_CTLR_ADV_EXT */ - -extern uint16_t ull_adv_lll_handle_get(struct lll_adv *lll); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_internal.h b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_internal.h index 11a569f58e2..57d3e237994 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_internal.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_internal.h @@ -4,6 +4,109 @@ * SPDX-License-Identifier: Apache-2.0 */ +int lll_adv_data_init(struct lll_adv_pdu *pdu); +int lll_adv_data_reset(struct lll_adv_pdu *pdu); +int lll_adv_data_release(struct lll_adv_pdu *pdu); + +struct pdu_adv *lll_adv_pdu_alloc(struct lll_adv_pdu *pdu, uint8_t *idx); + +static inline void lll_adv_pdu_enqueue(struct lll_adv_pdu *pdu, uint8_t idx) +{ + pdu->last = idx; +} + +static inline struct pdu_adv *lll_adv_data_alloc(struct lll_adv *lll, uint8_t *idx) +{ + return lll_adv_pdu_alloc(&lll->adv_data, idx); +} + +static inline void lll_adv_data_enqueue(struct lll_adv *lll, uint8_t idx) +{ + lll_adv_pdu_enqueue(&lll->adv_data, idx); +} + +static inline struct pdu_adv *lll_adv_data_peek(struct lll_adv *lll) +{ + return (void *)lll->adv_data.pdu[lll->adv_data.last]; +} + +static inline struct pdu_adv *lll_adv_scan_rsp_alloc(struct lll_adv *lll, + uint8_t *idx) +{ + return lll_adv_pdu_alloc(&lll->scan_rsp, idx); +} + +static inline void lll_adv_scan_rsp_enqueue(struct lll_adv *lll, uint8_t idx) +{ + lll_adv_pdu_enqueue(&lll->scan_rsp, idx); +} + +static inline struct pdu_adv *lll_adv_scan_rsp_peek(struct lll_adv *lll) +{ + return (void *)lll->scan_rsp.pdu[lll->scan_rsp.last]; +} + +#if defined(CONFIG_BT_CTLR_ADV_EXT) +static inline struct pdu_adv *lll_adv_aux_data_alloc(struct lll_adv_aux *lll, + uint8_t *idx) +{ + return lll_adv_pdu_alloc(&lll->data, idx); +} + +static inline void lll_adv_aux_data_enqueue(struct lll_adv_aux *lll, + uint8_t idx) +{ + lll_adv_pdu_enqueue(&lll->data, idx); +} + +static inline struct pdu_adv *lll_adv_aux_data_peek(struct lll_adv_aux *lll) +{ + return (void *)lll->data.pdu[lll->data.last]; +} + +#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) +static inline struct pdu_adv *lll_adv_sync_data_alloc(struct lll_adv_sync *lll, + void **extra_data, + uint8_t *idx) +{ +#if IS_ENABLED(CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY) + return lll_adv_pdu_and_extra_data_alloc(&lll->data, extra_data, idx); +#else + return lll_adv_pdu_alloc(&lll->data, idx); +#endif /* CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY */ +} + +static inline void lll_adv_sync_data_release(struct lll_adv_sync *lll) +{ +#if IS_ENABLED(CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY) + lll_adv_and_extra_data_release(&lll->data); +#else + lll_adv_data_release(&lll->data); +#endif /* CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY */ +} + +static inline void lll_adv_sync_data_enqueue(struct lll_adv_sync *lll, + uint8_t idx) +{ + lll_adv_pdu_enqueue(&lll->data, idx); +} + +static inline struct pdu_adv *lll_adv_sync_data_peek(struct lll_adv_sync *lll, + void **extra_data) +{ + uint8_t last = lll->data.last; + +#if IS_ENABLED(CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY) + if (extra_data) { + *extra_data = lll->data.extra_data[last]; + } +#endif /* CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY */ + + return (void *)lll->data.pdu[last]; +} +#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ +#endif /* CONFIG_BT_CTLR_ADV_EXT */ + struct pdu_adv *lll_adv_pdu_latest_get(struct lll_adv_pdu *pdu, uint8_t *is_modified); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_pdu.h b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_pdu.h new file mode 100644 index 00000000000..b2acc223a4b --- /dev/null +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_pdu.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2018-2019 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* Structure used to double buffer pointers of AD Data PDU buffer. + * The first and last members are used to make modification to AD data to be + * context safe. Thread always appends or updates the buffer pointed to + * the array element indexed by the member last. + * LLL in the ISR context, checks, traverses to the valid pointer indexed + * by the member first, such that the buffer is the latest committed by + * the thread context. + */ +struct lll_adv_pdu { + uint8_t volatile first; + uint8_t last; + uint8_t *pdu[DOUBLE_BUFFER_SIZE]; +#if IS_ENABLED(CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY) + /* This is a storage for LLL configuration that may be + * changed while LLL advertising role is started. + * Also it makes the configuration data to be in sync + * with extended advertising PDU e.g. CTE TX configuration + * and CTEInfo field. + */ + void *extra_data[DOUBLE_BUFFER_SIZE]; +#endif /* CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY */ +}; diff --git a/subsys/bluetooth/controller/ll_sw/lll_df_internal.h b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_df_internal.h similarity index 100% rename from subsys/bluetooth/controller/ll_sw/lll_df_internal.h rename to subsys/bluetooth/controller/ll_sw/nordic/lll/lll_df_internal.h diff --git a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv.h b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv.h deleted file mode 100644 index 43be5be2c35..00000000000 --- a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv.h +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (c) 2017-2019 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#if defined(CONFIG_BT_CTLR_ADV_SET) -#define BT_CTLR_ADV_SET CONFIG_BT_CTLR_ADV_SET -#else /* CONFIG_BT_CTLR_ADV_SET */ -#define BT_CTLR_ADV_SET 1 -#endif /* CONFIG_BT_CTLR_ADV_SET */ - -/* Structure used to double buffer pointers of AD Data PDU buffer. - * The first and last members are used to make modification to AD data to be - * context safe. Thread always appends or updates the buffer pointed to - * the array element indexed by the member last. - * LLL in the ISR context, checks, traverses to the valid pointer indexed - * by the member first, such that the buffer is the latest committed by - * the thread context. - */ -struct lll_adv_pdu { - uint8_t volatile first; - uint8_t last; - uint8_t *pdu[DOUBLE_BUFFER_SIZE]; -}; - -struct lll_adv_aux { - struct lll_hdr hdr; - struct lll_adv *adv; - - uint32_t ticks_offset; - - struct lll_adv_pdu data; - -#if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) - int8_t tx_pwr_lvl; -#endif /* CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ -}; - -struct lll_adv_sync { - struct lll_hdr hdr; - struct lll_adv *adv; - - uint8_t access_addr[4]; - uint8_t crc_init[3]; - - uint16_t latency_prepare; - uint16_t latency_event; - uint16_t event_counter; - - uint8_t data_chan_map[5]; - uint8_t data_chan_count:6; - uint16_t data_chan_id; - - uint32_t ticks_offset; - - struct lll_adv_pdu data; - -#if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) - int8_t tx_pwr_lvl; -#endif /* CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ -}; - -struct lll_adv { - struct lll_hdr hdr; - -#if defined(CONFIG_BT_PERIPHERAL) - /* NOTE: conn context has to be after lll_hdr */ - struct lll_conn *conn; - uint8_t is_hdcd:1; -#endif /* CONFIG_BT_PERIPHERAL */ - - uint8_t chan_map:3; - uint8_t chan_map_curr:3; - uint8_t filter_policy:2; - -#if defined(CONFIG_BT_CTLR_ADV_EXT) - uint8_t phy_p:3; - uint8_t phy_s:3; -#endif /* CONFIG_BT_CTLR_ADV_EXT */ - -#if defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) - uint8_t scan_req_notify:1; -#endif - -#if defined(CONFIG_BT_HCI_MESH_EXT) - uint8_t is_mesh:1; -#endif /* CONFIG_BT_HCI_MESH_EXT */ - -#if defined(CONFIG_BT_CTLR_PRIVACY) - uint8_t rl_idx; -#endif /* CONFIG_BT_CTLR_PRIVACY */ - - struct lll_adv_pdu adv_data; - struct lll_adv_pdu scan_rsp; - -#if defined(CONFIG_BT_CTLR_ADV_EXT) - struct lll_adv_aux *aux; - -#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) - struct lll_adv_sync *sync; -#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ -#endif /* CONFIG_BT_CTLR_ADV_EXT */ - -#if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) - int8_t tx_pwr_lvl; -#endif /* CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ - -#if defined(CONFIG_BT_CTLR_ADV_EXT) - struct node_rx_hdr *node_rx_adv_term; -#endif /* CONFIG_BT_CTLR_ADV_EXT */ -}; - -int lll_adv_init(void); -int lll_adv_reset(void); -int lll_adv_data_init(struct lll_adv_pdu *pdu); -int lll_adv_data_reset(struct lll_adv_pdu *pdu); -int lll_adv_data_release(struct lll_adv_pdu *pdu); -struct pdu_adv *lll_adv_pdu_alloc(struct lll_adv_pdu *pdu, uint8_t *idx); -void lll_adv_prepare(void *param); - -static inline void lll_adv_pdu_enqueue(struct lll_adv_pdu *pdu, uint8_t idx) -{ - pdu->last = idx; -} - -static inline struct pdu_adv *lll_adv_data_alloc(struct lll_adv *lll, uint8_t *idx) -{ - return lll_adv_pdu_alloc(&lll->adv_data, idx); -} - -static inline void lll_adv_data_enqueue(struct lll_adv *lll, uint8_t idx) -{ - lll_adv_pdu_enqueue(&lll->adv_data, idx); -} - -static inline struct pdu_adv *lll_adv_data_peek(struct lll_adv *lll) -{ - return (void *)lll->adv_data.pdu[lll->adv_data.last]; -} - -static inline struct pdu_adv *lll_adv_scan_rsp_alloc(struct lll_adv *lll, - uint8_t *idx) -{ - return lll_adv_pdu_alloc(&lll->scan_rsp, idx); -} - -static inline void lll_adv_scan_rsp_enqueue(struct lll_adv *lll, uint8_t idx) -{ - lll_adv_pdu_enqueue(&lll->scan_rsp, idx); -} - -static inline struct pdu_adv *lll_adv_scan_rsp_peek(struct lll_adv *lll) -{ - return (void *)lll->scan_rsp.pdu[lll->scan_rsp.last]; -} - -#if defined(CONFIG_BT_CTLR_ADV_EXT) -static inline struct pdu_adv *lll_adv_aux_data_alloc(struct lll_adv_aux *lll, - uint8_t *idx) -{ - return lll_adv_pdu_alloc(&lll->data, idx); -} - -static inline void lll_adv_aux_data_enqueue(struct lll_adv_aux *lll, - uint8_t idx) -{ - lll_adv_pdu_enqueue(&lll->data, idx); -} - -static inline struct pdu_adv *lll_adv_aux_data_peek(struct lll_adv_aux *lll) -{ - return (void *)lll->data.pdu[lll->data.last]; -} - -#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) -static inline struct pdu_adv *lll_adv_sync_data_alloc(struct lll_adv_sync *lll, - uint8_t *idx) -{ - return lll_adv_pdu_alloc(&lll->data, idx); -} - -static inline void lll_adv_sync_data_enqueue(struct lll_adv_sync *lll, - uint8_t idx) -{ - lll_adv_pdu_enqueue(&lll->data, idx); -} - -static inline struct pdu_adv *lll_adv_sync_data_peek(struct lll_adv_sync *lll) -{ - return (void *)lll->data.pdu[lll->data.last]; -} -#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ -#endif /* CONFIG_BT_CTLR_ADV_EXT */ - -extern uint16_t ull_adv_lll_handle_get(struct lll_adv *lll); diff --git a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv_internal.h b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv_internal.h index d0c2076cfda..f79ae7e30ca 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv_internal.h +++ b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv_internal.h @@ -4,6 +4,86 @@ * SPDX-License-Identifier: Apache-2.0 */ +int lll_adv_data_init(struct lll_adv_pdu *pdu); +int lll_adv_data_reset(struct lll_adv_pdu *pdu); +int lll_adv_data_release(struct lll_adv_pdu *pdu); + +struct pdu_adv *lll_adv_pdu_alloc(struct lll_adv_pdu *pdu, uint8_t *idx); + +static inline void lll_adv_pdu_enqueue(struct lll_adv_pdu *pdu, uint8_t idx) +{ + pdu->last = idx; +} + +static inline struct pdu_adv *lll_adv_data_alloc(struct lll_adv *lll, uint8_t *idx) +{ + return lll_adv_pdu_alloc(&lll->adv_data, idx); +} + +static inline void lll_adv_data_enqueue(struct lll_adv *lll, uint8_t idx) +{ + lll_adv_pdu_enqueue(&lll->adv_data, idx); +} + +static inline struct pdu_adv *lll_adv_data_peek(struct lll_adv *lll) +{ + return (void *)lll->adv_data.pdu[lll->adv_data.last]; +} + +static inline struct pdu_adv *lll_adv_scan_rsp_alloc(struct lll_adv *lll, + uint8_t *idx) +{ + return lll_adv_pdu_alloc(&lll->scan_rsp, idx); +} + +static inline void lll_adv_scan_rsp_enqueue(struct lll_adv *lll, uint8_t idx) +{ + lll_adv_pdu_enqueue(&lll->scan_rsp, idx); +} + +static inline struct pdu_adv *lll_adv_scan_rsp_peek(struct lll_adv *lll) +{ + return (void *)lll->scan_rsp.pdu[lll->scan_rsp.last]; +} + +#if defined(CONFIG_BT_CTLR_ADV_EXT) +static inline struct pdu_adv *lll_adv_aux_data_alloc(struct lll_adv_aux *lll, + uint8_t *idx) +{ + return lll_adv_pdu_alloc(&lll->data, idx); +} + +static inline void lll_adv_aux_data_enqueue(struct lll_adv_aux *lll, + uint8_t idx) +{ + lll_adv_pdu_enqueue(&lll->data, idx); +} + +static inline struct pdu_adv *lll_adv_aux_data_peek(struct lll_adv_aux *lll) +{ + return (void *)lll->data.pdu[lll->data.last]; +} + +#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) +static inline struct pdu_adv *lll_adv_sync_data_alloc(struct lll_adv_sync *lll, + uint8_t *idx) +{ + return lll_adv_pdu_alloc(&lll->data, idx); +} + +static inline void lll_adv_sync_data_enqueue(struct lll_adv_sync *lll, + uint8_t idx) +{ + lll_adv_pdu_enqueue(&lll->data, idx); +} + +static inline struct pdu_adv *lll_adv_sync_data_peek(struct lll_adv_sync *lll) +{ + return (void *)lll->data.pdu[lll->data.last]; +} +#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ +#endif /* CONFIG_BT_CTLR_ADV_EXT */ + struct pdu_adv *lll_adv_pdu_latest_get(struct lll_adv_pdu *pdu, uint8_t *is_modified); static inline struct pdu_adv *lll_adv_data_latest_get(struct lll_adv *lll, diff --git a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv_pdu.h b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv_pdu.h new file mode 100644 index 00000000000..b2acc223a4b --- /dev/null +++ b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv_pdu.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2018-2019 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* Structure used to double buffer pointers of AD Data PDU buffer. + * The first and last members are used to make modification to AD data to be + * context safe. Thread always appends or updates the buffer pointed to + * the array element indexed by the member last. + * LLL in the ISR context, checks, traverses to the valid pointer indexed + * by the member first, such that the buffer is the latest committed by + * the thread context. + */ +struct lll_adv_pdu { + uint8_t volatile first; + uint8_t last; + uint8_t *pdu[DOUBLE_BUFFER_SIZE]; +#if IS_ENABLED(CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY) + /* This is a storage for LLL configuration that may be + * changed while LLL advertising role is started. + * Also it makes the configuration data to be in sync + * with extended advertising PDU e.g. CTE TX configuration + * and CTEInfo field. + */ + void *extra_data[DOUBLE_BUFFER_SIZE]; +#endif /* CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY */ +}; diff --git a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_master.h b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_master.h deleted file mode 100644 index 64d73c1a171..00000000000 --- a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_master.h +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2018-2019 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -int lll_master_init(void); -int lll_master_reset(void); -void lll_master_prepare(void *param); diff --git a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_scan.h b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_scan.h deleted file mode 100644 index b31a48cc5f4..00000000000 --- a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_scan.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2018-2019 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -struct lll_scan { - struct lll_hdr hdr; - -#if defined(CONFIG_BT_CENTRAL) - /* NOTE: conn context has to be after lll_hdr */ - struct lll_conn *conn; - uint32_t conn_ticks_slot; - uint32_t conn_win_offset_us; - uint16_t conn_timeout; -#endif /* CONFIG_BT_CENTRAL */ - - uint8_t state:1; - uint8_t chan:2; - uint8_t filter_policy:2; - uint8_t adv_addr_type:1; - uint8_t init_addr_type:1; - uint8_t type:1; - -#if defined(CONFIG_BT_CTLR_ADV_EXT) - uint8_t phy:3; -#endif /* CONFIG_BT_CTLR_ADV_EXT */ - -#if defined(CONFIG_BT_CTLR_PRIVACY) - uint8_t rpa_gen:1; - /* initiator only */ - uint8_t rl_idx; -#endif /* CONFIG_BT_CTLR_PRIVACY */ - - uint8_t init_addr[BDADDR_SIZE]; - uint8_t adv_addr[BDADDR_SIZE]; - - uint16_t interval; - uint32_t ticks_window; -}; - -struct lll_scan_aux { - struct lll_hdr hdr; -}; - -int lll_scan_init(void); -int lll_scan_reset(void); - -void lll_scan_prepare(void *param); - -extern uint8_t ull_scan_lll_handle_get(struct lll_scan *lll); diff --git a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_slave.h b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_slave.h deleted file mode 100644 index 668f41fed6a..00000000000 --- a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_slave.h +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2018-2019 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -int lll_slave_init(void); -int lll_slave_reset(void); -void lll_slave_prepare(void *param); diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv.c b/subsys/bluetooth/controller/ll_sw/ull_adv.c index 3a21d4b27ac..24f8e60d7d4 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv.c @@ -35,6 +35,7 @@ #include "lll_conn.h" #include "lll_internal.h" #include "lll_filter.h" +#include "lll_adv_internal.h" #include "ull_adv_types.h" #include "ull_scan_types.h" diff --git a/subsys/bluetooth/controller/ll_sw/ull_filter.c b/subsys/bluetooth/controller/ll_sw/ull_filter.c index f321fbd1dab..723249415de 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_filter.c +++ b/subsys/bluetooth/controller/ll_sw/ull_filter.c @@ -27,6 +27,7 @@ #include "lll_scan.h" #include "lll_conn.h" #include "lll_filter.h" +#include "lll_adv_internal.h" #include "ull_adv_types.h" #include "ull_scan_types.h"