Skip to content

Commit d3a1acd

Browse files
committed
nimble/ll: Compile out not enabled GAP roles
This gives some FLASH and RAM savings for applications that use only subset of GAP roles. LL features are also tuned depending on selected GAP roles. Examples of FLASH and RAM usage: BLE_ROLE_CENTRAL: 1 BLE_ROLE_PERIPHERAL: 1 BLE_ROLE_BROADCASTER: 1 BLE_ROLE_OBSERVER: 1 56122 19661 @apache-mynewt-nimble_nimble_controller.a BLE_ROLE_CENTRAL: 0 BLE_ROLE_PERIPHERAL: 1 BLE_ROLE_BROADCASTER: 1 BLE_ROLE_OBSERVER: 1 51344 19589 @apache-mynewt-nimble_nimble_controller.a BLE_ROLE_CENTRAL: 0 BLE_ROLE_PERIPHERAL: 1 BLE_ROLE_BROADCASTER: 1 BLE_ROLE_OBSERVER: 0 35694 15232 @apache-mynewt-nimble_nimble_controller.a BLE_ROLE_CENTRAL: 1 BLE_ROLE_PERIPHERAL: 0 BLE_ROLE_BROADCASTER: 1 BLE_ROLE_OBSERVER: 1 53338 19593 @apache-mynewt-nimble_nimble_controller.a BLE_ROLE_CENTRAL: 1 BLE_ROLE_PERIPHERAL: 0 BLE_ROLE_BROADCASTER: 0 BLE_ROLE_OBSERVER: 1 42040 12925 @apache-mynewt-nimble_nimble_controller.a BLE_ROLE_CENTRAL: 0 BLE_ROLE_PERIPHERAL: 0 BLE_ROLE_BROADCASTER: 1 BLE_ROLE_OBSERVER: 1 34800 12525 @apache-mynewt-nimble_nimble_controller.a BLE_ROLE_CENTRAL: 0 BLE_ROLE_PERIPHERAL: 0 BLE_ROLE_BROADCASTER: 1 BLE_ROLE_OBSERVER: 0 19126 8168 @apache-mynewt-nimble_nimble_controller.a
1 parent 8c6f704 commit d3a1acd

20 files changed

+860
-151
lines changed

nimble/controller/include/controller/ble_ll.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,13 @@ struct ble_ll_obj
108108
/* Current Link Layer state */
109109
uint8_t ll_state;
110110

111+
#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL) || MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
111112
/* Number of ACL data packets supported */
112113
uint8_t ll_num_acl_pkts;
113114

114115
/* ACL data packet size */
115116
uint16_t ll_acl_pkt_size;
117+
#endif
116118

117119
/* Preferred PHY's */
118120
uint8_t ll_pref_tx_phys;
@@ -129,14 +131,18 @@ struct ble_ll_obj
129131
struct ble_ll_pkt_q ll_rx_pkt_q;
130132

131133
/* Packet transmit queue */
134+
#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL) || MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
132135
struct ble_npl_event ll_tx_pkt_ev;
136+
#endif
133137
struct ble_ll_pkt_q ll_tx_pkt_q;
134138

139+
#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL) || MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
135140
/* Data buffer overflow event */
136141
struct ble_npl_event ll_dbuf_overflow_ev;
137142

138143
/* Number of completed packets event */
139144
struct ble_npl_event ll_comp_pkt_ev;
145+
#endif
140146

141147
/* HW error callout */
142148
struct ble_npl_callout ll_hw_err_timer;
@@ -214,12 +220,24 @@ extern STATS_SECT_DECL(ble_ll_stats) ble_ll_stats;
214220

215221
/* States */
216222
#define BLE_LL_STATE_STANDBY (0)
223+
#if MYNEWT_VAL(BLE_LL_ROLE_BROADCASTER)
217224
#define BLE_LL_STATE_ADV (1)
225+
#endif
226+
#if MYNEWT_VAL(BLE_LL_ROLE_OBSERVER)
218227
#define BLE_LL_STATE_SCANNING (2)
228+
#endif
229+
#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
219230
#define BLE_LL_STATE_CONNECTION (4)
231+
#endif
232+
#if MYNEWT_VAL(BLE_LL_DTM)
220233
#define BLE_LL_STATE_DTM (5)
234+
#endif
235+
#if MYNEWT_VAL(BLE_LL_ROLE_OBSERVER) && MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PERIODIC_ADV)
221236
#define BLE_LL_STATE_SYNC (6)
237+
#endif
238+
#if MYNEWT_VAL(BLE_LL_ROLE_OBSERVER) && MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
222239
#define BLE_LL_STATE_SCAN_AUX (7)
240+
#endif
223241

224242
/* LL Features */
225243
#define BLE_LL_FEAT_LE_ENCRYPTION (0x0000000001)

nimble/controller/include/controller/ble_ll_conn.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ extern "C" {
3434

3535
/* Roles */
3636
#define BLE_LL_CONN_ROLE_NONE (0)
37+
38+
#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
3739
#define BLE_LL_CONN_ROLE_MASTER (1)
40+
#endif
41+
#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
3842
#define BLE_LL_CONN_ROLE_SLAVE (2)
43+
#endif
3944

4045
/* Connection states */
4146
#define BLE_LL_CONN_STATE_IDLE (0)
@@ -370,8 +375,17 @@ struct ble_ll_conn_sm
370375
#define CONN_F_AUX_CONN_REQ(csm) ((csm)->csmflags.cfbit.aux_conn_req)
371376

372377
/* Role */
378+
#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
373379
#define CONN_IS_MASTER(csm) (csm->conn_role == BLE_LL_CONN_ROLE_MASTER)
380+
#else
381+
#define CONN_IS_MASTER(csm) (false)
382+
#endif
383+
384+
#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
374385
#define CONN_IS_SLAVE(csm) (csm->conn_role == BLE_LL_CONN_ROLE_SLAVE)
386+
#else
387+
#define CONN_IS_SLAVE(csm) (false)
388+
#endif
375389

376390
/*
377391
* Given a handle, returns an active connection state machine (or NULL if the

nimble/controller/include/controller/ble_ll_scan.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,18 @@ struct ble_ll_scan_sm
152152
struct ble_ll_scan_phy *scanp_next;
153153
struct ble_ll_scan_phy scan_phys[BLE_LL_SCAN_PHY_NUMBER];
154154

155+
#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
155156
/* Connection sm for initiator scan */
156157
struct ble_ll_conn_sm *connsm;
158+
#endif
157159
};
158160

159161
/* Scan types */
160162
#define BLE_SCAN_TYPE_PASSIVE (BLE_HCI_SCAN_TYPE_PASSIVE)
161163
#define BLE_SCAN_TYPE_ACTIVE (BLE_HCI_SCAN_TYPE_ACTIVE)
164+
#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
162165
#define BLE_SCAN_TYPE_INITIATE (2)
166+
#endif
163167

164168
/*---- HCI ----*/
165169
/* Set scanning parameters */
@@ -219,7 +223,11 @@ uint8_t *ble_ll_scan_get_local_rpa(void);
219223
void ble_ll_scan_sm_stop(int chk_disable);
220224

221225
/* Resume scanning */
226+
#if MYNEWT_VAL(BLE_LL_ROLE_OBSERVER)
222227
void ble_ll_scan_chk_resume(void);
228+
#else
229+
static inline void ble_ll_scan_chk_resume(void) { };
230+
#endif
223231

224232
/* Called when wait for response timer expires in scanning mode */
225233
void ble_ll_scan_wfr_timer_exp(void);

0 commit comments

Comments
 (0)