MYNEWT-723: Some additional changes to get the basic 2Mbps PHY support.
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/230462f8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/230462f8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/230462f8 Branch: refs/heads/bluetooth5 Commit: 230462f8f6d76cd37ed58f0524f709ea1e9fe796 Parents: bb2c04e Author: William San Filippo <[email protected]> Authored: Wed Apr 26 16:45:03 2017 -0700 Committer: Åukasz Rymanowski <[email protected]> Committed: Thu Apr 27 23:39:50 2017 +0200 ---------------------------------------------------------------------- hw/drivers/nimble/nrf52/src/ble_phy.c | 3 ++- net/nimble/controller/include/controller/ble_ll.h | 2 +- .../controller/include/controller/ble_ll_conn.h | 13 ++++++++++--- net/nimble/controller/src/ble_ll_conn.c | 16 ++++++++-------- net/nimble/controller/src/ble_ll_ctrl.c | 14 ++++++++++++-- net/nimble/controller/src/ble_ll_hci.c | 8 ++++---- net/nimble/controller/src/ble_ll_hci_ev.c | 2 +- net/nimble/host/src/ble_hs_dbg.c | 5 +++++ net/nimble/host/src/ble_hs_startup.c | 3 ++- 9 files changed, 45 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/230462f8/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 0ab7cd6..00c0292 100644 --- a/hw/drivers/nimble/nrf52/src/ble_phy.c +++ b/hw/drivers/nimble/nrf52/src/ble_phy.c @@ -240,7 +240,8 @@ ble_phy_set_mode(int cur_phy, int txtorx_phy) 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; + NRF_RADIO->PCNF0 = g_ble_phy_data.phy_pcnf0 | + (RADIO_PCNF0_PLEN_16bit << RADIO_PCNF0_PLEN_Pos); } else { /* XXX: TODO added coded PHY */ assert(0); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/230462f8/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 373c3e5..a98d207 100644 --- a/net/nimble/controller/include/controller/ble_ll.h +++ b/net/nimble/controller/include/controller/ble_ll.h @@ -416,7 +416,7 @@ int ble_ll_rand_start(void); * XXX: temporary LL debug log. Will get removed once we transition to real * log */ -#undef BLE_LL_LOG +#define BLE_LL_LOG #include "console/console.h" #define BLE_LL_LOG_ID_PHY_SETCHAN (1) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/230462f8/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 8560316..99d9466 100644 --- a/net/nimble/controller/include/controller/ble_ll_conn.h +++ b/net/nimble/controller/include/controller/ble_ll_conn.h @@ -128,12 +128,19 @@ union ble_ll_conn_sm_flags { /** * Structure used for PHY data inside a connection. * + * NOTE: the new phy's are the phys we will change to when a phy update + * procedure is ongoing and the event counter hits the instant. + * * tx_phy_mode: chip specific phy mode for tx - * rx_phy_mode: chip specific phy mode for tx + * rx_phy_mode: chip specific phy mode for rx * cur_tx_phy: value denoting current tx_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 + * new_tx_phy: value denoting new tx_phy (not a bitmask!) + * new_rx_phy: value denoting new rx phy (not a bitmask!) + * req_pref_tx_phy: tx phy sent in a phy request (may be different than host) + * req_pref_rx_phy: rx phy sent in a phy request (may be different than host) + * host_pref_tx_phys: bitmask of preferred transmit PHYs sent by host + * host_pref_rx_phys: bitmask of preferred receive PHYs sent by host * phy_options: preferred phy options for coded phy */ struct ble_ll_conn_phy_data http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/230462f8/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 3236869..9e662ea 100644 --- a/net/nimble/controller/src/ble_ll_conn.c +++ b/net/nimble/controller/src/ble_ll_conn.c @@ -1025,7 +1025,7 @@ 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 + /* XXX: TODO: need to check this with phy update procedure. There are limitations if we have started update */ /* Determine packet length we will transmit */ @@ -1085,7 +1085,7 @@ 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 + /* XXX: TODO: need to check this with phy update procedure. There are limitations if we have started update */ /* @@ -1507,7 +1507,7 @@ 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 + /* XXX: TODO: need to check this with phy update procedure. There are limitations if we have started update */ if (txpdu) { txhdr = BLE_MBUF_HDR_PTR(txpdu); @@ -2062,6 +2062,7 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm) #if (BLE_LL_BT5_PHY_SUPPORTED == 1) if (CONN_F_PHY_UPDATE_SCHED(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; @@ -3287,8 +3288,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 */ + /* XXX: TODO need to check 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; @@ -3383,7 +3384,7 @@ 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 + /* XXX: TODO: 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 @@ -3675,8 +3676,7 @@ 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 */ - + /* NOTE: this all assumes that the default phy is 1Mbps */ 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 = http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/230462f8/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 1029bf2..10ec1c0 100644 --- a/net/nimble/controller/src/ble_ll_ctrl.c +++ b/net/nimble/controller/src/ble_ll_ctrl.c @@ -648,8 +648,17 @@ ble_ll_ctrl_phy_update_ind_make(struct ble_ll_conn_sm *connsm, uint8_t *dptr, static void ble_ll_ctrl_phy_req_rsp_make(struct ble_ll_conn_sm *connsm, uint8_t *ctrdata) { - ctrdata[0] = connsm->phy_data.host_pref_tx_phys; - ctrdata[1] = connsm->phy_data.host_pref_rx_phys; + /* If no preference we use current phy */ + if (connsm->phy_data.host_pref_tx_phys == 0) { + ctrdata[0] = CONN_CUR_TX_PHY_MASK(connsm); + } else { + ctrdata[0] = connsm->phy_data.host_pref_tx_phys; + } + if (connsm->phy_data.host_pref_rx_phys == 0) { + ctrdata[1] = CONN_CUR_RX_PHY_MASK(connsm); + } else { + ctrdata[1] = connsm->phy_data.host_pref_rx_phys; + } } static uint8_t @@ -727,6 +736,7 @@ ble_ll_ctrl_rx_phy_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr, if (connsm->conn_role == BLE_LL_CONN_ROLE_MASTER) { if (connsm->cur_ctrl_proc == BLE_LL_CTRL_PROC_PHY_UPDATE) { ble_ll_ctrl_phy_update_ind_make(connsm, dptr, rsp, 0); + os_callout_stop(&connsm->ctrl_proc_rsp_timer); rsp_opcode = BLE_LL_CTRL_PHY_UPDATE_IND; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/230462f8/net/nimble/controller/src/ble_ll_hci.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_hci.c b/net/nimble/controller/src/ble_ll_hci.c index a6e4c56..68cc17e 100644 --- a/net/nimble/controller/src/ble_ll_hci.c +++ b/net/nimble/controller/src/ble_ll_hci.c @@ -314,8 +314,8 @@ ble_ll_hci_chk_phy_masks(uint8_t *cmdbuf, uint8_t *txphy, uint8_t *rxphy) tx_phys = cmdbuf[1] & BLE_HCI_LE_PHY_PREF_MASK_ALL; rx_phys = cmdbuf[2] & BLE_HCI_LE_PHY_PREF_MASK_ALL; - if (((all_phys & BLE_HCI_LE_PHY_TX_PREF) && (tx_phys == 0)) || - ((all_phys & BLE_HCI_LE_PHY_RX_PREF) && (rx_phys == 0))) { + if ((!(all_phys & BLE_HCI_LE_PHY_NO_TX_PREF_MASK) && (tx_phys == 0)) || + (!(all_phys & BLE_HCI_LE_PHY_NO_RX_PREF_MASK) && (rx_phys == 0))) { rc = BLE_ERR_INV_HCI_CMD_PARMS; } else { /* If phy not supported, wipe its bit */ @@ -328,11 +328,11 @@ ble_ll_hci_chk_phy_masks(uint8_t *cmdbuf, uint8_t *txphy, uint8_t *rxphy) rx_phys &= ~BLE_HCI_LE_PHY_CODED_PREF_MASK; #endif /* Set the default PHY preferences */ - if ((all_phys & BLE_HCI_LE_PHY_TX_PREF) == 0) { + if (all_phys & BLE_HCI_LE_PHY_NO_TX_PREF_MASK) { tx_phys = 0; } *txphy = tx_phys; - if ((all_phys & BLE_HCI_LE_PHY_RX_PREF) == 0) { + if (all_phys & BLE_HCI_LE_PHY_NO_RX_PREF_MASK) { rx_phys = 0; } *rxphy = rx_phys; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/230462f8/net/nimble/controller/src/ble_ll_hci_ev.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_hci_ev.c b/net/nimble/controller/src/ble_ll_hci_ev.c index 2ee9908..bd7b8ad 100644 --- a/net/nimble/controller/src/ble_ll_hci_ev.c +++ b/net/nimble/controller/src/ble_ll_hci_ev.c @@ -311,7 +311,7 @@ ble_ll_hci_ev_phy_update(struct ble_ll_conn_sm *connsm, uint8_t status) evbuf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI); if (evbuf) { evbuf[0] = BLE_HCI_EVCODE_LE_META; - evbuf[1] = BLE_HCI_LE_PHY_UPD_COMP_LEN; + evbuf[1] = BLE_HCI_LE_PHY_UPD_LEN; evbuf[2] = BLE_HCI_LE_SUBEV_PHY_UPDATE_COMPLETE; evbuf[3] = status; put_le16(evbuf + 4, connsm->conn_handle); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/230462f8/net/nimble/host/src/ble_hs_dbg.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_hs_dbg.c b/net/nimble/host/src/ble_hs_dbg.c index 77c84f1..5599358 100644 --- a/net/nimble/host/src/ble_hs_dbg.c +++ b/net/nimble/host/src/ble_hs_dbg.c @@ -144,6 +144,11 @@ ble_hs_dbg_le_event_disp(uint8_t subev, uint8_t len, uint8_t *evdata) get_le32(evdata + 2), get_le16(evdata + 10)); break; + case BLE_HCI_LE_SUBEV_PHY_UPDATE_COMPLETE: + BLE_HS_LOG(DEBUG, "PHY update. handle=%u tx=%u rx=%u\n", + get_le16(evdata + 1), evdata[3], evdata[4]); + break; + default: BLE_HS_LOG(DEBUG, "\tUnknown LE event\n"); break; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/230462f8/net/nimble/host/src/ble_hs_startup.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_hs_startup.c b/net/nimble/host/src/ble_hs_startup.c index f7d5956..fc350de 100644 --- a/net/nimble/host/src/ble_hs_startup.c +++ b/net/nimble/host/src/ble_hs_startup.c @@ -117,8 +117,9 @@ ble_hs_startup_le_set_evmask_tx(void) * 0x0000000000000020 LE Remote Connection Parameter Request Event * 0x0000000000000040 LE Data Length Change Event * 0x0000000000000200 LE Enhanced Connection Complete Event + * 0x0000000000000800 LE PHY Update Complete Event */ - ble_hs_hci_cmd_build_le_set_event_mask(0x000000000000027f, + ble_hs_hci_cmd_build_le_set_event_mask(0x0000000000000A7f, buf, sizeof buf); rc = ble_hs_hci_cmd_tx_empty_ack(buf); if (rc != 0) {
