Skip to content

Commit

Permalink
Merge #1917
Browse files Browse the repository at this point in the history
1917: hil: ble_advertising: Pass the transmit buffer on callback r=ppannuto a=alistair23

### Pull Request Overview

Pass the BLE transmit buffer back to the capsule.

### Testing Strategy

### TODO or Help Wanted

### Documentation Updated

- [X] Updated the relevant files in `/docs`, or no updates are required.

### Formatting

- [X] Ran `make prepush`.


Co-authored-by: Alistair Francis <alistair@alistair23.me>
  • Loading branch information
bors[bot] and alistair23 committed Jun 15, 2020
2 parents 555b3a0 + 4c8d8b8 commit 671e151
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
7 changes: 3 additions & 4 deletions capsules/src/ble_advertising_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,8 @@ impl App {
data[..adv_data_len].copy_from_slice(adv_data_corrected);
}
let total_len = cmp::min(PACKET_LENGTH, payload_len + 2);
let result = ble
.radio
ble.radio
.transmit_advertisement(kernel_tx, total_len, channel);
ble.kernel_tx.replace(result);
ReturnCode::SUCCESS
})
})
Expand Down Expand Up @@ -507,7 +505,8 @@ where
{
// The ReturnCode indicates valid CRC or not, not used yet but could be used for
// re-transmissions for invalid CRCs
fn transmit_event(&self, _crc_ok: ReturnCode) {
fn transmit_event(&self, buf: &'static mut [u8], _crc_ok: ReturnCode) {
self.kernel_tx.replace(buf);
self.sending_app.map(|appid| {
let _ = self.app.enter(*appid, |app, _| {
match app.process_status {
Expand Down
15 changes: 7 additions & 8 deletions chips/nrf52/src/ble_radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use core::cell::Cell;
use core::convert::TryFrom;
use kernel::common::cells::OptionalCell;
use kernel::common::cells::TakeCell;
use kernel::common::registers::{register_bitfields, ReadOnly, ReadWrite, WriteOnly};
use kernel::common::StaticRef;
use kernel::hil::ble_advertising;
Expand Down Expand Up @@ -533,6 +534,7 @@ pub struct Radio {
tx_power: Cell<TxPower>,
rx_client: OptionalCell<&'static dyn ble_advertising::RxClient>,
tx_client: OptionalCell<&'static dyn ble_advertising::TxClient>,
buffer: TakeCell<'static, [u8]>,
}

pub static mut RADIO: Radio = Radio::new();
Expand All @@ -544,6 +546,7 @@ impl Radio {
tx_power: Cell::new(TxPower::ZerodBm),
rx_client: OptionalCell::empty(),
tx_client: OptionalCell::empty(),
buffer: TakeCell::empty(),
}
}

Expand Down Expand Up @@ -631,7 +634,8 @@ impl Radio {
| nrf5x::constants::RADIO_STATE_TXDISABLE
| nrf5x::constants::RADIO_STATE_TX => {
self.radio_off();
self.tx_client.map(|client| client.transmit_event(result));
self.tx_client
.map(|client| client.transmit_event(self.buffer.take().unwrap(), result));
}
nrf5x::constants::RADIO_STATE_RXRU
| nrf5x::constants::RADIO_STATE_RXIDLE
Expand Down Expand Up @@ -795,17 +799,12 @@ impl Radio {
}

impl ble_advertising::BleAdvertisementDriver for Radio {
fn transmit_advertisement(
&self,
buf: &'static mut [u8],
_len: usize,
channel: RadioChannel,
) -> &'static mut [u8] {
fn transmit_advertisement(&self, buf: &'static mut [u8], _len: usize, channel: RadioChannel) {
let res = self.replace_radio_buffer(buf);
self.buffer.replace(res);
self.ble_initialize(channel);
self.tx();
self.enable_interrupts();
res
}

fn receive_advertisement(&self, channel: RadioChannel) {
Expand Down
9 changes: 2 additions & 7 deletions kernel/src/hil/ble_advertising.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@
use crate::returncode::ReturnCode;

pub trait BleAdvertisementDriver {
fn transmit_advertisement(
&self,
buf: &'static mut [u8],
len: usize,
channel: RadioChannel,
) -> &'static mut [u8];
fn transmit_advertisement(&self, buf: &'static mut [u8], len: usize, channel: RadioChannel);
fn receive_advertisement(&self, channel: RadioChannel);
fn set_receive_client(&self, client: &'static dyn RxClient);
fn set_transmit_client(&self, client: &'static dyn TxClient);
Expand All @@ -70,7 +65,7 @@ pub trait RxClient {
}

pub trait TxClient {
fn transmit_event(&self, result: ReturnCode);
fn transmit_event(&self, buf: &'static mut [u8], result: ReturnCode);
}

// Bluetooth Core Specification:Vol. 6. Part B, section 1.4.1 Advertising and Data Channel Indices
Expand Down

0 comments on commit 671e151

Please sign in to comment.