Skip to content

Commit

Permalink
Merge #1934
Browse files Browse the repository at this point in the history
1934: Initial support for Apollo3 BLE r=bradjc a=alistair23

### Pull Request Overview

This PR adds initial support for the Apollo3 BLE module.

This PR can power up the module and write data to it and receive interrupts.

~~This PR applies on top of: #1917

### Testing Strategy

Try to run the `libtock-c` examples on the Apollo3.

### TODO or Help Wanted

Lots of things still aren't done, if anyone is willing to help I would be very grateful.

BLE still doesn't work (I can't see the device advertise itself from other devices).

This PR also doesn't apply the binaries (called patches) that are required to use the BLE module. I have a branch where I call the to HAL's C code to do this.

I currently just see the `ble_advertisment_driver` alarm firing and the same data being written to the BLE device over and over again. I'm not sure what else should be happening, but BLE is currently not working.

### 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>
Co-authored-by: Brad Campbell <bradjc5@gmail.com>
  • Loading branch information
3 people committed Jun 25, 2020
2 parents 079f44a + 92d337b commit 3fa20f8
Show file tree
Hide file tree
Showing 8 changed files with 799 additions and 4 deletions.
81 changes: 81 additions & 0 deletions boards/redboard_artemis_nano/src/ble.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//! Component for BLE radio on Apollo3 based platforms.
//!
//! Usage
//! -----
//! ```rust
//! let ble_radio = BLEComponent::new(board_kernel, &apollo3::ble::BLE, mux_alarm).finalize();
//! ```

#![allow(dead_code)] // Components are intended to be conditionally included

use capsules;
use capsules::virtual_alarm::VirtualMuxAlarm;
use kernel::capabilities;
use kernel::component::Component;
use kernel::hil;
use kernel::{create_capability, static_init};

/// BLE component for Apollo3 BLE
pub struct BLEComponent {
board_kernel: &'static kernel::Kernel,
radio: &'static apollo3::ble::Ble<'static>,
mux_alarm:
&'static capsules::virtual_alarm::MuxAlarm<'static, apollo3::stimer::STimer<'static>>,
}

/// BLE component for Apollo3 BLE
impl BLEComponent {
/// New instance
pub fn new(
board_kernel: &'static kernel::Kernel,
radio: &'static apollo3::ble::Ble,
mux_alarm: &'static capsules::virtual_alarm::MuxAlarm<'static, apollo3::stimer::STimer>,
) -> BLEComponent {
BLEComponent {
board_kernel: board_kernel,
radio: radio,
mux_alarm: mux_alarm,
}
}
}

impl Component for BLEComponent {
type StaticInput = ();
type Output = &'static capsules::ble_advertising_driver::BLE<
'static,
apollo3::ble::Ble<'static>,
VirtualMuxAlarm<'static, apollo3::stimer::STimer<'static>>,
>;

unsafe fn finalize(self, _s: Self::StaticInput) -> Self::Output {
let grant_cap = create_capability!(capabilities::MemoryAllocationCapability);

let ble_radio_virtual_alarm = static_init!(
capsules::virtual_alarm::VirtualMuxAlarm<'static, apollo3::stimer::STimer>,
capsules::virtual_alarm::VirtualMuxAlarm::new(self.mux_alarm)
);

let ble_radio = static_init!(
capsules::ble_advertising_driver::BLE<
'static,
apollo3::ble::Ble,
VirtualMuxAlarm<'static, apollo3::stimer::STimer>,
>,
capsules::ble_advertising_driver::BLE::new(
self.radio,
self.board_kernel.create_grant(&grant_cap),
&mut capsules::ble_advertising_driver::BUF,
ble_radio_virtual_alarm
)
);
kernel::hil::ble_advertising::BleAdvertisementDriver::set_receive_client(
self.radio, ble_radio,
);
kernel::hil::ble_advertising::BleAdvertisementDriver::set_transmit_client(
self.radio, ble_radio,
);
hil::time::Alarm::set_client(ble_radio_virtual_alarm, ble_radio);

ble_radio
}
}
22 changes: 22 additions & 0 deletions boards/redboard_artemis_nano/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use kernel::hil::i2c::I2CMaster;
use kernel::Platform;
use kernel::{create_capability, debug, static_init};

pub mod ble;
/// Support routines for debugging I/O.
pub mod io;

Expand Down Expand Up @@ -53,6 +54,11 @@ struct RedboardArtemisNano {
gpio: &'static capsules::gpio::GPIO<'static, apollo3::gpio::GpioPin>,
console: &'static capsules::console::Console<'static>,
i2c_master: &'static capsules::i2c_master::I2CMasterDriver<apollo3::iom::Iom<'static>>,
ble_radio: &'static capsules::ble_advertising_driver::BLE<
'static,
apollo3::ble::Ble<'static>,
VirtualMuxAlarm<'static, apollo3::stimer::STimer<'static>>,
>,
}

/// Mapping of integer syscalls to objects that implement syscalls.
Expand All @@ -67,6 +73,7 @@ impl Platform for RedboardArtemisNano {
capsules::gpio::DRIVER_NUM => f(Some(self.gpio)),
capsules::console::DRIVER_NUM => f(Some(self.console)),
capsules::i2c_master::DRIVER_NUM => f(Some(self.i2c_master)),
capsules::ble_advertising_driver::DRIVER_NUM => f(Some(self.ble_radio)),
_ => f(None),
}
}
Expand Down Expand Up @@ -178,6 +185,20 @@ pub unsafe fn reset_handler() {
apollo3::iom::IOM2.set_master_client(i2c_master);
apollo3::iom::IOM2.enable();

// Setup BLE
apollo3::mcuctrl::MCUCTRL.enable_ble();
apollo3::clkgen::CLKGEN.enable_ble();
apollo3::pwrctrl::PWRCTRL.enable_ble();
apollo3::ble::BLE.setup_clocks();
apollo3::mcuctrl::MCUCTRL.reset_ble();
apollo3::ble::BLE.power_up();
apollo3::ble::BLE.ble_initialise();

let ble_radio =
ble::BLEComponent::new(board_kernel, &apollo3::ble::BLE, mux_alarm).finalize(());

apollo3::mcuctrl::MCUCTRL.print_chip_revision();

debug!("Initialization complete. Entering main loop");

extern "C" {
Expand All @@ -198,6 +219,7 @@ pub unsafe fn reset_handler() {
gpio,
led,
i2c_master,
ble_radio,
};

kernel::procs::load_processes(
Expand Down

0 comments on commit 3fa20f8

Please sign in to comment.