feature: add derive macro for auto-CharDevice
This commit is contained in:
@@ -12,7 +12,6 @@ use libsys::error::Errno;
|
||||
use tock_registers::interfaces::{ReadWriteable, Readable, Writeable};
|
||||
use tock_registers::registers::{Aliased, ReadOnly, ReadWrite};
|
||||
use tock_registers::{register_bitfields, register_structs};
|
||||
use vfs::{CharDevice, IoctlCmd};
|
||||
|
||||
register_bitfields! [
|
||||
u32,
|
||||
@@ -78,6 +77,7 @@ struct UartInner {
|
||||
regs: DeviceMemoryIo<Regs>,
|
||||
}
|
||||
|
||||
#[derive(TtyCharDevice)]
|
||||
pub(super) struct Uart {
|
||||
inner: InitOnce<IrqSafeSpinLock<UartInner>>,
|
||||
ring: CharRing<16>,
|
||||
@@ -123,22 +123,6 @@ impl SerialDevice for Uart {
|
||||
}
|
||||
}
|
||||
|
||||
impl CharDevice for Uart {
|
||||
fn read(&self, blocking: bool, data: &mut [u8]) -> Result<usize, Errno> {
|
||||
assert!(blocking);
|
||||
self.line_read(data)
|
||||
}
|
||||
|
||||
fn write(&self, blocking: bool, data: &[u8]) -> Result<usize, Errno> {
|
||||
assert!(blocking);
|
||||
self.line_write(data)
|
||||
}
|
||||
|
||||
fn ioctl(&self, cmd: IoctlCmd, ptr: usize, len: usize) -> Result<usize, Errno> {
|
||||
self.tty_ioctl(cmd, ptr, len)
|
||||
}
|
||||
}
|
||||
|
||||
impl TtyDevice<16> for Uart {
|
||||
fn ring(&self) -> &CharRing<16> {
|
||||
&self.ring
|
||||
|
||||
@@ -78,6 +78,7 @@ struct Pl011Inner {
|
||||
}
|
||||
|
||||
/// Device struct for PL011
|
||||
#[derive(TtyCharDevice)]
|
||||
pub struct Pl011 {
|
||||
inner: InitOnce<IrqSafeSpinLock<Pl011Inner>>,
|
||||
ring: CharRing<16>,
|
||||
@@ -117,16 +118,16 @@ impl Pl011Inner {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Write for Pl011Inner {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
for &c in s.as_bytes() {
|
||||
unsafe {
|
||||
self.send(c);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
// impl fmt::Write for Pl011Inner {
|
||||
// fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
// for &c in s.as_bytes() {
|
||||
// unsafe {
|
||||
// self.send(c);
|
||||
// }
|
||||
// }
|
||||
// Ok(())
|
||||
// }
|
||||
// }
|
||||
|
||||
impl IntSource for Pl011 {
|
||||
fn handle_irq(&self) -> Result<(), Errno> {
|
||||
@@ -168,21 +169,21 @@ impl SerialDevice for Pl011 {
|
||||
}
|
||||
}
|
||||
|
||||
impl CharDevice for Pl011 {
|
||||
fn read(&self, blocking: bool, data: &mut [u8]) -> Result<usize, Errno> {
|
||||
assert!(blocking);
|
||||
self.line_read(data)
|
||||
}
|
||||
|
||||
fn write(&self, blocking: bool, data: &[u8]) -> Result<usize, Errno> {
|
||||
assert!(blocking);
|
||||
self.line_write(data)
|
||||
}
|
||||
|
||||
fn ioctl(&self, cmd: IoctlCmd, ptr: usize, len: usize) -> Result<usize, Errno> {
|
||||
self.tty_ioctl(cmd, ptr, len)
|
||||
}
|
||||
}
|
||||
// impl CharDevice for Pl011 {
|
||||
// fn read(&self, blocking: bool, data: &mut [u8]) -> Result<usize, Errno> {
|
||||
// assert!(blocking);
|
||||
// self.line_read(data)
|
||||
// }
|
||||
//
|
||||
// fn write(&self, blocking: bool, data: &[u8]) -> Result<usize, Errno> {
|
||||
// assert!(blocking);
|
||||
// self.line_write(data)
|
||||
// }
|
||||
//
|
||||
// fn ioctl(&self, cmd: IoctlCmd, ptr: usize, len: usize) -> Result<usize, Errno> {
|
||||
// self.tty_ioctl(cmd, ptr, len)
|
||||
// }
|
||||
// }
|
||||
|
||||
impl TtyDevice<16> for Pl011 {
|
||||
fn ring(&self) -> &CharRing<16> {
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#![no_main]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate macros;
|
||||
#[macro_use]
|
||||
extern crate cfg_if;
|
||||
#[macro_use]
|
||||
|
||||
Reference in New Issue
Block a user