Repository: incubator-mynewt-core Updated Branches: refs/heads/develop fc3116a91 -> 27a3fd47f
MYNEWT-96: Moved LL configuration items out of controller code into nimble_opt.h. This also caused the LL init API to change which is why the main C modules were modified in some of the apps Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/27a3fd47 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/27a3fd47 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/27a3fd47 Branch: refs/heads/develop Commit: 27a3fd47f30bb45d042ca734f1d875fa8b827cfa Parents: fc3116a Author: wes3 <w...@micosa.io> Authored: Mon Mar 14 16:31:45 2016 -0700 Committer: wes3 <w...@micosa.io> Committed: Mon Mar 14 16:32:03 2016 -0700 ---------------------------------------------------------------------- apps/bleprph/src/main.c | 2 +- apps/bletest/src/main.c | 32 ++++--- apps/bletiny/src/main.c | 3 +- .../controller/include/controller/ble_ll.h | 29 +++---- .../controller/include/controller/ble_ll_hci.h | 11 --- .../controller/include/controller/ble_ll_scan.h | 18 ---- .../include/controller/ble_ll_whitelist.h | 2 - net/nimble/controller/src/ble_ll.c | 6 +- net/nimble/controller/src/ble_ll_conn.c | 48 +++++------ net/nimble/controller/src/ble_ll_conn_hci.c | 10 +-- net/nimble/controller/src/ble_ll_ctrl.c | 3 +- net/nimble/controller/src/ble_ll_hci.c | 7 +- net/nimble/controller/src/ble_ll_scan.c | 19 ++++- net/nimble/controller/src/ble_ll_whitelist.c | 12 +-- net/nimble/include/nimble/nimble_opt.h | 89 +++++++++++++++++++- 15 files changed, 181 insertions(+), 110 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27a3fd47/apps/bleprph/src/main.c ---------------------------------------------------------------------- diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c index a67d4e1..b9e2d6d 100755 --- a/apps/bleprph/src/main.c +++ b/apps/bleprph/src/main.c @@ -269,7 +269,7 @@ main(void) bleprph_stack, BLEPRPH_STACK_SIZE); /* Initialize the BLE LL */ - rc = ble_ll_init(BLE_LL_TASK_PRI); + rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE); assert(rc == 0); /* Initialize the BLE host. */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27a3fd47/apps/bletest/src/main.c ---------------------------------------------------------------------- diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c index aa0578b..fe017d0 100755 --- a/apps/bletest/src/main.c +++ b/apps/bletest/src/main.c @@ -111,7 +111,11 @@ os_membuf_t g_mbuf_buffer[MBUF_MEMPOOL_SIZE]; #define BLETEST_CFG_MAX_CE_LEN (BLETEST_CFG_CONN_ITVL) #define BLETEST_CFG_CONN_PEER_ADDR_TYPE (BLE_HCI_CONN_PEER_ADDR_PUBLIC) #define BLETEST_CFG_CONN_OWN_ADDR_TYPE (BLE_HCI_ADV_OWN_ADDR_PUBLIC) -#define BLETEST_CFG_CONCURRENT_CONNS (16) +#define BLETEST_CFG_CONCURRENT_CONNS (1) + +/* Test configurations. One of these should be set to 1 */ +#define BLETEST_CONCURRENT_CONN_TEST (1) +#define BLETEST_THROUGHPUT_TEST (0) /* BLETEST variables */ #undef BLETEST_ADV_PKT_NUM @@ -511,13 +515,17 @@ static void bletest_execute_advertiser(void) { int i; +#if (BLETEST_CONCURRENT_CONN_TEST == 1) int j; +#endif int rc; - //os_sr_t sr; uint16_t handle; uint16_t pktlen; - //uint16_t completed_pkts; struct os_mbuf *om; +#if (BLETEST_THROUGHPUT_TEST == 1) + os_sr_t sr; + uint16_t completed_pkts; +#endif /* See if we should start advertising again */ if (g_bletest_current_conns < BLETEST_CFG_CONCURRENT_CONNS) { @@ -526,7 +534,7 @@ bletest_execute_advertiser(void) /* Set LED to slower blink rate */ g_bletest_led_rate = OS_TICKS_PER_SEC; -#if 0 +#if (BLETEST_THROUGHPUT_TEST == 1) /* Set next os time to 10 seconds after 1st connection */ if (g_next_os_time == 0) { g_next_os_time = os_time_get() + (10 * OS_TICKS_PER_SEC); @@ -577,6 +585,8 @@ bletest_execute_advertiser(void) } } #endif + +#if (BLETEST_CONCURRENT_CONN_TEST == 1) /* See if it is time to hand a data packet to the connection */ if ((int32_t)(os_time_get() - g_next_os_time) >= 0) { if (g_bletest_current_conns) { @@ -622,8 +632,9 @@ bletest_execute_advertiser(void) } g_next_os_time = os_time_get() + OS_TICKS_PER_SEC/4; } +#endif -#if 0 /* XXX: throughput test */ +#if (BLETEST_THROUGHPUT_TEST == 1) /* Nothing to do if no connections */ if (!g_bletest_current_conns) { return; @@ -641,7 +652,7 @@ bletest_execute_advertiser(void) assert(g_bletest_outstanding_pkts >= completed_pkts); g_bletest_outstanding_pkts -= completed_pkts; - while (g_bletest_outstanding_pkts < 8) { + while (g_bletest_outstanding_pkts < 20) { om = bletest_get_packet(); if (om) { /* set payload length */ @@ -659,8 +670,8 @@ bletest_execute_advertiser(void) om->om_len += 4; /* Fill with incrementing pattern (starting from 1) */ - for (j = 0; j < pktlen; ++j) { - om->om_data[8 + j] = (uint8_t)(j + 1); + for (i = 0; i < pktlen; ++i) { + om->om_data[8 + i] = (uint8_t)(i + 1); } /* Add length */ @@ -783,9 +794,8 @@ bletest_task_handler(void *arg) /* Wait some time before starting */ os_time_delay(OS_TICKS_PER_SEC); - /* Init bletest variables */ + /* Init state */ g_bletest_state = 0; - g_next_os_time = os_time_get(); /* Begin advertising if we are an advertiser */ #if (BLETEST_CFG_ROLE == BLETEST_ROLE_ADVERTISER) @@ -833,7 +843,7 @@ init_tasks(void) assert(rc == 0); /* Initialize the BLE LL */ - rc = ble_ll_init(BLE_LL_TASK_PRI); + rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE); assert(rc == 0); return 0; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27a3fd47/apps/bletiny/src/main.c ---------------------------------------------------------------------- diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c index 99cfca6..7e92e0e 100755 --- a/apps/bletiny/src/main.c +++ b/apps/bletiny/src/main.c @@ -1444,7 +1444,8 @@ main(void) assert(rc == 0); /* Initialize the BLE LL */ - ble_ll_init(BLE_LL_TASK_PRI); + rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE); + assert(rc == 0); rc = cmd_init(); assert(rc == 0); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27a3fd47/net/nimble/controller/include/controller/ble_ll.h ---------------------------------------------------------------------- diff --git a/net/nimble/controller/include/controller/ble_ll.h b/net/nimble/controller/include/controller/ble_ll.h index 8c04be5..d520427 100644 --- a/net/nimble/controller/include/controller/ble_ll.h +++ b/net/nimble/controller/include/controller/ble_ll.h @@ -25,7 +25,6 @@ /* Controller revision. */ #define BLE_LL_SUB_VERS_NR (0x0000) -#define BLE_LL_MFRG_ID (0xFFFF) /* XXX: replace with real one */ /* * The amount of time that we will wait to hear the start of a receive @@ -54,6 +53,14 @@ struct ble_ll_obj /* Supported features */ uint8_t ll_supp_features; + /* Number of ACL data packets supported */ + uint8_t ll_num_acl_pkts; + uint8_t _pad; + + /* ACL data packet size */ + uint16_t ll_acl_pkt_size; + uint16_t _pad16; + /* Task event queue */ struct os_eventq ll_evq; @@ -132,25 +139,14 @@ extern STATS_SECT_DECL(ble_ll_stats) ble_ll_stats; #define BLE_LL_FEAT_EXT_SCAN_FILT (0x80) /* LL timing */ -#define BLE_LL_IFS (150) /* usecs */ -#define BLE_CLOCK_DRIFT_ACTIVE (50) /* +/- ppm */ -#define BLE_CLOCK_DRIFT_SLEEP (500) /* +/- ppm */ - -/* - * Link Layer processing delay. This number is simply made up for now. We - * use it to insure that we have enough time to do some processing before - * the LL needs to do something. I made it one IFS time for now. It is used: - * -> When determining how much time we leave before the end of a connection - * event. - */ -#define BLE_LL_PROC_DELAY (150) +#define BLE_LL_IFS (150) /* usecs */ /* * BLE LL device address. Note that element 0 of the array is the LSB and * is sent over the air first. Byte 5 is the MSB and is the last one sent over * the air. */ -#define BLE_DEV_ADDR_LEN (6) /* bytes */ +#define BLE_DEV_ADDR_LEN (6) /* bytes */ struct ble_dev_addr { @@ -227,8 +223,6 @@ struct ble_dev_addr #define BLE_ADV_PDU_HDR_TXADD_RAND (0x40) #define BLE_ADV_PDU_HDR_RXADD_RAND (0x80) -/* Max length */ -#define BLE_LL_MAX_ADV_PYLD (37) /* * Data Channel format * @@ -287,7 +281,8 @@ struct ble_dev_addr /*--- External API ---*/ /* Initialize the Link Layer */ -int ble_ll_init(uint8_t ll_task_prio); +int +ble_ll_init(uint8_t ll_task_prio, uint8_t num_acl_pkts, uint16_t acl_pkt_size); /* Reset the Link Layer */ int ble_ll_reset(void); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27a3fd47/net/nimble/controller/include/controller/ble_ll_hci.h ---------------------------------------------------------------------- diff --git a/net/nimble/controller/include/controller/ble_ll_hci.h b/net/nimble/controller/include/controller/ble_ll_hci.h index 60b2956..3e1558f 100644 --- a/net/nimble/controller/include/controller/ble_ll_hci.h +++ b/net/nimble/controller/include/controller/ble_ll_hci.h @@ -20,23 +20,12 @@ #ifndef H_BLE_LL_HCI_ #define H_BLE_LL_HCI_ -/* Define the number of data packets that the controller can store */ -#define BLE_LL_CFG_NUM_ACL_DATA_PKTS (4) -#define BLE_LL_CFG_ACL_DATA_PKT_LEN (251) - /* * This determines the number of outstanding commands allowed from the * host to the controller. */ #define BLE_LL_CFG_NUM_HCI_CMD_PKTS (1) -/* - * Determines the maximum rate at which the controller will send the - * number of completed packets event to the host. This number is in - * milliseconds. - */ -#define BLE_LL_CFG_NUM_COMP_PKT_RATE (2000) /* msecs */ - /* Initialize LL HCI */ void ble_ll_hci_init(void); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27a3fd47/net/nimble/controller/include/controller/ble_ll_scan.h ---------------------------------------------------------------------- diff --git a/net/nimble/controller/include/controller/ble_ll_scan.h b/net/nimble/controller/include/controller/ble_ll_scan.h index 5e3632b..6967a1a 100644 --- a/net/nimble/controller/include/controller/ble_ll_scan.h +++ b/net/nimble/controller/include/controller/ble_ll_scan.h @@ -23,21 +23,6 @@ #include "controller/ble_ll_sched.h" #include "hal/hal_cputime.h" -/* - * Configuration items for the number of duplicate advertisers and the - * number of advertisers from which we have heard a scan response - */ -#define BLE_LL_SCAN_CFG_NUM_DUP_ADVS (8) -#define BLE_LL_SCAN_CFG_NUM_SCAN_RSP_ADVS (8) - -/* Dont allow more than 255 of these entries */ -#if BLE_LL_SCAN_CFG_NUM_DUP_ADVS > 255 - #error "Cannot have more than 255 duplicate entries!" -#endif -#if BLE_LL_SCAN_CFG_NUM_SCAN_RSP_ADVS > 255 - #error "Cannot have more than 255 scan response entries!" -#endif - /* * SCAN_REQ * -> ScanA (6 bytes) @@ -50,7 +35,6 @@ * state. The advertising address is the intended recipient of this frame. */ #define BLE_SCAN_REQ_LEN (12) -#define BLE_SCAN_REQ_TXTIME_USECS (176) /* * SCAN_RSP @@ -64,8 +48,6 @@ * scanning state. */ #define BLE_SCAN_RSP_DATA_MAX_LEN (31) -#define BLE_SCAN_RSP_MIN_LEN (6) -#define BLE_SCAN_RSP_MAX_LEN (6 + BLE_SCAN_RSP_DATA_MAX_LEN) /* Scanning state machine (used when initiating as well) */ struct ble_ll_scan_sm http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27a3fd47/net/nimble/controller/include/controller/ble_ll_whitelist.h ---------------------------------------------------------------------- diff --git a/net/nimble/controller/include/controller/ble_ll_whitelist.h b/net/nimble/controller/include/controller/ble_ll_whitelist.h index e460ba3..f8f4331 100644 --- a/net/nimble/controller/include/controller/ble_ll_whitelist.h +++ b/net/nimble/controller/include/controller/ble_ll_whitelist.h @@ -20,8 +20,6 @@ #ifndef H_BLE_LL_WHITELIST_ #define H_BLE_LL_WHITELIST_ -#define BLE_LL_CFG_WHITELIST_SIZE (8) - /* Clear the whitelist */ int ble_ll_whitelist_clear(void); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27a3fd47/net/nimble/controller/src/ble_ll.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll.c b/net/nimble/controller/src/ble_ll.c index 54bf2d1..36ec6ab 100644 --- a/net/nimble/controller/src/ble_ll.c +++ b/net/nimble/controller/src/ble_ll.c @@ -953,7 +953,7 @@ ble_ll_reset(void) * @return int */ int -ble_ll_init(uint8_t ll_task_prio) +ble_ll_init(uint8_t ll_task_prio, uint8_t num_acl_pkts, uint16_t acl_pkt_size) { int rc; uint8_t features; @@ -962,6 +962,10 @@ ble_ll_init(uint8_t ll_task_prio) /* Get pointer to global data object */ lldata = &g_ble_ll_data; + /* Set acl pkt size and number */ + lldata->ll_num_acl_pkts = num_acl_pkts; + lldata->ll_acl_pkt_size = acl_pkt_size; + /* Initialize eventq */ os_eventq_init(&lldata->ll_evq); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27a3fd47/net/nimble/controller/src/ble_ll_conn.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_conn.c b/net/nimble/controller/src/ble_ll_conn.c index e3a38d0..79a0450 100644 --- a/net/nimble/controller/src/ble_ll_conn.c +++ b/net/nimble/controller/src/ble_ll_conn.c @@ -36,6 +36,10 @@ #include "hal/hal_cputime.h" #include "hal/hal_gpio.h" +#if (BLETEST_THROUGHPUT_TEST == 1) +extern void bletest_completed_pkt(uint16_t handle); +#endif + /* XXX TODO * 1) I think if we are initiating and we already have a connection with * a device that we will still try and connect to it. Fix this. @@ -109,23 +113,11 @@ extern int ble_hs_rx_data(struct os_mbuf *om); */ #define BLE_LL_WFR_USECS (BLE_LL_IFS + 40 + 32) -/* Configuration parameters */ -#define BLE_LL_CFG_CONN_TX_WIN_SIZE (1) -#define BLE_LL_CFG_CONN_TX_WIN_OFF (0) -#define BLE_LL_CFG_CONN_MASTER_SCA (BLE_MASTER_SCA_51_75_PPM << 5) -#define BLE_LL_CFG_CONN_OUR_SCA (60) /* in ppm */ -#define BLE_LL_CFG_CONN_INIT_SLOTS (2) - /* We cannot have more than 254 connections given our current implementation */ #if (NIMBLE_OPT_MAX_CONNECTIONS >= 255) #error "Maximum # of connections is 254" #endif -/* LL configuration definitions */ -#define BLE_LL_CFG_SUPP_MAX_RX_BYTES (251) -#define BLE_LL_CFG_SUPP_MAX_TX_BYTES (251) -#define BLE_LL_CFG_CONN_INIT_MAX_TX_BYTES (251) - /* Sleep clock accuracy table (in ppm) */ static const uint16_t g_ble_sca_ppm_tbl[8] = { @@ -359,7 +351,7 @@ ble_ll_conn_calc_window_widening(struct ble_ll_conn_sm *connsm) if (time_since_last_anchor > 0) { delta_msec = cputime_ticks_to_usecs(time_since_last_anchor) / 1000; total_sca_ppm = g_ble_sca_ppm_tbl[connsm->master_sca] + - BLE_LL_CFG_CONN_OUR_SCA; + NIMBLE_OPT_LL_OUR_SCA; window_widening = (total_sca_ppm * delta_msec) / 1000; } @@ -1021,9 +1013,9 @@ ble_ll_conn_master_init(struct ble_ll_conn_sm *connsm, connsm->conn_role = BLE_LL_CONN_ROLE_MASTER; /* Set default ce parameters */ - connsm->tx_win_size = BLE_LL_CFG_CONN_TX_WIN_SIZE; - connsm->tx_win_off = BLE_LL_CFG_CONN_TX_WIN_OFF; - connsm->master_sca = BLE_LL_CFG_CONN_MASTER_SCA; + connsm->tx_win_size = BLE_LL_CONN_TX_WIN_MIN; + connsm->tx_win_off = 0; + connsm->master_sca = NIMBLE_OPT_LL_MASTER_SCA; /* Hop increment is a random value between 5 and 16. */ connsm->hop_inc = (rand() % 12) + 5; @@ -1425,7 +1417,7 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm) * Calculate ce end time. For a slave, we need to add window widening and * the transmit window if we still have one. */ - itvl = BLE_LL_CFG_CONN_INIT_SLOTS * BLE_LL_SCHED_USECS_PER_SLOT; + itvl = NIMBLE_OPT_LL_CONN_INIT_SLOTS * BLE_LL_SCHED_USECS_PER_SLOT; if (connsm->conn_role == BLE_LL_CONN_ROLE_SLAVE) { cur_ww = ble_ll_conn_calc_window_widening(connsm); max_ww = (connsm->conn_itvl * (BLE_LL_CONN_ITVL_USECS/2)) - BLE_LL_IFS; @@ -1489,8 +1481,8 @@ ble_ll_conn_created(struct ble_ll_conn_sm *connsm, uint32_t endtime) connsm->tx_win_size * BLE_LL_CONN_TX_WIN_USECS; usecs = 1250 + (connsm->tx_win_off * BLE_LL_CONN_TX_WIN_USECS); connsm->anchor_point = endtime + cputime_usecs_to_ticks(usecs); - usecs = connsm->slave_cur_tx_win_usecs + (BLE_LL_CFG_CONN_INIT_SLOTS * - BLE_LL_SCHED_USECS_PER_SLOT); + usecs = connsm->slave_cur_tx_win_usecs + + (NIMBLE_OPT_LL_CONN_INIT_SLOTS * BLE_LL_SCHED_USECS_PER_SLOT); connsm->ce_end_time = connsm->anchor_point + cputime_usecs_to_ticks(usecs); connsm->slave_cur_window_widening = 0; @@ -1859,7 +1851,7 @@ ble_ll_init_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) /* Attempt to schedule new connection. Possible that this might fail */ if (!ble_ll_sched_master_new(g_ble_ll_conn_create_sm, ble_hdr->end_cputime, - BLE_LL_CFG_CONN_INIT_SLOTS)) { + NIMBLE_OPT_LL_CONN_INIT_SLOTS)) { /* Setup to transmit the connect request */ rc = ble_ll_conn_request_send(addr_type, adv_addr, g_ble_ll_conn_create_sm->tx_win_off); @@ -2206,6 +2198,10 @@ ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu, uint32_t aa) /* If l2cap pdu, increment # of completed packets */ if (ble_ll_conn_is_l2cap_pdu(txhdr)) { +#if (BLETEST_THROUGHPUT_TEST == 1) + bletest_completed_pkt(connsm->conn_handle); +#endif + ++connsm->completed_pkts; } os_mbuf_free_chain(txpdu); @@ -2545,17 +2541,17 @@ ble_ll_conn_module_reset(void) /* Configure the global LL parameters */ conn_params = &g_ble_ll_conn_params; - maxbytes = BLE_LL_CFG_SUPP_MAX_RX_BYTES + BLE_LL_DATA_MIC_LEN; + maxbytes = NIMBLE_OPT_LL_SUPP_MAX_RX_BYTES + BLE_LL_DATA_MIC_LEN; conn_params->supp_max_rx_time = BLE_TX_DUR_USECS_M(maxbytes); - conn_params->supp_max_rx_octets = BLE_LL_CFG_SUPP_MAX_RX_BYTES; + conn_params->supp_max_rx_octets = NIMBLE_OPT_LL_SUPP_MAX_RX_BYTES; - maxbytes = BLE_LL_CFG_SUPP_MAX_TX_BYTES + BLE_LL_DATA_MIC_LEN; + maxbytes = NIMBLE_OPT_LL_SUPP_MAX_TX_BYTES + BLE_LL_DATA_MIC_LEN; conn_params->supp_max_tx_time = BLE_TX_DUR_USECS_M(maxbytes); - conn_params->supp_max_tx_octets = BLE_LL_CFG_SUPP_MAX_TX_BYTES; + conn_params->supp_max_tx_octets = NIMBLE_OPT_LL_SUPP_MAX_TX_BYTES; - maxbytes = BLE_LL_CFG_CONN_INIT_MAX_TX_BYTES + BLE_LL_DATA_MIC_LEN; + maxbytes = NIMBLE_OPT_LL_CONN_INIT_MAX_TX_BYTES + BLE_LL_DATA_MIC_LEN; conn_params->conn_init_max_tx_time = BLE_TX_DUR_USECS_M(maxbytes); - conn_params->conn_init_max_tx_octets = BLE_LL_CFG_CONN_INIT_MAX_TX_BYTES; + conn_params->conn_init_max_tx_octets = NIMBLE_OPT_LL_CONN_INIT_MAX_TX_BYTES; /* Mask in all channels by default */ conn_params->num_used_chans = BLE_PHY_NUM_DATA_CHANS; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27a3fd47/net/nimble/controller/src/ble_ll_conn_hci.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_conn_hci.c b/net/nimble/controller/src/ble_ll_conn_hci.c index 4b86403..9b9cefd 100644 --- a/net/nimble/controller/src/ble_ll_conn_hci.c +++ b/net/nimble/controller/src/ble_ll_conn_hci.c @@ -23,6 +23,7 @@ #include "bsp/bsp.h" #include "os/os.h" #include "nimble/ble.h" +#include "nimble/nimble_opt.h" #include "nimble/hci_common.h" #include "controller/ble_ll.h" #include "controller/ble_ll_hci.h" @@ -37,9 +38,6 @@ */ static uint32_t g_ble_ll_next_num_comp_pkt_evt; -#define BLE_LL_NUM_COMP_PKT_RATE \ - ((BLE_LL_CFG_NUM_COMP_PKT_RATE * OS_TICKS_PER_SEC) / 1000) - /** * Called to check that the connection parameters are within range * @@ -133,7 +131,7 @@ ble_ll_conn_req_pdu_make(struct ble_ll_conn_sm *connsm) htole16(dptr + 12, connsm->slave_latency); htole16(dptr + 14, connsm->supervision_tmo); memcpy(dptr + 16, &connsm->chanmap, BLE_LL_CONN_CHMAP_LEN); - dptr[21] = connsm->hop_inc | connsm->master_sca; + dptr[21] = connsm->hop_inc | (connsm->master_sca << 5); } /** @@ -191,7 +189,7 @@ ble_ll_conn_num_comp_pkts_event_send(void) /* Check rate limit */ if ((uint32_t)(g_ble_ll_next_num_comp_pkt_evt - os_time_get()) < - BLE_LL_NUM_COMP_PKT_RATE) { + NIMBLE_OPT_NUM_COMP_PKT_RATE) { return; } @@ -258,7 +256,7 @@ ble_ll_conn_num_comp_pkts_event_send(void) if (event_sent) { g_ble_ll_next_num_comp_pkt_evt = os_time_get() + - BLE_LL_NUM_COMP_PKT_RATE; + NIMBLE_OPT_NUM_COMP_PKT_RATE; } } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27a3fd47/net/nimble/controller/src/ble_ll_ctrl.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_ctrl.c b/net/nimble/controller/src/ble_ll_ctrl.c index 2322a6b..a9ace70 100644 --- a/net/nimble/controller/src/ble_ll_ctrl.c +++ b/net/nimble/controller/src/ble_ll_ctrl.c @@ -20,6 +20,7 @@ #include <assert.h> #include <string.h> #include "nimble/ble.h" +#include "nimble/nimble_opt.h" #include "nimble/hci_common.h" #include "controller/ble_ll.h" #include "controller/ble_ll_hci.h" @@ -378,7 +379,7 @@ ble_ll_ctrl_version_ind_make(struct ble_ll_conn_sm *connsm, uint8_t *pyld) /* Fill out response */ pyld[0] = BLE_HCI_VER_BCS_4_2; - htole16(pyld + 1, BLE_LL_MFRG_ID); + htole16(pyld + 1, NIMBLE_OPT_LL_MFRG_ID); htole16(pyld + 3, BLE_LL_SUB_VERS_NR); } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27a3fd47/net/nimble/controller/src/ble_ll_hci.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_hci.c b/net/nimble/controller/src/ble_ll_hci.c index 5d8eebf..9d38ba1 100644 --- a/net/nimble/controller/src/ble_ll_hci.c +++ b/net/nimble/controller/src/ble_ll_hci.c @@ -21,6 +21,7 @@ #include <string.h> #include "os/os.h" #include "nimble/ble.h" +#include "nimble/nimble_opt.h" #include "nimble/hci_common.h" #include "nimble/hci_transport.h" #include "controller/ble_ll_adv.h" @@ -109,7 +110,7 @@ ble_ll_hci_rd_local_version(uint8_t *rspbuf, uint8_t *rsplen) hci_rev = 0; lmp_subver = 0; - mfrg = BLE_LL_MFRG_ID; + mfrg = NIMBLE_OPT_LL_MFRG_ID; /* Place the data packet length and number of packets in the buffer */ rspbuf[0] = BLE_HCI_VER_BCS_4_2; @@ -153,8 +154,8 @@ static int ble_ll_hci_le_read_bufsize(uint8_t *rspbuf, uint8_t *rsplen) { /* Place the data packet length and number of packets in the buffer */ - htole16(rspbuf, BLE_LL_CFG_ACL_DATA_PKT_LEN); - rspbuf[2] = BLE_LL_CFG_NUM_ACL_DATA_PKTS; + htole16(rspbuf, g_ble_ll_data.ll_acl_pkt_size); + rspbuf[2] = g_ble_ll_data.ll_num_acl_pkts; *rsplen = BLE_HCI_RD_BUF_SIZE_RSPLEN; return BLE_ERR_SUCCESS; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27a3fd47/net/nimble/controller/src/ble_ll_scan.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_scan.c b/net/nimble/controller/src/ble_ll_scan.c index 9d74333..663ed99 100644 --- a/net/nimble/controller/src/ble_ll_scan.c +++ b/net/nimble/controller/src/ble_ll_scan.c @@ -23,6 +23,7 @@ #include "bsp/bsp.h" #include "os/os.h" #include "nimble/ble.h" +#include "nimble/nimble_opt.h" #include "nimble/hci_common.h" #include "controller/ble_phy.h" #include "controller/ble_ll.h" @@ -45,6 +46,14 @@ * receive a scan response from? Implement this. */ +/* Dont allow more than 255 of these entries */ +#if NIMBLE_OPT_LL_NUM_SCAN_DUP_ADVS > 255 + #error "Cannot have more than 255 duplicate entries!" +#endif +#if NIMBLE_OPT_LL_NUM_SCAN_RSP_ADVS > 255 + #error "Cannot have more than 255 scan response entries!" +#endif + /* The scanning state machine global object */ struct ble_ll_scan_sm g_ble_ll_scan_sm; @@ -66,11 +75,13 @@ struct ble_ll_scan_advertisers /* Contains list of advertisers that we have heard scan responses from */ static uint8_t g_ble_ll_scan_num_rsp_advs; -struct ble_ll_scan_advertisers g_ble_ll_scan_rsp_advs[BLE_LL_SCAN_CFG_NUM_SCAN_RSP_ADVS]; +struct ble_ll_scan_advertisers +g_ble_ll_scan_rsp_advs[NIMBLE_OPT_LL_NUM_SCAN_RSP_ADVS]; /* Used to filter duplicate advertising events to host */ static uint8_t g_ble_ll_scan_num_dup_advs; -struct ble_ll_scan_advertisers g_ble_ll_scan_dup_advs[BLE_LL_SCAN_CFG_NUM_DUP_ADVS]; +struct ble_ll_scan_advertisers +g_ble_ll_scan_dup_advs[NIMBLE_OPT_LL_NUM_SCAN_DUP_ADVS]; /* See Vol 6 Part B Section 4.4.3.2. Active scanning backoff */ static void @@ -240,7 +251,7 @@ ble_ll_scan_add_dup_adv(uint8_t *addr, uint8_t txadd) if (!adv) { /* XXX: for now, if we dont have room, just leave */ num_advs = g_ble_ll_scan_num_dup_advs; - if (num_advs == BLE_LL_SCAN_CFG_NUM_DUP_ADVS) { + if (num_advs == NIMBLE_OPT_LL_NUM_SCAN_DUP_ADVS) { return; } @@ -307,7 +318,7 @@ ble_ll_scan_add_scan_rsp_adv(uint8_t *addr, uint8_t txadd) /* XXX: for now, if we dont have room, just leave */ num_advs = g_ble_ll_scan_num_rsp_advs; - if (num_advs == BLE_LL_SCAN_CFG_NUM_SCAN_RSP_ADVS) { + if (num_advs == NIMBLE_OPT_LL_NUM_SCAN_RSP_ADVS) { return; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27a3fd47/net/nimble/controller/src/ble_ll_whitelist.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_whitelist.c b/net/nimble/controller/src/ble_ll_whitelist.c index 168a8c8..e5cce12 100644 --- a/net/nimble/controller/src/ble_ll_whitelist.c +++ b/net/nimble/controller/src/ble_ll_whitelist.c @@ -35,7 +35,7 @@ struct ble_ll_whitelist_entry uint8_t wl_dev_addr[BLE_DEV_ADDR_LEN]; }; -struct ble_ll_whitelist_entry g_ble_ll_whitelist[BLE_LL_CFG_WHITELIST_SIZE]; +struct ble_ll_whitelist_entry g_ble_ll_whitelist[NIMBLE_OPT_LL_WHITELIST_SIZE]; #endif static int @@ -79,7 +79,7 @@ ble_ll_whitelist_clear(void) /* Set the number of entries to 0 */ wl = &g_ble_ll_whitelist[0]; - for (i = 0; i < BLE_LL_CFG_WHITELIST_SIZE; ++i) { + for (i = 0; i < NIMBLE_OPT_LL_WHITELIST_SIZE; ++i) { wl->wl_valid = 0; ++wl; } @@ -102,7 +102,7 @@ ble_ll_whitelist_read_size(uint8_t *rspbuf, uint8_t *rsplen) #ifdef BLE_USES_HW_WHITELIST rspbuf[0] = ble_hw_whitelist_size(); #else - rspbuf[0] = BLE_LL_CFG_WHITELIST_SIZE; + rspbuf[0] = NIMBLE_OPT_LL_WHITELIST_SIZE; #endif *rsplen = 1; return BLE_ERR_SUCCESS; @@ -126,7 +126,7 @@ ble_ll_is_on_whitelist(uint8_t *addr, uint8_t addr_type) struct ble_ll_whitelist_entry *wl; wl = &g_ble_ll_whitelist[0]; - for (i = 0; i < BLE_LL_CFG_WHITELIST_SIZE; ++i) { + for (i = 0; i < NIMBLE_OPT_LL_WHITELIST_SIZE; ++i) { if ((wl->wl_valid) && (wl->wl_addr_type == addr_type) && (!memcmp(&wl->wl_dev_addr[0], addr, BLE_DEV_ADDR_LEN))) { return i + 1; @@ -183,7 +183,7 @@ ble_ll_whitelist_add(uint8_t *addr, uint8_t addr_type) rc = BLE_ERR_SUCCESS; if (!ble_ll_is_on_whitelist(addr, addr_type)) { wl = &g_ble_ll_whitelist[0]; - for (i = 0; i < BLE_LL_CFG_WHITELIST_SIZE; ++i) { + for (i = 0; i < NIMBLE_OPT_LL_WHITELIST_SIZE; ++i) { if (wl->wl_valid == 0) { memcpy(&wl->wl_dev_addr[0], addr, BLE_DEV_ADDR_LEN); wl->wl_addr_type = addr_type; @@ -193,7 +193,7 @@ ble_ll_whitelist_add(uint8_t *addr, uint8_t addr_type) ++wl; } - if (i == BLE_LL_CFG_WHITELIST_SIZE) { + if (i == NIMBLE_OPT_LL_WHITELIST_SIZE) { rc = BLE_ERR_MEM_CAPACITY; } } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27a3fd47/net/nimble/include/nimble/nimble_opt.h ---------------------------------------------------------------------- diff --git a/net/nimble/include/nimble/nimble_opt.h b/net/nimble/include/nimble/nimble_opt.h index 3ab8b27..4a8467a 100644 --- a/net/nimble/include/nimble/nimble_opt.h +++ b/net/nimble/include/nimble/nimble_opt.h @@ -182,9 +182,94 @@ #define NIMBLE_OPT_ATT_SVR_INDICATE 1 #endif -/** CONTROLLER: transmit power level */ +/*** CONTROLLER ***/ + +/* + * Sleep clock accuracy (sca). This is the amount of drift in the system during + * when the device is sleeping (in parts per million). + * + * NOTE: the master sca is an enumerated value based on the sca. Rather than + * have a piece of code calculate this value, the developer must set this + * value based on the value of the SCA using the following table: + * + * SCA between 251 and 500 ppm (inclusive); master sca = 0 + * SCA between 151 and 250 ppm (inclusive); master sca = 1 + * SCA between 101 and 150 ppm (inclusive); master sca = 2 + * SCA between 76 and 100 ppm (inclusive); master sca = 3 + * SCA between 51 and 75 ppm (inclusive); master sca = 4 + * SCA between 31 and 50 ppm (inclusive); master sca = 5 + * SCA between 21 and 30 ppm (inclusive); master sca = 6 + * SCA between 0 and 20 ppm (inclusive); master sca = 7 + * + * For example: + * if your clock drift is 101 ppm, your master should be set to 2. + * if your clock drift is 20, your master sca should be set to 7. + * + * The values provided below are merely meant to be an example and should + * be replaced by values appropriate for your platform. + */ +#ifndef NIMBLE_OPT_LL_OUR_SCA +#define NIMBLE_OPT_LL_OUR_SCA (60) /* in ppm */ +#endif + +#ifndef NIMBLE_OPT_LL_MASTER_SCA +#define NIMBLE_OPT_LL_MASTER_SCA (4) +#endif + +/* transmit power level */ #ifndef NIMBLE_OPT_LL_TX_PWR_DBM -#define NIMBLE_OPT_LL_TX_PWR_DBM 0 +#define NIMBLE_OPT_LL_TX_PWR_DBM (0) +#endif + +/* + * Determines the maximum rate at which the controller will send the + * number of completed packets event to the host. Rate is in os time ticks + */ +#ifndef NIMBLE_OPT_NUM_COMP_PKT_RATE +#define NIMBLE_OPT_NUM_COMP_PKT_RATE ((2000 * OS_TICKS_PER_SEC) / 1000) +#endif + +/* Manufacturer ID. Should be set to unique ID per manufacturer */ +#ifndef NIMBLE_OPT_LL_MFRG_ID +#define NIMBLE_OPT_LL_MFRG_ID (0xFFFF) +#endif + +/* + * Configuration items for the number of duplicate advertisers and the + * number of advertisers from which we have heard a scan response. + */ +#ifndef NIMBLE_OPT_LL_NUM_SCAN_DUP_ADVS +#define NIMBLE_OPT_LL_NUM_SCAN_DUP_ADVS (8) +#endif + +#ifndef NIMBLE_OPT_LL_NUM_SCAN_RSP_ADVS +#define NIMBLE_OPT_LL_NUM_SCAN_RSP_ADVS (8) +#endif + +/* Size of the LL whitelist */ +#ifndef NIMBLE_OPT_LL_WHITELIST_SIZE +#define NIMBLE_OPT_LL_WHITELIST_SIZE (8) +#endif + +/* + * Data length management definitions for connections. These define the maximum + * size of the PDU's that will be sent and/or received in a connection. + */ +#ifndef NIMBLE_OPT_LL_SUPP_MAX_RX_BYTES +#define NIMBLE_OPT_LL_SUPP_MAX_RX_BYTES (251) +#endif + +#ifndef NIMBLE_OPT_LL_SUPP_MAX_TX_BYTES +#define NIMBLE_OPT_LL_SUPP_MAX_TX_BYTES (251) +#endif + +#ifndef NIMBLE_OPT_LL_CONN_INIT_MAX_TX_BYTES +#define NIMBLE_OPT_LL_CONN_INIT_MAX_TX_BYTES (251) +#endif + +/* The number of slots that will be allocated to each connection */ +#ifndef NIMBLE_OPT_LL_CONN_INIT_SLOTS +#define NIMBLE_OPT_LL_CONN_INIT_SLOTS (2) #endif /* Include automatically-generated settings. */