MYNEWT-723: Add PHY support to change modulations for 2M phy.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/57414417 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/57414417 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/57414417 Branch: refs/heads/bluetooth5 Commit: 5741441768360699cf778022dea522f5e9992d01 Parents: 3f997c2 Author: William San Filippo <[email protected]> Authored: Tue Apr 25 17:17:22 2017 -0700 Committer: Åukasz Rymanowski <[email protected]> Committed: Thu Apr 27 23:39:25 2017 +0200 ---------------------------------------------------------------------- apps/bletest/src/main.c | 2 +- hw/drivers/nimble/nrf51/src/ble_phy.c | 26 ++-- hw/drivers/nimble/nrf52/src/ble_phy.c | 133 ++++++++++++++++--- .../controller/include/controller/ble_ll.h | 35 +---- .../controller/include/controller/ble_ll_conn.h | 24 ++-- .../include/controller/ble_ll_sched.h | 3 - .../controller/include/controller/ble_phy.h | 28 ++++ net/nimble/controller/src/ble_ll_adv.c | 7 +- net/nimble/controller/src/ble_ll_conn.c | 92 +++++++++---- net/nimble/controller/src/ble_ll_conn_priv.h | 3 - net/nimble/controller/src/ble_ll_ctrl.c | 32 ++--- net/nimble/controller/src/ble_ll_scan.c | 6 + net/nimble/controller/src/ble_ll_sched.c | 12 +- 13 files changed, 278 insertions(+), 125 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/57414417/apps/bletest/src/main.c ---------------------------------------------------------------------- diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c index e2519eb..d1eb1d5 100755 --- a/apps/bletest/src/main.c +++ b/apps/bletest/src/main.c @@ -178,7 +178,7 @@ bletest_multi_adv_instances[BLETEST_CFG_ADV_TEST_INSTANCES] = { #define BLETEST_CFG_RAND_PKT_SIZE (1) #define BLETEST_CFG_SUGG_DEF_TXOCTETS (251) #define BLETEST_CFG_SUGG_DEF_TXTIME \ - BLE_TX_DUR_USECS_M(BLETEST_CFG_SUGG_DEF_TXOCTETS + 4) + ble_phy_pdu_dur(BLETEST_CFG_SUGG_DEF_TXOCTETS + 4, BLE_PHY_1M) /* Test configurations. One of these should be set to 1 */ #if !defined(BLETEST_CONCURRENT_CONN_TEST) && !defined(BLETEST_THROUGHPUT_TEST) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/57414417/hw/drivers/nimble/nrf51/src/ble_phy.c ---------------------------------------------------------------------- diff --git a/hw/drivers/nimble/nrf51/src/ble_phy.c b/hw/drivers/nimble/nrf51/src/ble_phy.c index c9e2b74..4affa2c 100644 --- a/hw/drivers/nimble/nrf51/src/ble_phy.c +++ b/hw/drivers/nimble/nrf51/src/ble_phy.c @@ -55,7 +55,6 @@ extern uint32_t g_nrf_irk_list[]; /* Maximum length of frames */ #define NRF_MAXLEN (255) #define NRF_BALEN (3) /* For base address of 3 bytes */ -#define NRF_RX_START_OFFSET (5) /* Maximum tx power */ #define NRF_TX_PWR_MAX_DBM (4) @@ -385,16 +384,14 @@ ble_phy_wfr_enable(int txrx, uint32_t wfr_usecs) * Timeout occurs an IFS time plus time it takes to receive address * from the transmit end. We add additional time to make sure the * address event comes before the compare. Note that transmit end - * is captured in CC[2] - * - * XXX: this assumes 1Mbps as 40 usecs is header rx time for 1Mbps + * is captured in CC[2]. I just made up the 16 usecs I add here. */ - end_time = NRF_TIMER0->CC[2] + BLE_LL_IFS + 40 + 16; + end_time = NRF_TIMER0->CC[2] + BLE_LL_IFS + + ble_phy_pdu_start_off(BLE_PHY_1M) + 16; } else { - /* CC[0] is set to when RXEN occurs. NOTE: the extra 16 usecs is - jitter */ + /* CC[0] is set to when RXEN occurs. */ end_time = NRF_TIMER0->CC[0] + XCVR_RX_START_DELAY_USECS + wfr_usecs + - 40 + 16; + ble_phy_pdu_start_off(BLE_PHY_1M) + BLE_LL_JITTER_USECS; } /* wfr_secs is the time from rxen until timeout */ @@ -568,8 +565,10 @@ ble_phy_tx_end_isr(void) #if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768) ble_phy_wfr_enable(BLE_PHY_WFR_ENABLE_TXRX, 0); #else - wfr_time = BLE_LL_WFR_USECS - BLE_TX_LEN_USECS_M(NRF_RX_START_OFFSET); - wfr_time += BLE_TX_DUR_USECS_M(txlen); + wfr_time = (BLE_LL_IFS + ble_phy_pdu_start_off(BLE_PHY_1M) + + (2 * BLE_LL_JITTER_USECS)) - + ble_phy_pdu_start_off(BLE_PHY_1M); + wfr_time += ble_phy_pdu_dur(txlen, BLE_PHY_1M); wfr_time = os_cputime_usecs_to_ticks(wfr_time); ble_ll_wfr_enable(txstart + wfr_time); #endif @@ -699,12 +698,11 @@ ble_phy_rx_start_isr(void) #if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768) /* - * Calculate receive start time. We assume that the header time is - * 40 usecs (only 1 mbps supported right now). + * Calculate receive start time. * * XXX: possibly use other routine with remainder! */ - usecs = NRF_TIMER0->CC[1] - 40; + usecs = NRF_TIMER0->CC[1] - ble_phy_pdu_start_off(BLE_PHY_1M); ticks = os_cputime_usecs_to_ticks(usecs); ble_hdr->rem_usecs = usecs - os_cputime_ticks_to_usecs(ticks); if (ble_hdr->rem_usecs == 31) { @@ -714,7 +712,7 @@ ble_phy_rx_start_isr(void) 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_TX_LEN_USECS_M(NRF_RX_START_OFFSET)); + os_cputime_usecs_to_ticks(ble_phy_pdu_start_off(BLE_PHY_1M)); #endif /* Wait to get 1st byte of frame */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/57414417/hw/drivers/nimble/nrf52/src/ble_phy.c ---------------------------------------------------------------------- diff --git a/hw/drivers/nimble/nrf52/src/ble_phy.c b/hw/drivers/nimble/nrf52/src/ble_phy.c index e6b470e..0ab7cd6 100644 --- a/hw/drivers/nimble/nrf52/src/ble_phy.c +++ b/hw/drivers/nimble/nrf52/src/ble_phy.c @@ -28,7 +28,7 @@ #include "nimble/nimble_opt.h" #include "controller/ble_phy.h" #include "controller/ble_ll.h" -#include "nrf52_bitfields.h" +#include "nrf.h" /* XXX: 4) Make sure RF is higher priority interrupt than schedule */ @@ -55,12 +55,14 @@ extern uint32_t g_nrf_irk_list[]; /* Maximum length of frames */ #define NRF_MAXLEN (255) #define NRF_BALEN (3) /* For base address of 3 bytes */ -#define NRF_RX_START_OFFSET (5) /* Maximum tx power */ #define NRF_TX_PWR_MAX_DBM (4) #define NRF_TX_PWR_MIN_DBM (-40) +/* The number of different modulations */ +#define BLE_PHY_NUM_MODULATIONS (4) + /* BLE PHY data structure */ struct ble_phy_obj { @@ -73,8 +75,12 @@ struct ble_phy_obj uint8_t phy_encrypted; uint8_t phy_privacy; uint8_t phy_tx_pyld_len; + uint8_t phy_txtorx_phy; + uint8_t phy_cur_phy; + uint8_t phy_pkt_start_off[BLE_PHY_NUM_MODULATIONS]; uint32_t phy_aar_scratch; uint32_t phy_access_address; + uint32_t phy_pcnf0; struct ble_mbuf_hdr rxhdr; void *txend_arg; ble_phy_tx_end_func txend_cb; @@ -182,6 +188,68 @@ struct nrf_ccm_data struct nrf_ccm_data g_nrf_ccm_data; #endif +#if (BLE_LL_BT5_PHY_SUPPORTED == 1) +/** + * Calculate the length of BLE PDU + * + * Returns the number of usecs it will take to transmit a PDU of payload + * length 'len' bytes. Each byte takes 8 usecs. This routine includes the LL + * overhead: preamble (1), access addr (4) and crc (3) and the PDU header (2) + * for a total of 10 bytes. + * + * @param pyld_len PDU payload length (does not include include header). + * @param phy PHY modulation being used. + * + * @return uint32_t The number of usecs it will take to transmit a PDU of + * length 'len' bytes. + */ +uint32_t +ble_phy_pdu_dur(uint8_t pyld_len, int phy) +{ + uint32_t usecs; + + if (phy == BLE_PHY_1M) { + /* 8 usecs per byte */ + usecs = (pyld_len + BLE_LL_PREAMBLE_LEN + BLE_LL_ACC_ADDR_LEN + + BLE_LL_CRC_LEN + BLE_LL_PDU_HDR_LEN) << 3; + } else if (phy == BLE_PHY_2M) { + /* 4 usecs per byte */ + usecs = (pyld_len + (2 * BLE_LL_PREAMBLE_LEN) + BLE_LL_ACC_ADDR_LEN + + BLE_LL_CRC_LEN + BLE_LL_PDU_HDR_LEN) << 2; + } else { + /* XXX: TODO implement */ + assert(0); + } + return usecs; +} + + +/* Packet start offset (in usecs). This is the preamble plus access address. */ +uint32_t +ble_phy_pdu_start_off(int phy) +{ + return g_ble_phy_data.phy_pkt_start_off[phy]; +} + +void +ble_phy_set_mode(int cur_phy, int txtorx_phy) +{ + + if (cur_phy == BLE_PHY_1M) { + NRF_RADIO->MODE = RADIO_MODE_MODE_Ble_1Mbit; + NRF_RADIO->PCNF0 = g_ble_phy_data.phy_pcnf0; /* Default is 8 bits */ + } else if (cur_phy == BLE_PHY_2M) { + NRF_RADIO->MODE = RADIO_MODE_MODE_Ble_2Mbit; + NRF_RADIO->PCNF0 = g_ble_phy_data.phy_pcnf0 | RADIO_PCNF0_PLEN_16bit; + } else { + /* XXX: TODO added coded PHY */ + assert(0); + } + g_ble_phy_data.phy_cur_phy = (uint8_t)cur_phy; + g_ble_phy_data.phy_txtorx_phy = (uint8_t)txtorx_phy; +} +#endif + /** * Copies the data from the phy receive buffer into a mbuf chain. * @@ -381,21 +449,25 @@ ble_phy_wfr_enable(int txrx, uint32_t wfr_usecs) { uint32_t end_time; +#if (BLE_LL_BT5_PHY_SUPPORTED == 1) + int phy; + + phy = g_ble_phy_data.phy_cur_phy; +#endif if (txrx == BLE_PHY_WFR_ENABLE_TXRX) { /* * Timeout occurs an IFS time plus time it takes to receive address * from the transmit end. We add additional time to make sure the * address event comes before the compare. Note that transmit end * is captured in CC[2] - * - * XXX: this assumes 1Mbps as 40 usecs is header rx time for 1Mbps */ - end_time = NRF_TIMER0->CC[2] + BLE_LL_IFS + 40 + 16; + end_time = NRF_TIMER0->CC[2] + BLE_LL_IFS + + ble_phy_pdu_start_off(phy) + BLE_LL_JITTER_USECS; } else { /* CC[0] is set to when RXEN occurs. NOTE: the extra 16 usecs is jitter */ end_time = NRF_TIMER0->CC[0] + XCVR_RX_START_DELAY_USECS + wfr_usecs + - 40 + 16; + ble_phy_pdu_start_off(phy) + BLE_LL_JITTER_USECS; } /* wfr_secs is the time from rxen until timeout */ @@ -486,15 +558,16 @@ ble_phy_rx_xcvr_setup(void) static void ble_phy_tx_end_isr(void) { +#if (BLE_LL_BT5_PHY_SUPPORTED == 1) + int phy; +#endif uint8_t was_encrypted; 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 @@ -545,6 +618,15 @@ ble_phy_tx_end_isr(void) transition = g_ble_phy_data.phy_transition; if (transition == BLE_PHY_TRANSITION_TX_RX) { + +#if (BLE_LL_BT5_PHY_SUPPORTED == 1) + /* See if a new phy has been specified for tx to rx transition */ + phy = g_ble_phy_data.phy_txtorx_phy; + if (phy != g_ble_phy_data.phy_cur_phy) { + ble_phy_set_mode(phy, phy); + } +#endif + /* Packet pointer needs to be reset. */ ble_phy_rx_xcvr_setup(); @@ -559,8 +641,13 @@ ble_phy_tx_end_isr(void) #if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768) ble_phy_wfr_enable(BLE_PHY_WFR_ENABLE_TXRX, 0); #else - wfr_time = BLE_LL_WFR_USECS - BLE_TX_LEN_USECS_M(NRF_RX_START_OFFSET); - wfr_time += BLE_TX_DUR_USECS_M(txlen); + /* + * 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_pdu_start_off(phy) - ble_phy_pdu_start_off(phy); + wfr_time += ble_phy_pdu_dur(txlen, phy); wfr_time = os_cputime_usecs_to_ticks(wfr_time); ble_ll_wfr_enable(txstart + wfr_time); #endif @@ -686,12 +773,11 @@ ble_phy_rx_start_isr(void) #if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768) /* - * Calculate receive start time. We assume that the header time is - * 40 usecs (only 1 mbps supported right now). + * Calculate receive start time. * * XXX: possibly use other routine with remainder! */ - usecs = NRF_TIMER0->CC[1] - 40; + usecs = NRF_TIMER0->CC[1] - ble_phy_pdu_start_off(g_ble_phy_data.phy_cur_phy); ticks = os_cputime_usecs_to_ticks(usecs); ble_hdr->rem_usecs = usecs - os_cputime_ticks_to_usecs(ticks); if (ble_hdr->rem_usecs == 31) { @@ -701,7 +787,7 @@ ble_phy_rx_start_isr(void) 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_TX_LEN_USECS_M(NRF_RX_START_OFFSET)); + os_cputime_usecs_to_ticks(ble_phy_pdu_start_off(g_ble_phy_data.phy_cur_phy)); #endif /* XXX: I wonder if we always have the 1st byte. If we need to wait for @@ -812,6 +898,15 @@ ble_phy_init(void) { int rc; + /* XXX: TODO add coded phy */ + /* Set packet start offsets for various phys */ + g_ble_phy_data.phy_pkt_start_off[BLE_PHY_1M] = 40; /* 40 usecs */ + g_ble_phy_data.phy_pkt_start_off[BLE_PHY_2M] = 24; /* 24 usecs */ + + /* Default phy to use is 1M */ + g_ble_phy_data.phy_cur_phy = BLE_PHY_1M; + g_ble_phy_data.phy_txtorx_phy = BLE_PHY_1M; + #if !defined(BLE_XCVR_RFCLK) uint32_t os_tmo; @@ -841,10 +936,11 @@ ble_phy_init(void) /* Set configuration registers */ NRF_RADIO->MODE = RADIO_MODE_MODE_Ble_1Mbit; - NRF_RADIO->PCNF0 = (NRF_LFLEN_BITS << RADIO_PCNF0_LFLEN_Pos) | - RADIO_PCNF0_S1INCL_Msk | - (NRF_S0_LEN << RADIO_PCNF0_S0LEN_Pos) | - (RADIO_PCNF0_PLEN_8bit << RADIO_PCNF0_PLEN_Pos); + g_ble_phy_data.phy_pcnf0 = (NRF_LFLEN_BITS << RADIO_PCNF0_LFLEN_Pos) | + RADIO_PCNF0_S1INCL_Msk | + (NRF_S0_LEN << RADIO_PCNF0_S0LEN_Pos) | + (RADIO_PCNF0_PLEN_8bit << RADIO_PCNF0_PLEN_Pos); + NRF_RADIO->PCNF0 = g_ble_phy_data.phy_pcnf0; /* XXX: should maxlen be 251 for encryption? */ NRF_RADIO->PCNF1 = NRF_MAXLEN | @@ -1061,6 +1157,7 @@ ble_phy_tx_set_start_time(uint32_t cputime, uint8_t rem_usecs) } return rc; } + /** * Called to set the start time of a reception * http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/57414417/net/nimble/controller/include/controller/ble_ll.h ---------------------------------------------------------------------- diff --git a/net/nimble/controller/include/controller/ble_ll.h b/net/nimble/controller/include/controller/ble_ll.h index 619d1a9..373c3e5 100644 --- a/net/nimble/controller/include/controller/ble_ll.h +++ b/net/nimble/controller/include/controller/ble_ll.h @@ -66,16 +66,8 @@ extern "C" { /* Controller revision. */ #define BLE_LL_SUB_VERS_NR (0x0000) -/* - * The amount of time that we will wait to hear the start of a receive - * packet after we have transmitted a packet. This time is at least - * an IFS time plus the time to receive the preamble and access address (which - * is 40 usecs). We add an additional 32 usecs just to be safe. - * - * XXX: move this definition and figure out how we determine the worst-case - * jitter (spec. should have this). - */ -#define BLE_LL_WFR_USECS (BLE_LL_IFS + 40 + 32) +/* Timing jitter as per spec is +/16 usecs */ +#define BLE_LL_JITTER_USECS (16) /* Packet queue header definition */ STAILQ_HEAD(ble_ll_pkt_q, os_mbuf_pkthdr); @@ -219,7 +211,7 @@ struct ble_dev_addr /* * LL packet format * - * -> Preamble (1 byte) + * -> Preamble (1/2 bytes) * -> Access Address (4 bytes) * -> PDU (2 to 257 octets) * -> CRC (3 bytes) @@ -227,31 +219,10 @@ struct ble_dev_addr #define BLE_LL_PREAMBLE_LEN (1) #define BLE_LL_ACC_ADDR_LEN (4) #define BLE_LL_CRC_LEN (3) -#define BLE_LL_OVERHEAD_LEN \ - (BLE_LL_CRC_LEN + BLE_LL_ACC_ADDR_LEN + BLE_LL_PREAMBLE_LEN) #define BLE_LL_PDU_HDR_LEN (2) #define BLE_LL_MIN_PDU_LEN (BLE_LL_PDU_HDR_LEN) #define BLE_LL_MAX_PDU_LEN (257) #define BLE_LL_CRCINIT_ADV (0x555555) -#define BLE_LL_PDU_OVERHEAD (BLE_LL_OVERHEAD_LEN + BLE_LL_PDU_HDR_LEN) - -/** - * ll pdu tx time get - * - * Returns the number of usecs it will take to transmit a PDU of payload - * length 'len' bytes. Each byte takes 8 usecs. This routine includes the LL - * overhead: preamble (1), access addr (4) and crc (3) and the PDU header (2) - * for a total of 10 bytes. - * - * @param len The length of the PDU payload (does not include include header). - * - * @return uint16_t The number of usecs it will take to transmit a PDU of - * length 'len' bytes. - */ -#define BLE_TX_DUR_USECS_M(len) (((len) + BLE_LL_PDU_OVERHEAD) << 3) - -/* Calculates the time it takes to transmit 'len' bytes */ -#define BLE_TX_LEN_USECS_M(len) ((len) << 3) /* Access address for advertising channels */ #define BLE_ACCESS_ADDR_ADV (0x8E89BED6) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/57414417/net/nimble/controller/include/controller/ble_ll_conn.h ---------------------------------------------------------------------- diff --git a/net/nimble/controller/include/controller/ble_ll_conn.h b/net/nimble/controller/include/controller/ble_ll_conn.h index d3d7639..8560316 100644 --- a/net/nimble/controller/include/controller/ble_ll_conn.h +++ b/net/nimble/controller/include/controller/ble_ll_conn.h @@ -128,23 +128,27 @@ union ble_ll_conn_sm_flags { /** * Structure used for PHY data inside a connection. * + * tx_phy_mode: chip specific phy mode for tx + * rx_phy_mode: chip specific phy mode for tx * cur_tx_phy: value denoting current tx_phy (not a bitmask!) - * cur_rx_phy: value denoting current rx phy (not a bitmask) + * cur_rx_phy: value denoting current rx phy (not a bitmask!) * pref_tx_phys: bitmask of preferred transmit PHYs * pref_rx_phys: bitmask of preferred receive PHYs * phy_options: preferred phy options for coded phy */ struct ble_ll_conn_phy_data { - uint8_t cur_tx_phy: 2; - uint8_t cur_rx_phy: 2; - uint8_t new_tx_phy: 2; - uint8_t new_rx_phy: 2; - uint16_t host_pref_tx_phys: 3; - uint16_t host_pref_rx_phys: 3; - uint16_t req_pref_tx_phys: 3; - uint16_t req_pref_rx_phys: 3; - uint16_t phy_options: 2; + uint32_t tx_phy_mode: 2; + uint32_t rx_phy_mode: 2; + uint32_t cur_tx_phy: 2; + uint32_t cur_rx_phy: 2; + uint32_t new_tx_phy: 2; + uint32_t new_rx_phy: 2; + uint32_t host_pref_tx_phys: 3; + uint32_t host_pref_rx_phys: 3; + uint32_t req_pref_tx_phys: 3; + uint32_t req_pref_rx_phys: 3; + uint32_t phy_options: 2; } __attribute__((packed)); #define CONN_CUR_TX_PHY_MASK(csm) (1 << ((csm)->phy_data.cur_tx_phy - 1)) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/57414417/net/nimble/controller/include/controller/ble_ll_sched.h ---------------------------------------------------------------------- diff --git a/net/nimble/controller/include/controller/ble_ll_sched.h b/net/nimble/controller/include/controller/ble_ll_sched.h index d2321b7..c407397 100644 --- a/net/nimble/controller/include/controller/ble_ll_sched.h +++ b/net/nimble/controller/include/controller/ble_ll_sched.h @@ -47,9 +47,6 @@ extern "C" { #define BLE_LL_SCHED_DIRECT_ADV_MAX_USECS (502) #define BLE_LL_SCHED_MAX_ADV_PDU_USECS (376) -/* BLE Jitter (+/- 16 useecs) */ -#define BLE_LL_JITTER_USECS (16) - /* * This is the offset from the start of the scheduled item until the actual * tx/rx should occur, in ticks. http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/57414417/net/nimble/controller/include/controller/ble_phy.h ---------------------------------------------------------------------- diff --git a/net/nimble/controller/include/controller/ble_phy.h b/net/nimble/controller/include/controller/ble_phy.h index e62b216..d4d0b40 100644 --- a/net/nimble/controller/include/controller/ble_phy.h +++ b/net/nimble/controller/include/controller/ble_phy.h @@ -179,6 +179,34 @@ void ble_phy_resolv_list_enable(void); /* Disable phy resolving list */ void ble_phy_resolv_list_disable(void); +/* + * These definitions are used for the 'phy' parameters in the API listed below. + * These are numbered in a specific order to save code. The HCI definitions for + * the PHY modes for 1Mbps and 2Mbps are the same here. For the coded phy + * they need to be translated from the HCI number to either 0 or 3. This + * was done in order to save code when translating between the HCI phy value + * and the phy API. + */ +#define BLE_PHY_CODED_125KBPS (0) +#define BLE_PHY_1M (1) +#define BLE_PHY_2M (2) +#define BLE_PHY_CODED_500KBPS (3) + +#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_2M_PHY) || MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_CODED_PHY)) +uint32_t ble_phy_pdu_dur(uint8_t len, int phy); +uint32_t ble_phy_pdu_start_off(int phy); +void ble_phy_set_mode(int cur_phy, int txtorx_phy); +#else +#define ble_phy_pdu_dur(len, phy) \ + (((len) + BLE_LL_PDU_HDR_LEN + BLE_LL_ACC_ADDR_LEN + BLE_LL_PREAMBLE_LEN \ + + BLE_LL_CRC_LEN) << 3) + +#define ble_phy_pdu_start_off(phy) (40) + +#endif + + + #ifdef __cplusplus } #endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/57414417/net/nimble/controller/src/ble_ll_adv.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_adv.c b/net/nimble/controller/src/ble_ll_adv.c index 2c57573..c55c435 100644 --- a/net/nimble/controller/src/ble_ll_adv.c +++ b/net/nimble/controller/src/ble_ll_adv.c @@ -484,6 +484,10 @@ ble_ll_adv_tx_start_cb(struct ble_ll_sched_item *sch) ble_ll_adv_pdu_make(advsm, adv_pdu); +#if (BLE_LL_BT5_PHY_SUPPORTED == 1) + ble_phy_set_mode(BLE_PHY_1M, BLE_PHY_1M); +#endif + /* Transmit advertisement */ rc = ble_phy_tx(adv_pdu, end_trans); os_mbuf_free_chain(adv_pdu); @@ -523,7 +527,7 @@ ble_ll_adv_set_sched(struct ble_ll_adv_sm *advsm) sch->sched_type = BLE_LL_SCHED_TYPE_ADV; /* Set end time to maximum time this schedule item may take */ - max_usecs = BLE_TX_DUR_USECS_M(advsm->adv_pdu_len); + max_usecs = ble_phy_pdu_dur(advsm->adv_pdu_len, BLE_PHY_1M); switch (advsm->adv_type) { case BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_LD: case BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD: @@ -1216,6 +1220,7 @@ ble_ll_adv_rx_req(uint8_t pdu_type, struct os_mbuf *rxpdu) if (pdu_type == BLE_ADV_PDU_TYPE_SCAN_REQ) { scan_rsp = ble_ll_adv_scan_rsp_pdu_make(advsm); if (scan_rsp) { + /* XXX TODO: assume we do not need to change phy mode */ ble_phy_set_txend_cb(ble_ll_adv_tx_done, advsm); rc = ble_phy_tx(scan_rsp, BLE_PHY_TRANSITION_NONE); if (!rc) { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/57414417/net/nimble/controller/src/ble_ll_conn.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_conn.c b/net/nimble/controller/src/ble_ll_conn.c index 0efbba2..3236869 100644 --- a/net/nimble/controller/src/ble_ll_conn.c +++ b/net/nimble/controller/src/ble_ll_conn.c @@ -117,17 +117,6 @@ extern void bletest_completed_pkt(uint16_t handle); * 1) The current connection event has not ended but a schedule item starts */ -/* - * The amount of time that we will wait to hear the start of a receive - * packet after we have transmitted a packet. This time is at least - * an IFS time plus the time to receive the preamble and access address. We - * add an additional 32 usecs just to be safe. - * - * XXX: move this definition and figure out how we determine the worst-case - * jitter (spec. should have this). - */ -#define BLE_LL_WFR_USECS (BLE_LL_IFS + 40 + 32) - /* This is a dummy structure we use for the empty PDU */ struct ble_ll_empty_pdu { @@ -1036,6 +1025,9 @@ ble_ll_conn_tx_data_pdu(struct ble_ll_conn_sm *connsm) STAILQ_REMOVE_HEAD(&connsm->conn_txq, omp_next); ble_hdr = BLE_MBUF_HDR_PTR(m); + /* WWW: need to check this with phy update procedure. There are + limitations if we have started update */ + /* Determine packet length we will transmit */ cur_txlen = connsm->eff_max_tx_octets; pktlen = pkthdr->omp_len; @@ -1093,6 +1085,9 @@ ble_ll_conn_tx_data_pdu(struct ble_ll_conn_sm *connsm) /* Get next event time */ next_event_time = ble_ll_conn_get_next_sched_time(connsm); + /* WWW: need to check this with phy update procedure. There are + limitations if we have started update */ + /* * Dont bother to set the MD bit if we cannot do the following: * -> wait IFS, send the current frame. @@ -1122,8 +1117,8 @@ ble_ll_conn_tx_data_pdu(struct ble_ll_conn_sm *connsm) * received a frame and we are replying to it. */ ticks = (BLE_LL_IFS * 3) + connsm->eff_max_rx_time + - BLE_TX_DUR_USECS_M(next_txlen) + - BLE_TX_DUR_USECS_M(cur_txlen); + ble_phy_pdu_dur(next_txlen, connsm->phy_data.tx_phy_mode) + + ble_phy_pdu_dur(cur_txlen, connsm->phy_data.tx_phy_mode); if (connsm->conn_role == BLE_LL_CONN_ROLE_MASTER) { ticks += (BLE_LL_IFS + connsm->eff_max_rx_time); @@ -1271,6 +1266,10 @@ conn_tx_pdu: } #endif +#if (BLE_LL_BT5_PHY_SUPPORTED == 1) + ble_phy_set_mode(connsm->phy_data.tx_phy_mode,connsm->phy_data.rx_phy_mode); +#endif + /* Set transmit end callback */ ble_phy_set_txend_cb(txend_func, connsm); rc = ble_phy_tx(m, end_transition); @@ -1387,6 +1386,11 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch) ble_phy_encrypt_disable(); } #endif + +#if (BLE_LL_BT5_PHY_SUPPORTED == 1) + ble_phy_set_mode(connsm->phy_data.rx_phy_mode,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; @@ -1433,8 +1437,13 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch) (2 * connsm->slave_cur_window_widening); ble_phy_wfr_enable(BLE_PHY_WFR_ENABLE_RX, usecs); #else - usecs = connsm->slave_cur_tx_win_usecs + BLE_LL_WFR_USECS + - connsm->slave_cur_window_widening; + /* + * 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_pdu_start_off(connsm->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 @@ -1498,16 +1507,18 @@ ble_ll_conn_can_send_next_pdu(struct ble_ll_conn_sm *connsm, uint32_t begtime, pkthdr = OS_MBUF_PKTHDR(txpdu); } + /* WWW: need to check this with phy update procedure. There are + limitations if we have started update */ if (txpdu) { txhdr = BLE_MBUF_HDR_PTR(txpdu); rem_bytes = pkthdr->omp_len - txhdr->txinfo.offset; if (rem_bytes > connsm->eff_max_tx_octets) { rem_bytes = connsm->eff_max_tx_octets; } - usecs = BLE_TX_DUR_USECS_M(rem_bytes); + usecs = ble_phy_pdu_dur(rem_bytes, connsm->phy_data.tx_phy_mode); } else { /* We will send empty pdu (just a LL header) */ - usecs = BLE_TX_DUR_USECS_M(0); + usecs = ble_phy_pdu_dur(0, connsm->phy_data.tx_phy_mode); } usecs += (BLE_LL_IFS * 2) + connsm->eff_max_rx_time; @@ -1690,6 +1701,8 @@ ble_ll_conn_sm_new(struct ble_ll_conn_sm *connsm) #if (BLE_LL_BT5_PHY_SUPPORTED == 1) connsm->phy_data.cur_tx_phy = BLE_HCI_LE_PHY_1M; connsm->phy_data.cur_rx_phy = BLE_HCI_LE_PHY_1M; + connsm->phy_data.tx_phy_mode = BLE_PHY_1M; + connsm->phy_data.rx_phy_mode = BLE_PHY_1M; connsm->phy_data.req_pref_tx_phys = 0; connsm->phy_data.req_pref_rx_phys = 0; connsm->phy_data.host_pref_tx_phys = g_ble_ll_data.ll_pref_tx_phys; @@ -1921,6 +1934,12 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm) } /* + * XXX: TODO Probably want to add checks to see if we need to start + * a control procedure here as an instant may have prevented us from + * starting one. + */ + + /* * XXX TODO: I think this is technically incorrect. We can allow slave * latency if we are doing one of these updates as long as we * know that the master has received the ACK to the PDU that set @@ -2045,7 +2064,13 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm) (connsm->event_cntr == connsm->phy_instant)) { /* Set cur phy to new phy */ connsm->phy_data.cur_tx_phy = connsm->phy_data.new_tx_phy; + connsm->phy_data.tx_phy_mode = connsm->phy_data.cur_tx_phy; connsm->phy_data.cur_rx_phy = connsm->phy_data.new_rx_phy; + connsm->phy_data.rx_phy_mode = connsm->phy_data.cur_rx_phy; + +#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_CODED_PHY) + /* XXX: TODO convert to coded phy mode if new phy is coded */ +#endif /* Clear flags and set flag to send event at next instant */ CONN_F_PHY_UPDATE_SCHED(connsm) = 0; @@ -2129,6 +2154,8 @@ ble_ll_conn_created(struct ble_ll_conn_sm *connsm, struct ble_mbuf_hdr *rxhdr) uint32_t endtime; uint32_t usecs; + /* XXX: TODO this assumes we received in 1M phy */ + /* Set state to created */ connsm->conn_state = BLE_LL_CONN_STATE_CREATED; @@ -2162,7 +2189,7 @@ ble_ll_conn_created(struct ble_ll_conn_sm *connsm, struct ble_mbuf_hdr *rxhdr) usecs = rxhdr->rem_usecs + 1250 + (connsm->tx_win_off * BLE_LL_CONN_TX_WIN_USECS) + - BLE_TX_DUR_USECS_M(BLE_CONNECT_REQ_LEN); + ble_phy_pdu_dur(BLE_CONNECT_REQ_LEN, BLE_PHY_1M); /* Anchor point is cputime. */ endtime = os_cputime_usecs_to_ticks(usecs); @@ -2182,7 +2209,8 @@ ble_ll_conn_created(struct ble_ll_conn_sm *connsm, struct ble_mbuf_hdr *rxhdr) #else connsm->last_anchor_point = rxhdr->beg_cputime; endtime = rxhdr->beg_cputime + - os_cputime_usecs_to_ticks(BLE_TX_DUR_USECS_M(BLE_CONNECT_REQ_LEN)); + os_cputime_usecs_to_ticks(ble_phy_pdu_dur(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); @@ -2535,6 +2563,7 @@ ble_ll_conn_request_send(uint8_t addr_type, uint8_t *adva, uint16_t txoffset, int rc; struct os_mbuf *m; + /* XXX: TODO: assume we are already on correct phy */ m = ble_ll_scan_get_pdu(); ble_ll_conn_req_pdu_update(m, adva, addr_type, txoffset, rpa_index); ble_phy_set_txend_cb(ble_ll_conn_req_txend, NULL); @@ -3111,13 +3140,20 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr) goto conn_exit; } - /* Calculate the end time of the received PDU */ + /* + * Calculate the end time of the received PDU. NOTE: this looks strange + * 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_TX_DUR_USECS_M(rx_pyld_len); + add_usecs = rxhdr->rem_usecs + + ble_phy_pdu_dur(rx_pyld_len, connsm->phy_data.rx_phy_mode); #else endtime = rxhdr->beg_cputime + - os_cputime_usecs_to_ticks(BLE_TX_DUR_USECS_M(rx_pyld_len)); + os_cputime_usecs_to_ticks(ble_phy_pdu_dur(rx_pyld_len, + connsm->phy_data.rx_phy_mode)); + add_usecs = 0; #endif @@ -3251,6 +3287,8 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr) os_mbuf_free_chain(txpdu); connsm->cur_tx_pdu = NULL; } else { + /* WWW: need to check this with phy update procedure. There are + limitations if we have started update */ rem_bytes = OS_MBUF_PKTLEN(txpdu) - txhdr->txinfo.offset; if (rem_bytes > connsm->eff_max_tx_octets) { txhdr->txinfo.pyld_len = connsm->eff_max_tx_octets; @@ -3345,6 +3383,8 @@ ble_ll_conn_enqueue_pkt(struct ble_ll_conn_sm *connsm, struct os_mbuf *om, ble_hdr->txinfo.pyld_len = length; ble_hdr->txinfo.hdr_byte = hdr_byte; + /* WWW: need to check this with phy update procedure. There are + limitations if we have started update */ /* * We need to set the initial payload length if the total length of the * PDU exceeds the maximum allowed for the connection for any single tx. @@ -3635,20 +3675,22 @@ ble_ll_conn_module_reset(void) conn_params = &g_ble_ll_conn_params; max_phy_pyld = ble_phy_max_data_pdu_pyld(); + /* WWW: change these on change of phy */ + maxbytes = min(MYNEWT_VAL(BLE_LL_SUPP_MAX_RX_BYTES), max_phy_pyld); conn_params->supp_max_rx_octets = maxbytes; conn_params->supp_max_rx_time = - BLE_TX_DUR_USECS_M(maxbytes + BLE_LL_DATA_MIC_LEN); + ble_phy_pdu_dur(maxbytes + BLE_LL_DATA_MIC_LEN, BLE_PHY_1M); maxbytes = min(MYNEWT_VAL(BLE_LL_SUPP_MAX_TX_BYTES), max_phy_pyld); conn_params->supp_max_tx_octets = maxbytes; conn_params->supp_max_tx_time = - BLE_TX_DUR_USECS_M(maxbytes + BLE_LL_DATA_MIC_LEN); + ble_phy_pdu_dur(maxbytes + BLE_LL_DATA_MIC_LEN, BLE_PHY_1M); maxbytes = min(MYNEWT_VAL(BLE_LL_CONN_INIT_MAX_TX_BYTES), max_phy_pyld); conn_params->conn_init_max_tx_octets = maxbytes; conn_params->conn_init_max_tx_time = - BLE_TX_DUR_USECS_M(maxbytes + BLE_LL_DATA_MIC_LEN); + ble_phy_pdu_dur(maxbytes + BLE_LL_DATA_MIC_LEN, BLE_PHY_1M); conn_params->sugg_tx_octets = BLE_LL_CONN_SUPP_BYTES_MIN; conn_params->sugg_tx_time = BLE_LL_CONN_SUPP_TIME_MIN; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/57414417/net/nimble/controller/src/ble_ll_conn_priv.h ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_conn_priv.h b/net/nimble/controller/src/ble_ll_conn_priv.h index 13e03cf..ce18ddc 100644 --- a/net/nimble/controller/src/ble_ll_conn_priv.h +++ b/net/nimble/controller/src/ble_ll_conn_priv.h @@ -47,9 +47,6 @@ extern "C" { #define BLE_LL_CONN_TX_WIN_MIN (1) /* in tx win units */ #define BLE_LL_CONN_SLAVE_LATENCY_MAX (499) -/* Connection request duration (in usecs) */ -#define BLE_LL_CONN_REQ_DURATION (352) /* 1 Mbps only */ - /* Connection handle range */ #define BLE_LL_CONN_MAX_CONN_HANDLE (0x0EFF) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/57414417/net/nimble/controller/src/ble_ll_ctrl.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_ctrl.c b/net/nimble/controller/src/ble_ll_ctrl.c index 99a2cd8..1029bf2 100644 --- a/net/nimble/controller/src/ble_ll_ctrl.c +++ b/net/nimble/controller/src/ble_ll_ctrl.c @@ -198,7 +198,7 @@ ble_ll_ctrl_chk_supp_time(uint16_t t) * @param ble_err */ void -ble_ll_ctrl_phy_update_cancel(strcut ble_ll_conn_sm *connsm, uint8_t ble_err) +ble_ll_ctrl_phy_update_cancel(struct ble_ll_conn_sm *connsm, uint8_t ble_err) { /* cancel any pending phy update procedures */ CLR_PENDING_CTRL_PROC(connsm, BLE_LL_CTRL_PROC_PHY_UPDATE); @@ -754,11 +754,11 @@ ble_ll_ctrl_rx_phy_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr, void ble_ll_ctrl_rx_phy_update_ind(struct ble_ll_conn_sm *connsm, uint8_t *dptr) { - uint8_t new_tx_phy_mask; - uint8_t new_rx_phy_mask; + int no_change; + uint8_t new_m_to_s_mask; + uint8_t new_s_to_m_mask; uint8_t new_tx_phy; uint8_t new_rx_phy; - int no_change; uint16_t instant; uint16_t delta; @@ -777,17 +777,22 @@ ble_ll_ctrl_rx_phy_update_ind(struct ble_ll_conn_sm *connsm, uint8_t *dptr) * doing either a PEER, CTRLR, or HOST phy update. */ /* get the new phy masks and see if we need to change */ - new_tx_phy_mask = dptr[0]; - new_rx_phy_mask = dptr[1]; + new_m_to_s_mask = dptr[0]; + new_s_to_m_mask = dptr[1]; instant = get_le16(dptr + 2); - no_change = 0; - if ((new_tx_phy_mask == 0) && (new_rx_phy_mask == 0)) { + if ((new_m_to_s_mask == 0) && (new_s_to_m_mask == 0)) { /* No change in phy */ no_change = 1; } else { - new_tx_phy = ble_ll_ctrl_phy_mask_to_numeric(new_tx_phy_mask); - new_rx_phy = ble_ll_ctrl_phy_mask_to_numeric(new_rx_phy_mask); + no_change = 0; + /* + * NOTE: from the slaves perspective, the m to s phy is the one + * that the slave will receive on; s to m is the one it will + * transmit on + */ + new_rx_phy = ble_ll_ctrl_phy_mask_to_numeric(new_m_to_s_mask); + new_tx_phy = ble_ll_ctrl_phy_mask_to_numeric(new_s_to_m_mask); if ((new_tx_phy == 0) && (new_rx_phy == 0)) { /* XXX: this is an error! What to do??? */ @@ -795,7 +800,7 @@ ble_ll_ctrl_rx_phy_update_ind(struct ble_ll_conn_sm *connsm, uint8_t *dptr) } if ((new_tx_phy == connsm->phy_data.cur_tx_phy) && - (new_rx_phy == connsm->phy_data.cur_tx_phy)) { + (new_rx_phy == connsm->phy_data.cur_rx_phy)) { no_change = 1; } } @@ -1961,11 +1966,8 @@ ble_ll_ctrl_chk_proc_start(struct ble_ll_conn_sm *connsm) { int i; - /* WWW: new rules! Cannot start certain control procedures if other + /* XXX: TODO new rules! Cannot start certain control procedures if other * ones are peer initiated. We need to wait. Deal with this. - * - * WWW: Do not forget code that when some of these things end we need - * to check to start other control procedures */ /* http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/57414417/net/nimble/controller/src/ble_ll_scan.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_scan.c b/net/nimble/controller/src/ble_ll_scan.c index 7f0c40b..569823e 100644 --- a/net/nimble/controller/src/ble_ll_scan.c +++ b/net/nimble/controller/src/ble_ll_scan.c @@ -595,6 +595,10 @@ ble_ll_scan_start(struct ble_ll_scan_sm *scansm, uint8_t chan) } #endif +#if (BLE_LL_BT5_PHY_SUPPORTED == 1) + ble_phy_set_mode(BLE_PHY_1M, BLE_PHY_1M); +#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. */ @@ -1141,6 +1145,8 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) if (scansm->backoff_count == 0) { /* Setup to transmit the scan request */ adv_addr = rxbuf + BLE_LL_PDU_HDR_LEN; + + /* XXX: TODO assume we are on correct phy */ ble_ll_scan_req_pdu_make(scansm, adv_addr, addr_type); rc = ble_phy_tx(scansm->scan_req_pdu, BLE_PHY_TRANSITION_TX_RX); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/57414417/net/nimble/controller/src/ble_ll_sched.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_sched.c b/net/nimble/controller/src/ble_ll_sched.c index 7637ac9..5c292ae 100644 --- a/net/nimble/controller/src/ble_ll_sched.c +++ b/net/nimble/controller/src/ble_ll_sched.c @@ -306,6 +306,11 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm, struct ble_ll_sched_item *entry; struct ble_ll_sched_item *sch; + /* + * XXX: TODO this code assumes the advertisement and connect request were + * sent at 1Mbps. + */ + /* Get schedule element from connection */ rc = -1; sch = &connsm->conn_sch; @@ -360,7 +365,7 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm, itvl_t = connsm->conn_itvl_ticks; #else adv_rxend = ble_hdr->beg_cputime + - os_cputime_usecs_to_ticks(BLE_TX_DUR_USECS_M(pyld_len)); + os_cputime_usecs_to_ticks(ble_phy_pdu_dur(pyld_len, BLE_PHY_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 @@ -370,8 +375,9 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm, */ 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_CONN_REQ_DURATION + - BLE_LL_CONN_INITIAL_OFFSET); + os_cputime_usecs_to_ticks(BLE_LL_IFS + + ble_phy_pdu_dur(BLE_CONNECT_REQ_LEN, BLE_PHY_1M) + + BLE_LL_CONN_INITIAL_OFFSET); earliest_end = earliest_start + dur; itvl_t = os_cputime_usecs_to_ticks(connsm->conn_itvl * BLE_LL_CONN_ITVL_USECS); #endif
