Fixed suggestions, added nRF51 to BLE

This commit is contained in:
Erik Bånvik 2024-03-05 15:01:05 +01:00
parent 5b5d54c0c7
commit bb73d6b3fe
4 changed files with 10 additions and 57 deletions

View file

@ -11,8 +11,8 @@ pub use pac::radio::mode::MODE_A as Mode;
use pac::radio::pcnf0::PLEN_A as PreambleLength; use pac::radio::pcnf0::PLEN_A as PreambleLength;
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
pub use crate::radio::Error;
use crate::radio::*; use crate::radio::*;
pub use crate::radio::{Error, TxPower};
use crate::util::slice_in_ram_or; use crate::util::slice_in_ram_or;
/// Radio driver. /// Radio driver.
@ -103,15 +103,7 @@ impl<'d, T: Instance> Radio<'d, T> {
} }
fn state(&self) -> RadioState { fn state(&self) -> RadioState {
match T::regs().state.read().state().variant() { super::state(T::regs())
Some(s) => s,
None => unreachable!(),
}
}
#[allow(dead_code)]
fn trace_state(&self) {
super::trace_state(T::regs())
} }
/// Set the radio mode /// Set the radio mode
@ -318,9 +310,6 @@ impl<'d, T: Instance> Radio<'d, T> {
// Initialize the transmission // Initialize the transmission
// trace!("txen"); // trace!("txen");
#[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
r.tasks_txen.write(|w| w.tasks_txen().set_bit());
#[cfg(any(feature = "nrf51", feature = "nrf52832"))]
r.tasks_txen.write(|w| unsafe { w.bits(1) }); r.tasks_txen.write(|w| unsafe { w.bits(1) });
}) })
.await; .await;
@ -338,9 +327,6 @@ impl<'d, T: Instance> Radio<'d, T> {
self.trigger_and_wait_end(move || { self.trigger_and_wait_end(move || {
// Initialize the transmission // Initialize the transmission
// trace!("rxen"); // trace!("rxen");
#[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
r.tasks_rxen.write(|w| w.tasks_rxen().set_bit());
#[cfg(any(feature = "nrf51", feature = "nrf52832"))]
r.tasks_rxen.write(|w| unsafe { w.bits(1) }); r.tasks_rxen.write(|w| unsafe { w.bits(1) });
}) })
.await; .await;
@ -363,15 +349,9 @@ impl<'d, T: Instance> Radio<'d, T> {
r.intenclr.write(|w| w.end().clear()); r.intenclr.write(|w| w.end().clear());
r.events_end.reset(); r.events_end.reset();
#[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
r.tasks_stop.write(|w| w.tasks_stop().set_bit());
#[cfg(any(feature = "nrf51", feature = "nrf52832"))]
r.tasks_stop.write(|w| unsafe { w.bits(1) }); r.tasks_stop.write(|w| unsafe { w.bits(1) });
// The docs don't explicitly mention any event to acknowledge the stop task // The docs don't explicitly mention any event to acknowledge the stop task
#[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
while r.events_end.read().events_end().bit_is_clear() {}
#[cfg(any(feature = "nrf51", feature = "nrf52832"))]
while r.events_end.read().bits() == 0 {} while r.events_end.read().bits() == 0 {}
trace!("radio drop: stopped"); trace!("radio drop: stopped");
@ -393,11 +373,7 @@ impl<'d, T: Instance> Radio<'d, T> {
// On poll check if interrupt happen // On poll check if interrupt happen
poll_fn(|cx| { poll_fn(|cx| {
s.event_waker.register(cx.waker()); s.event_waker.register(cx.waker());
#[cfg(not(any(feature = "nrf51", feature = "nrf52832")))] if r.events_end.read().bits() == 1 {
let end_event = r.events_end.read().events_end().bit_is_set();
#[cfg(any(feature = "nrf51", feature = "nrf52832"))]
let end_event = r.events_end.read().bits() == 1;
if end_event {
// trace!("radio:end"); // trace!("radio:end");
return core::task::Poll::Ready(()); return core::task::Poll::Ready(());
} }
@ -421,15 +397,9 @@ impl<'d, T: Instance> Radio<'d, T> {
if self.state() != RadioState::DISABLED { if self.state() != RadioState::DISABLED {
trace!("radio:disable"); trace!("radio:disable");
// Trigger the disable task // Trigger the disable task
#[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
r.tasks_disable.write(|w| w.tasks_disable().set_bit());
#[cfg(any(feature = "nrf51", feature = "nrf52832"))]
r.tasks_disable.write(|w| unsafe { w.bits(1) }); r.tasks_disable.write(|w| unsafe { w.bits(1) });
// Wait until the radio is disabled // Wait until the radio is disabled
#[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
while r.events_disabled.read().events_disabled().bit_is_clear() {}
#[cfg(any(feature = "nrf51", feature = "nrf52832"))]
while r.events_disabled.read().bits() == 0 {} while r.events_disabled.read().bits() == 0 {}
compiler_fence(Ordering::SeqCst); compiler_fence(Ordering::SeqCst);

View file

@ -162,19 +162,19 @@ impl<'d, T: Instance> Radio<'d, T> {
self.needs_enable = true; self.needs_enable = true;
let tx_power: TxPower = match power { let tx_power: TxPower = match power {
#[cfg(not(feature = "_nrf5340-net"))] #[cfg(not(any(feature = "nrf52811", feature = "_nrf5340-net")))]
8 => TxPower::POS8D_BM, 8 => TxPower::POS8D_BM,
#[cfg(not(feature = "_nrf5340-net"))] #[cfg(not(any(feature = "nrf52811", feature = "_nrf5340-net")))]
7 => TxPower::POS7D_BM, 7 => TxPower::POS7D_BM,
#[cfg(not(feature = "_nrf5340-net"))] #[cfg(not(any(feature = "nrf52811", feature = "_nrf5340-net")))]
6 => TxPower::POS6D_BM, 6 => TxPower::POS6D_BM,
#[cfg(not(feature = "_nrf5340-net"))] #[cfg(not(any(feature = "nrf52811", feature = "_nrf5340-net")))]
5 => TxPower::POS5D_BM, 5 => TxPower::POS5D_BM,
#[cfg(not(feature = "_nrf5340-net"))] #[cfg(not(feature = "_nrf5340-net"))]
4 => TxPower::POS4D_BM, 4 => TxPower::POS4D_BM,
#[cfg(not(feature = "_nrf5340-net"))] #[cfg(not(feature = "_nrf5340-net"))]
3 => TxPower::POS3D_BM, 3 => TxPower::POS3D_BM,
#[cfg(not(feature = "_nrf5340-net"))] #[cfg(not(any(feature = "nrf52811", feature = "_nrf5340-net")))]
2 => TxPower::POS2D_BM, 2 => TxPower::POS2D_BM,
0 => TxPower::_0D_BM, 0 => TxPower::_0D_BM,
#[cfg(feature = "_nrf5340-net")] #[cfg(feature = "_nrf5340-net")]

View file

@ -6,9 +6,9 @@
#![macro_use] #![macro_use]
/// Bluetooth Low Energy Radio driver. /// Bluetooth Low Energy Radio driver.
#[cfg(not(feature = "nrf51"))]
pub mod ble; pub mod ble;
#[cfg(any( #[cfg(any(
feature = "nrf52811",
feature = "nrf52820", feature = "nrf52820",
feature = "nrf52833", feature = "nrf52833",
feature = "nrf52840", feature = "nrf52840",
@ -20,8 +20,7 @@ pub mod ieee802154;
use core::marker::PhantomData; use core::marker::PhantomData;
use pac::radio::state::STATE_A as RadioState; use pac::radio::state::STATE_A as RadioState;
#[cfg(not(feature = "nrf51"))] pub use pac::radio::txpower::TXPOWER_A as TxPower;
use pac::radio::txpower::TXPOWER_A as TxPower;
use crate::{interrupt, pac, Peripheral}; use crate::{interrupt, pac, Peripheral};
@ -109,18 +108,3 @@ pub(crate) fn state(radio: &pac::radio::RegisterBlock) -> RadioState {
None => unreachable!(), None => unreachable!(),
} }
} }
#[allow(dead_code)]
pub(crate) fn trace_state(radio: &pac::radio::RegisterBlock) {
match state(radio) {
RadioState::DISABLED => trace!("radio:state:DISABLED"),
RadioState::RX_RU => trace!("radio:state:RX_RU"),
RadioState::RX_IDLE => trace!("radio:state:RX_IDLE"),
RadioState::RX => trace!("radio:state:RX"),
RadioState::RX_DISABLE => trace!("radio:state:RX_DISABLE"),
RadioState::TX_RU => trace!("radio:state:TX_RU"),
RadioState::TX_IDLE => trace!("radio:state:TX_IDLE"),
RadioState::TX => trace!("radio:state:TX"),
RadioState::TX_DISABLE => trace!("radio:state:TX_DISABLE"),
}
}

View file

@ -34,7 +34,6 @@ pub(crate) fn slice_in_ram<T>(slice: *const [T]) -> bool {
} }
/// Return an error if slice is not in RAM. Skips check if slice is zero-length. /// Return an error if slice is not in RAM. Skips check if slice is zero-length.
#[cfg(not(feature = "nrf51"))]
pub(crate) fn slice_in_ram_or<T, E>(slice: *const [T], err: E) -> Result<(), E> { pub(crate) fn slice_in_ram_or<T, E>(slice: *const [T], err: E) -> Result<(), E> {
let (_, len) = slice_ptr_parts(slice); let (_, len) = slice_ptr_parts(slice);
if len == 0 || slice_in_ram(slice) { if len == 0 || slice_in_ram(slice) {