Skip to content

Commit 3fe6eaf

Browse files
committed
Bluetooth: controller: PHY Update Procedure
Add support for Bluetooth v5.0 PHY Update Procedure. Jira: ZEP-2086 Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
1 parent bdaa7ba commit 3fe6eaf

File tree

9 files changed

+742
-130
lines changed

9 files changed

+742
-130
lines changed

subsys/bluetooth/controller/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ config BLUETOOTH_CONTROLLER_CHAN_SEL_2
130130
Enable support for Bluetooth 5.0 LE Channel Selection Algorithm #2 in
131131
the Controller.
132132

133+
config BLUETOOTH_CONTROLLER_PHY
134+
bool "PHY Update"
135+
default y
136+
help
137+
Enable support for Bluetooth 5.0 PHY Update Procedure in the
138+
Controller.
139+
133140
config BLUETOOTH_CONTROLLER_ADVANCED_FEATURES
134141
bool "Show advanced features"
135142
help
@@ -211,6 +218,7 @@ config BLUETOOTH_CONTROLLER_SCHED_ADVANCED
211218

212219
config BLUETOOTH_CONTROLLER_TIFS_HW
213220
bool "H/w Accelerated tIFS Trx switching"
221+
depends on !BLUETOOTH_CONTROLLER_PHY
214222
default y
215223
help
216224
Enable use of hardware accelerated tIFS Trx switching.

subsys/bluetooth/controller/hal/nrf5/radio.c

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,42 @@ void radio_reset(void)
6060
RADIO_POWER_POWER_Msk);
6161
}
6262

63-
void radio_phy_set(u8_t phy)
63+
void radio_phy_set(u8_t phy, u8_t flags)
6464
{
65-
NRF_RADIO->MODE =
66-
(((phy) ? (u32_t)phy : RADIO_MODE_MODE_Ble_1Mbit) <<
67-
RADIO_MODE_MODE_Pos) & RADIO_MODE_MODE_Msk;
65+
u32_t mode;
66+
67+
switch (phy) {
68+
case BIT(0):
69+
default:
70+
mode = RADIO_MODE_MODE_Ble_1Mbit;
71+
break;
72+
73+
#if defined(CONFIG_SOC_SERIES_NRF51X)
74+
case BIT(1):
75+
mode = RADIO_MODE_MODE_Nrf_2Mbit;
76+
break;
77+
78+
#elif defined(CONFIG_SOC_SERIES_NRF52X)
79+
case BIT(1):
80+
mode = RADIO_MODE_MODE_Ble_2Mbit;
81+
break;
82+
83+
#else /* !CONFIG_SOC_SERIES_NRF52X */
84+
case BIT(1):
85+
mode = RADIO_MODE_MODE_Ble_2Mbit;
86+
break;
87+
88+
case BIT(2):
89+
if (flags & 0x01) {
90+
mode = RADIO_MODE_MODE_Ble_LR500Kbit;
91+
} else {
92+
mode = RADIO_MODE_MODE_Ble_LR125Kbit;
93+
}
94+
break;
95+
#endif /* !CONFIG_SOC_SERIES_NRF52X */
96+
}
97+
98+
NRF_RADIO->MODE = (mode << RADIO_MODE_MODE_Pos) & RADIO_MODE_MODE_Msk;
6899
}
69100

70101
void radio_tx_power_set(u32_t power)
@@ -96,12 +127,12 @@ void radio_aa_set(u8_t *aa)
96127

97128
void radio_pkt_configure(u8_t bits_len, u8_t max_len, u8_t flags)
98129
{
99-
u8_t p16 = (flags >> 1) & 0x01; /* 16-bit preamble */
100130
u8_t dc = flags & 0x01; /* Adv or Data channel */
101131
u32_t extra;
132+
u8_t phy;
102133

103134
#if defined(CONFIG_SOC_SERIES_NRF51X)
104-
ARG_UNUSED(p16);
135+
ARG_UNUSED(phy);
105136

106137
extra = 0;
107138

@@ -110,8 +141,28 @@ void radio_pkt_configure(u8_t bits_len, u8_t max_len, u8_t flags)
110141
bits_len = 5;
111142
}
112143
#else /* !CONFIG_SOC_SERIES_NRF51X */
113-
extra = (((p16) ? RADIO_PCNF0_PLEN_16bit : RADIO_PCNF0_PLEN_8bit) <<
114-
RADIO_PCNF0_PLEN_Pos) & RADIO_PCNF0_PLEN_Msk;
144+
extra = 0;
145+
146+
phy = (flags >> 1) & 0x07; /* phy */
147+
switch (phy) {
148+
case BIT(0):
149+
default:
150+
extra |= (RADIO_PCNF0_PLEN_8bit << RADIO_PCNF0_PLEN_Pos) &
151+
RADIO_PCNF0_PLEN_Msk;
152+
break;
153+
154+
case BIT(1):
155+
extra |= (RADIO_PCNF0_PLEN_16bit << RADIO_PCNF0_PLEN_Pos) &
156+
RADIO_PCNF0_PLEN_Msk;
157+
break;
158+
159+
#if !defined(CONFIG_SOC_SERIES_NRF52X)
160+
case BIT(2):
161+
extra |= (RADIO_PCNF0_PLEN_LongRange << RADIO_PCNF0_PLEN_Pos) &
162+
RADIO_PCNF0_PLEN_Msk;
163+
break;
164+
#endif
165+
}
115166

116167
/* To use same Data Channel PDU structure with nRF5 specific overhead
117168
* byte, include the S1 field in radio packet configuration.
@@ -555,28 +606,7 @@ void *radio_ccm_tx_pkt_set(struct ccm *ccm, void *pkt)
555606
NRF_CCM->EVENTS_ENDCRYPT = 0;
556607
NRF_CCM->EVENTS_ERROR = 0;
557608

558-
#if defined(CONFIG_SOC_SERIES_NRF51X)
559-
/* set up PPI to enable CCM */
560-
NRF_PPI->CH[6].EEP = (u32_t)&(NRF_RADIO->EVENTS_READY);
561-
NRF_PPI->CH[6].TEP = (u32_t)&(NRF_CCM->TASKS_KSGEN);
562-
NRF_PPI->CHENSET = PPI_CHEN_CH6_Msk;
563-
#elif 0
564-
/* encrypt tx packet */
565-
NRF_CCM->INTENSET = CCM_INTENSET_ENDCRYPT_Msk;
566-
NRF_CCM->TASKS_KSGEN = 1;
567-
while (NRF_CCM->EVENTS_ENDCRYPT == 0) {
568-
__WFE();
569-
__SEV();
570-
__WFE();
571-
}
572-
NRF_CCM->INTENCLR = CCM_INTENCLR_ENDCRYPT_Msk;
573-
NVIC_ClearPendingIRQ(CCM_AAR_IRQn);
574-
575-
LL_ASSERT(NRF_CCM->EVENTS_ERROR == 0);
576-
#else
577-
/* start KSGEN early, but dont wait for ENDCRYPT */
578609
NRF_CCM->TASKS_KSGEN = 1;
579-
#endif
580610

581611
return _pkt_scratch;
582612
}

subsys/bluetooth/controller/hal/radio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void isr_radio(void);
2626
void radio_isr_set(radio_isr_fp fp_radio_isr);
2727

2828
void radio_reset(void);
29-
void radio_phy_set(u8_t phy);
29+
void radio_phy_set(u8_t phy, u8_t flags);
3030
void radio_tx_power_set(u32_t power);
3131
void radio_freq_chan_set(u32_t chan);
3232
void radio_whiten_iv_set(u32_t iv);

subsys/bluetooth/controller/hci/hci.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,33 @@ static void le_chan_sel_algo(struct pdu_data *pdu_data, u16_t handle,
13391339
}
13401340
#endif /* CONFIG_BLUETOOTH_CONTROLLER_CHAN_SEL_2 */
13411341

1342+
#if defined(CONFIG_BLUETOOTH_CONTROLLER_PHY)
1343+
static void le_phy_upd_complete(struct pdu_data *pdu_data, u16_t handle,
1344+
struct net_buf *buf)
1345+
{
1346+
struct bt_hci_evt_le_phy_update_complete *sep;
1347+
struct radio_le_phy_upd_cmplt *radio_le_phy_upd_cmplt;
1348+
1349+
radio_le_phy_upd_cmplt = (struct radio_le_phy_upd_cmplt *)
1350+
pdu_data->payload.lldata;
1351+
1352+
if (!(event_mask & BT_EVT_MASK_LE_META_EVENT) ||
1353+
!(le_event_mask & BT_EVT_MASK_LE_PHY_UPDATE_COMPLETE)) {
1354+
BT_WARN("handle: 0x%04x, tx: %x, rx: %x.", handle,
1355+
radio_le_phy_upd_cmplt->tx,
1356+
radio_le_phy_upd_cmplt->rx);
1357+
return;
1358+
}
1359+
1360+
sep = meta_evt(buf, BT_HCI_EVT_LE_PHY_UPDATE_COMPLETE, sizeof(*sep));
1361+
1362+
sep->status = 0x00;
1363+
sep->handle = sys_cpu_to_le16(handle);
1364+
sep->tx_phy = radio_le_phy_upd_cmplt->tx;
1365+
sep->rx_phy = radio_le_phy_upd_cmplt->rx;
1366+
}
1367+
#endif /* CONFIG_BLUETOOTH_CONTROLLER_CHAN_SEL_2 */
1368+
13421369
static void encode_control(struct radio_pdu_node_rx *node_rx,
13431370
struct pdu_data *pdu_data, struct net_buf *buf)
13441371
{
@@ -1382,6 +1409,12 @@ static void encode_control(struct radio_pdu_node_rx *node_rx,
13821409
break;
13831410
#endif /* CONFIG_BLUETOOTH_CONTROLLER_CHAN_SEL_2 */
13841411

1412+
#if defined(CONFIG_BLUETOOTH_CONTROLLER_PHY)
1413+
case NODE_RX_TYPE_PHY_UPDATE:
1414+
le_phy_upd_complete(pdu_data, handle, buf);
1415+
return;
1416+
#endif /* CONFIG_BLUETOOTH_CONTROLLER_PHY */
1417+
13851418
#if defined(CONFIG_BLUETOOTH_CONTROLLER_CONN_RSSI)
13861419
case NODE_RX_TYPE_RSSI:
13871420
BT_INFO("handle: 0x%04x, rssi: -%d dB.", handle,
@@ -1717,6 +1750,9 @@ s8_t hci_get_class(struct radio_pdu_node_rx *node_rx)
17171750
#if defined(CONFIG_BLUETOOTH_CONTROLLER_CHAN_SEL_2)
17181751
case NODE_RX_TYPE_CHAN_SEL_ALGO:
17191752
#endif
1753+
#if defined(CONFIG_BLUETOOTH_CONTROLLER_PHY)
1754+
case NODE_RX_TYPE_PHY_UPDATE:
1755+
#endif /* CONFIG_BLUETOOTH_CONTROLLER_PHY */
17201756
return HCI_CLASS_EVT_CONNECTION;
17211757
default:
17221758
return -1;

subsys/bluetooth/controller/include/ll.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,8 @@ void ll_length_max_get(u16_t *max_tx_octets, u16_t *max_tx_time,
5555
u16_t *max_rx_octets, u16_t *max_rx_time);
5656
#endif /* CONFIG_BLUETOOTH_CONTROLLER_DATA_LENGTH */
5757

58+
#if defined(CONFIG_BLUETOOTH_CONTROLLER_PHY)
59+
u32_t ll_phy_req_send(u16_t handle, u8_t tx, u8_t rx);
60+
#endif /* CONFIG_BLUETOOTH_CONTROLLER_PHY */
61+
5862
#endif /* _LL_H_ */

0 commit comments

Comments
 (0)