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

hil: ble_advertising: Pass the transmit buffer on callback #1917

Merged
merged 1 commit into from
Jun 15, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions capsules/src/ble_advertising_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,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 @@ -502,7 +500,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