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:14 UTC

[01/12] incubator-mynewt-core git commit: nimble/controller: Fix applying PHY update

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/bluetooth5 2446dcb64 -> e84df52dd


nimble/controller: Fix applying PHY update

New m_to_s and s_to_m PHYs shall be applied before converting them to
bitmasks. This works now only because bitmasks for 1M and 2M are the
same as numeric values, but won't work for Coded.


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

Branch: refs/heads/bluetooth5
Commit: dfeee7b49b50aac54f455e84390b7f5bd0abe888
Parents: 502fbb7
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Tue May 9 15:21:17 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Wed May 17 11:55:28 2017 +0200

----------------------------------------------------------------------
 net/nimble/controller/src/ble_ll_ctrl.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dfeee7b4/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 dcd72bd..b38a457 100644
--- a/net/nimble/controller/src/ble_ll_ctrl.c
+++ b/net/nimble/controller/src/ble_ll_ctrl.c
@@ -625,13 +625,13 @@ ble_ll_ctrl_phy_update_ind_make(struct ble_ll_conn_sm *connsm, uint8_t *dptr,
         connsm->phy_instant = instant;
         CONN_F_PHY_UPDATE_SCHED(connsm) = 1;
 
-        /* Convert m_to_s and s_to_m to masks */
-        m_to_s = 1 << (m_to_s - 1);
-        s_to_m = 1 << (s_to_m - 1);
-
         /* Set new phys to use when instant occurs */
         connsm->phy_data.new_tx_phy = m_to_s;
         connsm->phy_data.new_rx_phy = s_to_m;
+
+        /* Convert m_to_s and s_to_m to masks */
+        m_to_s = 1 << (m_to_s - 1);
+        s_to_m = 1 << (s_to_m - 1);
     }
 
     ctrdata[0] = m_to_s;


[02/12] incubator-mynewt-core git commit: nimble/controller: Fix checking PHY Options in LE Set PHY

Posted by an...@apache.org.
nimble/controller: Fix checking PHY Options in LE Set PHY

We need to check complete value here, then we can store only lsb since
msb will be zero anyway.


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

Branch: refs/heads/bluetooth5
Commit: 502fbb752d18316eab8fb55e223a837b99452675
Parents: 2446dcb
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Fri Apr 28 00:44:15 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Wed May 17 11:55:28 2017 +0200

----------------------------------------------------------------------
 net/nimble/controller/src/ble_ll_conn_hci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/502fbb75/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 bea9e9b..f86b954 100644
--- a/net/nimble/controller/src/ble_ll_conn_hci.c
+++ b/net/nimble/controller/src/ble_ll_conn_hci.c
@@ -1233,7 +1233,7 @@ int
 ble_ll_conn_hci_le_set_phy(uint8_t *cmdbuf)
 {
     int rc;
-    uint8_t phy_options;
+    uint16_t phy_options;
     uint8_t tx_phys;
     uint8_t rx_phys;
     uint16_t handle;
@@ -1253,11 +1253,11 @@ ble_ll_conn_hci_le_set_phy(uint8_t *cmdbuf)
         return BLE_ERR_CMD_DISALLOWED;
     }
 
-    phy_options = cmdbuf[5];
+    phy_options = get_le16(cmdbuf + 5);
     if (phy_options > BLE_HCI_LE_PHY_CODED_S8_PREF) {
         return BLE_ERR_INV_HCI_CMD_PARMS;
     }
-    connsm->phy_data.phy_options = phy_options;
+    connsm->phy_data.phy_options = phy_options & 0x03;
 
     /* Check valid parameters */
     rc = ble_ll_hci_chk_phy_masks(cmdbuf + 2, &tx_phys, &rx_phys);


[12/12] incubator-mynewt-core git commit: This closes #283.

Posted by an...@apache.org.
This closes #283.

Merge branch 'bt5_phy' of https://github.com/andrzej-kaczmarek/incubator-mynewt-core into bluetooth5


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

Branch: refs/heads/bluetooth5
Commit: e84df52ddba83e5a10dc0ab9fea9ad8c408ba9d5
Parents: 2446dcb 5a8f516
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Thu May 18 10:50:50 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Thu May 18 10:50:50 2017 +0200

----------------------------------------------------------------------
 hw/drivers/nimble/nrf51/src/ble_phy.c           |  14 +-
 hw/drivers/nimble/nrf52/src/ble_phy.c           | 167 ++++++++++++-------
 .../controller/include/controller/ble_ll_conn.h |   8 +-
 .../controller/include/controller/ble_phy.h     |  32 ++--
 net/nimble/controller/src/ble_ll.c              |   2 +-
 net/nimble/controller/src/ble_ll_adv.c          |   4 +-
 net/nimble/controller/src/ble_ll_conn.c         | 113 +++++++++----
 net/nimble/controller/src/ble_ll_conn_hci.c     |  10 +-
 net/nimble/controller/src/ble_ll_ctrl.c         |  70 ++++----
 net/nimble/controller/src/ble_ll_scan.c         |   2 +-
 net/nimble/controller/src/ble_ll_sched.c        |   4 +-
 11 files changed, 264 insertions(+), 162 deletions(-)
----------------------------------------------------------------------



[10/12] incubator-mynewt-core git commit: nimble/controller: Add access address constraints for LE Coded PHY

Posted by an...@apache.org.
nimble/controller: Add access address constraints for LE Coded 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/1f5c04d2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1f5c04d2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1f5c04d2

Branch: refs/heads/bluetooth5
Commit: 1f5c04d24b144de3cbccfa422ca7f26a2641f261
Parents: b07f4a7
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Wed May 10 17:58:23 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Wed May 17 11:56:17 2017 +0200

----------------------------------------------------------------------
 net/nimble/controller/src/ble_ll_conn.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1f5c04d2/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 2aefdcd..f6a7379 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -531,6 +531,7 @@ ble_ll_conn_calc_access_addr(void)
     uint8_t bits_diff;
     uint8_t consecutive;
     uint8_t transitions;
+    uint8_t ones;
 
     /* Calculate a random access address */
     aa = 0;
@@ -570,6 +571,7 @@ ble_ll_conn_calc_access_addr(void)
         /* Cannot have more than 24 transitions */
         transitions = 0;
         consecutive = 0;
+        ones = 0;
         mask = 0x00000001;
         while (mask < 0x80000000) {
             prev_bit = aa & mask;
@@ -590,14 +592,33 @@ ble_ll_conn_calc_access_addr(void)
                 }
             }
 
+            if (prev_bit) {
+                ones++;
+            }
+
+            /* 8 lsb should have at least three 1 */
+            if (mask == 0x00000100 && ones < 3) {
+                break;
+            }
+
+            /* 16 lsb should have no more than 11 transitions */
+            if (mask == 0x00010000 && transitions > 11) {
+                break;
+            }
+
             /* This is invalid! */
             if (consecutive > 6) {
                 break;
             }
         }
 
+        /* Invalid sequence found */
+        if (mask != 0x80000000) {
+            continue;
+        }
+
         /* Cannot be more than 24 transitions */
-        if ((consecutive > 6) || (transitions > 24)) {
+        if (transitions > 24) {
             continue;
         }
 


[04/12] incubator-mynewt-core git commit: nimble/phy: Cleanup PCNF0 settings

Posted by an...@apache.org.
nimble/phy: Cleanup PCNF0 settings

This patch makes PCNF0 settings explicit to make code easier to read:
- always set S1LEN (even though it is predefined to 0)
- set PLEN in ble_phy_mode_set for each case (do not make "implicit" set
  to 8bits in ble_phy_init)


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

Branch: refs/heads/bluetooth5
Commit: c91bd6cf8a57bf67ab6bfd4c19365106af270545
Parents: 24131d5
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Fri May 12 10:58:54 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Wed May 17 11:56:17 2017 +0200

----------------------------------------------------------------------
 hw/drivers/nimble/nrf52/src/ble_phy.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c91bd6cf/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 a9d0150..0947975 100644
--- a/hw/drivers/nimble/nrf52/src/ble_phy.c
+++ b/hw/drivers/nimble/nrf52/src/ble_phy.c
@@ -50,9 +50,10 @@ extern uint32_t g_nrf_irk_list[];
  * zero bit S1 field. The preamble is 8 bits long.
  */
 #define NRF_LFLEN_BITS          (8)
-#define NRF_S0_LEN              (1)
-#define NRF_CI_LEN              (2)
-#define NRF_TERM_LEN            (3)
+#define NRF_S0LEN               (1)
+#define NRF_S1LEN_BITS          (0)
+#define NRF_CILEN_BITS          (2)
+#define NRF_TERMLEN_BITS        (3)
 
 /* Maximum length of frames */
 #define NRF_MAXLEN              (255)
@@ -253,7 +254,8 @@ ble_phy_mode_set(int cur_phy_mode, int txtorx_phy_mode)
 {
     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 */
+        NRF_RADIO->PCNF0 = g_ble_phy_data.phy_pcnf0 |
+            (RADIO_PCNF0_PLEN_8bit << RADIO_PCNF0_PLEN_Pos);
     } 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 |
@@ -262,14 +264,14 @@ ble_phy_mode_set(int cur_phy_mode, int txtorx_phy_mode)
         NRF_RADIO->MODE = RADIO_MODE_MODE_Ble_LR125Kbit;
         NRF_RADIO->PCNF0 = g_ble_phy_data.phy_pcnf0 |
             (RADIO_PCNF0_PLEN_LongRange << RADIO_PCNF0_PLEN_Pos) |
-            (NRF_CI_LEN << RADIO_PCNF0_CILEN_Pos) |
-            (NRF_TERM_LEN << RADIO_PCNF0_TERMLEN_Pos);
+            (NRF_CILEN_BITS << RADIO_PCNF0_CILEN_Pos) |
+            (NRF_TERMLEN_BITS << RADIO_PCNF0_TERMLEN_Pos);
     } else if (cur_phy_mode == BLE_PHY_MODE_CODED_500KBPS) {
         NRF_RADIO->MODE = RADIO_MODE_MODE_Ble_LR500Kbit;
         NRF_RADIO->PCNF0 = g_ble_phy_data.phy_pcnf0 |
             (RADIO_PCNF0_PLEN_LongRange << RADIO_PCNF0_PLEN_Pos) |
-            (NRF_CI_LEN << RADIO_PCNF0_CILEN_Pos) |
-            (NRF_TERM_LEN << RADIO_PCNF0_TERMLEN_Pos);
+            (NRF_CILEN_BITS << RADIO_PCNF0_CILEN_Pos) |
+            (NRF_TERMLEN_BITS << RADIO_PCNF0_TERMLEN_Pos);
     } else {
         assert(0);
     }
@@ -968,8 +970,8 @@ ble_phy_init(void)
     NRF_RADIO->MODE = RADIO_MODE_MODE_Ble_1Mbit;
     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_S0LEN << RADIO_PCNF0_S0LEN_Pos)        |
+                               (NRF_S1LEN_BITS << RADIO_PCNF0_S1LEN_Pos);
     NRF_RADIO->PCNF0 = g_ble_phy_data.phy_pcnf0;
 
     /* XXX: should maxlen be 251 for encryption? */


[03/12] incubator-mynewt-core git commit: nimble/controller: Add configuration for LE Coded PHY

Posted by an...@apache.org.
nimble/controller: Add configuration for LE Coded PHY

This patch adds nRF52 configuration for LE Coded 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/24131d55
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/24131d55
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/24131d55

Branch: refs/heads/bluetooth5
Commit: 24131d55f6f67f7015f7098d7fb2a3004abb6a84
Parents: 1f5c04d
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Sat Apr 29 00:55:31 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Wed May 17 11:56:17 2017 +0200

----------------------------------------------------------------------
 hw/drivers/nimble/nrf52/src/ble_phy.c   | 40 ++++++++++++++++++++++++----
 net/nimble/controller/src/ble_ll_conn.c |  4 ++-
 2 files changed, 38 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24131d55/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 a1da61e..a9d0150 100644
--- a/hw/drivers/nimble/nrf52/src/ble_phy.c
+++ b/hw/drivers/nimble/nrf52/src/ble_phy.c
@@ -51,6 +51,8 @@ extern uint32_t g_nrf_irk_list[];
  */
 #define NRF_LFLEN_BITS          (8)
 #define NRF_S0_LEN              (1)
+#define NRF_CI_LEN              (2)
+#define NRF_TERM_LEN            (3)
 
 /* Maximum length of frames */
 #define NRF_MAXLEN              (255)
@@ -77,7 +79,7 @@ struct ble_phy_obj
     uint8_t phy_tx_pyld_len;
     uint8_t phy_txtorx_phy_mode;
     uint8_t phy_cur_phy_mode;
-    uint8_t phy_mode_pkt_start_off[BLE_PHY_NUM_MODULATIONS];
+    uint16_t phy_mode_pkt_start_off[BLE_PHY_NUM_MODULATIONS];
     uint32_t phy_aar_scratch;
     uint32_t phy_access_address;
     uint32_t phy_pcnf0;
@@ -189,6 +191,17 @@ struct nrf_ccm_data g_nrf_ccm_data;
 #endif
 
 #if (BLE_LL_BT5_PHY_SUPPORTED == 1)
+
+static inline int ble_phy_pdu_coded_dur(int pyld_len, int s)
+{
+    /*
+     * Specification provides duration for each PDU field directly in us so we
+     * can use them directly here (Vol 6, Part B, 2.2).
+     */
+    return 80 + 256 + 16 + 24 + /* Preamble + Access Address + CI + TERM1 */
+            s * ((BLE_LL_PDU_HDR_LEN + pyld_len) * 8 + 24 + 3); /* PDU + CRC + TERM2 */
+}
+
 /**
  * Calculate the length of BLE PDU
  *
@@ -216,15 +229,19 @@ ble_phy_mode_pdu_dur(uint8_t pyld_len, int phy_mode)
         /* 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 if (phy_mode == BLE_PHY_MODE_CODED_125KBPS) {
+        usecs = ble_phy_pdu_coded_dur(pyld_len, 8);
+    } else if (phy_mode == BLE_PHY_MODE_CODED_500KBPS) {
+        usecs = ble_phy_pdu_coded_dur(pyld_len, 2);
     } else {
-        /* XXX: TODO implement */
         assert(0);
     }
     return usecs;
 }
 
 
-/* Packet start offset (in usecs). This is the preamble plus access address. */
+/* Packet start offset (in usecs). This is the preamble plus access address.
+ * For LE Coded PHY this also includes CI and TERM1. */
 uint32_t
 ble_phy_mode_pdu_start_off(int phy_mode)
 {
@@ -241,10 +258,22 @@ ble_phy_mode_set(int cur_phy_mode, int txtorx_phy_mode)
         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);
+    } else if (cur_phy_mode == BLE_PHY_MODE_CODED_125KBPS) {
+        NRF_RADIO->MODE = RADIO_MODE_MODE_Ble_LR125Kbit;
+        NRF_RADIO->PCNF0 = g_ble_phy_data.phy_pcnf0 |
+            (RADIO_PCNF0_PLEN_LongRange << RADIO_PCNF0_PLEN_Pos) |
+            (NRF_CI_LEN << RADIO_PCNF0_CILEN_Pos) |
+            (NRF_TERM_LEN << RADIO_PCNF0_TERMLEN_Pos);
+    } else if (cur_phy_mode == BLE_PHY_MODE_CODED_500KBPS) {
+        NRF_RADIO->MODE = RADIO_MODE_MODE_Ble_LR500Kbit;
+        NRF_RADIO->PCNF0 = g_ble_phy_data.phy_pcnf0 |
+            (RADIO_PCNF0_PLEN_LongRange << RADIO_PCNF0_PLEN_Pos) |
+            (NRF_CI_LEN << RADIO_PCNF0_CILEN_Pos) |
+            (NRF_TERM_LEN << RADIO_PCNF0_TERMLEN_Pos);
     } else {
-        /* XXX: TODO added coded PHY */
         assert(0);
     }
+
     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;
 }
@@ -898,10 +927,11 @@ ble_phy_init(void)
 {
     int rc;
 
-    /* XXX: TODO add coded phy */
     /* Set packet start offsets for various phys */
     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 */
+    g_ble_phy_data.phy_mode_pkt_start_off[BLE_PHY_MODE_CODED_125KBPS] = 376;  /* 376 usecs */
+    g_ble_phy_data.phy_mode_pkt_start_off[BLE_PHY_MODE_CODED_500KBPS] = 376;  /* 376 usecs */
 
     /* Default phy to use is 1M */
     g_ble_phy_data.phy_cur_phy_mode = BLE_PHY_MODE_1M;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24131d55/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 f6a7379..a7755ee 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -229,7 +229,9 @@ static inline int ble_ll_conn_phy_to_phy_mode(int phy, int phy_options)
     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 */
+    if (phy == BLE_PHY_CODED && phy_options == BLE_HCI_LE_PHY_CODED_S8_PREF) {
+        phy_mode = BLE_PHY_MODE_CODED_125KBPS;
+    }
 #endif
 
     return phy_mode;


[07/12] incubator-mynewt-core git commit: nimble/controller: Fix setting LE Coded PHY feature flag

Posted by an...@apache.org.
nimble/controller: Fix setting LE Coded PHY feature flag


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

Branch: refs/heads/bluetooth5
Commit: b07f4a7fe11517b1d8b4272eb59ad662a84df452
Parents: 8ae34ad
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Tue May 9 15:43:47 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Wed May 17 11:56:17 2017 +0200

----------------------------------------------------------------------
 net/nimble/controller/src/ble_ll.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b07f4a7f/net/nimble/controller/src/ble_ll.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll.c b/net/nimble/controller/src/ble_ll.c
index 930b44e..68b9ce4 100644
--- a/net/nimble/controller/src/ble_ll.c
+++ b/net/nimble/controller/src/ble_ll.c
@@ -1352,7 +1352,7 @@ ble_ll_init(void)
     features |= BLE_LL_FEAT_LE_2M_PHY;
 #endif
 
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_CSA2) == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_CODED_PHY) == 1)
     features |= BLE_LL_FEAT_LE_CODED_PHY;
 #endif
 


[08/12] incubator-mynewt-core git commit: nimble/phy: Fix access address configuration

Posted by an...@apache.org.
nimble/phy: Fix access address configuration

Currently logical address 0 was preconfigured for advertising and
address 1 was used for connection. This works fine for 1M and 2M PHYs
but for unknown reason nRF52 does not receive anything when using
logical address 1 on Coded PHY.

Althoough it works fine on Coded PHY with swapped logical addresses,
let's just use logical address 0 for everything instead so we don't
have problems soon again with scanning on Coded 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/af6be360
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/af6be360
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/af6be360

Branch: refs/heads/bluetooth5
Commit: af6be360a1589a3beccd02dc8943ccad1f2d41e2
Parents: aa387ad
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Mon May 15 18:01:41 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Wed May 17 11:56:17 2017 +0200

----------------------------------------------------------------------
 hw/drivers/nimble/nrf52/src/ble_phy.c | 50 ++++++++++++++++++------------
 1 file changed, 30 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/af6be360/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 85bcfd3..caf639e 100644
--- a/hw/drivers/nimble/nrf52/src/ble_phy.c
+++ b/hw/drivers/nimble/nrf52/src/ble_phy.c
@@ -980,9 +980,9 @@ ble_phy_init(void)
                        (NRF_BALEN << RADIO_PCNF1_BALEN_Pos) |
                        RADIO_PCNF1_WHITEEN_Msk;
 
-    /* Set base0 with the advertising access address */
-    NRF_RADIO->BASE0 = (BLE_ACCESS_ADDR_ADV << 8) & 0xFFFFFF00;
-    NRF_RADIO->PREFIX0 = (BLE_ACCESS_ADDR_ADV >> 24) & 0xFF;
+    /* Set logical address 1 for TX and RX */
+    NRF_RADIO->TXADDRESS  = 0;
+    NRF_RADIO->RXADDRESSES  = (1 << 0);
 
     /* Configure the CRC registers */
     NRF_RADIO->CRCCNF = (RADIO_CRCCNF_SKIPADDR_Skip << RADIO_CRCCNF_SKIPADDR_Pos) | RADIO_CRCCNF_LEN_Three;
@@ -1431,6 +1431,26 @@ ble_phy_txpwr_set(int dbm)
 }
 
 /**
+ * ble phy set access addr
+ *
+ * Set access address.
+ *
+ * @param access_addr Access address
+ *
+ * @return int 0: success; PHY error code otherwise
+ */
+int
+ble_phy_set_access_addr(uint32_t access_addr)
+{
+    NRF_RADIO->BASE0 = (access_addr << 8);
+    NRF_RADIO->PREFIX0 = (NRF_RADIO->PREFIX0 & 0xFFFFFF00) | (access_addr >> 24);
+
+    g_ble_phy_data.phy_access_address = access_addr;
+
+    return 0;
+}
+
+/**
  * ble phy txpwr get
  *
  * Get the transmit power.
@@ -1461,7 +1481,6 @@ int
 ble_phy_setchan(uint8_t chan, uint32_t access_addr, uint32_t crcinit)
 {
     uint8_t freq;
-    uint32_t prefix;
 
     assert(chan < BLE_PHY_NUM_CHANS);
 
@@ -1483,16 +1502,9 @@ ble_phy_setchan(uint8_t chan, uint32_t access_addr, uint32_t crcinit)
         }
 
         /* Set current access address */
-        g_ble_phy_data.phy_access_address = access_addr;
-
-        /* Configure logical address 1 and crcinit */
-        prefix = NRF_RADIO->PREFIX0;
-        prefix &= 0xffff00ff;
-        prefix |= ((access_addr >> 24) & 0xFF) << 8;
-        NRF_RADIO->BASE1 = (access_addr << 8) & 0xFFFFFF00;
-        NRF_RADIO->PREFIX0 = prefix;
-        NRF_RADIO->TXADDRESS = 1;
-        NRF_RADIO->RXADDRESSES = (1 << 1);
+        ble_phy_set_access_addr(access_addr);
+
+        /* Configure crcinit */
         NRF_RADIO->CRCINIT = crcinit;
     } else {
         if (chan == 37) {
@@ -1505,13 +1517,11 @@ ble_phy_setchan(uint8_t chan, uint32_t access_addr, uint32_t crcinit)
             freq = BLE_PHY_CHAN_SPACING_MHZ * 40;
         }
 
-        /* Logical adddress 0 preconfigured */
-        NRF_RADIO->TXADDRESS = 0;
-        NRF_RADIO->RXADDRESSES = (1 << 0);
-        NRF_RADIO->CRCINIT = BLE_LL_CRCINIT_ADV;
-
         /* Set current access address */
-        g_ble_phy_data.phy_access_address = BLE_ACCESS_ADDR_ADV;
+        ble_phy_set_access_addr(BLE_ACCESS_ADDR_ADV);
+
+        /* Configure crcinit */
+        NRF_RADIO->CRCINIT = BLE_LL_CRCINIT_ADV;
     }
 
     /* Set the frequency and the data whitening initial value */


[09/12] incubator-mynewt-core git commit: nimble/phy: Ugly hack for TX/RX transition timing

Posted by an...@apache.org.
nimble/phy: Ugly hack for TX/RX transition timing

Calculated RX time after TX/RX transition seems to be too short for
Coded PHY - not sure why, but adding extra 32us solves the problem.

This is temporary fix until we figure out what is really wrong.


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

Branch: refs/heads/bluetooth5
Commit: 5a8f5168d264bf8c9e12eb4a2848cc85c1a5e6ea
Parents: af6be36
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Tue May 16 12:12:47 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Wed May 17 11:56:17 2017 +0200

----------------------------------------------------------------------
 hw/drivers/nimble/nrf52/src/ble_phy.c | 8 ++++++++
 1 file changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5a8f5168/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 caf639e..094a5d4 100644
--- a/hw/drivers/nimble/nrf52/src/ble_phy.c
+++ b/hw/drivers/nimble/nrf52/src/ble_phy.c
@@ -494,6 +494,14 @@ ble_phy_wfr_enable(int txrx, uint32_t wfr_usecs)
          */
         end_time = NRF_TIMER0->CC[2] + BLE_LL_IFS +
             ble_phy_mode_pdu_start_off(phy) + BLE_LL_JITTER_USECS;
+
+        /*
+         * FIXME!
+         * on Coded PHY the time calculated above seems to be too short - adding
+         * extra 32us "solves" the problem (extra 16us, i.e. doubling the jitter
+         * is not enough). Need to figure out what is wrong here.
+         */
+        end_time += 32;
     } else {
         /* CC[0] is set to when RXEN occurs. NOTE: the extra 16 usecs is
            jitter */


[05/12] incubator-mynewt-core git commit: nimble/phy: Fix CRC configuration

Posted by an...@apache.org.
nimble/phy: Fix CRC configuration

The SKIPADDR field has allowed values 0, 1 and 2 - for unknown reason
it works even if set to 3 as we do, but better have this configured
properly.


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

Branch: refs/heads/bluetooth5
Commit: 01308580e7f673b38fdcfbb8642c223cfce36910
Parents: c91bd6c
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Mon May 15 17:21:45 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Wed May 17 11:56:17 2017 +0200

----------------------------------------------------------------------
 hw/drivers/nimble/nrf52/src/ble_phy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/01308580/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 0947975..773d8fb 100644
--- a/hw/drivers/nimble/nrf52/src/ble_phy.c
+++ b/hw/drivers/nimble/nrf52/src/ble_phy.c
@@ -985,7 +985,7 @@ ble_phy_init(void)
     NRF_RADIO->PREFIX0 = (BLE_ACCESS_ADDR_ADV >> 24) & 0xFF;
 
     /* Configure the CRC registers */
-    NRF_RADIO->CRCCNF = RADIO_CRCCNF_SKIPADDR_Msk | RADIO_CRCCNF_LEN_Three;
+    NRF_RADIO->CRCCNF = (RADIO_CRCCNF_SKIPADDR_Skip << RADIO_CRCCNF_SKIPADDR_Pos) | RADIO_CRCCNF_LEN_Three;
 
     /* Configure BLE poly */
     NRF_RADIO->CRCPOLY = 0x0100065B;


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

Posted by an...@apache.org.
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;


[11/12] incubator-mynewt-core git commit: nimble/phy: Fix CRC poly configuration

Posted by an...@apache.org.
nimble/phy: Fix CRC poly configuration

It works now probably because 8 MSb in CRCPOLY registers are unused
in nRF52 (for now).


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

Branch: refs/heads/bluetooth5
Commit: aa387adda43fccdf0eb141b7ee2f5985624d0670
Parents: 0130858
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Mon May 15 17:21:58 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Wed May 17 11:56:17 2017 +0200

----------------------------------------------------------------------
 hw/drivers/nimble/nrf52/src/ble_phy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/aa387add/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 773d8fb..85bcfd3 100644
--- a/hw/drivers/nimble/nrf52/src/ble_phy.c
+++ b/hw/drivers/nimble/nrf52/src/ble_phy.c
@@ -988,7 +988,7 @@ ble_phy_init(void)
     NRF_RADIO->CRCCNF = (RADIO_CRCCNF_SKIPADDR_Skip << RADIO_CRCCNF_SKIPADDR_Pos) | RADIO_CRCCNF_LEN_Three;
 
     /* Configure BLE poly */
-    NRF_RADIO->CRCPOLY = 0x0100065B;
+    NRF_RADIO->CRCPOLY = 0x0000065B;
 
     /* Configure IFS */
     NRF_RADIO->TIFS = BLE_LL_IFS;