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 <vich@nordicsemi.no>
This commit is contained in:
parent
adcb9eff64
commit
2627524162
12 changed files with 49 additions and 51 deletions
|
@ -9,3 +9,6 @@ int lll_clock_wait(void);
|
||||||
int lll_hfclock_on(void);
|
int lll_hfclock_on(void);
|
||||||
int lll_hfclock_on_wait(void);
|
int lll_hfclock_on_wait(void);
|
||||||
int lll_hfclock_off(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);
|
|
@ -124,10 +124,6 @@ int lll_conn_init(void);
|
||||||
int lll_conn_reset(void);
|
int lll_conn_reset(void);
|
||||||
void lll_conn_flush(uint16_t handle, struct lll_conn *lll);
|
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_prepare_reset(void);
|
||||||
void lll_conn_abort_cb(struct lll_prepare_param *prepare_param, void *param);
|
void lll_conn_abort_cb(struct lll_prepare_param *prepare_param, void *param);
|
||||||
void lll_conn_isr_rx(void *param);
|
void lll_conn_isr_rx(void *param);
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
#define LFCLOCK_TIMEOUT_MS 500
|
#define LFCLOCK_TIMEOUT_MS 500
|
||||||
#define HFCLOCK_TIMEOUT_MS 2
|
#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 lll_clock_state {
|
||||||
struct onoff_client cli;
|
struct onoff_client cli;
|
||||||
struct k_sem sem;
|
struct k_sem sem;
|
||||||
|
@ -113,3 +115,18 @@ int lll_hfclock_off(void)
|
||||||
|
|
||||||
return 0;
|
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];
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
struct node_tx **tx_release, uint8_t *is_done);
|
||||||
static void empty_tx_init(void);
|
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_expire;
|
||||||
static uint8_t crc_valid;
|
static uint8_t crc_valid;
|
||||||
static uint16_t trx_cnt;
|
static uint16_t trx_cnt;
|
||||||
|
@ -123,21 +122,6 @@ void lll_conn_flush(uint16_t handle, struct lll_conn *lll)
|
||||||
/* Nothing to be flushed */
|
/* 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)
|
void lll_conn_prepare_reset(void)
|
||||||
{
|
{
|
||||||
trx_cnt = 0U;
|
trx_cnt = 0U;
|
||||||
|
|
|
@ -777,7 +777,7 @@ static inline int isr_rx_pdu(struct lll_scan *lll, uint8_t devmatch_ok,
|
||||||
&lll_conn->data_chan_map[0],
|
&lll_conn->data_chan_map[0],
|
||||||
sizeof(pdu_tx->connect_ind.chan_map));
|
sizeof(pdu_tx->connect_ind.chan_map));
|
||||||
pdu_tx->connect_ind.hop = lll_conn->data_chan_hop;
|
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);
|
radio_pkt_tx_set(pdu_tx);
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,24 @@
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "hal/debug.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)
|
int lll_clock_wait(void)
|
||||||
{
|
{
|
||||||
return 0;
|
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];
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2018-2020 Nordic Semiconductor ASA
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
int lll_clock_wait(void);
|
|
|
@ -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);
|
struct node_tx **tx_release, uint8_t *is_rx_enqueue);
|
||||||
static struct pdu_data *empty_tx_enqueue(struct lll_conn *lll);
|
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_expire;
|
||||||
static uint8_t crc_valid;
|
static uint8_t crc_valid;
|
||||||
static uint16_t trx_cnt;
|
static uint16_t trx_cnt;
|
||||||
|
@ -73,21 +72,6 @@ int lll_conn_reset(void)
|
||||||
return 0;
|
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)
|
void lll_conn_prepare_reset(void)
|
||||||
{
|
{
|
||||||
trx_cnt = 0U;
|
trx_cnt = 0U;
|
||||||
|
|
|
@ -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],
|
&lll_conn->data_chan_map[0],
|
||||||
sizeof(pdu_tx->connect_ind.chan_map));
|
sizeof(pdu_tx->connect_ind.chan_map));
|
||||||
pdu_tx->connect_ind.hop = lll_conn->data_chan_hop;
|
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);
|
radio_pkt_tx_set(pdu_tx);
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,12 @@
|
||||||
#include "ticker/ticker.h"
|
#include "ticker/ticker.h"
|
||||||
|
|
||||||
#include "pdu.h"
|
#include "pdu.h"
|
||||||
|
|
||||||
#include "lll.h"
|
#include "lll.h"
|
||||||
#include "lll_tim_internal.h"
|
#include "lll_clock.h"
|
||||||
#include "lll_conn.h"
|
#include "lll_conn.h"
|
||||||
|
#include "lll_tim_internal.h"
|
||||||
|
|
||||||
#include "ull_conn_types.h"
|
#include "ull_conn_types.h"
|
||||||
#include "ull_internal.h"
|
#include "ull_internal.h"
|
||||||
#include "ull_sched_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;
|
instant_latency;
|
||||||
|
|
||||||
lll->slave.window_widening_periodic_us =
|
lll->slave.window_widening_periodic_us =
|
||||||
(((lll_conn_ppm_local_get() +
|
(((lll_clock_ppm_local_get() +
|
||||||
lll_conn_ppm_get(conn->slave.sca)) *
|
lll_clock_ppm_get(conn->slave.sca)) *
|
||||||
conn_interval_us) + (1000000 - 1)) / 1000000U;
|
conn_interval_us) + (1000000 - 1)) / 1000000U;
|
||||||
lll->slave.window_widening_max_us =
|
lll->slave.window_widening_max_us =
|
||||||
(conn_interval_us >> 1) - EVENT_IFS_US;
|
(conn_interval_us >> 1) - EVENT_IFS_US;
|
||||||
|
|
|
@ -593,7 +593,7 @@ void ull_master_setup(memq_link_t *link, struct node_rx_hdr *rx,
|
||||||
cc->interval = lll->interval;
|
cc->interval = lll->interval;
|
||||||
cc->latency = lll->latency;
|
cc->latency = lll->latency;
|
||||||
cc->timeout = scan->lll.conn_timeout;
|
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);
|
lll->handle = ll_conn_handle_get(conn);
|
||||||
rx->handle = lll->handle;
|
rx->handle = lll->handle;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "lll.h"
|
#include "lll.h"
|
||||||
#include "lll_vendor.h"
|
#include "lll_vendor.h"
|
||||||
|
#include "lll_clock.h"
|
||||||
#include "lll_adv.h"
|
#include "lll_adv.h"
|
||||||
#include "lll_conn.h"
|
#include "lll_conn.h"
|
||||||
#include "lll_slave.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 */
|
/* calculate the window widening */
|
||||||
conn->slave.sca = pdu_adv->connect_ind.sca;
|
conn->slave.sca = pdu_adv->connect_ind.sca;
|
||||||
lll->slave.window_widening_periodic_us =
|
lll->slave.window_widening_periodic_us =
|
||||||
(((lll_conn_ppm_local_get() +
|
(((lll_clock_ppm_local_get() +
|
||||||
lll_conn_ppm_get(conn->slave.sca)) *
|
lll_clock_ppm_get(conn->slave.sca)) *
|
||||||
conn_interval_us) + (1000000 - 1)) / 1000000U;
|
conn_interval_us) + (1000000 - 1)) / 1000000U;
|
||||||
lll->slave.window_widening_max_us = (conn_interval_us >> 1) -
|
lll->slave.window_widening_max_us = (conn_interval_us >> 1) -
|
||||||
EVENT_IFS_US;
|
EVENT_IFS_US;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue