Skip to content
Snippets Groups Projects
Commit c089e7e5 authored by Jorge Aparicio's avatar Jorge Aparicio
Browse files

rename Buffer.free to Buffer.release

parent 8e0b5333
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,7 @@ extern crate cortex_m_rtfm as rtfm; ...@@ -20,7 +20,7 @@ extern crate cortex_m_rtfm as rtfm;
#[macro_use] #[macro_use]
extern crate nb; extern crate nb;
use blue_pill::led::{Green, self}; use blue_pill::led::{self, Green};
use blue_pill::time::Hertz; use blue_pill::time::Hertz;
use blue_pill::{Timer, stm32f103xx}; use blue_pill::{Timer, stm32f103xx};
use hal::prelude::*; use hal::prelude::*;
......
...@@ -100,11 +100,9 @@ fn idle(ref prio: P0, ref thr: T0) -> ! { ...@@ -100,11 +100,9 @@ fn idle(ref prio: P0, ref thr: T0) -> ! {
} }
})(); })();
let mut loopback = (|| { let mut loopback = (|| loop {
loop {
let byte = await!(serial.read()).unwrap(); let byte = await!(serial.read()).unwrap();
await!(serial.write()).unwrap(); await!(serial.write()).unwrap();
}
})(); })();
// Resume the timer count // Resume the timer count
......
...@@ -13,7 +13,7 @@ extern crate cortex_m_rt; ...@@ -13,7 +13,7 @@ extern crate cortex_m_rt;
#[macro_use] #[macro_use]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
use blue_pill::gpio::{PB12, self}; use blue_pill::gpio::{self, PB12};
use blue_pill::stm32f103xx; use blue_pill::stm32f103xx;
use rtfm::{P0, T0, TMax}; use rtfm::{P0, T0, TMax};
......
...@@ -13,7 +13,7 @@ extern crate cortex_m_rt; ...@@ -13,7 +13,7 @@ extern crate cortex_m_rt;
#[macro_use] #[macro_use]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
use blue_pill::led::{Green, self}; use blue_pill::led::{self, Green};
use blue_pill::stm32f103xx; use blue_pill::stm32f103xx;
use rtfm::{P0, T0, TMax}; use rtfm::{P0, T0, TMax};
......
//! Test the USART1 instance //! Test receiving serial data using the DMA
//!
//! Connect the TX and RX pins to run this test
#![feature(const_fn)] #![feature(const_fn)]
#![feature(used)] #![feature(used)]
...@@ -87,7 +85,7 @@ fn done(_task: DMA1_CHANNEL5, ref prio: P1, ref thr: T1) { ...@@ -87,7 +85,7 @@ fn done(_task: DMA1_CHANNEL5, ref prio: P1, ref thr: T1) {
let buffer = BUFFER.access(prio, thr); let buffer = BUFFER.access(prio, thr);
let dma1 = &DMA1.access(prio, thr); let dma1 = &DMA1.access(prio, thr);
buffer.free(dma1).unwrap(); buffer.release(dma1).unwrap();
rtfm::bkpt(); rtfm::bkpt();
} }
//! Test the USART1 instance //! Test sending serial data using the DMA
//!
//! Connect the TX and RX pins to run this test
#![feature(const_fn)] #![feature(const_fn)]
#![feature(used)] #![feature(used)]
...@@ -88,7 +86,7 @@ fn done(_task: DMA1_CHANNEL4, ref prio: P1, ref thr: T1) { ...@@ -88,7 +86,7 @@ fn done(_task: DMA1_CHANNEL4, ref prio: P1, ref thr: T1) {
let buffer = BUFFER.access(prio, thr); let buffer = BUFFER.access(prio, thr);
let dma1 = &DMA1.access(prio, thr); let dma1 = &DMA1.access(prio, thr);
buffer.free(dma1).unwrap(); buffer.release(dma1).unwrap();
rtfm::bkpt(); rtfm::bkpt();
} }
...@@ -178,10 +178,10 @@ impl<T, CHANNEL> Buffer<T, CHANNEL> { ...@@ -178,10 +178,10 @@ impl<T, CHANNEL> Buffer<T, CHANNEL> {
} }
} }
// FIXME these `free` methods probably want some of sort of barrier // FIXME these `release` methods probably want some of sort of barrier
impl<T> Buffer<T, Dma1Channel4> { impl<T> Buffer<T, Dma1Channel4> {
/// Waits until this buffer is freed by the DMA /// Waits until the DMA releases this buffer
pub fn free(&self, dma1: &DMA1) -> nb::Result<(), Error> { pub fn release(&self, dma1: &DMA1) -> nb::Result<(), Error> {
let status = self.status.get(); let status = self.status.get();
if status == Status::Unlocked { if status == Status::Unlocked {
...@@ -202,8 +202,8 @@ impl<T> Buffer<T, Dma1Channel4> { ...@@ -202,8 +202,8 @@ impl<T> Buffer<T, Dma1Channel4> {
} }
impl<T> Buffer<T, Dma1Channel5> { impl<T> Buffer<T, Dma1Channel5> {
/// Waits until this buffer is freed by the DMA /// Waits until the DMA releases this buffer
pub fn free(&self, dma1: &DMA1) -> nb::Result<(), Error> { pub fn release(&self, dma1: &DMA1) -> nb::Result<(), Error> {
let status = self.status.get(); let status = self.status.get();
if status == Status::Unlocked { if status == Status::Unlocked {
......
...@@ -383,6 +383,9 @@ where ...@@ -383,6 +383,9 @@ where
impl<'a> Serial<'a, USART1> { impl<'a> Serial<'a, USART1> {
/// Starts a DMA transfer to receive serial data into a `buffer` /// Starts a DMA transfer to receive serial data into a `buffer`
///
/// This will mutably lock the `buffer` preventing borrowing its contents
/// The `buffer` can be `release`d after the DMA transfer finishes
// TODO support circular mode + half transfer interrupt as a double // TODO support circular mode + half transfer interrupt as a double
// buffering mode // buffering mode
pub fn read_exact<B>( pub fn read_exact<B>(
...@@ -416,6 +419,9 @@ impl<'a> Serial<'a, USART1> { ...@@ -416,6 +419,9 @@ impl<'a> Serial<'a, USART1> {
} }
/// Starts a DMA transfer to send `buffer` through this serial port /// Starts a DMA transfer to send `buffer` through this serial port
///
/// This will immutably lock the `buffer` preventing mutably borrowing its
/// contents. The `buffer` can be `release`d after the DMA transfer finishes
pub fn write_all<B>( pub fn write_all<B>(
&self, &self,
dma1: &DMA1, dma1: &DMA1,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment