Merge pull request #3588 from elagil/fix_sai_write_immediate
Right-align `write_immediate()` in ring buffers
This commit is contained in:
commit
8086fc4dff
@ -252,9 +252,20 @@ impl<'a, W: Word> WritableDmaRingBuffer<'a, W> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Write elements directly to the buffer.
|
/// Write elements directly to the buffer.
|
||||||
|
///
|
||||||
|
/// Subsequent writes will overwrite the content of the buffer, so it is not useful to call this more than once.
|
||||||
|
/// Data is aligned towards the end of the buffer.
|
||||||
|
///
|
||||||
|
/// In case of success, returns the written length, and the empty space in front of the written block.
|
||||||
|
/// Fails if the data to write exceeds the buffer capacity.
|
||||||
pub fn write_immediate(&mut self, buf: &[W]) -> Result<(usize, usize), Error> {
|
pub fn write_immediate(&mut self, buf: &[W]) -> Result<(usize, usize), Error> {
|
||||||
|
if buf.len() > self.cap() {
|
||||||
|
return Err(Error::Overrun);
|
||||||
|
}
|
||||||
|
|
||||||
|
let start = self.cap() - buf.len();
|
||||||
for (i, data) in buf.iter().enumerate() {
|
for (i, data) in buf.iter().enumerate() {
|
||||||
self.write_buf(i, *data)
|
self.write_buf(start + i, *data)
|
||||||
}
|
}
|
||||||
let written = buf.len().min(self.cap());
|
let written = buf.len().min(self.cap());
|
||||||
Ok((written, self.cap() - written))
|
Ok((written, self.cap() - written))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user