pub fn with_dma_quiesced<R>(
owners: DmaOwners<'_>,
f: impl FnOnce(&mut Quiesced<'_>) -> R,
) -> RExpand description
Run f with interrupts masked and every DMA channel idle, and hand it the Quiesced token
that lets it change the instruction cache.
The gate waits for the channels with interrupts on, masks, checks again, and backs out and
waits if a queued frame was kicked meanwhile (see QuiesceReport). owners stays
borrowed until f returns, so the closure cannot start a transfer. Keep f short:
VBlank and every other interrupt wait until it returns.
use psx_io::periph::{Cd, GpuDma, MdecDma, OrderingTableClearDma, SpuDma};
use psx_rt::cache::{with_dma_quiesced, DmaOwners};
// SAFETY: a doctest on the host; nothing else holds these tokens.
let (mut gpu, mut otc, mut mdec, mut spu, mut cd) = unsafe {
(GpuDma::steal(), OrderingTableClearDma::steal(), MdecDma::steal(), SpuDma::steal(), Cd::steal())
};
with_dma_quiesced(DmaOwners::new(&mut gpu, &mut otc, &mut mdec, &mut spu, &mut cd), |q| {
q.flush_icache();
});Starting a DMA inside the closure does not compile, because the token set is borrowed:
ⓘ
use psx_io::periph::{Cd, GpuDma, MdecDma, OrderingTableClearDma, SpuDma};
use psx_rt::cache::{with_dma_quiesced, DmaOwners};
// SAFETY: a doctest on the host; nothing else holds these tokens.
let (mut gpu, mut otc, mut mdec, mut spu, mut cd) = unsafe {
(GpuDma::steal(), OrderingTableClearDma::steal(), MdecDma::steal(), SpuDma::steal(), Cd::steal())
};
let mut table = [0u32; 16];
with_dma_quiesced(DmaOwners::new(&mut gpu, &mut otc, &mut mdec, &mut spu, &mut cd), |q| {
otc.clear_table(&mut table); // starts DMA 6 while the bus is held quiet
q.flush_icache();
});