Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
rcore-os
RCore Tutorial V3
提交
c3ce3724
R
RCore Tutorial V3
项目概览
rcore-os
/
RCore Tutorial V3
上一次同步 1 年多
通知
15
Star
793
Fork
260
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
RCore Tutorial V3
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c3ce3724
编写于
1月 07, 2023
作者:
chyyuu1972
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add get input_dev events in user app, but still have some problems
上级
9d59a827
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
151 addition
and
30 deletion
+151
-30
os/Cargo.toml
os/Cargo.toml
+3
-1
os/src/drivers/input/mod.rs
os/src/drivers/input/mod.rs
+94
-28
os/src/main.rs
os/src/main.rs
+2
-1
os/src/syscall/input.rs
os/src/syscall/input.rs
+17
-0
os/src/syscall/mod.rs
os/src/syscall/mod.rs
+4
-0
user/src/bin/inputdev_event.rs
user/src/bin/inputdev_event.rs
+21
-0
user/src/lib.rs
user/src/lib.rs
+5
-0
user/src/syscall.rs
user/src/syscall.rs
+5
-0
未找到文件。
os/Cargo.toml
浏览文件 @
c3ce3724
...
...
@@ -13,7 +13,9 @@ buddy_system_allocator = "0.6"
bitflags
=
"1.2.1"
xmas-elf
=
"0.7.0"
volatile
=
"0.3"
virtio-drivers
=
{
git
=
"https://github.com/rcore-os/virtio-drivers"
,
rev
=
"4ee80e5"
}
#virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers", rev = "4ee80e5" }
virtio-drivers
=
{
git
=
"https://github.com/rcore-os/virtio-drivers"
,
rev
=
"70b5850"
}
easy-fs
=
{
path
=
"../easy-fs"
}
virtio-input-decoder
=
"0.1.4"
embedded-graphics
=
"0.7.1"
...
...
os/src/drivers/input/mod.rs
浏览文件 @
c3ce3724
use
crate
::
drivers
::
bus
::
virtio
::
VirtioHal
;
use
crate
::
sync
::
UPIntrFreeCell
;
use
crate
::
sync
::{
Condvar
,
UPIntrFreeCell
};
use
crate
::
task
::
schedule
;
use
alloc
::
collections
::
BTreeMap
;
use
alloc
::
collections
::
VecDeque
;
use
alloc
::
sync
::
Arc
;
use
core
::
any
::
Any
;
use
virtio_drivers
::{
VirtIOHeader
,
VirtIOInput
};
...
...
@@ -8,50 +11,113 @@ use virtio_input_decoder::{Decoder, Key, KeyType};
const
VIRTIO5
:
usize
=
0x10005000
;
const
VIRTIO6
:
usize
=
0x10006000
;
struct
VirtIOInputWrapper
(
UPIntrFreeCell
<
VirtIOInput
<
'static
,
VirtioHal
>>
);
struct
VirtIOInputInner
{
virtio_input
:
VirtIOInput
<
'static
,
VirtioHal
>
,
events
:
VecDeque
<
u64
>
,
}
struct
VirtIOInputWrapper
{
inner
:
UPIntrFreeCell
<
VirtIOInputInner
>
,
//condvars: BTreeMap<u16, Condvar>,
//condvar: Arc::<Condvar> ,
condvar
:
Condvar
,
}
pub
trait
InputDevice
:
Send
+
Sync
+
Any
{
fn
read_event
(
&
self
)
->
u64
;
fn
handle_irq
(
&
self
);
// fn events(&self) -> &VecDeque<u64>;
fn
is_empty
(
&
self
)
->
bool
;
}
lazy_static
::
lazy_static!
(
pub
static
ref
KEYBOARD_DEVICE
:
Arc
<
dyn
InputDevice
>
=
Arc
::
new
(
VirtIOInputWrapper
::
new
(
VIRTIO5
));
pub
static
ref
MOUSE_DEVICE
:
Arc
<
dyn
InputDevice
>
=
Arc
::
new
(
VirtIOInputWrapper
::
new
(
VIRTIO6
));
// pub static ref INPUT_CONDVAR: Arc::<Condvar> = Arc::new(Condvar::new());
);
// from virtio-drivers/src/input.rs
//const QUEUE_SIZE: u16 = 32;
// pub fn read_input_event() -> u64 {
// loop {
// //let mut inner = self.inner.exclusive_access();
// let kb=KEYBOARD_DEVICE.clone();
// let evs = kb.events();
// if let Some(event) = evs.pop_front() {
// return event;
// } else {
// let task_cx_ptr = INPUT_CONDVAR.clone().wait_no_sched();
// drop(inner);
// schedule(task_cx_ptr);
// }
// }
// }
impl
VirtIOInputWrapper
{
pub
fn
new
(
addr
:
usize
)
->
Self
{
Self
(
unsafe
{
UPIntrFreeCell
::
new
(
VirtIOInput
::
<
VirtioHal
>
::
new
(
&
mut
*
(
addr
as
*
mut
VirtIOHeader
))
.unwrap
(),
)
})
let
inner
=
VirtIOInputInner
{
virtio_input
:
unsafe
{
VirtIOInput
::
<
VirtioHal
>
::
new
(
&
mut
*
(
addr
as
*
mut
VirtIOHeader
))
.unwrap
()
},
events
:
VecDeque
::
new
(),
};
// let mut condvars = BTreeMap::new();
// let channels = QUEUE_SIZE;
// for i in 0..channels {
// let condvar = Condvar::new();
// condvars.insert(i, condvar);
// }
Self
{
inner
:
unsafe
{
UPIntrFreeCell
::
new
(
inner
)
},
//condvar: INPUT_CONDVAR.clone(),
condvar
:
Condvar
::
new
(),
}
}
}
impl
InputDevice
for
VirtIOInputWrapper
{
fn
handle_irq
(
&
self
)
{
let
mut
input
=
self
.0
.exclusive_access
();
input
.ack_interrupt
();
while
let
Some
(
event
)
=
input
.pop_pending_event
()
{
let
dtype
=
match
Decoder
::
decode
(
event
.event_type
as
usize
,
event
.code
as
usize
,
event
.value
as
usize
,
)
{
Ok
(
dtype
)
=>
dtype
,
Err
(
_
)
=>
break
,
};
match
dtype
{
virtio_input_decoder
::
DecodeType
::
Key
(
key
,
r
#
type
)
=>
{
if
r
#
type
==
KeyType
::
Press
{
match
key
{
_
=>
{}
}
}
}
_
=>
{}
fn
is_empty
(
&
self
)
->
bool
{
self
.inner
.exclusive_access
()
.events
.is_empty
()
}
fn
read_event
(
&
self
)
->
u64
{
loop
{
let
mut
inner
=
self
.inner
.exclusive_access
();
if
let
Some
(
event
)
=
inner
.events
.pop_front
()
{
return
event
;
}
else
{
let
task_cx_ptr
=
self
.condvar
.wait_no_sched
();
drop
(
inner
);
schedule
(
task_cx_ptr
);
}
}
}
// fn events(&self) -> &VecDeque<u64> {
// &self.inner.exclusive_access().events
// }
fn
handle_irq
(
&
self
)
{
let
mut
count
=
0
;
let
mut
result
=
0
;
let
mut
key
=
0
;
self
.inner
.exclusive_session
(|
inner
|
{
inner
.virtio_input
.ack_interrupt
();
while
let
Some
((
token
,
event
))
=
inner
.virtio_input
.pop_pending_event
()
{
count
+=
1
;
key
=
token
;
result
=
(
event
.event_type
as
u64
)
<<
48
|
(
event
.code
as
u64
)
<<
32
|
(
event
.value
)
as
u64
;
inner
.events
.push_back
(
result
);
println!
(
"[KERN] inputdev_handle_irq: event: {:x}"
,
result
);
}
});
if
count
>
0
{
//self.condvars.get(&key).unwrap().signal();
self
.condvar
.signal
();
};
}
}
os/src/main.rs
浏览文件 @
c3ce3724
...
...
@@ -3,8 +3,8 @@
#![feature(panic_info_message)]
#![feature(alloc_error_handler)]
//use crate::drivers::{GPU_DEVICE, KEYBOARD_DEVICE, MOUSE_DEVICE, INPUT_CONDVAR};
use
crate
::
drivers
::{
GPU_DEVICE
,
KEYBOARD_DEVICE
,
MOUSE_DEVICE
};
extern
crate
alloc
;
#[macro_use]
...
...
@@ -59,6 +59,7 @@ pub fn rust_main() -> ! {
UART
.init
();
println!
(
"KERN: init gpu"
);
let
_
gpu
=
GPU_DEVICE
.clone
();
//let _input_condvar = INPUT_CONDVAR.clone();
println!
(
"KERN: init keyboard"
);
let
_
keyboard
=
KEYBOARD_DEVICE
.clone
();
println!
(
"KERN: init mouse"
);
...
...
os/src/syscall/input.rs
0 → 100644
浏览文件 @
c3ce3724
//use crate::drivers::{KEYBOARD_DEVICE,MOUSE_DEVICE,INPUT_CONDVAR,read_input_event};
use
crate
::
drivers
::{
KEYBOARD_DEVICE
,
MOUSE_DEVICE
};
pub
fn
sys_event_get
()
->
isize
{
let
kb
=
KEYBOARD_DEVICE
.clone
();
let
mouse
=
MOUSE_DEVICE
.clone
();
//let input=INPUT_CONDVAR.clone();
//read_input_event() as isize
if
!
kb
.is_empty
(){
kb
.read_event
()
as
isize
}
else
if
!
mouse
.is_empty
()
{
mouse
.read_event
()
as
isize
}
else
{
0
}
}
\ No newline at end of file
os/src/syscall/mod.rs
浏览文件 @
c3ce3724
...
...
@@ -27,18 +27,21 @@ const SYSCALL_CONDVAR_SIGNAL: usize = 1031;
const
SYSCALL_CONDVAR_WAIT
:
usize
=
1032
;
const
SYSCALL_FRAMEBUFFER
:
usize
=
2000
;
const
SYSCALL_FRAMEBUFFER_FLUSH
:
usize
=
2001
;
const
SYSCALL_EVENT_GET
:
usize
=
3000
;
mod
fs
;
mod
process
;
mod
sync
;
mod
thread
;
mod
gui
;
mod
input
;
use
fs
::
*
;
use
process
::
*
;
use
sync
::
*
;
use
thread
::
*
;
use
gui
::
*
;
use
input
::
*
;
pub
fn
syscall
(
syscall_id
:
usize
,
args
:
[
usize
;
3
])
->
isize
{
match
syscall_id
{
...
...
@@ -71,6 +74,7 @@ pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize {
SYSCALL_CONDVAR_WAIT
=>
sys_condvar_wait
(
args
[
0
],
args
[
1
]),
SYSCALL_FRAMEBUFFER
=>
sys_framebuffer
(),
SYSCALL_FRAMEBUFFER_FLUSH
=>
sys_framebuffer_flush
(),
SYSCALL_EVENT_GET
=>
sys_event_get
(),
_
=>
panic!
(
"Unsupported syscall_id: {}"
,
syscall_id
),
}
}
user/src/bin/inputdev_event.rs
0 → 100644
浏览文件 @
c3ce3724
#![no_std]
#![no_main]
use
user_lib
::{
event_get
};
#[macro_use]
extern
crate
user_lib
;
#[no_mangle]
pub
fn
main
()
->
i32
{
println!
(
"Input device event test"
);
let
mut
event
=
0
;
for
_
in
0
..
3
{
while
event
==
0
{
event
=
event_get
();
}
println!
(
"event: {:?}"
,
event
);
}
0
}
\ No newline at end of file
user/src/lib.rs
浏览文件 @
c3ce3724
...
...
@@ -205,6 +205,11 @@ pub fn framebuffer_flush() -> isize {
sys_framebuffer_flush
()
}
pub
fn
event_get
()
->
isize
{
sys_event_get
()
}
#[macro_export]
macro_rules!
vstore
{
(
$var_ref
:
expr
,
$value
:
expr
)
=>
{
...
...
user/src/syscall.rs
浏览文件 @
c3ce3724
...
...
@@ -27,6 +27,7 @@ const SYSCALL_CONDVAR_SIGNAL: usize = 1031;
const
SYSCALL_CONDVAR_WAIT
:
usize
=
1032
;
const
SYSCALL_FRAMEBUFFER
:
usize
=
2000
;
const
SYSCALL_FRAMEBUFFER_FLUSH
:
usize
=
2001
;
const
SYSCALL_EVENT_GET
:
usize
=
3000
;
fn
syscall
(
id
:
usize
,
args
:
[
usize
;
3
])
->
isize
{
let
mut
ret
:
isize
;
...
...
@@ -164,4 +165,8 @@ pub fn sys_framebuffer() -> isize {
pub
fn
sys_framebuffer_flush
()
->
isize
{
syscall
(
SYSCALL_FRAMEBUFFER_FLUSH
,
[
0
,
0
,
0
])
}
pub
fn
sys_event_get
()
->
isize
{
syscall
(
SYSCALL_EVENT_GET
,
[
0
,
0
,
0
])
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录