Skip to content

Commit 9fcd082

Browse files
cvinayakAnas Nashif
authored and
Anas Nashif
committed
Bluetooth: controller: Explicit AC and DC packet configure
In the Controller's radio hal, explicitly differentiate between Advertisement and Data channel packet configuration. Also, remove nRF5x specific extra overhead in Advertisement PDU structure. Change-id: I942b88a160af78f8900d7e49fb5f36c8aa493b97 Signed-off-by: Vinayak Chettimada <[email protected]>
1 parent 56f8af9 commit 9fcd082

File tree

5 files changed

+39
-34
lines changed

5 files changed

+39
-34
lines changed

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

+30-20
Original file line numberDiff line numberDiff line change
@@ -94,31 +94,41 @@ void radio_aa_set(u8_t *aa)
9494
NRF_RADIO->BASE0 = (aa[2] << 24) | (aa[1] << 16) | (aa[0] << 8);
9595
}
9696

97-
void radio_pkt_configure(u8_t preamble16, u8_t bits_len, u8_t max_len)
97+
void radio_pkt_configure(u8_t bits_len, u8_t max_len, u8_t flags)
9898
{
99+
u8_t p16 = (flags >> 1) & 0x01; /* 16-bit preamble */
100+
u8_t dc = flags & 0x01; /* Adv or Data channel */
101+
u32_t extra;
102+
99103
#if defined(CONFIG_SOC_SERIES_NRF51X)
100-
ARG_UNUSED(preamble16);
104+
ARG_UNUSED(p16);
105+
106+
extra = 0;
101107

102-
if (bits_len == 8) {
108+
/* nRF51 supports only 27 byte PDU when using h/w CCM for encryption. */
109+
if (dc) {
103110
bits_len = 5;
104111
}
105-
#endif
106-
107-
NRF_RADIO->PCNF0 = ((((1UL) << RADIO_PCNF0_S0LEN_Pos) &
108-
RADIO_PCNF0_S0LEN_Msk) |
109-
((((u32_t)bits_len) << RADIO_PCNF0_LFLEN_Pos) &
110-
RADIO_PCNF0_LFLEN_Msk) |
111-
#if !defined(CONFIG_SOC_SERIES_NRF51X)
112-
(((RADIO_PCNF0_S1INCL_Include) <<
113-
RADIO_PCNF0_S1INCL_Pos) &
114-
RADIO_PCNF0_S1INCL_Msk) |
115-
((((preamble16) ? RADIO_PCNF0_PLEN_16bit :
116-
RADIO_PCNF0_PLEN_8bit) << RADIO_PCNF0_PLEN_Pos) &
117-
RADIO_PCNF0_PLEN_Msk) |
118-
#endif
119-
((((u32_t)8-bits_len) <<
120-
RADIO_PCNF0_S1LEN_Pos) &
121-
RADIO_PCNF0_S1LEN_Msk));
112+
#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;
115+
116+
/* To use same Data Channel PDU structure with nRF5 specific overhead
117+
* byte, include the S1 field in radio packet configuration.
118+
*/
119+
if (dc) {
120+
extra |= (RADIO_PCNF0_S1INCL_Include <<
121+
RADIO_PCNF0_S1INCL_Pos) & RADIO_PCNF0_S1INCL_Msk;
122+
}
123+
#endif /* !CONFIG_SOC_SERIES_NRF51X */
124+
125+
NRF_RADIO->PCNF0 = (((1UL) << RADIO_PCNF0_S0LEN_Pos) &
126+
RADIO_PCNF0_S0LEN_Msk) |
127+
((((u32_t)bits_len) << RADIO_PCNF0_LFLEN_Pos) &
128+
RADIO_PCNF0_LFLEN_Msk) |
129+
((((u32_t)8-bits_len) << RADIO_PCNF0_S1LEN_Pos) &
130+
RADIO_PCNF0_S1LEN_Msk) |
131+
extra;
122132

123133
NRF_RADIO->PCNF1 = (((((u32_t)max_len) << RADIO_PCNF1_MAXLEN_Pos) &
124134
RADIO_PCNF1_MAXLEN_Msk) |

subsys/bluetooth/controller/hal/radio.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ 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);
3333
void radio_aa_set(u8_t *aa);
34-
void radio_pkt_configure(u8_t preamble16, u8_t bits_len, u8_t max_len);
34+
void radio_pkt_configure(u8_t bits_len, u8_t max_len, u8_t flags);
3535
void radio_pkt_rx_set(void *rx_packet);
3636
void radio_pkt_tx_set(void *tx_packet);
3737
void radio_rx_enable(void);

subsys/bluetooth/controller/ll_sw/ctrl.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -4309,7 +4309,7 @@ static void adv_obs_configure(u8_t phy)
43094309

43104310
adv_obs_conn_configure(phy);
43114311
radio_aa_set((u8_t *)&aa);
4312-
radio_pkt_configure(phy, 6, 37);
4312+
radio_pkt_configure(8, PDU_AC_PAYLOAD_SIZE_MAX, (phy << 1));
43134313
radio_crc_configure(((0x5bUL) | ((0x06UL) << 8) | ((0x00UL) << 16)),
43144314
0x555555);
43154315
}
@@ -6112,12 +6112,12 @@ static void rx_packet_set(struct connection *conn, struct pdu_data *pdu_data_rx)
61126112

61136113
phy = RADIO_PHY_CONN;
61146114
if (conn->enc_rx) {
6115-
radio_pkt_configure(phy, 8, (max_rx_octets + 4));
6115+
radio_pkt_configure(8, (max_rx_octets + 4), (phy << 1) | 0x01);
61166116

61176117
radio_pkt_rx_set(radio_ccm_rx_pkt_set(&conn->ccm_rx,
61186118
pdu_data_rx));
61196119
} else {
6120-
radio_pkt_configure(phy, 8, max_rx_octets);
6120+
radio_pkt_configure(8, max_rx_octets, (phy << 1) | 0x01);
61216121

61226122
radio_pkt_rx_set(pdu_data_rx);
61236123
}
@@ -6136,12 +6136,12 @@ static void tx_packet_set(struct connection *conn, struct pdu_data *pdu_data_tx)
61366136

61376137
phy = RADIO_PHY_CONN;
61386138
if (conn->enc_tx) {
6139-
radio_pkt_configure(phy, 8, (max_tx_octets + 4));
6139+
radio_pkt_configure(8, (max_tx_octets + 4), (phy << 1) | 0x01);
61406140

61416141
radio_pkt_tx_set(radio_ccm_tx_pkt_set(&conn->ccm_tx,
61426142
pdu_data_tx));
61436143
} else {
6144-
radio_pkt_configure(phy, 8, max_tx_octets);
6144+
radio_pkt_configure(8, max_tx_octets, (phy << 1) | 0x01);
61456145

61466146
radio_pkt_tx_set(pdu_data_tx);
61476147
}

subsys/bluetooth/controller/ll_sw/ll.c

-4
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ void ll_adv_params_set(u16_t interval, u8_t adv_type,
324324
pdu->len = BDADDR_SIZE;
325325
}
326326
pdu->rx_addr = _ll_adv_params.rx_addr;
327-
pdu->resv = 0;
328327

329328
/* update the current scan data */
330329
radio_adv_data = radio_scan_data_get();
@@ -337,7 +336,6 @@ void ll_adv_params_set(u16_t interval, u8_t adv_type,
337336
if (pdu->len == 0) {
338337
pdu->len = BDADDR_SIZE;
339338
}
340-
pdu->resv = 0;
341339
}
342340

343341
void ll_adv_data_set(u8_t len, u8_t const *const data)
@@ -384,7 +382,6 @@ void ll_adv_data_set(u8_t len, u8_t const *const data)
384382
memcpy(&pdu->payload.adv_ind.data[0], data, len);
385383
pdu->len = BDADDR_SIZE + len;
386384
}
387-
pdu->resv = 0;
388385

389386
/* commit the update so controller picks it. */
390387
radio_adv_data->last = last;
@@ -418,7 +415,6 @@ void ll_scan_data_set(u8_t len, u8_t const *const data)
418415
memcpy(&pdu->payload.scan_rsp.addr[0], &_ll_adv_params.adv_addr[0],
419416
BDADDR_SIZE);
420417
memcpy(&pdu->payload.scan_rsp.data[0], data, len);
421-
pdu->resv = 0;
422418

423419
/* commit the update so controller picks it. */
424420
radio_scan_data->last = last;

subsys/bluetooth/controller/ll_sw/pdu.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
/* PDU Sizes */
1414
#define PDU_EM_SIZE_MAX 3
15-
#define PDU_AC_SIZE_OVERHEAD 3
16-
#define PDU_AC_SIZE_MAX (37 + PDU_AC_SIZE_OVERHEAD)
15+
#define PDU_AC_SIZE_OVERHEAD 2
16+
#define PDU_AC_PAYLOAD_SIZE_MAX 37
17+
#define PDU_AC_SIZE_MAX (PDU_AC_PAYLOAD_SIZE_MAX + PDU_AC_SIZE_OVERHEAD)
1718

1819
struct pdu_adv_payload_adv_ind {
1920
u8_t addr[BDADDR_SIZE];
@@ -79,8 +80,6 @@ struct pdu_adv {
7980

8081
u8_t len:8;
8182

82-
u8_t resv:8; /* TODO: remove nRF specific code */
83-
8483
union {
8584
struct pdu_adv_payload_adv_ind adv_ind;
8685
struct pdu_adv_payload_direct_ind direct_ind;

0 commit comments

Comments
 (0)