Refactor: Move interrupt wakers/operations into separate modules

This commit is contained in:
Philipp Oppermann
2020-03-09 08:22:43 +01:00
parent 08582948c5
commit 3d485535ae
9 changed files with 106 additions and 74 deletions

View File

@@ -1,11 +1,38 @@
use crate::{interrupts, print};
use crate::{print, println, task::interrupt_wake};
use conquer_once::spin::OnceCell;
use core::future::Future;
use core::{
pin::Pin,
task::{Context, Poll},
};
use crossbeam_queue::ArrayQueue;
use futures_util::task::AtomicWaker;
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
static WAKER: AtomicWaker = AtomicWaker::new();
static SCANCODE_QUEUE: OnceCell<ArrayQueue<u8>> = OnceCell::uninit();
pub fn init() {
SCANCODE_QUEUE
.try_init_once(|| ArrayQueue::new(10))
.expect("failed to init scancode queue");
}
/// Called by the keyboard interrupt handler
///
/// Must not block (including spinlocks).
pub(crate) fn keyboard_scancode(scancode: u8) {
let scancode_queue = SCANCODE_QUEUE
.try_get()
.expect("scancode queue not initialized");
if let Err(_) = scancode_queue.push(scancode) {
println!("WARNING: dropping keyboard input");
}
if let Some(waker) = WAKER.take() {
interrupt_wake(waker);
}
}
fn next_scancode() -> impl Future<Output = u8> {
NextScancode
}
@@ -16,7 +43,7 @@ impl Future for NextScancode {
type Output = u8;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<u8> {
let scancodes = interrupts::SCANCODE_QUEUE
let scancodes = SCANCODE_QUEUE
.try_get()
.expect("scancode queue not initialized");
// fast path
@@ -24,7 +51,7 @@ impl Future for NextScancode {
return Poll::Ready(scancode);
}
interrupts::KEYBOARD_INTERRUPT_WAKER.register(&cx.waker());
WAKER.register(&cx.waker());
match scancodes.pop() {
Ok(scancode) => Poll::Ready(scancode),
Err(crossbeam_queue::PopError) => Poll::Pending,
@@ -32,7 +59,7 @@ impl Future for NextScancode {
}
}
pub async fn print_keypresses() {
pub async fn keyboard_task() {
let mut keyboard = Keyboard::new(layouts::Us104Key, ScancodeSet1, HandleControl::Ignore);
loop {