-
Notifications
You must be signed in to change notification settings - Fork 61
Closed
Description
Hi all!
I'm trying to force the Rust compiler to assume the contents of a &mut [u8]
has changed after a DMA operation.
In the std library, calls to things like std::fs::File::read
take a &mut [u8]
and after the call, the contents of that slice have changed. The Rust compiler knows it can not assume the contents of that buffer after the call to read
.
I need to do something similar with DMA. After a DMA operation has been completed (and hardware has written bytes to memory), the Rust compiler must assume the buf
has changed.
My current solution (below) is to use asm!
. Will that do the trick? Is there a more portable way?
Something like:
fn dma_read(&mut self, buf: &mut [u8]) {
// Zero out buffer
buf.fill(0);
let addr = buf.as_mut_ptr() as usize;
let len = buf.len();
// Setup DMA via MMIO
self.reg.dma_addr.set(addr);
self.reg.dma_len.set(len);
// Start DMA via MMIO
self.reg.dma_start.set(1);
// Wait for DMA to complete via MMIO
while self.reg.dma_done.get() != 1 {}
// Insert an `asm!` block to force Rust to assume `buf` has been modified
unsafe { core::arch::asm!("mov {},{}", out(reg) _, in(reg) addr) };
// Read "buf"
// At this point, how can I ensure the Rust compiler will assume buf has been modified?
}
Metadata
Metadata
Assignees
Labels
No labels