summaryrefslogtreecommitdiff
path: root/ports/nrf
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2021-04-01 14:13:58 -0700
committerScott Shawcroft <scott@tannewt.org>2021-04-01 14:16:35 -0700
commit58835e5a5b2e5f20357ad49d77d93a1aa9cf4364 (patch)
tree05c9e16f561b5755303c2de69c166cd4687eb8be /ports/nrf
parent0135c5cc79583780af2588fc1a59ced552b04a88 (diff)
Two small PacketBuffer fixes
1. Allow for ctrl-c during a write. 2. Handle disconnects when acting as a client.
Diffstat (limited to 'ports/nrf')
-rw-r--r--ports/nrf/common-hal/_bleio/PacketBuffer.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/ports/nrf/common-hal/_bleio/PacketBuffer.c b/ports/nrf/common-hal/_bleio/PacketBuffer.c
index 8f87b2497..311988eb4 100644
--- a/ports/nrf/common-hal/_bleio/PacketBuffer.c
+++ b/ports/nrf/common-hal/_bleio/PacketBuffer.c
@@ -106,13 +106,16 @@ STATIC uint32_t queue_next_write(bleio_packet_buffer_obj_t *self) {
STATIC bool packet_buffer_on_ble_client_evt(ble_evt_t *ble_evt, void *param) {
const uint16_t evt_id = ble_evt->header.evt_id;
+ bleio_packet_buffer_obj_t *self = (bleio_packet_buffer_obj_t *)param;
+ if (evt_id == BLE_GAP_EVT_DISCONNECTED && self->conn_handle == ble_evt->evt.gap_evt.conn_handle) {
+ self->conn_handle = BLE_CONN_HANDLE_INVALID;
+ }
// Check if this is a GATTC event so we can make sure the conn_handle is valid.
if (evt_id < BLE_GATTC_EVT_BASE || evt_id > BLE_GATTC_EVT_LAST) {
return false;
}
uint16_t conn_handle = ble_evt->evt.gattc_evt.conn_handle;
- bleio_packet_buffer_obj_t *self = (bleio_packet_buffer_obj_t *)param;
if (conn_handle != self->conn_handle) {
return false;
}
@@ -298,11 +301,14 @@ mp_int_t common_hal_bleio_packet_buffer_write(bleio_packet_buffer_obj_t *self, u
if (len + self->pending_size > outgoing_packet_length) {
// No room to append len bytes to packet. Wait until we get a free buffer,
// and keep checking that we haven't been disconnected.
- while (self->pending_size != 0 && self->conn_handle != BLE_CONN_HANDLE_INVALID) {
+ while (self->pending_size != 0 &&
+ self->conn_handle != BLE_CONN_HANDLE_INVALID &&
+ !mp_hal_is_interrupted()) {
RUN_BACKGROUND_TASKS;
}
}
- if (self->conn_handle == BLE_CONN_HANDLE_INVALID) {
+ if (self->conn_handle == BLE_CONN_HANDLE_INVALID ||
+ mp_hal_is_interrupted()) {
return -1;
}