Add ns16550a
This commit is contained in:
parent
fef12c79f1
commit
704eae3bb0
16 changed files with 311 additions and 129 deletions
|
@ -1,10 +1,8 @@
|
|||
use super::File;
|
||||
use crate::drivers::chardev::{CharDevice, UART};
|
||||
use crate::mm::UserBuffer;
|
||||
use crate::sbi::console_getchar;
|
||||
use crate::task::suspend_current_and_run_next;
|
||||
|
||||
pub struct Stdin;
|
||||
|
||||
pub struct Stdout;
|
||||
|
||||
impl File for Stdin {
|
||||
|
@ -16,18 +14,7 @@ impl File for Stdin {
|
|||
}
|
||||
fn read(&self, mut user_buf: UserBuffer) -> usize {
|
||||
assert_eq!(user_buf.len(), 1);
|
||||
// busy loop
|
||||
let mut c: usize;
|
||||
loop {
|
||||
c = console_getchar();
|
||||
if c == 0 {
|
||||
suspend_current_and_run_next();
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let ch = c as u8;
|
||||
let ch = UART.read();
|
||||
unsafe {
|
||||
user_buf.buffers[0].as_mut_ptr().write_volatile(ch);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue