Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a separate portal for receiving notification events #244

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nrf-softdevice/src/ble/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ impl ConnectionState {
// Signal possible in-progess operations that the connection has disconnected.
#[cfg(feature = "ble-gatt-client")]
crate::ble::gatt_client::portal(conn_handle).call(_ble_evt);
#[cfg(feature = "ble-gatt-client")]
crate::ble::gatt_client::hvx_portal(conn_handle).call(_ble_evt);
#[cfg(feature = "ble-gatt-server")]
crate::ble::gatt_server::portal(conn_handle).call(_ble_evt);
#[cfg(feature = "ble-l2cap")]
Expand Down
12 changes: 10 additions & 2 deletions nrf-softdevice/src/ble/gatt_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,11 @@ unsafe fn check_status(ble_evt: *const raw::ble_evt_t) -> Result<&'static raw::b

pub(crate) unsafe fn on_evt(ble_evt: *const raw::ble_evt_t) {
let gattc_evt = get_union_field(ble_evt, &(*ble_evt).evt.gattc_evt);
portal(gattc_evt.conn_handle).call(ble_evt);
if (*ble_evt).header.evt_id == raw::BLE_GATTC_EVTS_BLE_GATTC_EVT_HVX as u16 {
hvx_portal(gattc_evt.conn_handle).call(ble_evt);
} else {
portal(gattc_evt.conn_handle).call(ble_evt);
}
}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
Expand Down Expand Up @@ -606,9 +610,13 @@ pub(crate) async fn att_mtu_exchange(conn: &Connection, mtu: u16) -> Result<(),

const PORTAL_NEW: Portal<*const raw::ble_evt_t> = Portal::new();
static PORTALS: [Portal<*const raw::ble_evt_t>; CONNS_MAX] = [PORTAL_NEW; CONNS_MAX];
static HVX_PORTALS: [Portal<*const raw::ble_evt_t>; CONNS_MAX] = [PORTAL_NEW; CONNS_MAX];
pub(crate) fn portal(conn_handle: u16) -> &'static Portal<*const raw::ble_evt_t> {
&PORTALS[conn_handle as usize]
}
pub(crate) fn hvx_portal(conn_handle: u16) -> &'static Portal<*const raw::ble_evt_t> {
&HVX_PORTALS[conn_handle as usize]
}

pub async fn run<'a, F, C>(conn: &Connection, client: &C, mut f: F) -> DisconnectedError
where
Expand All @@ -620,7 +628,7 @@ where
Err(e) => return e,
};

portal(handle)
hvx_portal(handle)
.wait_many(|ble_evt| unsafe {
let ble_evt = &*ble_evt;
if u32::from(ble_evt.header.evt_id) == raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED {
Expand Down
Loading