Skip to content

Commit da064c7

Browse files
committed
DRAFT: Bluetooth: controller: PHY Update
Add support for Bluetooth v5.0 PHY Update Procedure. Jira: ZEP-2086 Signed-off-by: Vinayak Chettimada <[email protected]>
1 parent ed5569f commit da064c7

File tree

6 files changed

+345
-50
lines changed

6 files changed

+345
-50
lines changed

subsys/bluetooth/controller/Kconfig

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

124+
config BLUETOOTH_CONTROLLER_PHY
125+
bool "PHY Update"
126+
default y
127+
help
128+
Enable support for Bluetooth 5.0 PHY Update Procedure in the
129+
Controller.
130+
124131
config BLUETOOTH_CONTROLLER_ADVANCED_FEATURES
125132
bool "Show advanced features"
126133
help
@@ -202,6 +209,7 @@ config BLUETOOTH_CONTROLLER_SCHED_ADVANCED
202209

203210
config BLUETOOTH_CONTROLLER_TIFS_HW
204211
bool "H/w Accelerated tIFS Trx switching"
212+
depends on !BLUETOOTH_CONTROLLER_PHY
205213
default y
206214
help
207215
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);

0 commit comments

Comments
 (0)