Skip to content

Commit

Permalink
nimble/ll: add BLE_LL_PHY config
Browse files Browse the repository at this point in the history
This config infers value from PHY flags and replaces BLE_LL_BT5_PHY_SUPPORTED
define.
  • Loading branch information
KKopyscinski committed Oct 23, 2023
1 parent 745b6e2 commit 18c5e74
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 64 deletions.
6 changes: 0 additions & 6 deletions nimble/controller/include/controller/ble_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ void ble_ll_assert(const char *file, unsigned line) __attribute((noreturn));
#define BLE_LL_ASSERT(cond) assert(cond)
#endif

#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_2M_PHY) || MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_CODED_PHY)
#define BLE_LL_BT5_PHY_SUPPORTED (1)
#else
#define BLE_LL_BT5_PHY_SUPPORTED (0)
#endif

/* Controller revision. */
#define BLE_LL_SUB_VERS_NR (0x0000)

Expand Down
2 changes: 1 addition & 1 deletion nimble/controller/include/controller/ble_ll_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ struct ble_ll_conn_sm
uint16_t host_req_max_rx_time;
#endif

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
struct ble_ll_conn_phy_data phy_data;
uint16_t phy_instant;
uint8_t phy_tx_transition;
Expand Down
6 changes: 3 additions & 3 deletions nimble/controller/src/ble_ll_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ ble_ll_adv_tx_start_cb(struct ble_ll_sched_item *sch)
rc = ble_phy_setchan(advsm->adv_chan, BLE_ACCESS_ADDR_ADV, BLE_LL_CRCINIT_ADV);
BLE_LL_ASSERT(rc == 0);

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
/* Set phy mode */
#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
if (advsm->props & BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY) {
Expand Down Expand Up @@ -1269,7 +1269,7 @@ ble_ll_adv_secondary_tx_start_cb(struct ble_ll_sched_item *sch)
BLE_LL_CRCINIT_ADV);
BLE_LL_ASSERT(rc == 0);

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
/* Set phy mode */
ble_phy_mode_set(advsm->sec_phy, advsm->sec_phy);
#endif
Expand Down Expand Up @@ -2264,7 +2264,7 @@ ble_ll_adv_sync_tx_start_cb(struct ble_ll_sched_item *sch)

BLE_LL_ASSERT(rc == 0);

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
/* Set phy mode */
ble_phy_mode_set(advsm->sec_phy, advsm->sec_phy);
#endif
Expand Down
38 changes: 19 additions & 19 deletions nimble/controller/src/ble_ll_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ ble_ll_conn_find_by_peer_addr(const uint8_t *addr, uint8_t addr_type)
return NULL;
}

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
static inline int
ble_ll_conn_phy_should_update(uint8_t pref_mask, uint8_t curr_mask)
{
Expand Down Expand Up @@ -1003,7 +1003,7 @@ ble_ll_conn_chk_csm_flags(struct ble_ll_conn_sm *connsm)
}

/* Check if we need to send PHY update complete event */
#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
if (connsm->flags.phy_update_host_w4event) {
if (!ble_ll_hci_ev_phy_update(connsm, BLE_ERR_SUCCESS)) {
/* Sent event. Clear flag */
Expand Down Expand Up @@ -1040,7 +1040,7 @@ ble_ll_conn_adjust_pyld_len(struct ble_ll_conn_sm *connsm, uint16_t pyld_len)
uint16_t max_pyld_len;
uint16_t ret;

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
uint8_t phy_mode;

if (connsm->phy_tx_transition) {
Expand Down Expand Up @@ -1268,7 +1268,7 @@ ble_ll_conn_tx_pdu(struct ble_ll_conn_sm *connsm)
* now. This is not the most accurate especially if we have
* received a frame and we are replying to it.
*/
#if BLE_LL_BT5_PHY_SUPPORTED
#if MYNEWT_VAL(BLE_LL_PHY)
tx_phy_mode = connsm->phy_data.tx_phy_mode;
#else
tx_phy_mode = BLE_PHY_MODE_1M;
Expand Down Expand Up @@ -1522,7 +1522,7 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch)
ble_phy_resolv_list_disable();
#endif

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
ble_phy_mode_set(connsm->phy_data.tx_phy_mode, connsm->phy_data.rx_phy_mode);
#endif

Expand Down Expand Up @@ -1659,7 +1659,7 @@ ble_ll_conn_can_send_next_pdu(struct ble_ll_conn_sm *connsm, uint32_t begtime,
uint32_t allowed_usecs;
int tx_phy_mode;

#if BLE_LL_BT5_PHY_SUPPORTED
#if MYNEWT_VAL(BLE_LL_PHY)
tx_phy_mode = connsm->phy_data.tx_phy_mode;
#else
tx_phy_mode = BLE_PHY_MODE_1M;
Expand Down Expand Up @@ -1868,7 +1868,7 @@ ble_ll_conn_set_data_len(struct ble_ll_conn_sm *connsm,
}
#endif

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))

static void
ble_ll_conn_set_phy(struct ble_ll_conn_sm *connsm, int tx_phy, int rx_phy)
Expand Down Expand Up @@ -2005,7 +2005,7 @@ ble_ll_conn_sm_new(struct ble_ll_conn_sm *connsm)
#endif

/* XXX: TODO set these based on PHY that started connection */
#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
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;
Expand Down Expand Up @@ -2136,7 +2136,7 @@ ble_ll_conn_update_eff_data_len(struct ble_ll_conn_sm *connsm)
* connection events timings.
*/
if (ota_max_rx_time_calc) {
#if BLE_LL_BT5_PHY_SUPPORTED
#if MYNEWT_VAL(BLE_LL_PHY)
phy_mode = ble_ll_phy_to_phy_mode(connsm->phy_data.cur_rx_phy,
BLE_HCI_LE_PHY_CODED_S8_PREF);
#else
Expand Down Expand Up @@ -2639,7 +2639,7 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm)
}
#endif

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
if (connsm->flags.phy_update_sched &&
(connsm->event_cntr == connsm->phy_instant)) {

Expand Down Expand Up @@ -2846,7 +2846,7 @@ ble_ll_conn_created(struct ble_ll_conn_sm *connsm, struct ble_mbuf_hdr *rxhdr)

/* Send connection complete event to inform host of connection */
if (rc) {
#if (BLE_LL_BT5_PHY_SUPPORTED == 1) && MYNEWT_VAL(BLE_LL_CONN_PHY_INIT_UPDATE)
#if (MYNEWT_VAL(BLE_LL_PHY)) && MYNEWT_VAL(BLE_LL_CONN_PHY_INIT_UPDATE)
/*
* If we have default phy preferences and they are different than
* the current PHY's in use, start update procedure.
Expand Down Expand Up @@ -3216,7 +3216,7 @@ ble_ll_conn_send_connect_req(struct os_mbuf *rxpdu,

#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
if (ext) {
#if BLE_LL_BT5_PHY_SUPPORTED
#if MYNEWT_VAL(BLE_LL_PHY)
phy = rxhdr->rxinfo.phy;
#else
phy = BLE_PHY_1M;
Expand All @@ -3240,7 +3240,7 @@ ble_ll_conn_send_connect_req(struct os_mbuf *rxpdu,
return -1;
}

#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV) && BLE_LL_BT5_PHY_SUPPORTED
#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV) && MYNEWT_VAL(BLE_LL_PHY)
if (ext) {
ble_ll_conn_init_phy(connsm, phy);
}
Expand Down Expand Up @@ -3288,7 +3288,7 @@ ble_ll_conn_central_start(uint8_t phy, uint8_t csa,
#endif

ble_ll_conn_set_csa(connsm, csa);
#if BLE_LL_BT5_PHY_SUPPORTED
#if MYNEWT_VAL(BLE_LL_PHY)
ble_ll_conn_init_phy(connsm, phy);
#endif
ble_ll_conn_created(connsm, NULL);
Expand Down Expand Up @@ -3316,12 +3316,12 @@ ble_ll_conn_created_on_aux(struct os_mbuf *rxpdu,
struct ble_ll_scan_addr_data *addrd,
uint8_t *targeta)
{
#if BLE_LL_BT5_PHY_SUPPORTED
#if MYNEWT_VAL(BLE_LL_PHY)
struct ble_mbuf_hdr *rxhdr;
#endif
uint8_t phy;

#if BLE_LL_BT5_PHY_SUPPORTED
#if MYNEWT_VAL(BLE_LL_PHY)
rxhdr = BLE_MBUF_HDR_PTR(rxpdu);
phy = rxhdr->rxinfo.phy;
#else
Expand Down Expand Up @@ -3698,7 +3698,7 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
* to the 'additional usecs' field to save some calculations.
*/
begtime = rxhdr->beg_cputime;
#if BLE_LL_BT5_PHY_SUPPORTED
#if MYNEWT_VAL(BLE_LL_PHY)
rx_phy_mode = connsm->phy_data.rx_phy_mode;
#else
rx_phy_mode = BLE_PHY_MODE_1M;
Expand Down Expand Up @@ -3834,7 +3834,7 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
rem_bytes = OS_MBUF_PKTLEN(txpdu) - txhdr->txinfo.offset;
/* Adjust payload for max TX time and octets */

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
if (BLE_LL_LLID_IS_CTRL(hdr_byte) &&
CONN_IS_PERIPHERAL(connsm) &&
(opcode == BLE_LL_CTRL_PHY_UPDATE_IND)) {
Expand Down Expand Up @@ -4167,7 +4167,7 @@ ble_ll_conn_periph_start(uint8_t *rxbuf, uint8_t pat, struct ble_mbuf_hdr *rxhdr
connsm->conn_role = BLE_LL_CONN_ROLE_PERIPHERAL;
ble_ll_conn_sm_new(connsm);

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
/* Use the same PHY as we received CONNECT_REQ on */
ble_ll_conn_init_phy(connsm, rxhdr->rxinfo.phy);
#endif
Expand Down
2 changes: 1 addition & 1 deletion nimble/controller/src/ble_ll_conn_hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,7 @@ ble_ll_conn_hci_wr_auth_pyld_tmo(const uint8_t *cmdbuf, uint8_t len,
}
#endif

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
/**
* Read current phy for connection (OGF=8, OCF==0x0030)
*
Expand Down
14 changes: 7 additions & 7 deletions nimble/controller/src/ble_ll_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ ble_ll_ctrl_rej_ext_ind_make(uint8_t rej_opcode, uint8_t err, uint8_t *ctrdata)
ctrdata[1] = err;
}

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
/**
* Called to cancel a phy update procedure.
*
Expand Down Expand Up @@ -546,7 +546,7 @@ ble_ll_ctrl_proc_unk_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr, uint8_t *
ctrl_proc = BLE_LL_CTRL_PROC_LE_PING;
BLE_LL_CONN_CLEAR_FEATURE(connsm, BLE_LL_FEAT_LE_PING);
break;
#if (BLE_LL_BT5_PHY_SUPPORTED ==1)
#if (MYNEWT_VAL(BLE_LL_PHY))
case BLE_LL_CTRL_PHY_REQ:
ble_ll_ctrl_phy_update_cancel(connsm, BLE_ERR_UNSUPP_REM_FEATURE);
ctrl_proc = BLE_LL_CTRL_PROC_PHY_UPDATE;
Expand Down Expand Up @@ -656,7 +656,7 @@ ble_ll_ctrl_phy_from_phy_mask(uint8_t phy_mask)
return phy;
}

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
uint8_t
ble_ll_ctrl_phy_tx_transition_get(uint8_t phy_mask)
{
Expand Down Expand Up @@ -1970,7 +1970,7 @@ ble_ll_ctrl_rx_reject_ind(struct ble_ll_conn_sm *connsm, uint8_t *dptr,
connsm->enc_data.enc_state = CONN_ENC_S_UNENCRYPTED;
break;
#endif
#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
case BLE_LL_CTRL_PROC_PHY_UPDATE:
ble_ll_ctrl_phy_update_cancel(connsm, ble_error);
ble_ll_ctrl_proc_stop(connsm, BLE_LL_CTRL_PROC_PHY_UPDATE);
Expand Down Expand Up @@ -2502,7 +2502,7 @@ ble_ll_ctrl_proc_init(struct ble_ll_conn_sm *connsm, int ctrl_proc, void *data)
}
break;
#endif
#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
case BLE_LL_CTRL_PROC_PHY_UPDATE:
opcode = BLE_LL_CTRL_PHY_REQ;
ble_ll_ctrl_phy_req_rsp_make(connsm, ctrdata);
Expand Down Expand Up @@ -2957,7 +2957,7 @@ ble_ll_ctrl_rx_pdu(struct ble_ll_conn_sm *connsm, struct os_mbuf *om)
/* Sometimes reject triggers sending other LL CTRL msg */
rsp_opcode = ble_ll_ctrl_rx_reject_ind(connsm, dptr, opcode, rspdata);
break;
#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
case BLE_LL_CTRL_PHY_REQ:
rsp_opcode = ble_ll_ctrl_rx_phy_req(connsm, dptr, rspdata);
break;
Expand Down Expand Up @@ -3177,7 +3177,7 @@ ble_ll_ctrl_tx_done(struct os_mbuf *txpdu, struct ble_ll_conn_sm *connsm)
break;
#endif
#endif
#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
case BLE_LL_CTRL_PHY_REQ:
if (connsm->conn_role == BLE_LL_CONN_ROLE_PERIPHERAL) {
Expand Down
4 changes: 2 additions & 2 deletions nimble/controller/src/ble_ll_hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ ble_ll_hci_le_read_bufsize_v2(uint8_t *rspbuf, uint8_t *rsplen)
}
#endif

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
/**
* Checks the preferred phy masks for validity and places the preferred masks
* in the input phy masks
Expand Down Expand Up @@ -1110,7 +1110,7 @@ ble_ll_hci_le_cmd_proc(const uint8_t *cmdbuf, uint8_t len, uint16_t ocf,
}
break;
#endif
#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
case BLE_HCI_OCF_LE_RD_PHY:
rc = ble_ll_conn_hci_le_rd_phy(cmdbuf, len, rspbuf, rsplen);
Expand Down
2 changes: 1 addition & 1 deletion nimble/controller/src/ble_ll_hci_ev.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ ble_ll_hci_ev_send_adv_set_terminated(uint8_t status, uint8_t adv_handle,
* @param connsm Pointer to connection state machine
* @param status error status of event
*/
#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
int
ble_ll_hci_ev_phy_update(struct ble_ll_conn_sm *connsm, uint8_t status)
{
Expand Down
2 changes: 1 addition & 1 deletion nimble/controller/src/ble_ll_hci_supp_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static const uint8_t octet_35 = OCTET(
BIT(2) /* HCI LE Set Resolvable Private Address Timeout */
#endif
BIT(3) /* HCI LE Read Maximum Data Length */
#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
BIT(4) /* HCI LE Read PHY */
BIT(5) /* HCI LE Set Default PHY */
Expand Down
4 changes: 2 additions & 2 deletions nimble/controller/src/ble_ll_iso_big.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ ble_ll_iso_big_event_sched_cb(struct ble_ll_sched_item *sch)
{
struct ble_ll_iso_big *big;
struct ble_ll_iso_bis *bis;
#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
uint8_t phy_mode;
#endif
int rc;
Expand All @@ -755,7 +755,7 @@ ble_ll_iso_big_event_sched_cb(struct ble_ll_sched_item *sch)
#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
ble_phy_resolv_list_disable();
#endif
#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
phy_mode = ble_ll_phy_to_phy_mode(big->phy, 0);
ble_phy_mode_set(phy_mode, phy_mode);
#endif
Expand Down
4 changes: 2 additions & 2 deletions nimble/controller/src/ble_ll_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ ble_ll_scan_start(struct ble_ll_scan_sm *scansm)
int rc;
struct ble_ll_scan_phy *scanp = scansm->scanp;
uint8_t chan;
#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
uint8_t phy_mode;
int phy;
#endif
Expand Down Expand Up @@ -779,7 +779,7 @@ ble_ll_scan_start(struct ble_ll_scan_sm *scansm)
}
#endif

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
phy = scanp->phy;
phy_mode = ble_ll_phy_to_phy_mode(phy, BLE_HCI_LE_PHY_CODED_ANY);
ble_phy_mode_set(phy_mode, phy_mode);
Expand Down
4 changes: 2 additions & 2 deletions nimble/controller/src/ble_ll_scan_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static int
ble_ll_scan_aux_sched_cb(struct ble_ll_sched_item *sch)
{
struct ble_ll_scan_aux_data *aux = sch->cb_arg;
#if BLE_LL_BT5_PHY_SUPPORTED
#if MYNEWT_VAL(BLE_LL_PHY)
uint8_t phy_mode;
#endif
uint8_t lls;
Expand All @@ -137,7 +137,7 @@ ble_ll_scan_aux_sched_cb(struct ble_ll_sched_item *sch)
}
#endif

#if BLE_LL_BT5_PHY_SUPPORTED
#if MYNEWT_VAL(BLE_LL_PHY)
phy_mode = ble_ll_phy_to_phy_mode(aux->sec_phy, BLE_HCI_LE_PHY_CODED_ANY);
ble_phy_mode_set(phy_mode, phy_mode);
#endif
Expand Down
4 changes: 2 additions & 2 deletions nimble/controller/src/ble_ll_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ ble_ll_sync_sm_clear(struct ble_ll_sync_sm *sm)
static uint8_t
ble_ll_sync_phy_mode_to_hci(int8_t phy_mode)
{
#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
switch (phy_mode) {
case BLE_PHY_MODE_1M:
return BLE_HCI_LE_PHY_1M;
Expand Down Expand Up @@ -475,7 +475,7 @@ ble_ll_sync_event_start_cb(struct ble_ll_sched_item *sch)
ble_phy_encrypt_disable();
#endif

#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
#if (MYNEWT_VAL(BLE_LL_PHY))
ble_phy_mode_set(sm->phy_mode, sm->phy_mode);
#endif

Expand Down
Loading

0 comments on commit 18c5e74

Please sign in to comment.