mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-22 16:16:16 +04:00
mutex added.
This commit is contained in:
parent
edf9cf1225
commit
8c3323c4d4
@ -8,6 +8,7 @@ use crate::arch::driver::ide;
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
use crate::arch::board::emmc;
|
||||
use crate::sync::SpinNoIrqLock as Mutex;
|
||||
|
||||
pub struct MemBuf(RwLock<&'static mut [u8]>);
|
||||
|
||||
@ -63,20 +64,25 @@ impl BlockDevice for ide::IDE {
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
impl BlockDevice for emmc::EmmcCtl {
|
||||
pub struct EmmcDriver(Mutex<emmc::EmmcCtl>);
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
impl BlockDevice for EmmcDriver {
|
||||
const BLOCK_SIZE_LOG2: u8 = 9;
|
||||
fn read_at(&self, block_id: usize, buf: &mut [u8]) -> Result<()> {
|
||||
use core::slice;
|
||||
assert!(buf.len() >= emmc::BLOCK_SIZE);
|
||||
let buf = unsafe { slice::from_raw_parts_mut(buf.as_ptr() as *mut u32, emmc::BLOCK_SIZE / 4) };
|
||||
self.read(block_id as u32, 1, buf).map_err(|_| DevError)?;
|
||||
let mut ctrl = self.0.lock();
|
||||
ctrl.read(block_id as u32, 1, buf).map_err(|_| DevError)?;
|
||||
Ok(())
|
||||
}
|
||||
fn write_at(&self, block_id: usize, buf: &[u8]) -> Result<()> {
|
||||
use core::slice;
|
||||
assert!(buf.len() >= emmc::BLOCK_SIZE);
|
||||
let buf = unsafe { slice::from_raw_parts(buf.as_ptr() as *mut u32, emmc::BLOCK_SIZE / 4) };
|
||||
self.write(block_id as u32, 1, buf).map_err(|_| DevError)?;
|
||||
let mut ctrl = self.0.lock();
|
||||
ctrl.write(block_id as u32, 1, buf).map_err(|_| DevError)?;
|
||||
Ok(())
|
||||
}
|
||||
fn sync(&self) -> Result<()> {
|
||||
|
Loading…
Reference in New Issue
Block a user