1
0
Fork 0

sdio: convert Adma2Desc32 to VolatileCells, make ADMA2_DESCR32_TABLE: MaybeUninit

This commit is contained in:
Astro 2020-06-10 00:17:53 +02:00 committed by Gitea
parent b942cdcbc8
commit 32349e9dec
1 changed files with 11 additions and 20 deletions

View File

@ -1,22 +1,18 @@
/// ADMA library /// ADMA library
use core::mem::MaybeUninit;
use super::SDIO; use super::SDIO;
use libcortex_a9::cache; use libcortex_a9::cache;
use libregister::RegisterR; use libregister::{RegisterR, VolatileCell};
#[repr(C, align(4))] #[repr(C, align(4))]
#[derive(Clone, Copy)]
pub struct Adma2Desc32 { pub struct Adma2Desc32 {
attribute: u16, attribute: VolatileCell<u16>,
length: u16, length: VolatileCell<u16>,
address: u32, address: VolatileCell<u32>,
} }
// Default::default() cannot be used as it is not a constant function... // Default::default() cannot be used as it is not a constant function...
static mut ADMA2_DESCR32_TABLE: [Adma2Desc32; 32] = [Adma2Desc32 { static mut ADMA2_DESCR32_TABLE: MaybeUninit<[Adma2Desc32; 32]> = MaybeUninit::uninit();
attribute: 0,
length: 0,
address: 0,
}; 32];
#[allow(unused)] #[allow(unused)]
const DESC_MAX_LENGTH: u32 = 65536; const DESC_MAX_LENGTH: u32 = 65536;
@ -32,26 +28,21 @@ const DESC_VALID: u16 = 0x1 << 0;
#[allow(unused)] #[allow(unused)]
impl Adma2Desc32 { impl Adma2Desc32 {
pub fn set_attribute(&mut self, attribute: u16) { pub fn set_attribute(&mut self, attribute: u16) {
unsafe { self.attribute.set(attribute)
core::ptr::write_volatile(&mut self.attribute as *mut u16, attribute);
}
} }
pub fn set_length(&mut self, length: u16) { pub fn set_length(&mut self, length: u16) {
unsafe { self.length.set(length)
core::ptr::write_volatile(&mut self.length as *mut u16, length);
}
} }
pub fn set_address(&mut self, address: u32) { pub fn set_address(&mut self, address: u32) {
unsafe { self.address.set(address)
core::ptr::write_volatile(&mut self.address as *mut u32, address);
}
} }
} }
/// Initialize `ADMA2_DESCR32_TABLE` and setup `adma_system_address`
pub fn setup_adma2_descr32(sdio: &mut SDIO, blk_cnt: u32, buffer: &[u8]) { pub fn setup_adma2_descr32(sdio: &mut SDIO, blk_cnt: u32, buffer: &[u8]) {
let descr_table = unsafe { &mut ADMA2_DESCR32_TABLE }; let descr_table = unsafe { &mut *ADMA2_DESCR32_TABLE.as_mut_ptr() };
let blk_size = sdio let blk_size = sdio
.regs .regs
.block_size_block_count .block_size_block_count