Skip to content

Commit

Permalink
Merge pull request #236 from kalkyl/spis-static
Browse files Browse the repository at this point in the history
Add 'static lifetime bounds to SPIS DMA buffers
  • Loading branch information
jonas-schievink authored Sep 29, 2020
2 parents 22910ee + 6a36313 commit 7d5f2cd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions nrf-hal-common/src/spis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ where
#[allow(unused_mut)]
pub fn transfer<W, B>(mut self, mut buffer: B) -> Result<Transfer<T, B>, (Error, Spis<T>, B)>
where
B: WriteBuffer<Word = W>,
B: WriteBuffer<Word = W> + 'static,
{
let (ptr, len) = unsafe { buffer.write_buffer() };
let maxcnt = len * core::mem::size_of::<W>();
Expand Down Expand Up @@ -371,8 +371,8 @@ where
mut rx_buffer: RxB,
) -> Result<TransferSplit<T, TxB, RxB>, (Error, Spis<T>, TxB, RxB)>
where
TxB: ReadBuffer<Word = TxW>,
RxB: WriteBuffer<Word = RxW>,
TxB: ReadBuffer<Word = TxW> + 'static,
RxB: WriteBuffer<Word = RxW> + 'static,
{
let (rx_ptr, rx_len) = unsafe { rx_buffer.write_buffer() };
let (tx_ptr, tx_len) = unsafe { tx_buffer.read_buffer() };
Expand Down Expand Up @@ -420,6 +420,7 @@ where

/// A DMA transfer
pub struct Transfer<T: Instance, B> {
// FIXME: Always `Some`, only using `Option` here to allow moving fields out of `inner`.
inner: Option<Inner<T, B>>,
}

Expand Down Expand Up @@ -463,6 +464,7 @@ impl<T: Instance, B> Drop for Transfer<T, B> {
}
/// A full duplex DMA transfer
pub struct TransferSplit<T: Instance, TxB, RxB> {
// FIXME: Always `Some`, only using `Option` here to allow moving fields out of `inner`.
inner: Option<InnerSplit<T, TxB, RxB>>,
}

Expand Down Expand Up @@ -490,15 +492,15 @@ impl<T: Instance, TxB, RxB> TransferSplit<T, TxB, RxB> {
pub fn is_done(&mut self) -> bool {
let inner = self
.inner
.take()
.as_mut()
.unwrap_or_else(|| unsafe { core::hint::unreachable_unchecked() });
inner.spis.is_done()
}
}

impl<T: Instance, TxB, RxB> Drop for TransferSplit<T, TxB, RxB> {
fn drop(&mut self) {
if let Some(inner) = self.inner.as_mut() {
if let Some(inner) = self.inner.take() {
compiler_fence(Ordering::SeqCst);
while !inner.spis.is_done() {}
inner.spis.disable();
Expand Down

0 comments on commit 7d5f2cd

Please sign in to comment.