rp/uart: extract fifo draining from blocking_read
this will also be needed for dma operations.
This commit is contained in:
parent
be66e0f7ce
commit
1d5adb8974
@ -238,16 +238,22 @@ impl<'d, T: Instance, M: Mode> UartRx<'d, T, M> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error> {
|
pub fn blocking_read(&mut self, mut buffer: &mut [u8]) -> Result<(), Error> {
|
||||||
let r = T::regs();
|
while buffer.len() > 0 {
|
||||||
unsafe {
|
let received = self.drain_fifo(buffer)?;
|
||||||
for b in buffer {
|
buffer = &mut buffer[received..];
|
||||||
*b = loop {
|
}
|
||||||
if r.uartfr().read().rxfe() {
|
Ok(())
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let dr = r.uartdr().read();
|
fn drain_fifo(&mut self, buffer: &mut [u8]) -> Result<usize, Error> {
|
||||||
|
let r = T::regs();
|
||||||
|
for (i, b) in buffer.iter_mut().enumerate() {
|
||||||
|
if unsafe { r.uartfr().read().rxfe() } {
|
||||||
|
return Ok(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
let dr = unsafe { r.uartdr().read() };
|
||||||
|
|
||||||
if dr.oe() {
|
if dr.oe() {
|
||||||
return Err(Error::Overrun);
|
return Err(Error::Overrun);
|
||||||
@ -258,12 +264,10 @@ impl<'d, T: Instance, M: Mode> UartRx<'d, T, M> {
|
|||||||
} else if dr.fe() {
|
} else if dr.fe() {
|
||||||
return Err(Error::Framing);
|
return Err(Error::Framing);
|
||||||
} else {
|
} else {
|
||||||
break dr.data();
|
*b = dr.data();
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(buffer.len())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user