make build BOARD=k210 sucessfully
This commit is contained in:
parent
8e6f364ecc
commit
e7d6406f45
8 changed files with 96 additions and 9 deletions
|
@ -1,6 +1,12 @@
|
|||
use super::File;
|
||||
use crate::drivers::chardev::{CharDevice, UART};
|
||||
use crate::drivers::chardev::CharDevice;
|
||||
#[cfg(feature = "board_qemu")]
|
||||
use crate::drivers::chardev::UART;
|
||||
use crate::mm::UserBuffer;
|
||||
#[cfg(feature = "board_k210")]
|
||||
use crate::sbi::console_getchar;
|
||||
#[cfg(feature = "board_k210")]
|
||||
use crate::task::suspend_current_and_run_next;
|
||||
|
||||
pub struct Stdin;
|
||||
pub struct Stdout;
|
||||
|
@ -12,6 +18,7 @@ impl File for Stdin {
|
|||
fn writable(&self) -> bool {
|
||||
false
|
||||
}
|
||||
#[cfg(feature = "board_qemu")]
|
||||
fn read(&self, mut user_buf: UserBuffer) -> usize {
|
||||
assert_eq!(user_buf.len(), 1);
|
||||
//println!("before UART.read() in Stdin::read()");
|
||||
|
@ -21,6 +28,27 @@ impl File for Stdin {
|
|||
}
|
||||
1
|
||||
}
|
||||
#[cfg(feature = "board_k210")]
|
||||
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;
|
||||
unsafe {
|
||||
user_buf.buffers[0].as_mut_ptr().write_volatile(ch);
|
||||
}
|
||||
1
|
||||
}
|
||||
|
||||
fn write(&self, _user_buf: UserBuffer) -> usize {
|
||||
panic!("Cannot write to stdin!");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue