Small Fix && cargo fmt
This commit is contained in:
parent
c9583b0f53
commit
ae3ba9c26f
83 changed files with 1085 additions and 1079 deletions
|
@ -1,9 +1,9 @@
|
|||
mod virtio_blk;
|
||||
mod sdcard;
|
||||
mod virtio_blk;
|
||||
|
||||
use lazy_static::*;
|
||||
use alloc::sync::Arc;
|
||||
use easy_fs::BlockDevice;
|
||||
use lazy_static::*;
|
||||
|
||||
#[cfg(feature = "board_qemu")]
|
||||
type BlockDeviceImpl = virtio_blk::VirtIOBlock;
|
||||
|
@ -21,10 +21,12 @@ pub fn block_device_test() {
|
|||
let mut write_buffer = [0u8; 512];
|
||||
let mut read_buffer = [0u8; 512];
|
||||
for i in 0..512 {
|
||||
for byte in write_buffer.iter_mut() { *byte = i as u8; }
|
||||
for byte in write_buffer.iter_mut() {
|
||||
*byte = i as u8;
|
||||
}
|
||||
block_device.write_block(i as usize, &write_buffer);
|
||||
block_device.read_block(i as usize, &mut read_buffer);
|
||||
assert_eq!(write_buffer, read_buffer);
|
||||
}
|
||||
println!("block device test passed!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,21 +2,21 @@
|
|||
#![allow(non_camel_case_types)]
|
||||
#![allow(unused)]
|
||||
|
||||
use k210_pac::{Peripherals, SPI0};
|
||||
use super::BlockDevice;
|
||||
use crate::sync::UPSafeCell;
|
||||
use core::convert::TryInto;
|
||||
use k210_hal::prelude::*;
|
||||
use k210_pac::{Peripherals, SPI0};
|
||||
use k210_soc::{
|
||||
fpioa::{self, io},
|
||||
//dmac::{dma_channel, DMAC, DMACExt},
|
||||
gpio,
|
||||
gpiohs,
|
||||
spi::{aitm, frame_format, tmod, work_mode, SPI, SPIExt, SPIImpl},
|
||||
fpioa::{self, io},
|
||||
sysctl,
|
||||
sleep::usleep,
|
||||
spi::{aitm, frame_format, tmod, work_mode, SPIExt, SPIImpl, SPI},
|
||||
sysctl,
|
||||
};
|
||||
use crate::sync::UPSafeCell;
|
||||
use lazy_static::*;
|
||||
use super::BlockDevice;
|
||||
use core::convert::TryInto;
|
||||
|
||||
pub struct SDCard<SPI> {
|
||||
spi: SPI,
|
||||
|
@ -160,7 +160,11 @@ pub struct SDCardInfo {
|
|||
}
|
||||
|
||||
impl</*'a,*/ X: SPI> SDCard</*'a,*/ X> {
|
||||
pub fn new(spi: X, spi_cs: u32, cs_gpionum: u8/*, dmac: &'a DMAC, channel: dma_channel*/) -> Self {
|
||||
pub fn new(
|
||||
spi: X,
|
||||
spi_cs: u32,
|
||||
cs_gpionum: u8, /*, dmac: &'a DMAC, channel: dma_channel*/
|
||||
) -> Self {
|
||||
Self {
|
||||
spi,
|
||||
spi_cs,
|
||||
|
@ -606,7 +610,7 @@ impl</*'a,*/ X: SPI> SDCard</*'a,*/ X> {
|
|||
}
|
||||
let mut error = false;
|
||||
//let mut dma_chunk = [0u32; SEC_LEN];
|
||||
let mut tmp_chunk= [0u8; SEC_LEN];
|
||||
let mut tmp_chunk = [0u8; SEC_LEN];
|
||||
for chunk in data_buf.chunks_mut(SEC_LEN) {
|
||||
if self.get_response() != SD_START_DATA_SINGLE_BLOCK_READ {
|
||||
error = true;
|
||||
|
@ -616,7 +620,7 @@ impl</*'a,*/ X: SPI> SDCard</*'a,*/ X> {
|
|||
//self.read_data_dma(&mut dma_chunk);
|
||||
self.read_data(&mut tmp_chunk);
|
||||
/* Place the data received as u32 units from DMA into the u8 target buffer */
|
||||
for (a, b) in chunk.iter_mut().zip(/*dma_chunk*/tmp_chunk.iter()) {
|
||||
for (a, b) in chunk.iter_mut().zip(/*dma_chunk*/ tmp_chunk.iter()) {
|
||||
//*a = (b & 0xff) as u8;
|
||||
*a = *b;
|
||||
}
|
||||
|
@ -675,7 +679,7 @@ impl</*'a,*/ X: SPI> SDCard</*'a,*/ X> {
|
|||
/* Send the data token to signify the start of the data */
|
||||
self.write_data(&frame);
|
||||
/* Write the block data to SD : write count data by block */
|
||||
for (a, &b) in /*dma_chunk*/tmp_chunk.iter_mut().zip(chunk.iter()) {
|
||||
for (a, &b) in /*dma_chunk*/ tmp_chunk.iter_mut().zip(chunk.iter()) {
|
||||
//*a = b.into();
|
||||
*a = b;
|
||||
}
|
||||
|
@ -711,9 +715,8 @@ fn io_init() {
|
|||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref PERIPHERALS: UPSafeCell<Peripherals> = unsafe {
|
||||
UPSafeCell::new(Peripherals::take().unwrap())
|
||||
};
|
||||
static ref PERIPHERALS: UPSafeCell<Peripherals> =
|
||||
unsafe { UPSafeCell::new(Peripherals::take().unwrap()) };
|
||||
}
|
||||
|
||||
fn init_sdcard() -> SDCard<SPIImpl<SPI0>> {
|
||||
|
@ -747,9 +750,15 @@ impl SDCardWrapper {
|
|||
|
||||
impl BlockDevice for SDCardWrapper {
|
||||
fn read_block(&self, block_id: usize, buf: &mut [u8]) {
|
||||
self.0.exclusive_access().read_sector(buf,block_id as u32).unwrap();
|
||||
self.0
|
||||
.exclusive_access()
|
||||
.read_sector(buf, block_id as u32)
|
||||
.unwrap();
|
||||
}
|
||||
fn write_block(&self, block_id: usize, buf: &[u8]) {
|
||||
self.0.exclusive_access().write_sector(buf,block_id as u32).unwrap();
|
||||
self.0
|
||||
.exclusive_access()
|
||||
.write_sector(buf, block_id as u32)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,12 @@
|
|||
|
||||
use virtio_drivers::{VirtIOBlk, VirtIOHeader};
|
||||
use crate::mm::{
|
||||
PhysAddr,
|
||||
VirtAddr,
|
||||
frame_alloc,
|
||||
frame_dealloc,
|
||||
PhysPageNum,
|
||||
FrameTracker,
|
||||
StepByOne,
|
||||
PageTable,
|
||||
kernel_token,
|
||||
};
|
||||
use super::BlockDevice;
|
||||
use crate::mm::{
|
||||
frame_alloc, frame_dealloc, kernel_token, FrameTracker, PageTable, PhysAddr, PhysPageNum,
|
||||
StepByOne, VirtAddr,
|
||||
};
|
||||
use crate::sync::UPSafeCell;
|
||||
use alloc::vec::Vec;
|
||||
use lazy_static::*;
|
||||
use virtio_drivers::{VirtIOBlk, VirtIOHeader};
|
||||
|
||||
#[allow(unused)]
|
||||
const VIRTIO0: usize = 0x10001000;
|
||||
|
@ -22,21 +14,21 @@ const VIRTIO0: usize = 0x10001000;
|
|||
pub struct VirtIOBlock(UPSafeCell<VirtIOBlk<'static>>);
|
||||
|
||||
lazy_static! {
|
||||
static ref QUEUE_FRAMES: UPSafeCell<Vec<FrameTracker>> = unsafe {
|
||||
UPSafeCell::new(Vec::new())
|
||||
};
|
||||
static ref QUEUE_FRAMES: UPSafeCell<Vec<FrameTracker>> = unsafe { UPSafeCell::new(Vec::new()) };
|
||||
}
|
||||
|
||||
impl BlockDevice for VirtIOBlock {
|
||||
fn read_block(&self, block_id: usize, buf: &mut [u8]) {
|
||||
self.0.exclusive_access()
|
||||
.read_block(block_id, buf)
|
||||
.expect("Error when reading VirtIOBlk");
|
||||
self.0
|
||||
.exclusive_access()
|
||||
.read_block(block_id, buf)
|
||||
.expect("Error when reading VirtIOBlk");
|
||||
}
|
||||
fn write_block(&self, block_id: usize, buf: &[u8]) {
|
||||
self.0.exclusive_access()
|
||||
.write_block(block_id, buf)
|
||||
.expect("Error when writing VirtIOBlk");
|
||||
self.0
|
||||
.exclusive_access()
|
||||
.write_block(block_id, buf)
|
||||
.expect("Error when writing VirtIOBlk");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,9 +36,9 @@ impl VirtIOBlock {
|
|||
#[allow(unused)]
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
Self(UPSafeCell::new(VirtIOBlk::new(
|
||||
&mut *(VIRTIO0 as *mut VirtIOHeader)
|
||||
).unwrap()))
|
||||
Self(UPSafeCell::new(
|
||||
VirtIOBlk::new(&mut *(VIRTIO0 as *mut VirtIOHeader)).unwrap(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +48,9 @@ pub extern "C" fn virtio_dma_alloc(pages: usize) -> PhysAddr {
|
|||
let mut ppn_base = PhysPageNum(0);
|
||||
for i in 0..pages {
|
||||
let frame = frame_alloc().unwrap();
|
||||
if i == 0 { ppn_base = frame.ppn; }
|
||||
if i == 0 {
|
||||
ppn_base = frame.ppn;
|
||||
}
|
||||
assert_eq!(frame.ppn.0, ppn_base.0 + i);
|
||||
QUEUE_FRAMES.exclusive_access().push(frame);
|
||||
}
|
||||
|
@ -80,5 +74,7 @@ pub extern "C" fn virtio_phys_to_virt(paddr: PhysAddr) -> VirtAddr {
|
|||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn virtio_virt_to_phys(vaddr: VirtAddr) -> PhysAddr {
|
||||
PageTable::from_token(kernel_token()).translate_va(vaddr).unwrap()
|
||||
PageTable::from_token(kernel_token())
|
||||
.translate_va(vaddr)
|
||||
.unwrap()
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
mod block;
|
||||
|
||||
pub use block::BLOCK_DEVICE;
|
||||
pub use block::BLOCK_DEVICE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue