From 2627524162941550db22fe482cb382b6cc1d8aa9 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Tue, 11 Aug 2020 10:18:59 +0530 Subject: [PATCH] Bluetooth: controller: Refactor out clock ppm interface Refactor out clock ppm interface so that it can be reused for Periodic Advertising Sync feature. Signed-off-by: Vinayak Kariappa Chettimada --- .../ll_sw/{nordic/lll => }/lll_clock.h | 3 +++ subsys/bluetooth/controller/ll_sw/lll_conn.h | 4 ---- .../controller/ll_sw/nordic/lll/lll_clock.c | 17 +++++++++++++++++ .../controller/ll_sw/nordic/lll/lll_conn.c | 16 ---------------- .../controller/ll_sw/nordic/lll/lll_scan.c | 2 +- .../controller/ll_sw/openisa/lll/lll_clock.c | 17 +++++++++++++++++ .../controller/ll_sw/openisa/lll/lll_clock.h | 7 ------- .../controller/ll_sw/openisa/lll/lll_conn.c | 16 ---------------- .../controller/ll_sw/openisa/lll/lll_scan.c | 2 +- subsys/bluetooth/controller/ll_sw/ull_conn.c | 9 ++++++--- subsys/bluetooth/controller/ll_sw/ull_master.c | 2 +- subsys/bluetooth/controller/ll_sw/ull_slave.c | 5 +++-- 12 files changed, 49 insertions(+), 51 deletions(-) rename subsys/bluetooth/controller/ll_sw/{nordic/lll => }/lll_clock.h (66%) delete mode 100644 subsys/bluetooth/controller/ll_sw/openisa/lll/lll_clock.h diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_clock.h b/subsys/bluetooth/controller/ll_sw/lll_clock.h similarity index 66% rename from subsys/bluetooth/controller/ll_sw/nordic/lll/lll_clock.h rename to subsys/bluetooth/controller/ll_sw/lll_clock.h index d304313a286..374e6b51b60 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_clock.h +++ b/subsys/bluetooth/controller/ll_sw/lll_clock.h @@ -9,3 +9,6 @@ int lll_clock_wait(void); int lll_hfclock_on(void); int lll_hfclock_on_wait(void); int lll_hfclock_off(void); +uint8_t lll_clock_sca_local_get(void); +uint32_t lll_clock_ppm_local_get(void); +uint32_t lll_clock_ppm_get(uint8_t sca); diff --git a/subsys/bluetooth/controller/ll_sw/lll_conn.h b/subsys/bluetooth/controller/ll_sw/lll_conn.h index 9e2955fd2cb..d416ec9a794 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_conn.h +++ b/subsys/bluetooth/controller/ll_sw/lll_conn.h @@ -124,10 +124,6 @@ int lll_conn_init(void); int lll_conn_reset(void); void lll_conn_flush(uint16_t handle, struct lll_conn *lll); -uint8_t lll_conn_sca_local_get(void); -uint32_t lll_conn_ppm_local_get(void); -uint32_t lll_conn_ppm_get(uint8_t sca); - void lll_conn_prepare_reset(void); void lll_conn_abort_cb(struct lll_prepare_param *prepare_param, void *param); void lll_conn_isr_rx(void *param); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_clock.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_clock.c index 1fdf964081d..4b3aff80dee 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_clock.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_clock.c @@ -19,6 +19,8 @@ #define LFCLOCK_TIMEOUT_MS 500 #define HFCLOCK_TIMEOUT_MS 2 +static uint16_t const sca_ppm_lut[] = {500, 250, 150, 100, 75, 50, 30, 20}; + struct lll_clock_state { struct onoff_client cli; struct k_sem sem; @@ -113,3 +115,18 @@ int lll_hfclock_off(void) return 0; } + +uint8_t lll_clock_sca_local_get(void) +{ + return CLOCK_CONTROL_NRF_K32SRC_ACCURACY; +} + +uint32_t lll_clock_ppm_local_get(void) +{ + return sca_ppm_lut[CLOCK_CONTROL_NRF_K32SRC_ACCURACY]; +} + +uint32_t lll_clock_ppm_get(uint8_t sca) +{ + return sca_ppm_lut[sca]; +} diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c index aabe19ff484..0f0fccaf105 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c @@ -42,7 +42,6 @@ static inline int isr_rx_pdu(struct lll_conn *lll, struct pdu_data *pdu_data_rx, struct node_tx **tx_release, uint8_t *is_done); static void empty_tx_init(void); -static uint16_t const sca_ppm_lut[] = {500, 250, 150, 100, 75, 50, 30, 20}; static uint8_t crc_expire; static uint8_t crc_valid; static uint16_t trx_cnt; @@ -123,21 +122,6 @@ void lll_conn_flush(uint16_t handle, struct lll_conn *lll) /* Nothing to be flushed */ } -uint8_t lll_conn_sca_local_get(void) -{ - return CLOCK_CONTROL_NRF_K32SRC_ACCURACY; -} - -uint32_t lll_conn_ppm_local_get(void) -{ - return sca_ppm_lut[CLOCK_CONTROL_NRF_K32SRC_ACCURACY]; -} - -uint32_t lll_conn_ppm_get(uint8_t sca) -{ - return sca_ppm_lut[sca]; -} - void lll_conn_prepare_reset(void) { trx_cnt = 0U; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan.c index af3b5ec9a4a..967987127ba 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan.c @@ -777,7 +777,7 @@ static inline int isr_rx_pdu(struct lll_scan *lll, uint8_t devmatch_ok, &lll_conn->data_chan_map[0], sizeof(pdu_tx->connect_ind.chan_map)); pdu_tx->connect_ind.hop = lll_conn->data_chan_hop; - pdu_tx->connect_ind.sca = lll_conn_sca_local_get(); + pdu_tx->connect_ind.sca = lll_clock_sca_local_get(); radio_pkt_tx_set(pdu_tx); diff --git a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_clock.c b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_clock.c index e94d91376b5..f0ea969800b 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_clock.c +++ b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_clock.c @@ -13,7 +13,24 @@ #include "common/log.h" #include "hal/debug.h" +static uint16_t const sca_ppm_lut[] = {500, 250, 150, 100, 75, 50, 30, 20}; + int lll_clock_wait(void) { return 0; } + +uint8_t lll_clock_sca_local_get(void) +{ + return 0; +} + +uint32_t lll_clock_ppm_local_get(void) +{ + return sca_ppm_lut[0]; +} + +uint32_t lll_clock_ppm_get(uint8_t sca) +{ + return sca_ppm_lut[sca]; +} diff --git a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_clock.h b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_clock.h deleted file mode 100644 index 1093be6e0e9..00000000000 --- a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_clock.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c) 2018-2020 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -int lll_clock_wait(void); diff --git a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_conn.c b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_conn.c index 3cb622e3573..03b41a48e68 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_conn.c +++ b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_conn.c @@ -40,7 +40,6 @@ static int isr_rx_pdu(struct lll_conn *lll, struct pdu_data *pdu_data_rx, struct node_tx **tx_release, uint8_t *is_rx_enqueue); static struct pdu_data *empty_tx_enqueue(struct lll_conn *lll); -static uint16_t const sca_ppm_lut[] = {500, 250, 150, 100, 75, 50, 30, 20}; static uint8_t crc_expire; static uint8_t crc_valid; static uint16_t trx_cnt; @@ -73,21 +72,6 @@ int lll_conn_reset(void) return 0; } -uint8_t lll_conn_sca_local_get(void) -{ - return 0; -} - -uint32_t lll_conn_ppm_local_get(void) -{ - return sca_ppm_lut[0]; -} - -uint32_t lll_conn_ppm_get(uint8_t sca) -{ - return sca_ppm_lut[sca]; -} - void lll_conn_prepare_reset(void) { trx_cnt = 0U; diff --git a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_scan.c b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_scan.c index 100c3321351..908bbe6bd67 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_scan.c +++ b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_scan.c @@ -780,7 +780,7 @@ static inline uint32_t isr_rx_pdu(struct lll_scan *lll, uint8_t devmatch_ok, &lll_conn->data_chan_map[0], sizeof(pdu_tx->connect_ind.chan_map)); pdu_tx->connect_ind.hop = lll_conn->data_chan_hop; - pdu_tx->connect_ind.sca = lll_conn_sca_local_get(); + pdu_tx->connect_ind.sca = lll_clock_sca_local_get(); radio_pkt_tx_set(pdu_tx); diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index 8a9a1a07edc..693aa1c371b 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -23,9 +23,12 @@ #include "ticker/ticker.h" #include "pdu.h" + #include "lll.h" -#include "lll_tim_internal.h" +#include "lll_clock.h" #include "lll_conn.h" +#include "lll_tim_internal.h" + #include "ull_conn_types.h" #include "ull_internal.h" #include "ull_sched_internal.h" @@ -2357,8 +2360,8 @@ static inline int event_conn_upd_prep(struct ll_conn *conn, uint16_t lazy, instant_latency; lll->slave.window_widening_periodic_us = - (((lll_conn_ppm_local_get() + - lll_conn_ppm_get(conn->slave.sca)) * + (((lll_clock_ppm_local_get() + + lll_clock_ppm_get(conn->slave.sca)) * conn_interval_us) + (1000000 - 1)) / 1000000U; lll->slave.window_widening_max_us = (conn_interval_us >> 1) - EVENT_IFS_US; diff --git a/subsys/bluetooth/controller/ll_sw/ull_master.c b/subsys/bluetooth/controller/ll_sw/ull_master.c index 53abb17f5b6..f94b62f25a4 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_master.c +++ b/subsys/bluetooth/controller/ll_sw/ull_master.c @@ -593,7 +593,7 @@ void ull_master_setup(memq_link_t *link, struct node_rx_hdr *rx, cc->interval = lll->interval; cc->latency = lll->latency; cc->timeout = scan->lll.conn_timeout; - cc->sca = lll_conn_sca_local_get(); + cc->sca = lll_clock_sca_local_get(); lll->handle = ll_conn_handle_get(conn); rx->handle = lll->handle; diff --git a/subsys/bluetooth/controller/ll_sw/ull_slave.c b/subsys/bluetooth/controller/ll_sw/ull_slave.c index d9426c8f397..1da3e1f561c 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_slave.c +++ b/subsys/bluetooth/controller/ll_sw/ull_slave.c @@ -25,6 +25,7 @@ #include "lll.h" #include "lll_vendor.h" +#include "lll_clock.h" #include "lll_adv.h" #include "lll_conn.h" #include "lll_slave.h" @@ -101,8 +102,8 @@ void ull_slave_setup(memq_link_t *link, struct node_rx_hdr *rx, /* calculate the window widening */ conn->slave.sca = pdu_adv->connect_ind.sca; lll->slave.window_widening_periodic_us = - (((lll_conn_ppm_local_get() + - lll_conn_ppm_get(conn->slave.sca)) * + (((lll_clock_ppm_local_get() + + lll_clock_ppm_get(conn->slave.sca)) * conn_interval_us) + (1000000 - 1)) / 1000000U; lll->slave.window_widening_max_us = (conn_interval_us >> 1) - EVENT_IFS_US;