You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2017/05/18 08:51:19 UTC

[06/12] incubator-mynewt-core git commit: nimble/controller: Cleanup PHY symbols names

nimble/controller: Cleanup PHY symbols names

To avoid confusion which phy-value goes where, let's use following
terms in LL code:
- phy = numeric PHY value (1M, 2M, Coded => 1, 2, 3)
- phy_mask = PHY bitmask (1M, 2M, Coded -> 0x01, 0x02, 0x04)
- phy_mode = actual PHY used in radio (1M, 2M, Coded S=2, Coded S=8)

Values for phy and phy_mask are the same as used in HCI and LL so can
be exchanged between layers.

Value for phy_mode is calculated from phy and phy_options using helper.

This patch adjusts various symbols names to the above, so in case e.g.
phy-variable is assigned to phy_mode-variable directly somewhere, this
potentially could indicate there is some issue in code.


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/8ae34ada
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/8ae34ada
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/8ae34ada

Branch: refs/heads/bluetooth5
Commit: 8ae34ada1413714da929b709d2cbe5b25b8d38fe
Parents: dfeee7b
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Tue May 9 14:51:22 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Wed May 17 11:56:17 2017 +0200

----------------------------------------------------------------------
 hw/drivers/nimble/nrf51/src/ble_phy.c           | 14 ++--
 hw/drivers/nimble/nrf52/src/ble_phy.c           | 57 +++++++------
 .../controller/include/controller/ble_ll_conn.h |  8 +-
 .../controller/include/controller/ble_phy.h     | 32 ++++---
 net/nimble/controller/src/ble_ll_adv.c          |  4 +-
 net/nimble/controller/src/ble_ll_conn.c         | 88 ++++++++++++--------
 net/nimble/controller/src/ble_ll_conn_hci.c     |  4 +-
 net/nimble/controller/src/ble_ll_ctrl.c         | 62 +++++++-------
 net/nimble/controller/src/ble_ll_scan.c         |  2 +-
 net/nimble/controller/src/ble_ll_sched.c        |  4 +-
 10 files changed, 152 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8ae34ada/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 4affa2c..a6bd025 100644
--- a/hw/drivers/nimble/nrf51/src/ble_phy.c
+++ b/hw/drivers/nimble/nrf51/src/ble_phy.c
@@ -387,11 +387,11 @@ ble_phy_wfr_enable(int txrx, uint32_t wfr_usecs)
          * is captured in CC[2]. I just made up the 16 usecs I add here.
          */
         end_time = NRF_TIMER0->CC[2] + BLE_LL_IFS +
-            ble_phy_pdu_start_off(BLE_PHY_1M) + 16;
+            ble_phy_mode_pdu_start_off(BLE_PHY_MODE_1M) + 16;
     } else {
         /* CC[0] is set to when RXEN occurs. */
         end_time = NRF_TIMER0->CC[0] + XCVR_RX_START_DELAY_USECS + wfr_usecs +
-            ble_phy_pdu_start_off(BLE_PHY_1M) + BLE_LL_JITTER_USECS;
+            ble_phy_mode_pdu_start_off(BLE_PHY_MODE_1M) + BLE_LL_JITTER_USECS;
     }
 
     /* wfr_secs is the time from rxen until timeout */
@@ -565,10 +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_IFS + ble_phy_pdu_start_off(BLE_PHY_1M) +
+        wfr_time = (BLE_LL_IFS + ble_phy_mode_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);
+                    ble_phy_mode_pdu_start_off(BLE_PHY_1M);
+        wfr_time += ble_phy_mode_pdu_dur(txlen, BLE_PHY_1M);
         wfr_time = os_cputime_usecs_to_ticks(wfr_time);
         ble_ll_wfr_enable(txstart + wfr_time);
 #endif
@@ -702,7 +702,7 @@ ble_phy_rx_start_isr(void)
      *
      * XXX: possibly use other routine with remainder!
      */
-    usecs = NRF_TIMER0->CC[1] - ble_phy_pdu_start_off(BLE_PHY_1M);
+    usecs = NRF_TIMER0->CC[1] - ble_phy_mode_pdu_start_off(BLE_PHY_MODE_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) {
@@ -712,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_phy_pdu_start_off(BLE_PHY_1M));
+        os_cputime_usecs_to_ticks(ble_phy_mode_pdu_start_off(BLE_PHY_MODE_1M));
 #endif
 
     /* Wait to get 1st byte of frame */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8ae34ada/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 00c0292..a1da61e 100644
--- a/hw/drivers/nimble/nrf52/src/ble_phy.c
+++ b/hw/drivers/nimble/nrf52/src/ble_phy.c
@@ -75,9 +75,9 @@ 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];
+    uint8_t phy_txtorx_phy_mode;
+    uint8_t phy_cur_phy_mode;
+    uint8_t phy_mode_pkt_start_off[BLE_PHY_NUM_MODULATIONS];
     uint32_t phy_aar_scratch;
     uint32_t phy_access_address;
     uint32_t phy_pcnf0;
@@ -198,21 +198,21 @@ struct nrf_ccm_data g_nrf_ccm_data;
  * for a total of 10 bytes.
  *
  * @param pyld_len PDU payload length (does not include include header).
- * @param phy PHY modulation being used.
+ * @param phy_mode 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)
+ble_phy_mode_pdu_dur(uint8_t pyld_len, int phy_mode)
 {
     uint32_t usecs;
 
-    if (phy == BLE_PHY_1M) {
+    if (phy_mode == BLE_PHY_MODE_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) {
+    } else if (phy_mode == BLE_PHY_MODE_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;
@@ -226,19 +226,18 @@ ble_phy_pdu_dur(uint8_t pyld_len, int phy)
 
 /* Packet start offset (in usecs). This is the preamble plus access address. */
 uint32_t
-ble_phy_pdu_start_off(int phy)
+ble_phy_mode_pdu_start_off(int phy_mode)
 {
-    return g_ble_phy_data.phy_pkt_start_off[phy];
+    return g_ble_phy_data.phy_mode_pkt_start_off[phy_mode];
 }
 
 void
-ble_phy_set_mode(int cur_phy, int txtorx_phy)
+ble_phy_mode_set(int cur_phy_mode, int txtorx_phy_mode)
 {
-
-    if (cur_phy == BLE_PHY_1M) {
+    if (cur_phy_mode == BLE_PHY_MODE_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) {
+    } else if (cur_phy_mode == BLE_PHY_MODE_2M) {
         NRF_RADIO->MODE = RADIO_MODE_MODE_Ble_2Mbit;
         NRF_RADIO->PCNF0 = g_ble_phy_data.phy_pcnf0 |
             (RADIO_PCNF0_PLEN_16bit << RADIO_PCNF0_PLEN_Pos);
@@ -246,8 +245,8 @@ ble_phy_set_mode(int cur_phy, int txtorx_phy)
         /* 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;
+    g_ble_phy_data.phy_cur_phy_mode = (uint8_t)cur_phy_mode;
+    g_ble_phy_data.phy_txtorx_phy_mode = (uint8_t)txtorx_phy_mode;
 }
 #endif
 
@@ -453,7 +452,7 @@ ble_phy_wfr_enable(int txrx, uint32_t wfr_usecs)
 #if (BLE_LL_BT5_PHY_SUPPORTED == 1)
     int phy;
 
-    phy = g_ble_phy_data.phy_cur_phy;
+    phy = g_ble_phy_data.phy_cur_phy_mode;
 #endif
     if (txrx == BLE_PHY_WFR_ENABLE_TXRX) {
         /*
@@ -463,12 +462,12 @@ ble_phy_wfr_enable(int txrx, uint32_t wfr_usecs)
          * is captured in CC[2]
          */
         end_time = NRF_TIMER0->CC[2] + BLE_LL_IFS +
-            ble_phy_pdu_start_off(phy) + BLE_LL_JITTER_USECS;
+            ble_phy_mode_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 +
-            ble_phy_pdu_start_off(phy) + BLE_LL_JITTER_USECS;
+            ble_phy_mode_pdu_start_off(phy) + BLE_LL_JITTER_USECS;
     }
 
     /* wfr_secs is the time from rxen until timeout */
@@ -622,9 +621,9 @@ ble_phy_tx_end_isr(void)
 
 #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);
+        phy = g_ble_phy_data.phy_txtorx_phy_mode;
+        if (phy != g_ble_phy_data.phy_cur_phy_mode) {
+            ble_phy_mode_set(phy, phy);
         }
 #endif
 
@@ -647,8 +646,8 @@ ble_phy_tx_end_isr(void)
          * 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);
+            ble_phy_mode_pdu_start_off(phy) - ble_phy_mode_pdu_start_off(phy);
+        wfr_time += ble_phy_mode_pdu_dur(txlen, phy);
         wfr_time = os_cputime_usecs_to_ticks(wfr_time);
         ble_ll_wfr_enable(txstart + wfr_time);
 #endif
@@ -778,7 +777,7 @@ ble_phy_rx_start_isr(void)
      *
      * XXX: possibly use other routine with remainder!
      */
-    usecs = NRF_TIMER0->CC[1] - ble_phy_pdu_start_off(g_ble_phy_data.phy_cur_phy);
+    usecs = NRF_TIMER0->CC[1] - ble_phy_mode_pdu_start_off(g_ble_phy_data.phy_cur_phy_mode);
     ticks = os_cputime_usecs_to_ticks(usecs);
     ble_hdr->rem_usecs = usecs - os_cputime_ticks_to_usecs(ticks);
     if (ble_hdr->rem_usecs == 31) {
@@ -788,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_phy_pdu_start_off(g_ble_phy_data.phy_cur_phy));
+        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
@@ -901,12 +900,12 @@ ble_phy_init(void)
 
     /* 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 */
+    g_ble_phy_data.phy_mode_pkt_start_off[BLE_PHY_MODE_1M] = 40;  /* 40 usecs */
+    g_ble_phy_data.phy_mode_pkt_start_off[BLE_PHY_MODE_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;
+    g_ble_phy_data.phy_cur_phy_mode = BLE_PHY_MODE_1M;
+    g_ble_phy_data.phy_txtorx_phy_mode = BLE_PHY_MODE_1M;
 
 #if !defined(BLE_XCVR_RFCLK)
     uint32_t os_tmo;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8ae34ada/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 99d9466..a8c050e 100644
--- a/net/nimble/controller/include/controller/ble_ll_conn.h
+++ b/net/nimble/controller/include/controller/ble_ll_conn.h
@@ -151,10 +151,10 @@ struct ble_ll_conn_phy_data
     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 host_pref_tx_phys_mask: 3;
+    uint32_t host_pref_rx_phys_mask: 3;
+    uint32_t req_pref_tx_phys_mask: 3;
+    uint32_t req_pref_rx_phys_mask: 3;
     uint32_t phy_options: 2;
 }  __attribute__((packed));
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8ae34ada/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 d4d0b40..d617266 100644
--- a/net/nimble/controller/include/controller/ble_phy.h
+++ b/net/nimble/controller/include/controller/ble_phy.h
@@ -20,6 +20,8 @@
 #ifndef H_BLE_PHY_
 #define H_BLE_PHY_
 
+#include "nimble/hci_common.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -187,26 +189,34 @@ void ble_phy_resolv_list_disable(void);
  * 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)
+#define BLE_PHY_MODE_1M             (1)
+#define BLE_PHY_MODE_2M             (2)
+#define BLE_PHY_MODE_CODED_125KBPS  (0)
+#define BLE_PHY_MODE_CODED_500KBPS  (3)
+
+/* PHY numbers (compatible with HCI) */
+#define BLE_PHY_1M                  (BLE_HCI_LE_PHY_1M)
+#define BLE_PHY_2M                  (BLE_HCI_LE_PHY_2M)
+#define BLE_PHY_CODED               (BLE_HCI_LE_PHY_CODED)
+
+/* PHY bitmasks (compatible with HCI) */
+#define BLE_PHY_MASK_1M             (BLE_HCI_LE_PHY_1M_PREF_MASK)
+#define BLE_PHY_MASK_2M             (BLE_HCI_LE_PHY_2M_PREF_MASK)
+#define BLE_PHY_MASK_CODED          (BLE_HCI_LE_PHY_CODED_PREF_MASK)
 
 #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);
+uint32_t ble_phy_mode_pdu_dur(uint8_t len, int phy);
+uint32_t ble_phy_mode_pdu_start_off(int phy);
+void ble_phy_mode_set(int cur_phy, int txtorx_phy);
 #else
-#define ble_phy_pdu_dur(len, phy)   \
+#define ble_phy_mode_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)
+#define ble_phy_mode_pdu_start_off(phy)     (40)
 
 #endif
 
-
-
 #ifdef __cplusplus
 }
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8ae34ada/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 c55c435..60ced36 100644
--- a/net/nimble/controller/src/ble_ll_adv.c
+++ b/net/nimble/controller/src/ble_ll_adv.c
@@ -485,7 +485,7 @@ 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);
+    ble_phy_mode_set(BLE_PHY_MODE_1M, BLE_PHY_MODE_1M);
 #endif
 
     /* Transmit advertisement */
@@ -527,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_phy_pdu_dur(advsm->adv_pdu_len, BLE_PHY_1M);
+    max_usecs = ble_phy_mode_pdu_dur(advsm->adv_pdu_len, BLE_PHY_MODE_1M);
     switch (advsm->adv_type) {
     case BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_LD:
     case BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8ae34ada/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 9bbf7c2..2aefdcd 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -216,6 +216,25 @@ STATS_NAME_START(ble_ll_conn_stats)
     STATS_NAME(ble_ll_conn_stats, mic_failures)
 STATS_NAME_END(ble_ll_conn_stats)
 
+static inline int ble_ll_conn_phy_to_phy_mode(int phy, int phy_options)
+{
+    int phy_mode;
+
+    /*
+     * Mode values are set in a way that 1M, 2M and Coded(S=2) are equivalent
+     * to 1M, 2M and Coded in HCI. The only conversion is needed for Coded(S=8)
+     * which uses non-HCI value.
+     */
+
+    phy_mode = phy;
+
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_CODED_PHY)
+        /* XXX: TODO convert to coded phy mode if new phy is coded */
+#endif
+
+    return phy_mode;
+}
+
 static void ble_ll_conn_event_end(struct os_event *ev);
 
 #if (BLE_LL_BT5_PHY_SUPPORTED == 1)
@@ -238,14 +257,14 @@ ble_ll_conn_chk_phy_upd_start(struct ble_ll_conn_sm *csm)
     int rc;
 
     /* If no host preferences or  */
-    if (((csm->phy_data.host_pref_tx_phys == 0) &&
-         (csm->phy_data.host_pref_rx_phys == 0)) ||
-        ((csm->phy_data.host_pref_tx_phys & CONN_CUR_TX_PHY_MASK(csm)) &&
-         (csm->phy_data.host_pref_rx_phys & CONN_CUR_RX_PHY_MASK(csm)))) {
+    if (((csm->phy_data.host_pref_tx_phys_mask == 0) &&
+         (csm->phy_data.host_pref_rx_phys_mask == 0)) ||
+        ((csm->phy_data.host_pref_tx_phys_mask & CONN_CUR_TX_PHY_MASK(csm)) &&
+         (csm->phy_data.host_pref_rx_phys_mask & CONN_CUR_RX_PHY_MASK(csm)))) {
         rc = -1;
     } else {
-        csm->phy_data.req_pref_tx_phys = csm->phy_data.host_pref_tx_phys;
-        csm->phy_data.req_pref_rx_phys = csm->phy_data.host_pref_rx_phys;
+        csm->phy_data.req_pref_tx_phys_mask = csm->phy_data.host_pref_tx_phys_mask;
+        csm->phy_data.req_pref_rx_phys_mask = csm->phy_data.host_pref_rx_phys_mask;
         ble_ll_ctrl_proc_start(csm, BLE_LL_CTRL_PROC_PHY_UPDATE);
         rc = 0;
     }
@@ -1117,8 +1136,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_phy_pdu_dur(next_txlen, connsm->phy_data.tx_phy_mode) +
-                ble_phy_pdu_dur(cur_txlen, connsm->phy_data.tx_phy_mode);
+                ble_phy_mode_pdu_dur(next_txlen, connsm->phy_data.tx_phy_mode) +
+                ble_phy_mode_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);
@@ -1267,7 +1286,7 @@ 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);
+    ble_phy_mode_set(connsm->phy_data.tx_phy_mode,connsm->phy_data.rx_phy_mode);
 #endif
 
     /* Set transmit end callback */
@@ -1388,7 +1407,7 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch)
 #endif
 
 #if (BLE_LL_BT5_PHY_SUPPORTED == 1)
-    ble_phy_set_mode(connsm->phy_data.rx_phy_mode,connsm->phy_data.rx_phy_mode);
+    ble_phy_mode_set(connsm->phy_data.rx_phy_mode,connsm->phy_data.rx_phy_mode);
 #endif
 
 #if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
@@ -1442,7 +1461,7 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch)
              * 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->phy_data.rx_phy_mode) +
+                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);
@@ -1515,10 +1534,10 @@ ble_ll_conn_can_send_next_pdu(struct ble_ll_conn_sm *connsm, uint32_t begtime,
             if (rem_bytes > connsm->eff_max_tx_octets) {
                 rem_bytes = connsm->eff_max_tx_octets;
             }
-            usecs = ble_phy_pdu_dur(rem_bytes, connsm->phy_data.tx_phy_mode);
+            usecs = ble_phy_mode_pdu_dur(rem_bytes, connsm->phy_data.tx_phy_mode);
         } else {
             /* We will send empty pdu (just a LL header) */
-            usecs = ble_phy_pdu_dur(0, connsm->phy_data.tx_phy_mode);
+            usecs = ble_phy_mode_pdu_dur(0, connsm->phy_data.tx_phy_mode);
         }
         usecs += (BLE_LL_IFS * 2) + connsm->eff_max_rx_time;
 
@@ -1699,14 +1718,14 @@ ble_ll_conn_sm_new(struct ble_ll_conn_sm *connsm)
 
     /* XXX: TODO set these based on PHY that started connection */
 #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;
-    connsm->phy_data.host_pref_rx_phys = g_ble_ll_data.ll_pref_rx_phys;
+    connsm->phy_data.cur_tx_phy = BLE_PHY_1M;
+    connsm->phy_data.cur_rx_phy = BLE_PHY_1M;
+    connsm->phy_data.tx_phy_mode = BLE_PHY_MODE_1M;
+    connsm->phy_data.rx_phy_mode = BLE_PHY_MODE_1M;
+    connsm->phy_data.req_pref_tx_phys_mask = 0;
+    connsm->phy_data.req_pref_rx_phys_mask = 0;
+    connsm->phy_data.host_pref_tx_phys_mask = g_ble_ll_data.ll_pref_tx_phys;
+    connsm->phy_data.host_pref_rx_phys_mask = g_ble_ll_data.ll_pref_rx_phys;
     connsm->phy_data.phy_options = 0;
 #endif
 
@@ -2066,16 +2085,17 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm)
         /* Set cur phy to new phy */
         if (connsm->phy_data.new_tx_phy) {
             connsm->phy_data.cur_tx_phy = connsm->phy_data.new_tx_phy;
+            connsm->phy_data.tx_phy_mode =
+                                ble_ll_conn_phy_to_phy_mode(connsm->phy_data.cur_tx_phy,
+                                                   connsm->phy_data.phy_options);
         }
-        connsm->phy_data.tx_phy_mode = connsm->phy_data.cur_tx_phy;
+
         if (connsm->phy_data.new_rx_phy) {
             connsm->phy_data.cur_rx_phy = connsm->phy_data.new_rx_phy;
+            connsm->phy_data.rx_phy_mode =
+                                ble_ll_conn_phy_to_phy_mode(connsm->phy_data.cur_rx_phy,
+                                                   connsm->phy_data.phy_options);
         }
-        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;
@@ -2194,7 +2214,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_phy_pdu_dur(BLE_CONNECT_REQ_LEN, BLE_PHY_1M);
+            ble_phy_mode_pdu_dur(BLE_CONNECT_REQ_LEN, BLE_PHY_MODE_1M);
 
         /* Anchor point is cputime. */
         endtime = os_cputime_usecs_to_ticks(usecs);
@@ -2214,7 +2234,7 @@ 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_phy_pdu_dur(BLE_CONNECT_REQ_LEN,
+            os_cputime_usecs_to_ticks(ble_phy_mode_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;
@@ -3153,10 +3173,10 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
 #if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768
     endtime = rxhdr->beg_cputime;
     add_usecs = rxhdr->rem_usecs +
-        ble_phy_pdu_dur(rx_pyld_len, connsm->phy_data.rx_phy_mode);
+        ble_phy_mode_pdu_dur(rx_pyld_len, connsm->phy_data.rx_phy_mode);
 #else
     endtime = rxhdr->beg_cputime +
-        os_cputime_usecs_to_ticks(ble_phy_pdu_dur(rx_pyld_len,
+        os_cputime_usecs_to_ticks(ble_phy_mode_pdu_dur(rx_pyld_len,
                                                   connsm->phy_data.rx_phy_mode));
 
     add_usecs = 0;
@@ -3684,17 +3704,17 @@ ble_ll_conn_module_reset(void)
     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_phy_pdu_dur(maxbytes + BLE_LL_DATA_MIC_LEN, BLE_PHY_1M);
+        ble_phy_mode_pdu_dur(maxbytes + BLE_LL_DATA_MIC_LEN, BLE_PHY_MODE_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_phy_pdu_dur(maxbytes + BLE_LL_DATA_MIC_LEN, BLE_PHY_1M);
+        ble_phy_mode_pdu_dur(maxbytes + BLE_LL_DATA_MIC_LEN, BLE_PHY_MODE_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_phy_pdu_dur(maxbytes + BLE_LL_DATA_MIC_LEN, BLE_PHY_1M);
+        ble_phy_mode_pdu_dur(maxbytes + BLE_LL_DATA_MIC_LEN, BLE_PHY_MODE_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/8ae34ada/net/nimble/controller/src/ble_ll_conn_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn_hci.c b/net/nimble/controller/src/ble_ll_conn_hci.c
index f86b954..3e20a7c 100644
--- a/net/nimble/controller/src/ble_ll_conn_hci.c
+++ b/net/nimble/controller/src/ble_ll_conn_hci.c
@@ -1265,8 +1265,8 @@ ble_ll_conn_hci_le_set_phy(uint8_t *cmdbuf)
         goto phy_cmd_param_err;
     }
 
-    connsm->phy_data.host_pref_tx_phys = tx_phys,
-    connsm->phy_data.host_pref_rx_phys = rx_phys;
+    connsm->phy_data.host_pref_tx_phys_mask = tx_phys,
+    connsm->phy_data.host_pref_rx_phys_mask = rx_phys;
 
     /*
      * The host preferences override the default phy preferences. Currently,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8ae34ada/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 b38a457..9b4253e 100644
--- a/net/nimble/controller/src/ble_ll_ctrl.c
+++ b/net/nimble/controller/src/ble_ll_ctrl.c
@@ -492,9 +492,9 @@ ble_ll_ctrl_phy_update_proc_complete(struct ble_ll_conn_sm *connsm)
  * BLE_HCI_LE_PHY_CODED                 (3)
  */
 static uint8_t
-ble_ll_ctrl_phy_mask_to_numeric(uint8_t phy_mask)
+ble_ll_ctrl_phy_from_phy_mask(uint8_t phy_mask)
 {
-    uint8_t numeric;
+    uint8_t phy;
 
     /*
      * NOTE: wipe out unsupported PHYs. There should not be an unsupported
@@ -507,24 +507,24 @@ ble_ll_ctrl_phy_mask_to_numeric(uint8_t phy_mask)
     phy_mask &= ~BLE_HCI_LE_PHY_CODED_PREF_MASK;
 #endif
 
-    if (phy_mask & BLE_HCI_LE_PHY_1M_PREF_MASK) {
-        numeric = BLE_HCI_LE_PHY_1M;
-        phy_mask &= ~BLE_HCI_LE_PHY_1M_PREF_MASK;
-    } else if (phy_mask & BLE_HCI_LE_PHY_2M_PREF_MASK) {
-        numeric = BLE_HCI_LE_PHY_2M;
-        phy_mask &= ~BLE_HCI_LE_PHY_2M_PREF_MASK;
-    } else if (phy_mask & BLE_HCI_LE_PHY_CODED_PREF_MASK) {
-        numeric = BLE_HCI_LE_PHY_CODED;
-        phy_mask &= ~BLE_HCI_LE_PHY_CODED_PREF_MASK;
+    if (phy_mask & BLE_PHY_MASK_1M) {
+        phy = BLE_PHY_1M;
+        phy_mask &= ~BLE_PHY_MASK_1M;
+    } else if (phy_mask & BLE_PHY_MASK_2M) {
+        phy = BLE_PHY_2M;
+        phy_mask &= ~BLE_PHY_MASK_2M;
+    } else if (phy_mask & BLE_PHY_MASK_CODED) {
+        phy = BLE_PHY_CODED;
+        phy_mask &= ~BLE_PHY_MASK_CODED;
     } else {
-        numeric = 0;
+        phy = 0;
     }
 
     if (phy_mask != 0) {
-        numeric = 0;
+        phy = 0;
     }
 
-    return numeric;
+    return phy;
 }
 
 /**
@@ -540,18 +540,18 @@ ble_ll_ctrl_phy_mask_to_numeric(uint8_t phy_mask)
  * @return uint8_t The phy to use (not a mask)
  */
 static uint8_t
-ble_ll_ctrl_find_new_phy(uint8_t prefs)
+ble_ll_ctrl_find_new_phy(uint8_t phy_mask_prefs)
 {
     uint8_t new_phy;
 
-    new_phy = prefs;
+    new_phy = phy_mask_prefs;
     if (new_phy) {
-        if (new_phy & BLE_HCI_LE_PHY_2M_PREF_MASK) {
-            new_phy = BLE_HCI_LE_PHY_2M;
-        } else if (new_phy & BLE_HCI_LE_PHY_1M_PREF_MASK) {
-            new_phy = BLE_HCI_LE_PHY_1M;
+        if (new_phy & BLE_PHY_MASK_2M) {
+            new_phy = BLE_PHY_2M;
+        } else if (new_phy & BLE_PHY_MASK_1M) {
+            new_phy = BLE_PHY_1M;
         } else {
-            new_phy = BLE_HCI_LE_PHY_CODED;
+            new_phy = BLE_PHY_CODED;
         }
     }
 
@@ -582,11 +582,11 @@ ble_ll_ctrl_phy_update_ind_make(struct ble_ll_conn_sm *connsm, uint8_t *dptr,
 
     /* Get m_to_s and s_to_m masks */
     if (slave_req) {
-        m_to_s = connsm->phy_data.host_pref_tx_phys & rx_phys;
-        s_to_m = connsm->phy_data.host_pref_rx_phys & tx_phys;
+        m_to_s = connsm->phy_data.host_pref_tx_phys_mask & rx_phys;
+        s_to_m = connsm->phy_data.host_pref_rx_phys_mask & tx_phys;
     } else {
-        m_to_s = connsm->phy_data.req_pref_tx_phys & rx_phys;
-        s_to_m = connsm->phy_data.req_pref_rx_phys & tx_phys;
+        m_to_s = connsm->phy_data.req_pref_tx_phys_mask & rx_phys;
+        s_to_m = connsm->phy_data.req_pref_rx_phys_mask & tx_phys;
     }
 
     /* Find new phys. If not different than current, set to 0 */
@@ -649,15 +649,15 @@ static void
 ble_ll_ctrl_phy_req_rsp_make(struct ble_ll_conn_sm *connsm, uint8_t *ctrdata)
 {
     /* If no preference we use current phy */
-    if (connsm->phy_data.host_pref_tx_phys == 0) {
+    if (connsm->phy_data.host_pref_tx_phys_mask == 0) {
         ctrdata[0] = CONN_CUR_TX_PHY_MASK(connsm);
     } else {
-        ctrdata[0] = connsm->phy_data.host_pref_tx_phys;
+        ctrdata[0] = connsm->phy_data.host_pref_tx_phys_mask;
     }
-    if (connsm->phy_data.host_pref_rx_phys == 0) {
+    if (connsm->phy_data.host_pref_rx_phys_mask == 0) {
         ctrdata[1] = CONN_CUR_RX_PHY_MASK(connsm);
     } else {
-        ctrdata[1] = connsm->phy_data.host_pref_rx_phys;
+        ctrdata[1] = connsm->phy_data.host_pref_rx_phys_mask;
     }
 }
 
@@ -801,8 +801,8 @@ ble_ll_ctrl_rx_phy_update_ind(struct ble_ll_conn_sm *connsm, uint8_t *dptr)
              * 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);
+            new_rx_phy = ble_ll_ctrl_phy_from_phy_mask(new_m_to_s_mask);
+            new_tx_phy = ble_ll_ctrl_phy_from_phy_mask(new_s_to_m_mask);
 
             if ((new_tx_phy == 0) && (new_rx_phy == 0)) {
                 /* XXX: this is an error! What to do??? */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8ae34ada/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 3f45d98..e4df3bc 100644
--- a/net/nimble/controller/src/ble_ll_scan.c
+++ b/net/nimble/controller/src/ble_ll_scan.c
@@ -596,7 +596,7 @@ 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);
+    ble_phy_mode_set(BLE_PHY_MODE_1M, BLE_PHY_MODE_1M);
 #endif
 
 #if MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8ae34ada/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 c7a5a95..8f537f0 100644
--- a/net/nimble/controller/src/ble_ll_sched.c
+++ b/net/nimble/controller/src/ble_ll_sched.c
@@ -365,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_phy_pdu_dur(pyld_len, BLE_PHY_1M));
+        os_cputime_usecs_to_ticks(ble_phy_mode_pdu_dur(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
@@ -376,7 +376,7 @@ 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_phy_pdu_dur(BLE_CONNECT_REQ_LEN, BLE_PHY_1M) +
+                                  ble_phy_mode_pdu_dur(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;