From 6d10d3e3a332a413e6ea584f12ae8fb3a7cfb166 Mon Sep 17 00:00:00 2001 From: Yu Chen Date: Mon, 20 Jun 2022 23:57:11 +0800 Subject: [PATCH] in gui app, can recv keyboard and mouse info --- os/src/boards/qemu.rs | 6 +++++- os/src/drivers/input/mod.rs | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/os/src/boards/qemu.rs b/os/src/boards/qemu.rs index 93d1bad8..a3916dce 100644 --- a/os/src/boards/qemu.rs +++ b/os/src/boards/qemu.rs @@ -16,6 +16,7 @@ pub const VIRT_UART: usize = 0x1000_0000; use crate::drivers::block::BLOCK_DEVICE; use crate::drivers::chardev::{CharDevice, UART}; use crate::drivers::plic::{IntrTargetPriority, PLIC}; +use crate::drivers::{KEYBOARD_DEVICE, MOUSE_DEVICE}; pub fn device_init() { use riscv::register::sie; @@ -25,7 +26,8 @@ pub fn device_init() { let machine = IntrTargetPriority::Machine; plic.set_threshold(hart_id, supervisor, 0); plic.set_threshold(hart_id, machine, 1); - for intr_src_id in [8usize, 10] { + //irq nums: 5 keyboard, 6 mouse, 8 block, 10 uart + for intr_src_id in [5usize, 6, 8 , 10] { plic.enable(hart_id, supervisor, intr_src_id); plic.set_priority(intr_src_id, 1); } @@ -38,6 +40,8 @@ pub fn irq_handler() { let mut plic = unsafe { PLIC::new(VIRT_PLIC) }; let intr_src_id = plic.claim(0, IntrTargetPriority::Supervisor); match intr_src_id { + 5 => KEYBOARD_DEVICE.handle_irq(), + 6 => MOUSE_DEVICE.handle_irq(), 8 => BLOCK_DEVICE.handle_irq(), 10 => UART.handle_irq(), _ => panic!("unsupported IRQ {}", intr_src_id), diff --git a/os/src/drivers/input/mod.rs b/os/src/drivers/input/mod.rs index aa3022f3..0acb0345 100644 --- a/os/src/drivers/input/mod.rs +++ b/os/src/drivers/input/mod.rs @@ -21,7 +21,7 @@ const VIRTIO6: usize = 0x10006000; struct VirtIOINPUT(UPIntrFreeCell>); pub trait INPUTDevice: Send + Sync + Any { - fn handler_interrupt(&self); + fn handle_irq(&self); } lazy_static::lazy_static!( @@ -38,7 +38,7 @@ impl VirtIOINPUT { } impl INPUTDevice for VirtIOINPUT { - fn handler_interrupt(&self) { + fn handle_irq(&self) { let mut input = self.0.exclusive_access(); input.ack_interrupt(); let event = input.pop_pending_event().unwrap();