use core::ops::Deref;
use proc_bitfield::bitfield;
use crate::RW;
pub struct PeripheralInterface {
r: &'static mut RegisterBlock,
}
#[repr(C)]
pub struct RegisterBlock {
pub dram_addr: RW<u32>,
pub cart_addr: RW<u32>,
pub rd_len: RW<u32>,
pub wr_len: RW<u32>,
pub status: RW<StatusReg>,
pub dom1_lat: RW<u32>,
pub dom1_pwd: RW<u32>,
pub dom1_pgs: RW<u32>,
pub dom1_rls: RW<u32>,
pub dom2_lat: RW<u32>,
pub dom2_pwd: RW<u32>,
pub dom2_pgs: RW<u32>,
pub dom2_rls: RW<u32>,
}
impl PeripheralInterface {
#[inline(always)]
pub unsafe fn new() -> Self { Self {
r: &mut *(0xA4600000 as *mut RegisterBlock)
}}
}
impl Deref for PeripheralInterface {
type Target = RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
self.r
}
}
regfn_rw_union!(PeripheralInterface, status, STATUS, StatusReg);
#[derive(Copy, Clone)]
#[repr(C)]
pub union StatusReg {
pub raw: u32,
pub read: StatusRegRead,
pub write: StatusRegWrite,
}
bitfield! {
#[derive(Copy, Clone, PartialEq, Eq)]
pub struct StatusRegRead(pub u32): Debug {
pub dma_busy: bool [ro] @ 0,
pub io_busy: bool [ro] @ 1,
pub dma_error: bool [ro] @ 2,
pub interrupt: bool [ro] @ 3,
}
}
bitfield! {
#[derive(Copy, Clone, PartialEq, Eq)]
pub struct StatusRegWrite(pub u32): Debug {
clear_interrupt: bool [wo] @ 0,
reset_dma: bool [wo] @ 1,
}
}
impl StatusRegWrite {
#[inline(always)]
pub fn clear_interrupt(self) -> Self {
self.with_clear_interrupt(true)
}
#[inline(always)]
pub fn reset_dma(self) -> Self {
self.with_reset_dma(true)
}
}