mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-01 23:00:01 +00:00
nimble/controller: Remove code for 1MHz clock
We will only support LP 32.768kHz clock from now on. X-Original-Commit: e399b1518de3fd9acf44cf6ddf9ca19f9518d4e4
This commit is contained in:
@@ -250,11 +250,9 @@ struct ble_ll_conn_sm
|
||||
uint16_t max_ce_len;
|
||||
uint16_t tx_win_off;
|
||||
uint32_t anchor_point;
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
uint8_t anchor_point_usecs; /* XXX: can this be uint8_t ?*/
|
||||
uint8_t conn_itvl_usecs;
|
||||
uint32_t conn_itvl_ticks;
|
||||
#endif
|
||||
uint32_t last_anchor_point; /* Slave only */
|
||||
uint32_t slave_cur_tx_win_usecs;
|
||||
uint32_t slave_cur_window_widening;
|
||||
|
||||
@@ -51,9 +51,7 @@ extern "C" {
|
||||
* This is the offset from the start of the scheduled item until the actual
|
||||
* tx/rx should occur, in ticks.
|
||||
*/
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
extern uint8_t g_ble_ll_sched_offset_ticks;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is the number of slots needed to transmit and receive a maximum
|
||||
|
||||
@@ -97,16 +97,11 @@ int ble_phy_reset(void);
|
||||
/* Set the PHY channel */
|
||||
int ble_phy_setchan(uint8_t chan, uint32_t access_addr, uint32_t crcinit);
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/* Set transmit start time */
|
||||
int ble_phy_tx_set_start_time(uint32_t cputime, uint8_t rem_usecs);
|
||||
|
||||
/* Set receive start time */
|
||||
int ble_phy_rx_set_start_time(uint32_t cputime, uint8_t rem_usecs);
|
||||
#else
|
||||
/* Set transmit start time */
|
||||
int ble_phy_tx_set_start_time(uint32_t cputime);
|
||||
#endif
|
||||
|
||||
/* Set the transmit end callback and argument */
|
||||
void ble_phy_set_txend_cb(ble_phy_tx_end_func txend_cb, void *arg);
|
||||
@@ -135,13 +130,8 @@ void ble_phy_disable(void);
|
||||
#define BLE_PHY_WFR_ENABLE_RX (0)
|
||||
#define BLE_PHY_WFR_ENABLE_TXRX (1)
|
||||
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
void ble_phy_stop_usec_timer(void);
|
||||
void ble_phy_wfr_enable(int txrx, uint32_t wfr_usecs);
|
||||
#else
|
||||
#define ble_phy_stop_usec_timer()
|
||||
#define ble_phy_wfr_enable(txrx, wfr_usecs)
|
||||
#endif
|
||||
|
||||
/* Starts rf clock */
|
||||
void ble_phy_rfclk_enable(void);
|
||||
|
||||
@@ -577,9 +577,6 @@ ble_ll_wfr_timer_exp(void *arg)
|
||||
void
|
||||
ble_ll_wfr_enable(uint32_t cputime)
|
||||
{
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) != 32768
|
||||
os_cputime_timer_start(&g_ble_ll_data.ll_wfr_timer, cputime);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -588,9 +585,6 @@ ble_ll_wfr_enable(uint32_t cputime)
|
||||
void
|
||||
ble_ll_wfr_disable(void)
|
||||
{
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) != 32768
|
||||
os_cputime_timer_stop(&g_ble_ll_data.ll_wfr_timer);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -834,12 +828,8 @@ ble_ll_rx_start(uint8_t *rxbuf, uint8_t chan, struct ble_mbuf_hdr *rxhdr)
|
||||
uint8_t pdu_type;
|
||||
struct ble_ll_conn_sm *connsm;
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
ble_ll_log(BLE_LL_LOG_ID_RX_START, chan, rxhdr->rem_usecs,
|
||||
rxhdr->beg_cputime);
|
||||
#else
|
||||
ble_ll_log(BLE_LL_LOG_ID_RX_START, chan, 0, rxhdr->beg_cputime);
|
||||
#endif
|
||||
|
||||
/* Advertising channel PDU */
|
||||
pdu_type = rxbuf[0] & BLE_ADV_PDU_HDR_TYPE_MASK;
|
||||
@@ -1394,12 +1384,6 @@ ble_ll_init(void)
|
||||
ble_ll_hw_err_timer_cb,
|
||||
NULL);
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) != 32768
|
||||
/* Initialize wait for response timer */
|
||||
os_cputime_timer_init(&g_ble_ll_data.ll_wfr_timer, ble_ll_wfr_timer_exp,
|
||||
NULL);
|
||||
#endif
|
||||
|
||||
/* Initialize LL HCI */
|
||||
ble_ll_hci_init();
|
||||
|
||||
|
||||
@@ -438,14 +438,8 @@ ble_ll_adv_tx_start_cb(struct ble_ll_sched_item *sch)
|
||||
assert(rc == 0);
|
||||
|
||||
/* Set transmit start time. */
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
txstart = sch->start_time + g_ble_ll_sched_offset_ticks;
|
||||
rc = ble_phy_tx_set_start_time(txstart, sch->remainder);
|
||||
#else
|
||||
txstart = sch->start_time +
|
||||
os_cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
|
||||
rc = ble_phy_tx_set_start_time(txstart);
|
||||
#endif
|
||||
if (rc) {
|
||||
STATS_INC(ble_ll_stats, adv_late_starts);
|
||||
goto adv_tx_done;
|
||||
@@ -547,13 +541,8 @@ ble_ll_adv_set_sched(struct ble_ll_adv_sm *advsm)
|
||||
*/
|
||||
max_usecs += XCVR_PROC_DELAY_USECS;
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
sch->start_time = advsm->adv_pdu_start_time - g_ble_ll_sched_offset_ticks;
|
||||
sch->remainder = 0;
|
||||
#else
|
||||
sch->start_time = advsm->adv_pdu_start_time -
|
||||
os_cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
|
||||
#endif
|
||||
sch->end_time = advsm->adv_pdu_start_time +
|
||||
os_cputime_usecs_to_ticks(max_usecs);
|
||||
}
|
||||
@@ -918,14 +907,8 @@ ble_ll_adv_sm_start(struct ble_ll_adv_sm *advsm)
|
||||
void
|
||||
ble_ll_adv_scheduled(struct ble_ll_adv_sm *advsm, uint32_t sch_start)
|
||||
{
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/* The event start time is when we start transmission of the adv PDU */
|
||||
advsm->adv_event_start_time = sch_start + g_ble_ll_sched_offset_ticks;
|
||||
#else
|
||||
/* The event start time is when we start transmission of the adv PDU */
|
||||
advsm->adv_event_start_time = sch_start +
|
||||
os_cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
|
||||
#endif
|
||||
|
||||
advsm->adv_pdu_start_time = advsm->adv_event_start_time;
|
||||
|
||||
@@ -1556,12 +1539,7 @@ ble_ll_adv_done(struct ble_ll_adv_sm *advsm)
|
||||
* The scheduled time better be in the future! If it is not, we will
|
||||
* just keep advancing until we the time is in the future
|
||||
*/
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
start_time = advsm->adv_pdu_start_time - g_ble_ll_sched_offset_ticks;
|
||||
#else
|
||||
start_time = advsm->adv_pdu_start_time -
|
||||
os_cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
|
||||
#endif
|
||||
|
||||
delta_t = (int32_t)(start_time - os_cputime_get32());
|
||||
if (delta_t < 0) {
|
||||
@@ -1592,13 +1570,8 @@ ble_ll_adv_done(struct ble_ll_adv_sm *advsm)
|
||||
* We will transmit right away. Set next pdu start time to now
|
||||
* plus a xcvr start delay just so we dont count late adv starts
|
||||
*/
|
||||
advsm->adv_pdu_start_time = os_cputime_get32();
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
advsm->adv_pdu_start_time += g_ble_ll_sched_offset_ticks;
|
||||
#else
|
||||
advsm->adv_pdu_start_time +=
|
||||
os_cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
|
||||
#endif
|
||||
advsm->adv_pdu_start_time = os_cputime_get32() +
|
||||
g_ble_ll_sched_offset_ticks;
|
||||
resched_pdu = 1;
|
||||
}
|
||||
|
||||
@@ -1637,11 +1610,7 @@ ble_ll_adv_done(struct ble_ll_adv_sm *advsm)
|
||||
rc = ble_ll_sched_adv_reschedule(&advsm->adv_sch, &start_time,
|
||||
max_delay_ticks);
|
||||
if (!rc) {
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
start_time += g_ble_ll_sched_offset_ticks;
|
||||
#else
|
||||
start_time += os_cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
|
||||
#endif
|
||||
advsm->adv_event_start_time = start_time;
|
||||
advsm->adv_pdu_start_time = start_time;
|
||||
}
|
||||
|
||||
@@ -254,7 +254,6 @@ ble_ll_conn_chk_phy_upd_start(struct ble_ll_conn_sm *csm)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
static void
|
||||
ble_ll_conn_calc_itvl_ticks(struct ble_ll_conn_sm *connsm)
|
||||
{
|
||||
@@ -275,7 +274,6 @@ ble_ll_conn_calc_itvl_ticks(struct ble_ll_conn_sm *connsm)
|
||||
}
|
||||
connsm->conn_itvl_ticks = ticks;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Get the event buffer allocated to send the connection complete event
|
||||
@@ -899,25 +897,16 @@ ble_ll_conn_continue_rx_encrypt(void *arg)
|
||||
static uint32_t
|
||||
ble_ll_conn_get_next_sched_time(struct ble_ll_conn_sm *connsm)
|
||||
{
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) != 32768
|
||||
uint32_t itvl;
|
||||
#endif
|
||||
uint32_t ce_end;
|
||||
uint32_t next_sched_time;
|
||||
|
||||
/* Calculate time at which next connection event will start */
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/* NOTE: We dont care if this time is tick short. */
|
||||
ce_end = connsm->anchor_point + connsm->conn_itvl_ticks -
|
||||
g_ble_ll_sched_offset_ticks;
|
||||
if ((connsm->anchor_point_usecs + connsm->conn_itvl_usecs) >= 31) {
|
||||
++ce_end;
|
||||
}
|
||||
#else
|
||||
itvl = (connsm->conn_itvl * BLE_LL_CONN_ITVL_USECS) -
|
||||
XCVR_TX_SCHED_DELAY_USECS;
|
||||
ce_end = connsm->anchor_point + os_cputime_usecs_to_ticks(itvl);
|
||||
#endif
|
||||
|
||||
if (ble_ll_sched_next_time(&next_sched_time)) {
|
||||
if (CPUTIME_LT(next_sched_time, ce_end)) {
|
||||
@@ -1374,9 +1363,6 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch)
|
||||
{
|
||||
int rc;
|
||||
uint32_t usecs;
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) != 32768
|
||||
uint32_t wfr_time;
|
||||
#endif
|
||||
uint32_t start;
|
||||
struct ble_ll_conn_sm *connsm;
|
||||
|
||||
@@ -1416,15 +1402,9 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch)
|
||||
#endif
|
||||
|
||||
if (connsm->conn_role == BLE_LL_CONN_ROLE_MASTER) {
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/* Set start time of transmission */
|
||||
start = sch->start_time + g_ble_ll_sched_offset_ticks;
|
||||
rc = ble_phy_tx_set_start_time(start, sch->remainder);
|
||||
#else
|
||||
/* Set start time of transmission */
|
||||
start = sch->start_time + os_cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
|
||||
rc = ble_phy_tx_set_start_time(start);
|
||||
#endif
|
||||
if (!rc) {
|
||||
#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
|
||||
if (CONN_F_ENCRYPTED(connsm)) {
|
||||
@@ -1464,13 +1444,9 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch)
|
||||
connsm->phy_data.rx_phy_mode);
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/* XXX: what is this really for the slave? */
|
||||
start = sch->start_time + g_ble_ll_sched_offset_ticks;
|
||||
rc = ble_phy_rx_set_start_time(start, sch->remainder);
|
||||
#else
|
||||
rc = ble_phy_rx();
|
||||
#endif
|
||||
if (rc) {
|
||||
/* End the connection event as we have no more buffers */
|
||||
STATS_INC(ble_ll_conn_stats, slave_ce_failures);
|
||||
@@ -1491,7 +1467,7 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch)
|
||||
* -> Amount of time it takes to detect packet start.
|
||||
* -> Some extra time (16 usec) to insure timing is OK
|
||||
*/
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
|
||||
/*
|
||||
* For the 32 kHz crystal, the amount of usecs we have to wait
|
||||
* is not from the anchor point; we have to account for the time
|
||||
@@ -1509,17 +1485,6 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch)
|
||||
usecs = connsm->slave_cur_tx_win_usecs + 61 +
|
||||
(2 * connsm->slave_cur_window_widening);
|
||||
ble_phy_wfr_enable(BLE_PHY_WFR_ENABLE_RX, usecs);
|
||||
#else
|
||||
/*
|
||||
* NOTE: technically we do not need twice the jitter but I want
|
||||
* to be sure we do not bail out early.
|
||||
*/
|
||||
usecs = connsm->slave_cur_tx_win_usecs + BLE_LL_IFS +
|
||||
ble_phy_mode_pdu_start_off(connsm->phy_data.rx_phy_mode) +
|
||||
(BLE_LL_JITTER_USECS * 2) + connsm->slave_cur_window_widening;
|
||||
wfr_time = connsm->anchor_point + os_cputime_usecs_to_ticks(usecs);
|
||||
ble_ll_wfr_enable(wfr_time);
|
||||
#endif
|
||||
/* Set next wakeup time to connection event end time */
|
||||
rc = BLE_LL_SCHED_STATE_RUNNING;
|
||||
}
|
||||
@@ -1561,9 +1526,7 @@ ble_ll_conn_can_send_next_pdu(struct ble_ll_conn_sm *connsm, uint32_t begtime,
|
||||
struct os_mbuf *txpdu;
|
||||
struct os_mbuf_pkthdr *pkthdr;
|
||||
struct ble_mbuf_hdr *txhdr;
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
uint32_t allowed_usecs;
|
||||
#endif
|
||||
|
||||
rc = 1;
|
||||
if (connsm->conn_role == BLE_LL_CONN_ROLE_MASTER) {
|
||||
@@ -1596,18 +1559,11 @@ ble_ll_conn_can_send_next_pdu(struct ble_ll_conn_sm *connsm, uint32_t begtime,
|
||||
}
|
||||
usecs += (BLE_LL_IFS * 2) + connsm->eff_max_rx_time;
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
ticks = (uint32_t)(next_sched_time - begtime);
|
||||
allowed_usecs = os_cputime_ticks_to_usecs(ticks);
|
||||
if ((usecs + add_usecs) >= allowed_usecs) {
|
||||
rc = 0;
|
||||
}
|
||||
#else
|
||||
ticks = os_cputime_usecs_to_ticks(usecs);
|
||||
if ((begtime + ticks) >= next_sched_time) {
|
||||
rc = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return rc;
|
||||
@@ -1659,15 +1615,12 @@ ble_ll_conn_master_common_init(struct ble_ll_conn_sm *connsm)
|
||||
connsm->conn_role = BLE_LL_CONN_ROLE_MASTER;
|
||||
|
||||
/* Set default ce parameters */
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
|
||||
/*
|
||||
* XXX: for now, we need twice the transmit window as our calculations
|
||||
* for the transmit window offset could be off.
|
||||
*/
|
||||
connsm->tx_win_size = BLE_LL_CONN_TX_WIN_MIN + 1;
|
||||
#else
|
||||
connsm->tx_win_size = BLE_LL_CONN_TX_WIN_MIN;
|
||||
#endif
|
||||
connsm->tx_win_off = 0;
|
||||
connsm->master_sca = MYNEWT_VAL(BLE_LL_MASTER_SCA);
|
||||
|
||||
@@ -1937,9 +1890,7 @@ ble_ll_conn_sm_new(struct ble_ll_conn_sm *connsm)
|
||||
connsm);
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
ble_ll_conn_calc_itvl_ticks(connsm);
|
||||
#endif
|
||||
|
||||
/* Add to list of active connections */
|
||||
SLIST_INSERT_HEAD(&g_ble_ll_conn_active_list, connsm, act_sle);
|
||||
@@ -2094,10 +2045,8 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm)
|
||||
uint32_t cur_ww;
|
||||
uint32_t max_ww;
|
||||
struct ble_ll_conn_upd_req *upd;
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
uint32_t ticks;
|
||||
uint32_t usecs;
|
||||
#endif
|
||||
|
||||
/* XXX: deal with connection request procedure here as well */
|
||||
ble_ll_conn_chk_csm_flags(connsm);
|
||||
@@ -2134,7 +2083,6 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm)
|
||||
connsm->event_cntr += latency;
|
||||
|
||||
/* Set next connection event start time */
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/* We can use pre-calculated values for one interval if latency is 1. */
|
||||
if (latency == 1) {
|
||||
connsm->anchor_point += connsm->conn_itvl_ticks;
|
||||
@@ -2149,9 +2097,6 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm)
|
||||
++connsm->anchor_point;
|
||||
connsm->anchor_point_usecs -= 31;
|
||||
}
|
||||
#else
|
||||
connsm->anchor_point += os_cputime_usecs_to_ticks(itvl);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If a connection update has been scheduled and the event counter
|
||||
@@ -2180,7 +2125,6 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm)
|
||||
connsm->tx_win_size * BLE_LL_CONN_TX_WIN_USECS;
|
||||
connsm->tx_win_off = upd->winoffset;
|
||||
connsm->conn_itvl = upd->interval;
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
ble_ll_conn_calc_itvl_ticks(connsm);
|
||||
if (upd->winoffset != 0) {
|
||||
usecs = upd->winoffset * BLE_LL_CONN_ITVL_USECS;
|
||||
@@ -2193,10 +2137,6 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm)
|
||||
connsm->anchor_point_usecs -= 31;
|
||||
}
|
||||
}
|
||||
#else
|
||||
connsm->anchor_point +=
|
||||
os_cputime_usecs_to_ticks(upd->winoffset * BLE_LL_CONN_ITVL_USECS);
|
||||
#endif
|
||||
|
||||
/* Reset the starting point of the connection supervision timeout */
|
||||
connsm->last_rxd_pdu_cputime = connsm->anchor_point;
|
||||
@@ -2278,7 +2218,6 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm)
|
||||
* Calculate ce end time. For a slave, we need to add window widening and
|
||||
* the transmit window if we still have one.
|
||||
*/
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
itvl = MYNEWT_VAL(BLE_LL_CONN_INIT_SLOTS) * BLE_LL_SCHED_32KHZ_TICKS_PER_SLOT;
|
||||
if (connsm->conn_role == BLE_LL_CONN_ROLE_SLAVE) {
|
||||
cur_ww = ble_ll_conn_calc_window_widening(connsm);
|
||||
@@ -2292,21 +2231,6 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm)
|
||||
}
|
||||
itvl -= g_ble_ll_sched_offset_ticks;
|
||||
connsm->ce_end_time = connsm->anchor_point + itvl;
|
||||
#else
|
||||
itvl = MYNEWT_VAL(BLE_LL_CONN_INIT_SLOTS) * BLE_LL_SCHED_USECS_PER_SLOT;
|
||||
if (connsm->conn_role == BLE_LL_CONN_ROLE_SLAVE) {
|
||||
cur_ww = ble_ll_conn_calc_window_widening(connsm);
|
||||
max_ww = (connsm->conn_itvl * (BLE_LL_CONN_ITVL_USECS/2)) - BLE_LL_IFS;
|
||||
if (cur_ww >= max_ww) {
|
||||
return -1;
|
||||
}
|
||||
connsm->slave_cur_window_widening = cur_ww + BLE_LL_JITTER_USECS;
|
||||
itvl += cur_ww + connsm->slave_cur_tx_win_usecs;
|
||||
} else {
|
||||
itvl -= XCVR_TX_SCHED_DELAY_USECS;
|
||||
}
|
||||
connsm->ce_end_time = connsm->anchor_point + os_cputime_usecs_to_ticks(itvl);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -2358,7 +2282,6 @@ ble_ll_conn_created(struct ble_ll_conn_sm *connsm, struct ble_mbuf_hdr *rxhdr)
|
||||
*/
|
||||
rc = 1;
|
||||
if (connsm->conn_role == BLE_LL_CONN_ROLE_SLAVE) {
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/*
|
||||
* With a 32.768 kHz crystal we dont care about the remaining usecs
|
||||
* when setting last anchor point. The only thing last anchor is used
|
||||
@@ -2387,20 +2310,6 @@ ble_ll_conn_created(struct ble_ll_conn_sm *connsm, struct ble_mbuf_hdr *rxhdr)
|
||||
connsm->ce_end_time = connsm->anchor_point +
|
||||
(MYNEWT_VAL(BLE_LL_CONN_INIT_SLOTS) * BLE_LL_SCHED_32KHZ_TICKS_PER_SLOT)
|
||||
+ os_cputime_usecs_to_ticks(connsm->slave_cur_tx_win_usecs) + 1;
|
||||
#else
|
||||
connsm->last_anchor_point = rxhdr->beg_cputime;
|
||||
endtime = rxhdr->beg_cputime +
|
||||
os_cputime_usecs_to_ticks(ble_ll_pdu_tx_time_get(BLE_CONNECT_REQ_LEN,
|
||||
BLE_PHY_1M));
|
||||
connsm->slave_cur_tx_win_usecs =
|
||||
connsm->tx_win_size * BLE_LL_CONN_TX_WIN_USECS;
|
||||
usecs = 1250 + (connsm->tx_win_off * BLE_LL_CONN_TX_WIN_USECS);
|
||||
connsm->anchor_point = endtime + os_cputime_usecs_to_ticks(usecs);
|
||||
usecs = connsm->slave_cur_tx_win_usecs +
|
||||
(MYNEWT_VAL(BLE_LL_CONN_INIT_SLOTS) * BLE_LL_SCHED_USECS_PER_SLOT);
|
||||
connsm->ce_end_time = connsm->anchor_point +
|
||||
os_cputime_usecs_to_ticks(usecs);
|
||||
#endif
|
||||
connsm->slave_cur_window_widening = BLE_LL_JITTER_USECS;
|
||||
|
||||
/* Start the scheduler for the first connection event */
|
||||
@@ -3241,9 +3150,7 @@ ble_ll_conn_rx_isr_start(struct ble_mbuf_hdr *rxhdr, uint32_t aa)
|
||||
connsm->csmflags.cfbit.slave_set_last_anchor = 0;
|
||||
connsm->last_anchor_point = rxhdr->beg_cputime;
|
||||
connsm->anchor_point = connsm->last_anchor_point;
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
connsm->anchor_point_usecs = rxhdr->rem_usecs;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
@@ -3440,17 +3347,9 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
|
||||
* but for the 32768 crystal we add the time it takes to send the packet
|
||||
* to the 'additional usecs' field to save some calculations.
|
||||
*/
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
endtime = rxhdr->beg_cputime;
|
||||
add_usecs = rxhdr->rem_usecs +
|
||||
ble_ll_pdu_tx_time_get(rx_pyld_len, connsm->phy_data.rx_phy_mode);
|
||||
#else
|
||||
endtime = rxhdr->beg_cputime +
|
||||
os_cputime_usecs_to_ticks(ble_ll_pdu_tx_time_get(rx_pyld_len,
|
||||
connsm->phy_data.rx_phy_mode));
|
||||
|
||||
add_usecs = 0;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Check the packet CRC. A connection event can continue even if the
|
||||
|
||||
@@ -852,14 +852,10 @@ ble_ll_scan_start(struct ble_ll_scan_sm *scansm)
|
||||
ble_phy_mode_set(phy_mode, phy_mode);
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/* XXX: probably need to make sure hfxo is running too */
|
||||
/* XXX: can make this better; want to just start asap. */
|
||||
rc = ble_phy_rx_set_start_time(os_cputime_get32() +
|
||||
g_ble_ll_sched_offset_ticks, 0);
|
||||
#else
|
||||
rc = ble_phy_rx();
|
||||
#endif
|
||||
if (!rc) {
|
||||
/* Enable/disable whitelisting */
|
||||
if (scansm->scan_filt_policy & 1) {
|
||||
|
||||
@@ -39,9 +39,7 @@ struct hal_timer g_ble_ll_sched_timer;
|
||||
uint8_t g_ble_ll_sched_xtal_ticks;
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
uint8_t g_ble_ll_sched_offset_ticks;
|
||||
#endif
|
||||
|
||||
#define BLE_LL_SCHED_ADV_WORST_CASE_USECS \
|
||||
(BLE_LL_SCHED_MAX_ADV_PDU_USECS + BLE_LL_IFS + BLE_LL_SCHED_ADV_MAX_USECS \
|
||||
@@ -166,7 +164,6 @@ ble_ll_sched_conn_reschedule(struct ble_ll_conn_sm *connsm)
|
||||
/* Get schedule element from connection */
|
||||
sch = &connsm->conn_sch;
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/* Set schedule start and end times */
|
||||
sch->start_time = connsm->anchor_point - g_ble_ll_sched_offset_ticks;
|
||||
if (connsm->conn_role == BLE_LL_CONN_ROLE_SLAVE) {
|
||||
@@ -176,16 +173,6 @@ ble_ll_sched_conn_reschedule(struct ble_ll_conn_sm *connsm)
|
||||
} else {
|
||||
sch->remainder = connsm->anchor_point_usecs;
|
||||
}
|
||||
#else
|
||||
/* Set schedule start and end times */
|
||||
if (connsm->conn_role == BLE_LL_CONN_ROLE_SLAVE) {
|
||||
usecs = XCVR_RX_SCHED_DELAY_USECS;
|
||||
usecs += connsm->slave_cur_window_widening;
|
||||
} else {
|
||||
usecs = XCVR_TX_SCHED_DELAY_USECS;
|
||||
}
|
||||
sch->start_time = connsm->anchor_point - os_cputime_usecs_to_ticks(usecs);
|
||||
#endif
|
||||
sch->end_time = connsm->ce_end_time;
|
||||
|
||||
/* Better be past current time or we just leave */
|
||||
@@ -333,7 +320,6 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm,
|
||||
sch = &connsm->conn_sch;
|
||||
req_slots = MYNEWT_VAL(BLE_LL_CONN_INIT_SLOTS);
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/* XXX:
|
||||
* The calculations for the 32kHz crystal bear alot of explanation. The
|
||||
* earliest possible time that the master can start the connection with a
|
||||
@@ -417,25 +403,6 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm,
|
||||
}
|
||||
earliest_end = earliest_start + dur;
|
||||
itvl_t = connsm->conn_itvl_ticks;
|
||||
#else
|
||||
adv_rxend = ble_hdr->beg_cputime +
|
||||
os_cputime_usecs_to_ticks(ble_ll_pdu_tx_time_get(pyld_len, BLE_PHY_MODE_1M));
|
||||
/*
|
||||
* The earliest start time is 1.25 msecs from the end of the connect
|
||||
* request transmission. Note that adv_rxend is the end of the received
|
||||
* advertisement, so we need to add an IFS plus the time it takes to send
|
||||
* the connection request. The 1.25 msecs starts from the end of the conn
|
||||
* request. Also include minimum WindowOffset value if configured.
|
||||
*/
|
||||
dur = os_cputime_usecs_to_ticks(req_slots * BLE_LL_SCHED_USECS_PER_SLOT);
|
||||
earliest_start = adv_rxend +
|
||||
os_cputime_usecs_to_ticks(BLE_LL_IFS +
|
||||
ble_ll_pdu_tx_time_get(BLE_CONNECT_REQ_LEN, BLE_PHY_MODE_1M) +
|
||||
BLE_LL_CONN_INITIAL_OFFSET +
|
||||
MYNEWT_VAL(BLE_LL_CONN_INIT_MIN_WIN_OFFSET) * BLE_LL_CONN_TX_OFF_USECS);
|
||||
earliest_end = earliest_start + dur;
|
||||
itvl_t = os_cputime_usecs_to_ticks(connsm->conn_itvl * BLE_LL_CONN_ITVL_USECS);
|
||||
#endif
|
||||
|
||||
/* We have to find a place for this schedule */
|
||||
OS_ENTER_CRITICAL(sr);
|
||||
@@ -483,7 +450,6 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm,
|
||||
if (!rc) {
|
||||
/* calculate number of window offsets. Each offset is 1.25 ms */
|
||||
sch->enqueued = 1;
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/*
|
||||
* NOTE: we dont add sched offset ticks as we want to under-estimate
|
||||
* the transmit window slightly since the window size is currently
|
||||
@@ -491,28 +457,18 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm,
|
||||
*/
|
||||
dur = os_cputime_ticks_to_usecs(earliest_start - initial_start);
|
||||
connsm->tx_win_off = dur / BLE_LL_CONN_TX_OFF_USECS;
|
||||
#else
|
||||
dur = os_cputime_ticks_to_usecs(earliest_start - initial_start);
|
||||
dur += XCVR_TX_SCHED_DELAY_USECS;
|
||||
connsm->tx_win_off = dur / BLE_LL_CONN_TX_OFF_USECS;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (!rc) {
|
||||
sch->start_time = earliest_start;
|
||||
sch->end_time = earliest_end;
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/*
|
||||
* Since we have the transmit window to transmit in, we dont need
|
||||
* to set the anchor point usecs; just transmit to the nearest tick.
|
||||
*/
|
||||
connsm->anchor_point = earliest_start + g_ble_ll_sched_offset_ticks;
|
||||
connsm->anchor_point_usecs = 0;
|
||||
#else
|
||||
connsm->anchor_point = earliest_start +
|
||||
os_cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
|
||||
#endif
|
||||
connsm->ce_end_time = earliest_end;
|
||||
}
|
||||
|
||||
@@ -554,7 +510,6 @@ ble_ll_sched_slave_new(struct ble_ll_conn_sm *connsm)
|
||||
sch = &connsm->conn_sch;
|
||||
|
||||
/* Set schedule start and end times */
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/*
|
||||
* XXX: for now, we dont care about anchor point usecs for the slave. It
|
||||
* does not matter if we turn on the receiver up to one tick before w
|
||||
@@ -563,11 +518,6 @@ ble_ll_sched_slave_new(struct ble_ll_conn_sm *connsm)
|
||||
*/
|
||||
sch->start_time = connsm->anchor_point - g_ble_ll_sched_offset_ticks -
|
||||
os_cputime_usecs_to_ticks(connsm->slave_cur_window_widening) - 1;
|
||||
#else
|
||||
sch->start_time = connsm->anchor_point -
|
||||
os_cputime_usecs_to_ticks(XCVR_RX_SCHED_DELAY_USECS +
|
||||
connsm->slave_cur_window_widening);
|
||||
#endif
|
||||
sch->end_time = connsm->ce_end_time;
|
||||
sch->remainder = 0;
|
||||
|
||||
@@ -1224,10 +1174,8 @@ ble_ll_sched_init(void)
|
||||
* This is the offset from the start of the scheduled item until the actual
|
||||
* tx/rx should occur, in ticks. We also "round up" to the nearest tick.
|
||||
*/
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
g_ble_ll_sched_offset_ticks =
|
||||
os_cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS + 30);
|
||||
#endif
|
||||
|
||||
/* Initialize cputimer for the scheduler */
|
||||
os_cputime_timer_init(&g_ble_ll_sched_timer, ble_ll_sched_run, NULL);
|
||||
|
||||
@@ -25,15 +25,8 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* Transceiver specific defintions */
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/*
|
||||
* NOTE: we have to account for the RTC output compare issue, which is why
|
||||
* this number is much larger when using the 32.768 crystal.
|
||||
*/
|
||||
/* NOTE: we have to account for the RTC output compare issue */
|
||||
#define XCVR_PROC_DELAY_USECS (230)
|
||||
#else
|
||||
#define XCVR_PROC_DELAY_USECS (100)
|
||||
#endif
|
||||
|
||||
#define XCVR_RX_START_DELAY_USECS (140)
|
||||
#define XCVR_TX_START_DELAY_USECS (140)
|
||||
|
||||
@@ -84,9 +84,7 @@ struct ble_phy_obj
|
||||
struct ble_mbuf_hdr rxhdr;
|
||||
void *txend_arg;
|
||||
ble_phy_tx_end_func txend_cb;
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
uint32_t phy_start_cputime;
|
||||
#endif
|
||||
};
|
||||
struct ble_phy_obj g_ble_phy_data;
|
||||
|
||||
@@ -281,7 +279,6 @@ nrf_wait_disabled(void)
|
||||
}
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -404,7 +401,6 @@ ble_phy_wfr_enable(int txrx, uint32_t wfr_usecs)
|
||||
/* Enable the disabled interrupt so we time out on events compare */
|
||||
NRF_RADIO->INTENSET = RADIO_INTENSET_DISABLED_Msk;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Setup transceiver for receive.
|
||||
@@ -496,18 +492,6 @@ ble_phy_tx_end_isr(void)
|
||||
uint8_t transition;
|
||||
uint8_t txlen;
|
||||
uint32_t wfr_time;
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) != 32768)
|
||||
uint32_t txstart;
|
||||
#endif
|
||||
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) != 32768)
|
||||
/*
|
||||
* Read captured tx start time. This is not the actual transmit start
|
||||
* time but it is the time at which the address event occurred
|
||||
* (after transmission of access address)
|
||||
*/
|
||||
txstart = NRF_TIMER0->CC[1];
|
||||
#endif
|
||||
|
||||
/* If this transmission was encrypted we need to remember it */
|
||||
was_encrypted = g_ble_phy_data.phy_encrypted;
|
||||
@@ -516,13 +500,8 @@ ble_phy_tx_end_isr(void)
|
||||
assert(g_ble_phy_data.phy_state == BLE_PHY_STATE_TX);
|
||||
|
||||
/* Log the event */
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
ble_ll_log(BLE_LL_LOG_ID_PHY_TXEND, g_ble_phy_data.phy_tx_pyld_len,
|
||||
was_encrypted, NRF_TIMER0->CC[2]);
|
||||
#else
|
||||
ble_ll_log(BLE_LL_LOG_ID_PHY_TXEND, g_ble_phy_data.phy_tx_pyld_len,
|
||||
was_encrypted, txstart);
|
||||
#endif
|
||||
|
||||
/* Clear events and clear interrupt on disabled event */
|
||||
NRF_RADIO->EVENTS_DISABLED = 0;
|
||||
@@ -562,18 +541,8 @@ ble_phy_tx_end_isr(void)
|
||||
if (txlen && was_encrypted) {
|
||||
txlen += BLE_LL_DATA_MIC_LEN;
|
||||
}
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
ble_phy_wfr_enable(BLE_PHY_WFR_ENABLE_TXRX, 0);
|
||||
#else
|
||||
wfr_time = (BLE_LL_IFS + ble_phy_mode_pdu_start_off(BLE_PHY_1M) +
|
||||
(2 * BLE_LL_JITTER_USECS)) -
|
||||
ble_phy_mode_pdu_start_off(BLE_PHY_1M);
|
||||
wfr_time += ble_ll_pdu_tx_time_get(txlen, BLE_PHY_1M);
|
||||
wfr_time = os_cputime_usecs_to_ticks(wfr_time);
|
||||
ble_ll_wfr_enable(txstart + wfr_time);
|
||||
#endif
|
||||
} else {
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
/*
|
||||
* XXX: not sure we need to stop the timer here all the time. Or that
|
||||
* it should be stopped here.
|
||||
@@ -582,10 +551,6 @@ ble_phy_tx_end_isr(void)
|
||||
NRF_TIMER0->TASKS_SHUTDOWN = 1;
|
||||
NRF_PPI->CHENCLR = PPI_CHEN_CH4_Msk | PPI_CHEN_CH5_Msk |
|
||||
PPI_CHEN_CH20_Msk | PPI_CHEN_CH31_Msk;
|
||||
#else
|
||||
/* Disable automatic TXEN */
|
||||
NRF_PPI->CHENCLR = PPI_CHEN_CH20_Msk;
|
||||
#endif
|
||||
assert(transition == BLE_PHY_TRANSITION_NONE);
|
||||
}
|
||||
}
|
||||
@@ -673,22 +638,16 @@ ble_phy_rx_start_isr(void)
|
||||
{
|
||||
int rc;
|
||||
uint32_t state;
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
uint32_t usecs;
|
||||
uint32_t ticks;
|
||||
#endif
|
||||
struct ble_mbuf_hdr *ble_hdr;
|
||||
|
||||
/* Clear events and clear interrupt */
|
||||
NRF_RADIO->EVENTS_ADDRESS = 0;
|
||||
|
||||
/* Clear wfr timer channels and DISABLED interrupt */
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
NRF_RADIO->INTENCLR = RADIO_INTENCLR_DISABLED_Msk | RADIO_INTENCLR_ADDRESS_Msk;
|
||||
NRF_PPI->CHENCLR = PPI_CHEN_CH4_Msk | PPI_CHEN_CH5_Msk;
|
||||
#else
|
||||
NRF_RADIO->INTENCLR = RADIO_INTENCLR_ADDRESS_Msk;
|
||||
#endif
|
||||
|
||||
/* Initialize flags, channel and state in ble header at rx start */
|
||||
ble_hdr = &g_ble_phy_data.rxhdr;
|
||||
@@ -696,7 +655,6 @@ ble_phy_rx_start_isr(void)
|
||||
ble_hdr->rxinfo.channel = g_ble_phy_data.phy_chan;
|
||||
ble_hdr->rxinfo.handle = 0;
|
||||
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
/*
|
||||
* Calculate receive start time.
|
||||
*
|
||||
@@ -710,10 +668,6 @@ ble_phy_rx_start_isr(void)
|
||||
++ticks;
|
||||
}
|
||||
ble_hdr->beg_cputime = g_ble_phy_data.phy_start_cputime + ticks;
|
||||
#else
|
||||
ble_hdr->beg_cputime = NRF_TIMER0->CC[1] -
|
||||
os_cputime_usecs_to_ticks(ble_phy_mode_pdu_start_off(BLE_PHY_MODE_1M));
|
||||
#endif
|
||||
|
||||
/* Wait to get 1st byte of frame */
|
||||
while (1) {
|
||||
@@ -775,24 +729,18 @@ ble_phy_isr(void)
|
||||
|
||||
/* We get this if we have started to receive a frame */
|
||||
if ((irq_en & RADIO_INTENCLR_ADDRESS_Msk) && NRF_RADIO->EVENTS_ADDRESS) {
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
irq_en &= ~RADIO_INTENCLR_DISABLED_Msk;
|
||||
#endif
|
||||
ble_phy_rx_start_isr();
|
||||
}
|
||||
|
||||
/* Check for disabled event. This only happens for transmits now */
|
||||
if ((irq_en & RADIO_INTENCLR_DISABLED_Msk) && NRF_RADIO->EVENTS_DISABLED) {
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
if (g_ble_phy_data.phy_state == BLE_PHY_STATE_RX) {
|
||||
NRF_RADIO->EVENTS_DISABLED = 0;
|
||||
ble_ll_wfr_timer_exp(NULL);
|
||||
} else {
|
||||
ble_phy_tx_end_isr();
|
||||
}
|
||||
#else
|
||||
ble_phy_tx_end_isr();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Receive packet end (we dont enable this for transmit) */
|
||||
@@ -869,13 +817,8 @@ ble_phy_init(void)
|
||||
/* Configure IFS */
|
||||
NRF_RADIO->TIFS = BLE_LL_IFS;
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/* Captures tx/rx start in timer0 cc 1 and tx/rx end in timer0 cc 2 */
|
||||
NRF_PPI->CHENSET = PPI_CHEN_CH26_Msk | PPI_CHEN_CH27_Msk;
|
||||
#else
|
||||
/* Captures tx/rx start in timer0 capture 1 */
|
||||
NRF_PPI->CHENSET = PPI_CHEN_CH26_Msk;
|
||||
#endif
|
||||
|
||||
#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
|
||||
NRF_CCM->INTENCLR = 0xffffffff;
|
||||
@@ -895,7 +838,6 @@ ble_phy_init(void)
|
||||
#endif
|
||||
|
||||
/* TIMER0 setup for PHY when using RTC */
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
NRF_TIMER0->TASKS_STOP = 1;
|
||||
NRF_TIMER0->TASKS_SHUTDOWN = 1;
|
||||
NRF_TIMER0->BITMODE = 3; /* 32-bit timer */
|
||||
@@ -913,7 +855,6 @@ ble_phy_init(void)
|
||||
NRF_PPI->CH[4].TEP = (uint32_t)&(NRF_TIMER0->TASKS_CAPTURE[3]);
|
||||
NRF_PPI->CH[5].EEP = (uint32_t)&(NRF_TIMER0->EVENTS_COMPARE[3]);
|
||||
NRF_PPI->CH[5].TEP = (uint32_t)&(NRF_RADIO->TASKS_DISABLE);
|
||||
#endif
|
||||
|
||||
/* Set isr in vector table and enable interrupt */
|
||||
NVIC_SetPriority(RADIO_IRQn, 0);
|
||||
@@ -1033,7 +974,6 @@ ble_phy_set_txend_cb(ble_phy_tx_end_func txend_cb, void *arg)
|
||||
g_ble_phy_data.txend_arg = arg;
|
||||
}
|
||||
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
/**
|
||||
* Called to set the start time of a transmission.
|
||||
*
|
||||
@@ -1115,65 +1055,6 @@ ble_phy_rx_set_start_time(uint32_t cputime, uint8_t rem_usecs)
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#else
|
||||
/**
|
||||
* Called to set the start time of a transmission.
|
||||
*
|
||||
* This function is called to set the start time when we are not going from
|
||||
* rx to tx automatically.
|
||||
*
|
||||
* NOTE: care must be taken when calling this function. The channel should
|
||||
* already be set.
|
||||
*
|
||||
* @param cputime This is the tick at which the 1st bit of the preamble
|
||||
* should be transmitted
|
||||
* @return int
|
||||
*/
|
||||
int
|
||||
ble_phy_tx_set_start_time(uint32_t cputime)
|
||||
{
|
||||
int rc;
|
||||
|
||||
cputime -= os_cputime_usecs_to_ticks(XCVR_TX_START_DELAY_USECS);
|
||||
NRF_PPI->CHENCLR = PPI_CHEN_CH21_Msk;
|
||||
NRF_TIMER0->CC[0] = cputime;
|
||||
NRF_TIMER0->EVENTS_COMPARE[0] = 0;
|
||||
NRF_PPI->CHENSET = PPI_CHEN_CH20_Msk;
|
||||
if ((int32_t)(os_cputime_get32() - cputime) >= 0) {
|
||||
STATS_INC(ble_phy_stats, tx_late);
|
||||
ble_phy_disable();
|
||||
rc = BLE_PHY_ERR_TX_LATE;
|
||||
} else {
|
||||
rc = 0;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int
|
||||
ble_phy_rx_set_start_time(void)
|
||||
{
|
||||
/*
|
||||
* XXX: For now, we dont use this function if we are not using the
|
||||
* RTC. Keeping the code around just in case we want to use it later.
|
||||
*/
|
||||
NRF_PPI->CHENCLR = PPI_CHEN_CH20_Msk;
|
||||
NRF_TIMER0->CC[0] = cputime;
|
||||
NRF_TIMER0->EVENTS_COMPARE[0] = 0;
|
||||
NRF_PPI->CHENSET = PPI_CHEN_CH21_Msk;
|
||||
if ((int32_t)(os_cputime_get32() - cputime) >= 0) {
|
||||
STATS_INC(ble_phy_stats, rx_late);
|
||||
NRF_PPI->CHENCLR = PPI_CHEN_CH21_Msk;
|
||||
NRF_RADIO->TASKS_RXEN = 1;
|
||||
rc = BLE_PHY_ERR_RX_LATE;
|
||||
} else {
|
||||
rc = 0;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int
|
||||
ble_phy_tx(struct os_mbuf *txpdu, uint8_t end_trans)
|
||||
@@ -1421,7 +1302,6 @@ ble_phy_setchan(uint8_t chan, uint32_t access_addr, uint32_t crcinit)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
/**
|
||||
* Stop the timer used to count microseconds when using RTC for cputime
|
||||
*/
|
||||
@@ -1432,7 +1312,6 @@ ble_phy_stop_usec_timer(void)
|
||||
NRF_TIMER0->TASKS_SHUTDOWN = 1;
|
||||
NRF_RTC0->EVTENCLR = RTC_EVTENSET_COMPARE0_Msk;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ble phy disable irq and ppi
|
||||
|
||||
@@ -24,16 +24,11 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/*
|
||||
* NOTE: we have to account for the RTC output compare issue, which is why
|
||||
* this number is much larger when using the 32.768 crystal for cputime. We
|
||||
* want it to be 5 ticks.
|
||||
* NOTE: we have to account for the RTC output compare issue. We want it to be
|
||||
* 5 ticks.
|
||||
*/
|
||||
#define XCVR_PROC_DELAY_USECS (153)
|
||||
#else
|
||||
#define XCVR_PROC_DELAY_USECS (50)
|
||||
#endif
|
||||
#define XCVR_RX_START_DELAY_USECS (140)
|
||||
#define XCVR_TX_START_DELAY_USECS (140)
|
||||
#define XCVR_TX_SCHED_DELAY_USECS \
|
||||
|
||||
@@ -84,9 +84,7 @@ struct ble_phy_obj
|
||||
struct ble_mbuf_hdr rxhdr;
|
||||
void *txend_arg;
|
||||
ble_phy_tx_end_func txend_cb;
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
uint32_t phy_start_cputime;
|
||||
#endif
|
||||
};
|
||||
struct ble_phy_obj g_ble_phy_data;
|
||||
|
||||
@@ -352,7 +350,6 @@ nrf_wait_disabled(void)
|
||||
}
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -489,7 +486,6 @@ ble_phy_wfr_enable(int txrx, uint32_t wfr_usecs)
|
||||
/* Enable the disabled interrupt so we time out on events compare */
|
||||
NRF_RADIO->INTENSET = RADIO_INTENSET_DISABLED_Msk;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Setup transceiver for receive.
|
||||
@@ -574,16 +570,6 @@ ble_phy_tx_end_isr(void)
|
||||
uint8_t transition;
|
||||
uint8_t txlen;
|
||||
uint32_t wfr_time;
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) != 32768)
|
||||
uint32_t txstart;
|
||||
|
||||
/*
|
||||
* Read captured tx start time. This is not the actual transmit start
|
||||
* time but it is the time at which the address event occurred
|
||||
* (after transmission of access address)
|
||||
*/
|
||||
txstart = NRF_TIMER0->CC[1];
|
||||
#endif
|
||||
|
||||
/* If this transmission was encrypted we need to remember it */
|
||||
was_encrypted = g_ble_phy_data.phy_encrypted;
|
||||
@@ -592,13 +578,8 @@ ble_phy_tx_end_isr(void)
|
||||
assert(g_ble_phy_data.phy_state == BLE_PHY_STATE_TX);
|
||||
|
||||
/* Log the event */
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
ble_ll_log(BLE_LL_LOG_ID_PHY_TXEND, g_ble_phy_data.phy_tx_pyld_len,
|
||||
was_encrypted, NRF_TIMER0->CC[2]);
|
||||
#else
|
||||
ble_ll_log(BLE_LL_LOG_ID_PHY_TXEND, g_ble_phy_data.phy_tx_pyld_len,
|
||||
was_encrypted, txstart);
|
||||
#endif
|
||||
|
||||
/* Clear events and clear interrupt on disabled event */
|
||||
NRF_RADIO->EVENTS_DISABLED = 0;
|
||||
@@ -647,21 +628,8 @@ ble_phy_tx_end_isr(void)
|
||||
if (txlen && was_encrypted) {
|
||||
txlen += BLE_LL_DATA_MIC_LEN;
|
||||
}
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
ble_phy_wfr_enable(BLE_PHY_WFR_ENABLE_TXRX, 0);
|
||||
#else
|
||||
/*
|
||||
* NOTE: technically we only need to add the jitter once but we
|
||||
* add twice the jitter just to be sure.
|
||||
*/
|
||||
wfr_time = BLE_LL_IFS + (2 * BLE_LL_JITTER_USECS) +
|
||||
ble_phy_mode_pdu_start_off(phy) - ble_phy_mode_pdu_start_off(phy);
|
||||
wfr_time += ble_ll_pdu_tx_time_get(txlen, phy);
|
||||
wfr_time = os_cputime_usecs_to_ticks(wfr_time);
|
||||
ble_ll_wfr_enable(txstart + wfr_time);
|
||||
#endif
|
||||
} else {
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
/*
|
||||
* XXX: not sure we need to stop the timer here all the time. Or that
|
||||
* it should be stopped here.
|
||||
@@ -670,10 +638,6 @@ ble_phy_tx_end_isr(void)
|
||||
NRF_TIMER0->TASKS_SHUTDOWN = 1;
|
||||
NRF_PPI->CHENCLR = PPI_CHEN_CH4_Msk | PPI_CHEN_CH5_Msk |
|
||||
PPI_CHEN_CH20_Msk | PPI_CHEN_CH31_Msk;
|
||||
#else
|
||||
/* Disable automatic TXEN */
|
||||
NRF_PPI->CHENCLR = PPI_CHEN_CH20_Msk;
|
||||
#endif
|
||||
assert(transition == BLE_PHY_TRANSITION_NONE);
|
||||
}
|
||||
}
|
||||
@@ -757,22 +721,16 @@ ble_phy_rx_start_isr(void)
|
||||
{
|
||||
int rc;
|
||||
uint32_t state;
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
uint32_t usecs;
|
||||
uint32_t ticks;
|
||||
#endif
|
||||
struct ble_mbuf_hdr *ble_hdr;
|
||||
|
||||
/* Clear events and clear interrupt */
|
||||
NRF_RADIO->EVENTS_ADDRESS = 0;
|
||||
|
||||
/* Clear wfr timer channels and DISABLED interrupt */
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
NRF_RADIO->INTENCLR = RADIO_INTENCLR_DISABLED_Msk | RADIO_INTENCLR_ADDRESS_Msk;
|
||||
NRF_PPI->CHENCLR = PPI_CHEN_CH4_Msk | PPI_CHEN_CH5_Msk;
|
||||
#else
|
||||
NRF_RADIO->INTENCLR = RADIO_INTENCLR_ADDRESS_Msk;
|
||||
#endif
|
||||
|
||||
/* Initialize the ble mbuf header */
|
||||
ble_hdr = &g_ble_phy_data.rxhdr;
|
||||
@@ -784,7 +742,6 @@ ble_phy_rx_start_isr(void)
|
||||
ble_hdr->rxinfo.aux_data = NULL;
|
||||
#endif
|
||||
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
/*
|
||||
* Calculate receive start time.
|
||||
*
|
||||
@@ -798,10 +755,6 @@ ble_phy_rx_start_isr(void)
|
||||
++ticks;
|
||||
}
|
||||
ble_hdr->beg_cputime = g_ble_phy_data.phy_start_cputime + ticks;
|
||||
#else
|
||||
ble_hdr->beg_cputime = NRF_TIMER0->CC[1] -
|
||||
os_cputime_usecs_to_ticks(ble_phy_mode_pdu_start_off(g_ble_phy_data.phy_cur_phy_mode));
|
||||
#endif
|
||||
|
||||
/* XXX: I wonder if we always have the 1st byte. If we need to wait for
|
||||
* rx chain delay, it could be 18 usecs from address interrupt. The
|
||||
@@ -867,15 +820,12 @@ ble_phy_isr(void)
|
||||
|
||||
/* We get this if we have started to receive a frame */
|
||||
if ((irq_en & RADIO_INTENCLR_ADDRESS_Msk) && NRF_RADIO->EVENTS_ADDRESS) {
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
irq_en &= ~RADIO_INTENCLR_DISABLED_Msk;
|
||||
#endif
|
||||
ble_phy_rx_start_isr();
|
||||
}
|
||||
|
||||
/* Check for disabled event. This only happens for transmits now */
|
||||
if ((irq_en & RADIO_INTENCLR_DISABLED_Msk) && NRF_RADIO->EVENTS_DISABLED) {
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
if (g_ble_phy_data.phy_state == BLE_PHY_STATE_RX) {
|
||||
NRF_RADIO->EVENTS_DISABLED = 0;
|
||||
ble_ll_wfr_timer_exp(NULL);
|
||||
@@ -884,9 +834,6 @@ ble_phy_isr(void)
|
||||
} else {
|
||||
ble_phy_tx_end_isr();
|
||||
}
|
||||
#else
|
||||
ble_phy_tx_end_isr();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Receive packet end (we dont enable this for transmit) */
|
||||
@@ -977,13 +924,8 @@ ble_phy_init(void)
|
||||
/* Configure IFS */
|
||||
NRF_RADIO->TIFS = BLE_LL_IFS;
|
||||
|
||||
#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
|
||||
/* Captures tx/rx start in timer0 cc 1 and tx/rx end in timer0 cc 2 */
|
||||
NRF_PPI->CHENSET = PPI_CHEN_CH26_Msk | PPI_CHEN_CH27_Msk;
|
||||
#else
|
||||
/* Captures tx/rx start in timer0 capture 1 */
|
||||
NRF_PPI->CHENSET = PPI_CHEN_CH26_Msk;
|
||||
#endif
|
||||
|
||||
#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
|
||||
NRF_CCM->INTENCLR = 0xffffffff;
|
||||
@@ -1003,7 +945,6 @@ ble_phy_init(void)
|
||||
#endif
|
||||
|
||||
/* TIMER0 setup for PHY when using RTC */
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
NRF_TIMER0->TASKS_STOP = 1;
|
||||
NRF_TIMER0->TASKS_SHUTDOWN = 1;
|
||||
NRF_TIMER0->BITMODE = 3; /* 32-bit timer */
|
||||
@@ -1021,7 +962,6 @@ ble_phy_init(void)
|
||||
NRF_PPI->CH[4].TEP = (uint32_t)&(NRF_TIMER0->TASKS_CAPTURE[3]);
|
||||
NRF_PPI->CH[5].EEP = (uint32_t)&(NRF_TIMER0->EVENTS_COMPARE[3]);
|
||||
NRF_PPI->CH[5].TEP = (uint32_t)&(NRF_RADIO->TASKS_DISABLE);
|
||||
#endif
|
||||
|
||||
/* Set isr in vector table and enable interrupt */
|
||||
NVIC_SetPriority(RADIO_IRQn, 0);
|
||||
@@ -1131,7 +1071,6 @@ ble_phy_set_txend_cb(ble_phy_tx_end_func txend_cb, void *arg)
|
||||
g_ble_phy_data.txend_arg = arg;
|
||||
}
|
||||
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
/**
|
||||
* Called to set the start time of a transmission.
|
||||
*
|
||||
@@ -1214,65 +1153,6 @@ ble_phy_rx_set_start_time(uint32_t cputime, uint8_t rem_usecs)
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#else
|
||||
/**
|
||||
* Called to set the start time of a transmission.
|
||||
*
|
||||
* This function is called to set the start time when we are not going from
|
||||
* rx to tx automatically.
|
||||
*
|
||||
* NOTE: care must be taken when calling this function. The channel should
|
||||
* already be set.
|
||||
*
|
||||
* @param cputime This is the tick at which the 1st bit of the preamble
|
||||
* should be transmitted
|
||||
* @return int
|
||||
*/
|
||||
int
|
||||
ble_phy_tx_set_start_time(uint32_t cputime)
|
||||
{
|
||||
int rc;
|
||||
|
||||
cputime -= os_cputime_usecs_to_ticks(XCVR_TX_START_DELAY_USECS);
|
||||
NRF_PPI->CHENCLR = PPI_CHEN_CH21_Msk;
|
||||
NRF_TIMER0->CC[0] = cputime;
|
||||
NRF_TIMER0->EVENTS_COMPARE[0] = 0;
|
||||
NRF_PPI->CHENSET = PPI_CHEN_CH20_Msk;
|
||||
if ((int32_t)(os_cputime_get32() - cputime) >= 0) {
|
||||
STATS_INC(ble_phy_stats, tx_late);
|
||||
ble_phy_disable();
|
||||
rc = BLE_PHY_ERR_TX_LATE;
|
||||
} else {
|
||||
rc = 0;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int
|
||||
ble_phy_rx_set_start_time(void)
|
||||
{
|
||||
/*
|
||||
* XXX: For now, we dont use this function if we are not using the
|
||||
* RTC. Keeping the code around just in case we want to use it later.
|
||||
*/
|
||||
NRF_PPI->CHENCLR = PPI_CHEN_CH20_Msk;
|
||||
NRF_TIMER0->CC[0] = cputime;
|
||||
NRF_TIMER0->EVENTS_COMPARE[0] = 0;
|
||||
NRF_PPI->CHENSET = PPI_CHEN_CH21_Msk;
|
||||
if ((int32_t)(os_cputime_get32() - cputime) >= 0) {
|
||||
STATS_INC(ble_phy_stats, rx_late);
|
||||
NRF_PPI->CHENCLR = PPI_CHEN_CH21_Msk;
|
||||
NRF_RADIO->TASKS_RXEN = 1;
|
||||
rc = BLE_PHY_ERR_RX_LATE;
|
||||
} else {
|
||||
rc = 0;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int
|
||||
ble_phy_tx(struct os_mbuf *txpdu, uint8_t end_trans)
|
||||
@@ -1518,7 +1398,6 @@ ble_phy_setchan(uint8_t chan, uint32_t access_addr, uint32_t crcinit)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
/**
|
||||
* Stop the timer used to count microseconds when using RTC for cputime
|
||||
*/
|
||||
@@ -1529,7 +1408,6 @@ ble_phy_stop_usec_timer(void)
|
||||
NRF_TIMER0->TASKS_SHUTDOWN = 1;
|
||||
NRF_RTC0->EVTENCLR = RTC_EVTENSET_COMPARE0_Msk;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ble phy disable irq and ppi
|
||||
|
||||
@@ -103,9 +103,7 @@ struct ble_mbuf_hdr
|
||||
struct ble_mbuf_hdr_txinfo txinfo;
|
||||
};
|
||||
uint32_t beg_cputime;
|
||||
#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
|
||||
uint32_t rem_usecs;
|
||||
#endif
|
||||
};
|
||||
|
||||
#define BLE_MBUF_HDR_AUX_INVALID(hdr) \
|
||||
|
||||
Reference in New Issue
Block a user