From 0ebc4a61c8b012376960294a3b93f78182ab2ee7 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Tue, 9 Jun 2020 17:03:17 +0800 Subject: [PATCH] Modified SDIO to handle u8 buffer instead of u32. --- experiments/src/main.rs | 8 ++++---- libboard_zynq/src/sdio/adma.rs | 2 +- libboard_zynq/src/sdio/sd_card.rs | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/experiments/src/main.rs b/experiments/src/main.rs index 3c96cf2..c7594ad 100644 --- a/experiments/src/main.rs +++ b/experiments/src/main.rs @@ -91,17 +91,17 @@ pub fn main_core0() { Ok(_) => info!("OK!"), Err(a) => info!("{:?}", a), }; - const SIZE: usize = 512 / 2; + const SIZE: usize = 512 * 2 + 1; let mut sd_card = result.unwrap(); - let mut buffer: [u32; SIZE] = [0; SIZE]; + let mut buffer: [u8; SIZE] = [0; SIZE]; for i in 0..buffer.len() { - buffer[i] = (i % 16) as u32; + buffer[i] = (i % 16) as u8; } sd_card.write_block(0x0, 2, &mut buffer).unwrap(); for i in 0..buffer.len() { buffer[i] = 0; } - sd_card.read_block(0x1, 2, &mut buffer).unwrap(); + sd_card.read_block(0x1, 2, &mut buffer[1..]).unwrap(); for i in 0..buffer.len() { info!("buffer[{}] = {}", i, buffer[i]); } diff --git a/libboard_zynq/src/sdio/adma.rs b/libboard_zynq/src/sdio/adma.rs index 3d6f4a3..9f80b7f 100644 --- a/libboard_zynq/src/sdio/adma.rs +++ b/libboard_zynq/src/sdio/adma.rs @@ -62,7 +62,7 @@ impl Adma2Desc32 { } } -pub fn setup_adma2_descr32(sdio: &mut SDIO, blk_cnt: u32, buffer: &mut [u32]) { +pub fn setup_adma2_descr32(sdio: &mut SDIO, blk_cnt: u32, buffer: &mut [u8]) { let descr_table = unsafe { &mut ADMA2_DESCR32_TABLE }; let blk_size = sdio .regs diff --git a/libboard_zynq/src/sdio/sd_card.rs b/libboard_zynq/src/sdio/sd_card.rs index 26824f9..a58f605 100644 --- a/libboard_zynq/src/sdio/sd_card.rs +++ b/libboard_zynq/src/sdio/sd_card.rs @@ -143,7 +143,7 @@ impl SdCard { self.sdio.cmd_transfer(CMD55, self.rel_card_addr, 0)?; self.sdio.cmd_transfer(ACMD42, 0, 0)?; - let mut scr: [u32; 8] = [0; 8]; + let mut scr: [u8; 32] = [0; 32]; self.get_bus_width(&mut scr)?; debug!("{:?}", scr); if scr[1] & 0x4 != 0 { @@ -188,9 +188,9 @@ impl SdCard { &mut self, address: u32, block_cnt: u16, - buffer: &mut [u32], + buffer: &mut [u8], ) -> Result<(), CmdTransferError> { - assert!(buffer.len() >= (block_cnt as usize) * (512 / 4)); + assert!(buffer.len() >= (block_cnt as usize) * 512); // set block size if not set already if self .sdio @@ -241,9 +241,9 @@ impl SdCard { &mut self, address: u32, block_cnt: u16, - buffer: &mut [u32], + buffer: &mut [u8], ) -> Result<(), CmdTransferError> { - assert!(buffer.len() >= (block_cnt as usize) * (512 / 4)); + assert!(buffer.len() >= (block_cnt as usize) * 512); // set block size if not set already if self .sdio @@ -287,7 +287,7 @@ impl SdCard { Ok(()) } - fn get_bus_width(&mut self, buf: &mut [u32]) -> Result<(), CmdTransferError> { + fn get_bus_width(&mut self, buf: &mut [u8]) -> Result<(), CmdTransferError> { use cmd::SdCmd::*; debug!("Getting bus width"); for i in 0..8 {