Bluetooth: controller: Refactor to use ull_sync naming
Refactored to use ull_sync naming instead of ull_scan_sync. Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
This commit is contained in:
parent
7a5413dcca
commit
99916bead0
7 changed files with 199 additions and 48 deletions
|
@ -45,7 +45,7 @@ if(CONFIG_BT_LL_SW_SPLIT)
|
||||||
)
|
)
|
||||||
zephyr_library_sources_ifdef(
|
zephyr_library_sources_ifdef(
|
||||||
CONFIG_BT_CTLR_SCAN_PERIODIC
|
CONFIG_BT_CTLR_SCAN_PERIODIC
|
||||||
ll_sw/ull_scan_sync.c
|
ll_sw/ull_sync.c
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
if(CONFIG_BT_CONN)
|
if(CONFIG_BT_CONN)
|
||||||
|
|
|
@ -2065,9 +2065,9 @@ static void le_per_adv_create_sync(struct net_buf *buf, struct net_buf **evt)
|
||||||
skip = sys_le16_to_cpu(cmd->skip);
|
skip = sys_le16_to_cpu(cmd->skip);
|
||||||
sync_timeout = sys_le16_to_cpu(cmd->sync_timeout);
|
sync_timeout = sys_le16_to_cpu(cmd->sync_timeout);
|
||||||
|
|
||||||
status = ll_scan_sync_create(cmd->options, cmd->sid, cmd->addr.type,
|
status = ll_sync_create(cmd->options, cmd->sid, cmd->addr.type,
|
||||||
cmd->addr.a.val, skip, sync_timeout,
|
cmd->addr.a.val, skip, sync_timeout,
|
||||||
cmd->cte_type);
|
cmd->cte_type);
|
||||||
|
|
||||||
*evt = cmd_status(status);
|
*evt = cmd_status(status);
|
||||||
}
|
}
|
||||||
|
@ -2078,7 +2078,7 @@ static void le_per_adv_create_sync_cancel(struct net_buf *buf,
|
||||||
struct bt_hci_evt_cc_status *ccst;
|
struct bt_hci_evt_cc_status *ccst;
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
|
|
||||||
status = ll_scan_sync_create_cancel();
|
status = ll_sync_create_cancel();
|
||||||
|
|
||||||
ccst = hci_cmd_complete(evt, sizeof(*ccst));
|
ccst = hci_cmd_complete(evt, sizeof(*ccst));
|
||||||
ccst->status = status;
|
ccst->status = status;
|
||||||
|
@ -2093,7 +2093,7 @@ static void le_per_adv_terminate_sync(struct net_buf *buf, struct net_buf **evt)
|
||||||
|
|
||||||
handle = sys_le16_to_cpu(cmd->handle);
|
handle = sys_le16_to_cpu(cmd->handle);
|
||||||
|
|
||||||
status = ll_scan_sync_terminate(handle);
|
status = ll_sync_terminate(handle);
|
||||||
|
|
||||||
ccst = hci_cmd_complete(evt, sizeof(*ccst));
|
ccst = hci_cmd_complete(evt, sizeof(*ccst));
|
||||||
ccst->status = status;
|
ccst->status = status;
|
||||||
|
@ -2108,7 +2108,7 @@ static void le_per_adv_recv_enable(struct net_buf *buf, struct net_buf **evt)
|
||||||
|
|
||||||
handle = sys_le16_to_cpu(cmd->handle);
|
handle = sys_le16_to_cpu(cmd->handle);
|
||||||
|
|
||||||
status = ll_scan_sync_recv_enable(handle, cmd->enable);
|
status = ll_sync_recv_enable(handle, cmd->enable);
|
||||||
|
|
||||||
ccst = hci_cmd_complete(evt, sizeof(*ccst));
|
ccst = hci_cmd_complete(evt, sizeof(*ccst));
|
||||||
ccst->status = status;
|
ccst->status = status;
|
||||||
|
|
|
@ -98,12 +98,12 @@ uint8_t ll_adv_enable(uint8_t enable);
|
||||||
uint8_t ll_scan_params_set(uint8_t type, uint16_t interval, uint16_t window,
|
uint8_t ll_scan_params_set(uint8_t type, uint16_t interval, uint16_t window,
|
||||||
uint8_t own_addr_type, uint8_t filter_policy);
|
uint8_t own_addr_type, uint8_t filter_policy);
|
||||||
uint8_t ll_scan_enable(uint8_t enable);
|
uint8_t ll_scan_enable(uint8_t enable);
|
||||||
uint8_t ll_scan_sync_create(uint8_t options, uint8_t sid, uint8_t adv_addr_type,
|
uint8_t ll_sync_create(uint8_t options, uint8_t sid, uint8_t adv_addr_type,
|
||||||
uint8_t *adv_addr, uint16_t skip,
|
uint8_t *adv_addr, uint16_t skip,
|
||||||
uint16_t sync_timeout, uint8_t sync_cte_type);
|
uint16_t sync_timeout, uint8_t sync_cte_type);
|
||||||
uint8_t ll_scan_sync_create_cancel(void);
|
uint8_t ll_sync_create_cancel(void);
|
||||||
uint8_t ll_scan_sync_terminate(uint16_t handle);
|
uint8_t ll_sync_terminate(uint16_t handle);
|
||||||
uint8_t ll_scan_sync_recv_enable(uint16_t handle, uint8_t enable);
|
uint8_t ll_sync_recv_enable(uint16_t handle, uint8_t enable);
|
||||||
#else /* !CONFIG_BT_CTLR_ADV_EXT */
|
#else /* !CONFIG_BT_CTLR_ADV_EXT */
|
||||||
uint8_t ll_scan_params_set(uint8_t type, uint16_t interval, uint16_t window,
|
uint8_t ll_scan_params_set(uint8_t type, uint16_t interval, uint16_t window,
|
||||||
uint8_t own_addr_type, uint8_t filter_policy);
|
uint8_t own_addr_type, uint8_t filter_policy);
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "lll_scan_aux.h"
|
#include "lll_scan_aux.h"
|
||||||
|
|
||||||
#include "ull_scan_types.h"
|
#include "ull_scan_types.h"
|
||||||
|
#include "ull_sync_types.h"
|
||||||
|
|
||||||
#include "ull_internal.h"
|
#include "ull_internal.h"
|
||||||
#include "ull_scan_internal.h"
|
#include "ull_scan_internal.h"
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020 Nordic Semiconductor ASA
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include <bluetooth/hci.h>
|
|
||||||
|
|
||||||
uint8_t ll_scan_sync_create(uint8_t options, uint8_t sid, uint8_t adv_addr_type,
|
|
||||||
uint8_t *adv_addr, uint16_t skip,
|
|
||||||
uint16_t sync_timeout, uint8_t sync_cte_type)
|
|
||||||
{
|
|
||||||
/* TODO: */
|
|
||||||
return BT_HCI_ERR_CMD_DISALLOWED;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t ll_scan_sync_create_cancel(void)
|
|
||||||
{
|
|
||||||
/* TODO: */
|
|
||||||
return BT_HCI_ERR_CMD_DISALLOWED;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t ll_scan_sync_terminate(uint16_t handle)
|
|
||||||
{
|
|
||||||
/* TODO: */
|
|
||||||
return BT_HCI_ERR_CMD_DISALLOWED;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t ll_scan_sync_recv_enable(uint16_t handle, uint8_t enable)
|
|
||||||
{
|
|
||||||
/* TODO: */
|
|
||||||
return BT_HCI_ERR_CMD_DISALLOWED;
|
|
||||||
}
|
|
158
subsys/bluetooth/controller/ll_sw/ull_sync.c
Normal file
158
subsys/bluetooth/controller/ll_sw/ull_sync.c
Normal file
|
@ -0,0 +1,158 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr.h>
|
||||||
|
#include <bluetooth/hci.h>
|
||||||
|
|
||||||
|
#include "hal/ccm.h"
|
||||||
|
#include "hal/radio.h"
|
||||||
|
|
||||||
|
#include "util/util.h"
|
||||||
|
#include "util/mem.h"
|
||||||
|
#include "util/memq.h"
|
||||||
|
|
||||||
|
#include "pdu.h"
|
||||||
|
#include "ll.h"
|
||||||
|
|
||||||
|
#include "lll.h"
|
||||||
|
#include "lll_scan.h"
|
||||||
|
#include "lll_sync.h"
|
||||||
|
|
||||||
|
#include "ull_scan_types.h"
|
||||||
|
#include "ull_sync_types.h"
|
||||||
|
|
||||||
|
#include "ull_scan_internal.h"
|
||||||
|
|
||||||
|
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
|
||||||
|
#define LOG_MODULE_NAME bt_ctlr_ull_sync
|
||||||
|
#include "common/log.h"
|
||||||
|
#include <soc.h>
|
||||||
|
#include "hal/debug.h"
|
||||||
|
|
||||||
|
static int init_reset(void);
|
||||||
|
static inline struct ll_sync_set *sync_acquire(void);
|
||||||
|
|
||||||
|
static struct ll_sync_set ll_sync_pool[CONFIG_BT_CTLR_SCAN_SYNC_SET];
|
||||||
|
static void *sync_free;
|
||||||
|
|
||||||
|
uint8_t ll_sync_create(uint8_t options, uint8_t sid, uint8_t adv_addr_type,
|
||||||
|
uint8_t *adv_addr, uint16_t skip,
|
||||||
|
uint16_t sync_timeout, uint8_t sync_cte_type)
|
||||||
|
{
|
||||||
|
struct ll_scan_set *scan_coded = NULL;
|
||||||
|
struct ll_scan_set *scan = NULL;
|
||||||
|
struct ll_sync_set *sync;
|
||||||
|
|
||||||
|
scan = ull_scan_set_get(SCAN_HANDLE_1M);
|
||||||
|
if (!scan || scan->sync) {
|
||||||
|
return BT_HCI_ERR_CMD_DISALLOWED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IS_ENABLED(CONFIG_BT_CTLR_PHY_CODED)) {
|
||||||
|
scan_coded = ull_scan_set_get(SCAN_HANDLE_PHY_CODED);
|
||||||
|
if (!scan_coded || scan_coded->sync) {
|
||||||
|
return BT_HCI_ERR_CMD_DISALLOWED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sync = sync_acquire();
|
||||||
|
if (!sync) {
|
||||||
|
return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
sync->filter_policy = options & BIT(0);
|
||||||
|
if (!sync->filter_policy) {
|
||||||
|
sync->sid = sid;
|
||||||
|
sync->adv_addr_type = adv_addr_type;
|
||||||
|
memcpy(sync->adv_addr, adv_addr, BDADDR_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
sync->skip = skip;
|
||||||
|
sync->skip_countdown = skip;
|
||||||
|
|
||||||
|
sync->timeout = sync_timeout;
|
||||||
|
|
||||||
|
/* TODO: Support for CTE type */
|
||||||
|
|
||||||
|
/* Reporting initially enabled/disabled */
|
||||||
|
sync->lll.is_enabled = options & BIT(1);
|
||||||
|
|
||||||
|
/* Enable scanner to create sync */
|
||||||
|
scan->sync = sync;
|
||||||
|
if (IS_ENABLED(CONFIG_BT_CTLR_PHY_CODED)) {
|
||||||
|
scan_coded->sync = sync;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ll_sync_create_cancel(void)
|
||||||
|
{
|
||||||
|
/* TODO: */
|
||||||
|
return BT_HCI_ERR_CMD_DISALLOWED;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ll_sync_terminate(uint16_t handle)
|
||||||
|
{
|
||||||
|
/* TODO: */
|
||||||
|
return BT_HCI_ERR_CMD_DISALLOWED;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ll_sync_recv_enable(uint16_t handle, uint8_t enable)
|
||||||
|
{
|
||||||
|
/* TODO: */
|
||||||
|
return BT_HCI_ERR_CMD_DISALLOWED;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ull_sync_init(void)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = init_reset();
|
||||||
|
if (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ull_sync_reset(void)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = init_reset();
|
||||||
|
if (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int init_reset(void)
|
||||||
|
{
|
||||||
|
/* Initialize sync pool. */
|
||||||
|
mem_init(ll_sync_pool, sizeof(struct ll_sync_set),
|
||||||
|
sizeof(ll_sync_pool) / sizeof(struct ll_sync_set),
|
||||||
|
&sync_free);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline struct ll_sync_set *sync_acquire(void)
|
||||||
|
{
|
||||||
|
return mem_acquire(&sync_free);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void sync_release(struct ll_sync_set *sync)
|
||||||
|
{
|
||||||
|
mem_release(sync, &sync_free);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint8_t sync_handle_get(struct ll_sync_set *sync)
|
||||||
|
{
|
||||||
|
return mem_index_get(sync, ll_sync_pool, sizeof(struct ll_sync_set));
|
||||||
|
}
|
||||||
|
|
27
subsys/bluetooth/controller/ll_sw/ull_sync_types.h
Normal file
27
subsys/bluetooth/controller/ll_sw/ull_sync_types.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define LL_SYNC_STATE_IDLE 0x00
|
||||||
|
#define LL_SYNC_STATE_ADDR_MATCH 0x01
|
||||||
|
#define LL_SYNC_STATE_CREATED 0x02
|
||||||
|
|
||||||
|
struct ll_sync_set {
|
||||||
|
struct evt_hdr evt;
|
||||||
|
struct ull_hdr ull;
|
||||||
|
struct lll_sync lll;
|
||||||
|
|
||||||
|
uint8_t sid;
|
||||||
|
uint8_t adv_addr_type:1;
|
||||||
|
uint8_t filter_policy:1;
|
||||||
|
uint8_t state:2;
|
||||||
|
|
||||||
|
uint8_t adv_addr[BDADDR_SIZE];
|
||||||
|
uint16_t skip;
|
||||||
|
uint16_t skip_countdown;
|
||||||
|
uint16_t timeout;
|
||||||
|
|
||||||
|
/* TODO: handling of sync CTE type */
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue