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

Interrupted uart example missing from #102 #106

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
DMA_SIZE now parametrised
perlindgren authored and jacobrosenthal committed Jul 15, 2019
commit bc93bc259113ccfb309a4d4427271e6374126254
8 changes: 8 additions & 0 deletions nrf52-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -56,3 +56,11 @@ default = ["52832"]
52810 = ["nrf52810-pac"]
52832 = ["nrf52832-pac"]
52840 = ["nrf52840-pac"]
POOL = []
DMA_SIZE_4 = []
DMA_SIZE_8 = []
DMA_SIZE_16 = []
DMA_SIZE_32 = []
DMA_SIZE_64 = []
DMA_SIZE_128 = []
DMA_SIZE_256 = []
68 changes: 53 additions & 15 deletions nrf52-hal-common/src/uarte.rs
Original file line number Diff line number Diff line change
@@ -24,9 +24,7 @@ use heapless::{
};

// Re-export SVD variants to allow user to directly set values
pub use crate::target::uarte0::{
baudrate::BAUDRATEW as Baudrate, config::PARITYW as Parity,
};
pub use crate::target::uarte0::{baudrate::BAUDRATEW as Baudrate, config::PARITYW as Parity};

/// Interface to a UARTE instance
///
@@ -42,12 +40,7 @@ impl<T> Uarte<T>
where
T: Instance,
{
pub fn new(
uarte: T,
mut pins: Pins,
parity: Parity,
baudrate: Baudrate,
) -> Self {
pub fn new(uarte: T, mut pins: Pins, parity: Parity, baudrate: Baudrate) -> Self {
// Select pins
uarte.psel.rxd.write(|w| {
let w = unsafe { w.pin().bits(pins.rxd.pin) };
@@ -91,9 +84,9 @@ where

// Configure
let hardware_flow_control = pins.rts.is_some() && pins.cts.is_some();
uarte.config.write(|w| {
w.hwfc().bit(hardware_flow_control).parity().variant(parity)
});
uarte
.config
.write(|w| w.hwfc().bit(hardware_flow_control).parity().variant(parity));

// Configure frequency
uarte.baudrate.write(|w| w.baudrate().variant(baudrate));
@@ -344,7 +337,54 @@ where
}

/// DMA block size
/// Defaults to DMA_SIZE = 16 if not explicitly set
#[cfg(not(any(
feature = "DMA_SIZE_4",
feature = "DMA_SIZE_8",
feature = "DMA_SIZE_16",
feature = "DMA_SIZE_32",
feature = "DMA_SIZE_64",
feature = "DMA_SIZE_128",
feature = "DMA_SIZE_256"
)))]
pub const DMA_SIZE: usize = 16;

#[cfg(feature = "DMA_SIZE_4")]
pub const DMA_SIZE: usize = 4;

#[cfg(feature = "DMA_SIZE_8")]
pub const DMA_SIZE: usize = 8;

#[cfg(feature = "DMA_SIZE_16")]
pub const DMA_SIZE: usize = 16;

#[cfg(feature = "DMA_SIZE_32")]
pub const DMA_SIZE: usize = 32;

#[cfg(feature = "DMA_SIZE_64")]
pub const DMA_SIZE: usize = 64;

#[cfg(feature = "DMA_SIZE_128")]
pub const DMA_SIZE: usize = 128;

// Currently causes internal OOM, needs fixing
#[cfg(feature = "DMA_SIZE_256")]
pub const DMA_SIZE: usize = 256;

// An alternative solution to the above is to define the DMA_SIZE
// in a separate (default) crate, which can be overridden
// by a patch in the user Cargo.toml, pointing to
// a local crate with the user defined DMA_SIZE constant.
// What would you prefer?

// The DMA implementation shuld be hidden behind a feature POOL
// This likely requires a mod {} around the related code
// or the non-ergonomic repetition of the gate.
// Is there a better solution?
//
// The reason to have a POOL gate is that we don't want the POOL
// to cause memory OH if not used by the application

pool!(DMAPool: [u8; DMA_SIZE]);

/// UARTE RX part, used in interrupt driven contexts
@@ -434,9 +474,7 @@ where
/// 1. `Ok(Some(Box<DMAPool>))` if data was received
/// 2. `Ok(None)` if there was no data, i.e. UARTE interrupt was due to other events
/// 3. `Err(RXError::OOM)` if the memory pool was depleted, see `RXError` for mitigations
pub fn process_interrupt(
&mut self,
) -> Result<Option<Box<DMAPool>>, RXError> {
pub fn process_interrupt(&mut self) -> Result<Option<Box<DMAPool>>, RXError> {
// This operation is safe due to type-state programming guaranteeing that the RX and TX are
// unique within the driver
let uarte = unsafe { &*T::ptr() };
13 changes: 12 additions & 1 deletion nrf52810-hal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -41,4 +41,15 @@ version = "0.2.1"
[features]
doc = []
rt = ["nrf52810-pac/rt"]
default = ["rt"]
default = ["rt", "POOL"]
POOL = ["nrf52-hal-common/POOL"]
DMA_SIZE_4 = ["nrf52-hal-common/DMA_SIZE_4"]
DMA_SIZE_8 = ["nrf52-hal-common/DMA_SIZE_8"]
DMA_SIZE_16 = ["nrf52-hal-common/DMA_SIZE_16"]
DMA_SIZE_32 = ["nrf52-hal-common/DMA_SIZE_32"]
DMA_SIZE_64 = ["nrf52-hal-common/DMA_SIZE_64"]
DMA_SIZE_128 = ["nrf52-hal-common/DMA_SIZE_128"]
DMA_SIZE_256 = ["nrf52-hal-common/DMA_SIZE_256"]



13 changes: 11 additions & 2 deletions nrf52832-hal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -42,8 +42,17 @@ doc = []
rt = ["nrf52832-pac/rt"]
xxAA-package = []
xxAB-package = []
POOL = ["nrf52-hal-common/POOL"]
DMA_SIZE_4 = ["nrf52-hal-common/DMA_SIZE_4"]
DMA_SIZE_8 = ["nrf52-hal-common/DMA_SIZE_8"]
DMA_SIZE_16 = ["nrf52-hal-common/DMA_SIZE_16"]
DMA_SIZE_32 = ["nrf52-hal-common/DMA_SIZE_32"]
DMA_SIZE_64 = ["nrf52-hal-common/DMA_SIZE_64"]
DMA_SIZE_128 = ["nrf52-hal-common/DMA_SIZE_128"]
DMA_SIZE_256 = ["nrf52-hal-common/DMA_SIZE_256"]


# Note: We use the xxAB package because it has the least amount of available resources.
# However, most users will want to use the xxAA package.
default = ["rt", "xxAB-package"]

# If disabling default features, "POOL" and "DMA_SIZE_XX" should be manually set.
default = ["rt", "xxAB-package", "POOL"]
12 changes: 11 additions & 1 deletion nrf52840-hal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -42,5 +42,15 @@ version = "0.2.1"
[features]
doc = []
rt = ["nrf52840-pac/rt"]
default = ["rt"]
default = ["rt", "POOL"]
POOL = ["nrf52-hal-common/POOL"]
DMA_SIZE_4 = ["nrf52-hal-common/DMA_SIZE_4"]
DMA_SIZE_8 = ["nrf52-hal-common/DMA_SIZE_8"]
DMA_SIZE_16 = ["nrf52-hal-common/DMA_SIZE_16"]
DMA_SIZE_32 = ["nrf52-hal-common/DMA_SIZE_32"]
DMA_SIZE_64 = ["nrf52-hal-common/DMA_SIZE_64"]
DMA_SIZE_128 = ["nrf52-hal-common/DMA_SIZE_128"]
DMA_SIZE_256 = ["nrf52-hal-common/DMA_SIZE_256"]