Rm spin::Mutex except for easy-fs & add new test huge_write & flush cache to disk after a write transaction

This commit is contained in:
Yifan Wu 2021-07-21 19:10:04 +08:00
parent 569e2fe2fe
commit b8a14182cd
36 changed files with 339 additions and 229 deletions

View file

@ -13,7 +13,7 @@ use k210_soc::{
sysctl,
sleep::usleep,
};
use spin::Mutex;
use crate::sync::UPSafeCell;
use lazy_static::*;
use super::BlockDevice;
use core::convert::TryInto;
@ -711,7 +711,9 @@ fn io_init() {
}
lazy_static! {
static ref PERIPHERALS: Mutex<Peripherals> = Mutex::new(Peripherals::take().unwrap());
static ref PERIPHERALS: UPSafeCell<Peripherals> = unsafe {
UPSafeCell::new(Peripherals::take().unwrap())
};
}
fn init_sdcard() -> SDCard<SPIImpl<SPI0>> {
@ -735,19 +737,19 @@ fn init_sdcard() -> SDCard<SPIImpl<SPI0>> {
sd
}
pub struct SDCardWrapper(Mutex<SDCard<SPIImpl<SPI0>>>);
pub struct SDCardWrapper(UPSafeCell<SDCard<SPIImpl<SPI0>>>);
impl SDCardWrapper {
pub fn new() -> Self {
Self(Mutex::new(init_sdcard()))
unsafe { Self(UPSafeCell::new(init_sdcard())) }
}
}
impl BlockDevice for SDCardWrapper {
fn read_block(&self, block_id: usize, buf: &mut [u8]) {
self.0.lock().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.lock().write_sector(buf,block_id as u32).unwrap();
self.0.exclusive_access().write_sector(buf,block_id as u32).unwrap();
}
}