You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2016/03/10 00:56:09 UTC
incubator-mynewt-core git commit: MYNEWT-84: extend connection events
beyond originally scheduled connection event
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop a601f78b3 -> 4d1854dca
MYNEWT-84: extend connection events beyond originally scheduled connection event
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/4d1854dc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4d1854dc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4d1854dc
Branch: refs/heads/develop
Commit: 4d1854dca59a5ceb3b03ef6da159876c1d2f568c
Parents: a601f78
Author: wes3 <wi...@micosa.io>
Authored: Wed Mar 9 15:50:46 2016 -0800
Committer: wes3 <wi...@micosa.io>
Committed: Wed Mar 9 15:55:32 2016 -0800
----------------------------------------------------------------------
apps/bletest/src/main.c | 169 ++++++++---------
.../controller/include/controller/ble_ll_conn.h | 1 +
.../include/controller/ble_ll_sched.h | 19 ++
net/nimble/controller/src/ble_ll_conn.c | 181 ++++++++++++++-----
net/nimble/controller/src/ble_ll_ctrl.c | 3 -
net/nimble/controller/src/ble_ll_sched.c | 53 +++++-
net/nimble/drivers/nrf52/src/ble_phy.c | 4 +-
7 files changed, 287 insertions(+), 143 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4d1854dc/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index d004aa9..8fdc06f 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -110,12 +110,12 @@ os_membuf_t g_mbuf_buffer[MBUF_MEMPOOL_SIZE];
#define BLETEST_CFG_MIN_CE_LEN (6)
#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_RANDOM)
-#define BLETEST_CFG_CONCURRENT_CONNS (1)
+#define BLETEST_CFG_CONN_OWN_ADDR_TYPE (BLE_HCI_ADV_OWN_ADDR_PUBLIC)
+#define BLETEST_CFG_CONCURRENT_CONNS (16)
/* BLETEST variables */
#undef BLETEST_ADV_PKT_NUM
-#define BLETEST_PKT_SIZE (251)
+#define BLETEST_PKT_SIZE (247)
#define BLETEST_STACK_SIZE (256)
uint32_t g_next_os_time;
int g_bletest_state;
@@ -132,6 +132,23 @@ uint8_t g_last_handle_used;
uint8_t g_bletest_led_state;
uint32_t g_bletest_led_rate;
uint32_t g_bletest_next_led_time;
+uint16_t g_bletest_handle;
+uint16_t g_bletest_completed_pkts;
+uint16_t g_bletest_outstanding_pkts;
+
+#if (BLETEST_THROUGHPUT_TEST == 1)
+void
+bletest_completed_pkt(uint16_t handle)
+{
+ os_sr_t sr;
+
+ OS_ENTER_CRITICAL(sr);
+ if (handle == g_bletest_handle) {
+ ++g_bletest_completed_pkts;
+ }
+ OS_EXIT_CRITICAL(sr);
+}
+#endif
#ifdef BLETEST_ADV_PKT_NUM
void
@@ -490,87 +507,16 @@ bletest_get_packet(void)
return om;
}
-#if 0
-void
-bletest_execute(void)
-{
- int rc;
-
- int i;
- uint16_t pktlen;
- uint16_t handle;
- struct os_mbuf *om;
- struct ble_ll_conn_sm *connsm;
-
- handle = 1;
- if ((int32_t)(os_time_get() - g_next_os_time) >= 0) {
- if (g_bletest_state == 0) {
- rc = host_hci_cmd_le_set_adv_enable(1);
- host_hci_outstanding_opcode = 0;
- assert(rc == 0);
- g_bletest_state = 1;
- } else if (g_bletest_state == 1) {
- /* See if handle 1 has been created. If so, send packets */
- connsm = ble_ll_conn_find_active_conn(handle);
- if (connsm) {
- /* Set connection end time */
- g_bletest_conn_end = os_time_get() +
- (OS_TICKS_PER_SEC * (60 * 15));
- g_bletest_state = 2;
- }
- } else if (g_bletest_state == 2) {
- if ((int32_t)(os_time_get() - g_bletest_conn_end) >= 0) {
- g_bletest_state = 3;
- host_hci_cmd_disconnect(handle, BLE_ERR_REM_USER_CONN_TERM);
- } else {
- om = bletest_get_packet();
- if (om) {
- /* set payload length */
- pktlen = BLETEST_PKT_SIZE;
- om->om_len = BLETEST_PKT_SIZE + 4;
-
- /* Put the HCI header in the mbuf */
- htole16(om->om_data, handle);
- htole16(om->om_data + 2, om->om_len);
-
- /* Place L2CAP header in packet */
- htole16(om->om_data + 4, pktlen);
- om->om_data[6] = 0;
- om->om_data[7] = 0;
-
- /* Fill with incrementing pattern (starting from 1) */
- for (i = 0; i < pktlen; ++i) {
- om->om_data[8 + i] = (uint8_t)(i + 1);
- }
-
- /* Add length */
- om->om_len += 4;
- OS_MBUF_PKTHDR(om)->omp_len = om->om_len;
- ble_hci_transport_host_acl_data_send(om);
- }
- g_next_os_time += OS_TICKS_PER_SEC / 10;
- return;
- }
- } else if (g_bletest_state == 3) {
- /* We should be waiting for disconnect */
- connsm = ble_ll_conn_find_active_conn(handle);
- if (!connsm) {
- /* Set to 0 if you want to restart advertising */
- //g_bletest_state = 0;
- g_bletest_state = 4;
- }
- }
- g_next_os_time += OS_TICKS_PER_SEC;
- }
-}
-#else
static void
bletest_execute_advertiser(void)
{
- int i,j;
+ int i;
+ int j;
int rc;
+ //os_sr_t sr;
uint16_t handle;
uint16_t pktlen;
+ //uint16_t completed_pkts;
struct os_mbuf *om;
/* See if we should start advertising again */
@@ -580,6 +526,14 @@ bletest_execute_advertiser(void)
/* Set LED to slower blink rate */
g_bletest_led_rate = OS_TICKS_PER_SEC;
+#if 0
+ /* 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);
+ g_bletest_handle = handle;
+ }
+#endif
+
/* advertising better be stopped! */
assert(ble_ll_adv_enabled() == 0);
@@ -666,11 +620,60 @@ bletest_execute_advertiser(void)
}
}
}
- g_next_os_time = os_time_get() + OS_TICKS_PER_SEC;
+ g_next_os_time = os_time_get() + OS_TICKS_PER_SEC/4;
}
+
+#if 0 /* XXX: throughput test */
+ /* Nothing to do if no connections */
+ if (!g_bletest_current_conns) {
+ return;
+ }
+
+ /* See if it is time to start throughput testing */
+ if ((int32_t)(os_time_get() - g_next_os_time) >= 0) {
+
+ /* Keep window full */
+ OS_ENTER_CRITICAL(sr);
+ completed_pkts = g_bletest_completed_pkts;
+ g_bletest_completed_pkts = 0;
+ OS_EXIT_CRITICAL(sr);
+
+ assert(g_bletest_outstanding_pkts >= completed_pkts);
+ g_bletest_outstanding_pkts -= completed_pkts;
+
+ while (g_bletest_outstanding_pkts < 8) {
+ om = bletest_get_packet();
+ if (om) {
+ /* set payload length */
+ pktlen = BLETEST_PKT_SIZE;
+ om->om_len = BLETEST_PKT_SIZE + 4;
+
+ /* Put the HCI header in the mbuf */
+ htole16(om->om_data, g_bletest_handle);
+ htole16(om->om_data + 2, om->om_len);
+
+ /* Place L2CAP header in packet */
+ htole16(om->om_data + 4, pktlen);
+ om->om_data[6] = 0;
+ om->om_data[7] = 0;
+ 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);
+ }
+
+ /* Add length */
+ OS_MBUF_PKTHDR(om)->omp_len = om->om_len;
+ ble_hci_transport_host_acl_data_send(om);
+
+ ++g_bletest_outstanding_pkts;
+ }
+ }
+ }
+#endif /* XXX: throughput test */
}
-#endif
-#endif
+#endif
/**
* Main bletest function. Called by the task timer every 50 msecs.
@@ -706,8 +709,8 @@ bletest_timer_cb(void *arg)
/* Call the bletest code */
bletest_execute();
- /* Re-start the timer (run every 50 msecs) */
- os_callout_reset(&g_bletest_timer.cf_c, OS_TICKS_PER_SEC / 20);
+ /* Re-start the timer (run every 10 msecs) */
+ os_callout_reset(&g_bletest_timer.cf_c, OS_TICKS_PER_SEC / 100);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4d1854dc/net/nimble/controller/include/controller/ble_ll_conn.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_conn.h b/net/nimble/controller/include/controller/ble_ll_conn.h
index b1bceca..7670ac0 100644
--- a/net/nimble/controller/include/controller/ble_ll_conn.h
+++ b/net/nimble/controller/include/controller/ble_ll_conn.h
@@ -147,6 +147,7 @@ struct ble_ll_conn_sm
uint32_t access_addr;
uint32_t crcinit; /* only low 24 bits used */
+ /* XXX: do we need ce_end_time? Cant this be sched end time? */
uint32_t ce_end_time; /* cputime at which connection event should end */
uint32_t terminate_timeout;
uint32_t last_scheduled;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4d1854dc/net/nimble/controller/include/controller/ble_ll_sched.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_sched.h b/net/nimble/controller/include/controller/ble_ll_sched.h
index 7fe2b06..00a2c6b 100644
--- a/net/nimble/controller/include/controller/ble_ll_sched.h
+++ b/net/nimble/controller/include/controller/ble_ll_sched.h
@@ -23,6 +23,13 @@
/* Time per BLE scheduler slot */
#define BLE_LL_SCHED_USECS_PER_SLOT (1250)
+/*
+ * This is the number of slots needed to transmit and receive a maximum
+ * size PDU, including an IFS time before each. The actual time is
+ * 2120 usecs for tx/rx and 150 for IFS = 4540 usecs.
+ */
+#define BLE_LL_SCHED_MAX_TXRX_SLOT (4 * BLE_LL_SCHED_USECS_PER_SLOT)
+
/* BLE scheduler errors */
#define BLE_LL_SCHED_ERR_OVERLAP (1)
@@ -79,6 +86,18 @@ int ble_ll_sched_adv_reschedule(struct ble_ll_sched_item *sch);
/* Reschedule a connection that had previously been scheduled or that is over */
int ble_ll_sched_conn_reschedule(struct ble_ll_conn_sm * connsm);
+/**
+ * Called to determine when the next scheduled event will occur.
+ *
+ * If there are not scheduled events this function returns 0; otherwise it
+ * returns 1 and *next_event_time is set to the start time of the next event.
+ *
+ * @param next_event_time cputime at which next scheduled event will occur
+ *
+ * @return int 0: No events are scheduled 1: there is an upcoming event
+ */
+int ble_ll_sched_next_time(uint32_t *next_event_time);
+
/* Stop the scheduler */
void ble_ll_sched_stop(void);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4d1854dc/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 36c63e3..e3a38d0 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -36,34 +36,54 @@
#include "hal/hal_cputime.h"
#include "hal/hal_gpio.h"
-/*
- * XXX: looks like the current code will allow the 1st packet in a
- * connection to extend past the end of the allocated connection end
- * time. That is not good. Need to deal with that. Need to extend connection
- * end time.
- */
-
/* XXX TODO
- * 1) Add set channel map command and implement channel change procedure.
- * 2) I think if we are initiating and we already have a connection with
+ * 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.
- * 3) Make sure we check incoming data packets for size and all that. You
+ * -> This is true. There are a couple things to do
+ * i) When a connection create is issued, if we already are connected
+ * deny it. BLE ERROR = 0x0B (ACL connection exists).
+ * ii) If we receive an advertisement while initiating and want to send
+ * a connect request to the device, make sure we dont have it.
+ * iii) I think I need to do something like this: I am initiating and
+ * advertising. Suppose the device I want to connect to sends me a connect
+ * request because I am advertising? What happens to connection? Deal
+ * with this!
+ *
+ * 2) Make sure we check incoming data packets for size and all that. You
* know, supported octets and all that. For both rx and tx.
- * 4) Make sure we are setting the schedule end time properly for both slave
+ *
+ * 3) Make sure we are setting the schedule end time properly for both slave
* and master. We should just set this to the end of the connection event.
* We might want to guarantee a IFS time as well since the next event needs
* to be scheduled prior to the start of the event to account for the time it
* takes to get a frame ready (which is pretty much the IFS time).
- * 5) Do we need to check the terminate timeout inside the connection event?
- * I think we do.
+ *
+ * 4) looks like the current code will allow the 1st packet in a
+ * connection to extend past the end of the allocated connection end
+ * time. That is not good. Need to deal with that. Need to extend connection
+ * end time.
+ *
* 6) Use error code 0x3E correctly! Connection failed to establish. If you
* read the LE connection complete event, it says that if the connection
* fails to be established that the connection complete event gets sent to
- * the host that issued the create connection.
+ * the host that issued the create connection. Need to resolve this.
+ *
* 7) How does peer address get set if we are using whitelist? Look at filter
* policy and make sure you are doing this correctly.
+ *
* 8) Right now I use a fixed definition for required slots. CHange this.
+ *
* 9) Use output compare for transmit.
+ *
+ * 10) See what connection state machine elements are purely master and
+ * purely slave. We can make a union of them.
+ *
+ * 11) Need to trim elements from the connection state machine.
+ *
+ * 12) When a slave receives a data packet in a connection it has to send a
+ * response. Well, it should. If this packet will overrun the next scheduled
+ * event, what should we do? Transmit anyway? Not transmit? For now, we just
+ * transmit.
*/
/*
@@ -79,12 +99,6 @@
extern int ble_hs_rx_data(struct os_mbuf *om);
/*
- * XXX: Possible improvements
- * 1) See what connection state machine elements are purely master and
- * purely slave. We can make a union of them.
- */
-
-/*
* The amount of time that we will wait to hear the start of a receive
* packet after we have transmitted a packet. This time is at least
* an IFS time plus the time to receive the preamble and access address. We
@@ -580,6 +594,39 @@ ble_ll_conn_wait_txend(void *arg)
}
/**
+ * Returns the cputime of the next scheduled item on the scheduler list or
+ * when the current connection will start its next interval (whichever is
+ * earlier). This API is called when determining at what time we should end
+ * the current connection event. The current connection event must end before
+ * the next scheduled item. However, the current connection itself is not
+ * in the scheduler list! Thus, we need to calculate the time at which the
+ * next connection will start and not overrun it.
+ *
+ * @param connsm
+ *
+ * @return uint32_t
+ */
+static uint32_t
+ble_ll_conn_get_next_sched_time(struct ble_ll_conn_sm *connsm)
+{
+ uint32_t itvl;
+ uint32_t ce_end;
+ uint32_t next_sched_time;
+
+ /* Calculate time at which next connection event will start */
+ itvl = connsm->conn_itvl * BLE_LL_CONN_ITVL_USECS;
+ ce_end = connsm->anchor_point + cputime_usecs_to_ticks(itvl);
+
+ if (ble_ll_sched_next_time(&next_sched_time)) {
+ if (CPUTIME_LT(next_sched_time, ce_end)) {
+ ce_end = next_sched_time;
+ }
+ }
+
+ return ce_end;
+}
+
+/**
* Called when we want to send a data channel pdu inside a connection event.
*
* Context: interrupt
@@ -597,7 +644,9 @@ ble_ll_conn_tx_data_pdu(struct ble_ll_conn_sm *connsm, int beg_transition)
uint8_t hdr_byte;
uint8_t end_transition;
uint8_t cur_txlen;
+ uint8_t next_txlen;
uint8_t rem_bytes;
+ uint32_t next_event_time;
uint32_t ticks;
struct os_mbuf *m;
struct ble_mbuf_hdr *ble_hdr;
@@ -607,11 +656,7 @@ ble_ll_conn_tx_data_pdu(struct ble_ll_conn_sm *connsm, int beg_transition)
/*
* Get packet off transmit queue. If not available, send empty PDU. Set
- * the more data bit as well. For a slave, we will set it regardless of
- * connection event end timing (master will deal with that for us or the
- * connection event will be terminated locally). For a master, we only
- * set the MD bit if we have enough time to send the current PDU, get
- * a response and send the next packet and get a response.
+ * the more data bit as well.
*/
md = 0;
tx_empty_pdu = 0;
@@ -655,32 +700,60 @@ ble_ll_conn_tx_data_pdu(struct ble_ll_conn_sm *connsm, int beg_transition)
ble_hdr->txinfo.pyld_len = cur_txlen;
}
+ /*
+ * Set the more data data flag if we have more data to send and we
+ * have not been asked to terminate
+ */
if ((nextpkthdr ||
((ble_hdr->txinfo.offset + cur_txlen) < pkthdr->omp_len)) &&
!connsm->csmflags.cfbit.terminate_ind_rxd) {
- md = 1;
- if (connsm->conn_role == BLE_LL_CONN_ROLE_MASTER) {
- /*
- * Dont bother to set the MD bit if we cannot do the following:
- * -> wait IFS, send the current frame.
- * -> wait IFS, receive a mininim size frame.
- * -> wait IFS, send a mininim size frame.
- * -> wait IFS, receive a mininim size frame.
- */
- /*
- * XXX: this calculation is based on using the current time
- * and assuming the transmission will occur an IFS time from
- * now. This is not the most accurate especially if we have
- * received a frame and we are replying to it.
- */
- ticks = (BLE_LL_IFS * 4) + (3 * BLE_LL_CONN_SUPP_TIME_MIN) +
- BLE_TX_DUR_USECS_M(cur_txlen);
- ticks = cputime_usecs_to_ticks(ticks);
- if ((cputime_get32() + ticks) >= connsm->ce_end_time) {
- md = 0;
+ /* Get next event time */
+ next_event_time = ble_ll_conn_get_next_sched_time(connsm);
+
+ /*
+ * Dont bother to set the MD bit if we cannot do the following:
+ * -> wait IFS, send the current frame.
+ * -> wait IFS, receive a maximum size frame.
+ * -> wait IFS, send the next frame.
+ * -> wait IFS, receive a maximum size frame.
+ *
+ * For slave:
+ * -> wait IFS, send current frame.
+ * -> wait IFS, receive maximum size frame.
+ * -> wait IFS, send next frame.
+ */
+ if ((ble_hdr->txinfo.offset + cur_txlen) < pkthdr->omp_len) {
+ next_txlen = pkthdr->omp_len -
+ (ble_hdr->txinfo.offset + cur_txlen);
+ } else {
+ if (nextpkthdr->omp_len > connsm->eff_max_tx_octets) {
+ next_txlen = connsm->eff_max_tx_octets;
+ } else {
+ next_txlen = nextpkthdr->omp_len;
}
}
- }
+
+ /*
+ * XXX: this calculation is based on using the current time
+ * and assuming the transmission will occur an IFS time from
+ * now. This is not the most accurate especially if we have
+ * received a frame and we are replying to it.
+ */
+ ticks = (BLE_LL_IFS * 3) + connsm->eff_max_rx_time +
+ BLE_TX_DUR_USECS_M(next_txlen) +
+ BLE_TX_DUR_USECS_M(cur_txlen);
+
+ if (connsm->conn_role == BLE_LL_CONN_ROLE_MASTER) {
+ ticks += (BLE_LL_IFS + connsm->eff_max_rx_time);
+ }
+
+ ticks = cputime_usecs_to_ticks(ticks);
+ if ((cputime_get32() + ticks) >= next_event_time) {
+ md = 0;
+ } else {
+ md = 1;
+ }
+ }
} else {
/* Send empty pdu. Need to reset some items since we re-use it. */
m = (struct os_mbuf *)&connsm->conn_empty_pdu;
@@ -718,6 +791,13 @@ ble_ll_conn_tx_data_pdu(struct ble_ll_conn_sm *connsm, int beg_transition)
* connection event. We will end the connection event if we have
* received a valid frame with the more data bit set to 0 and we dont
* have more data.
+ *
+ * XXX: for a slave, we dont check to see if we can:
+ * -> wait IFS, rx frame from master (either big or small).
+ * -> wait IFS, send empty pdu or next pdu.
+ *
+ * We could do this. Now, we just keep going and hope that we dont
+ * overrun next scheduled item.
*/
if ((connsm->csmflags.cfbit.terminate_ind_rxd) ||
((connsm->conn_role == BLE_LL_CONN_ROLE_SLAVE) && (md == 0) &&
@@ -873,12 +953,17 @@ ble_ll_conn_can_send_next_pdu(struct ble_ll_conn_sm *connsm, uint32_t begtime)
int rc;
uint8_t rem_bytes;
uint32_t ticks;
+ uint32_t next_sched_time;
struct os_mbuf *txpdu;
struct os_mbuf_pkthdr *pkthdr;
struct ble_mbuf_hdr *txhdr;
rc = 1;
if (connsm->conn_role == BLE_LL_CONN_ROLE_MASTER) {
+ /* Get next scheduled item time */
+ next_sched_time = ble_ll_conn_get_next_sched_time(connsm);
+
+ /* Check if there is a packet on the queue. */
pkthdr = STAILQ_FIRST(&connsm->conn_txq);
if (pkthdr) {
txpdu = OS_MBUF_PKTHDR_TO_MBUF(pkthdr);
@@ -892,9 +977,9 @@ ble_ll_conn_can_send_next_pdu(struct ble_ll_conn_sm *connsm, uint32_t begtime)
/* We will send empty pdu (just a LL header) */
ticks = BLE_TX_DUR_USECS_M(0);
}
- ticks += (BLE_LL_IFS * 2) + BLE_LL_CONN_SUPP_TIME_MIN;
+ ticks += (BLE_LL_IFS * 2) + connsm->eff_max_rx_time;
ticks = cputime_usecs_to_ticks(ticks);
- if ((begtime + ticks) >= connsm->ce_end_time) {
+ if ((begtime + ticks) >= next_sched_time) {
rc = 0;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4d1854dc/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 ec77808..2322a6b 100644
--- a/net/nimble/controller/src/ble_ll_ctrl.c
+++ b/net/nimble/controller/src/ble_ll_ctrl.c
@@ -72,9 +72,6 @@ const uint8_t g_ble_ll_ctrl_pkt_lengths[BLE_LL_CTRL_OPCODES] =
11, 7, 1, 22, 12, 0, 0, 1, 8, 8, 0, 0, 5, 1, 8, 23, 23, 2, 0, 0, 8, 8
};
-/* XXX: Improvements
- * 1) We can inititalize the procedure timer once per connection state machine
- */
static int
ble_ll_ctrl_chk_supp_bytes(uint16_t bytes)
{
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4d1854dc/net/nimble/controller/src/ble_ll_sched.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_sched.c b/net/nimble/controller/src/ble_ll_sched.c
index dae0947..11601d8 100644
--- a/net/nimble/controller/src/ble_ll_sched.c
+++ b/net/nimble/controller/src/ble_ll_sched.c
@@ -241,6 +241,7 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm, uint32_t adv_rxend,
{
int rc;
os_sr_t sr;
+ uint32_t tps;
uint32_t initial_start;
uint32_t earliest_start;
uint32_t earliest_end;
@@ -282,11 +283,18 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm, uint32_t adv_rxend,
* earliest start so we can end the connection reasonably.
*/
if (ble_ll_state_get() == BLE_LL_STATE_CONNECTION) {
+ tps = cputime_usecs_to_ticks(BLE_LL_SCHED_USECS_PER_SLOT);
ce_end_time = ble_ll_conn_get_ce_end_time();
- if ((int32_t)(ce_end_time - sch->start_time) >= 0) {
- earliest_start = ce_end_time;
- earliest_end = earliest_start + dur;
+ while ((int32_t)(ce_end_time - cputime_get32()) < 0) {
+ ce_end_time += tps;
}
+
+ /* Start at next slot boundary past earliest */
+ while ((int32_t)(ce_end_time - earliest_start) < 0) {
+ ce_end_time += tps;
+ }
+ earliest_start = ce_end_time;
+ earliest_end = earliest_start + dur;
}
initial_start = earliest_start;
@@ -430,6 +438,7 @@ ble_ll_sched_adv_new(struct ble_ll_sched_item *sch)
{
int rc;
os_sr_t sr;
+ int32_t ticks;
uint32_t ce_end_time;
uint32_t adv_start;
uint32_t duration;
@@ -445,12 +454,13 @@ ble_ll_sched_adv_new(struct ble_ll_sched_item *sch)
* earliest start so we can end the connection reasonably.
*/
if (ble_ll_state_get() == BLE_LL_STATE_CONNECTION) {
- sch->start_time += cputime_usecs_to_ticks(BLE_LL_SCHED_USECS_PER_SLOT);
+ ticks = (int32_t)cputime_usecs_to_ticks(BLE_LL_SCHED_MAX_TXRX_SLOT);
ce_end_time = ble_ll_conn_get_ce_end_time();
- if ((int32_t)(ce_end_time - sch->start_time) >= 0) {
- sch->start_time = ce_end_time;
+ if ((int32_t)(ce_end_time - sch->start_time) < ticks) {
+ ce_end_time += ticks;
}
- sch->end_time = sch->start_time + duration;
+ sch->start_time = ce_end_time;
+ sch->end_time = ce_end_time + duration;
}
entry = ble_ll_sched_insert_if_empty(sch);
@@ -670,6 +680,35 @@ ble_ll_sched_run(void *arg)
}
/**
+ * Called to determine when the next scheduled event will occur.
+ *
+ * If there are not scheduled events this function returns 0; otherwise it
+ * returns 1 and *next_event_time is set to the start time of the next event.
+ *
+ * @param next_event_time
+ *
+ * @return int 0: No events are scheduled 1: there is an upcoming event
+ */
+int
+ble_ll_sched_next_time(uint32_t *next_event_time)
+{
+ int rc;
+ os_sr_t sr;
+ struct ble_ll_sched_item *first;
+
+ rc = 0;
+ OS_ENTER_CRITICAL(sr);
+ first = TAILQ_FIRST(&g_ble_ll_sched_q);
+ if (first) {
+ *next_event_time = first->start_time;
+ rc = 1;
+ }
+ OS_EXIT_CRITICAL(sr);
+
+ return rc;
+}
+
+/**
* Stop the scheduler
*
* Context: Link Layer task
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4d1854dc/net/nimble/drivers/nrf52/src/ble_phy.c
----------------------------------------------------------------------
diff --git a/net/nimble/drivers/nrf52/src/ble_phy.c b/net/nimble/drivers/nrf52/src/ble_phy.c
index 1f6e101..58befeb 100644
--- a/net/nimble/drivers/nrf52/src/ble_phy.c
+++ b/net/nimble/drivers/nrf52/src/ble_phy.c
@@ -179,8 +179,8 @@ ble_phy_isr(void)
/* Better be in TX state! */
assert(g_ble_phy_data.phy_state == BLE_PHY_STATE_TX);
- ble_ll_log(BLE_LL_LOG_ID_PHY_TXEND, g_ble_phy_txrx_buf[1], 0,
- NRF_TIMER0->CC[2]);
+ ble_ll_log(BLE_LL_LOG_ID_PHY_TXEND, (g_ble_phy_txrx_buf[0] >> 8) & 0xFF,
+ 0, NRF_TIMER0->CC[2]);
/* Clear events and clear interrupt on disabled event */
NRF_RADIO->EVENTS_DISABLED = 0;