Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nimble/phy: Fix tx-tx transition timing #1822

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions nimble/drivers/nrf5x/src/ble_phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,22 @@ static const uint8_t g_ble_phy_t_rxenddelay[BLE_PHY_NUM_MODE] = {
#else
/* delay between EVENTS_READY and start of tx */
static const uint8_t g_ble_phy_t_txdelay[BLE_PHY_NUM_MODE] = {
[BLE_PHY_MODE_1M] = 4,
[BLE_PHY_MODE_2M] = 3,
[BLE_PHY_MODE_1M] = 6,
[BLE_PHY_MODE_2M] = 5,
[BLE_PHY_MODE_CODED_125KBPS] = 5,
[BLE_PHY_MODE_CODED_500KBPS] = 5
};
/* delay between EVENTS_ADDRESS and txd access address */
static const uint8_t g_ble_phy_t_txaddrdelay[BLE_PHY_NUM_MODE] = {
[BLE_PHY_MODE_1M] = 7,
[BLE_PHY_MODE_2M] = 5,
[BLE_PHY_MODE_CODED_125KBPS] = 17,
[BLE_PHY_MODE_CODED_500KBPS] = 17
};
/* delay between EVENTS_END and end of txd packet */
static const uint8_t g_ble_phy_t_txenddelay[BLE_PHY_NUM_MODE] = {
[BLE_PHY_MODE_1M] = 4,
[BLE_PHY_MODE_2M] = 3,
[BLE_PHY_MODE_1M] = 6,
[BLE_PHY_MODE_2M] = 4,
[BLE_PHY_MODE_CODED_125KBPS] = 9,
[BLE_PHY_MODE_CODED_500KBPS] = 3
};
Expand All @@ -243,8 +250,8 @@ static const uint8_t g_ble_phy_t_rxaddrdelay[BLE_PHY_NUM_MODE] = {
};
/* delay between end of rxd packet and EVENTS_END */
static const uint8_t g_ble_phy_t_rxenddelay[BLE_PHY_NUM_MODE] = {
[BLE_PHY_MODE_1M] = 6,
[BLE_PHY_MODE_2M] = 2,
[BLE_PHY_MODE_1M] = 4,
[BLE_PHY_MODE_2M] = 1,
[BLE_PHY_MODE_CODED_125KBPS] = 27,
[BLE_PHY_MODE_CODED_500KBPS] = 22
};
Expand Down Expand Up @@ -1104,25 +1111,24 @@ ble_phy_tx_end_isr(void)
*/
} else if (transition == BLE_PHY_TRANSITION_TX_TX) {
if (g_ble_phy_data.txtx_time_anchor) {
/* Schedule next TX relative to current TX end. TX end timestamp is
* captured in CC[2].
*/
tx_time = NRF_TIMER0->CC[2] + g_ble_phy_data.txtx_time_us;
} else {
/* Schedule next TX relative to current TX start. AA timestamp is
* captured in CC[1], we need to adjust for sync word to get TX
* start.
*/
tx_time = NRF_TIMER0->CC[1] - ble_ll_pdu_syncword_us(tx_phy_mode) +
g_ble_phy_data.txtx_time_us;
/* Adjust for delay between EVENT_ADDRESS and actual address TX time */
/* FIXME assume this is the same as EVENT_END to end, but we should
* measure this to be sure */
/* Calculate TX anchor relative to current TX end */

/* TX end timestamp is captured in CC[2] */
tx_time = NRF_TIMER0->CC[2];
/* Adjust for delay between EVENT_END and actual TX end time */
tx_time += g_ble_phy_t_txenddelay[tx_phy_mode];
} else {
/* Calculate TX anchor relative to current TX start */

/* AA timestamp is captured in CC[1] */
tx_time = NRF_TIMER0->CC[1];
/* Adjust for delay between EVENT_ADDRESS and actual AA time ota */
tx_time += g_ble_phy_t_txaddrdelay[tx_phy_mode];
/* Adjust by sync word length to get TX start time */
tx_time -= ble_ll_pdu_syncword_us(tx_phy_mode);
}

/* Adjust for delay between EVENT_END and actual TX end time */
tx_time += g_ble_phy_t_txenddelay[tx_phy_mode];
tx_time += g_ble_phy_data.txtx_time_us;

#if PHY_USE_FEM_PA
fem_time = tx_time - MYNEWT_VAL(BLE_FEM_PA_TURN_ON_US);
Expand Down
Loading