Suspend process waiting for keyboard input
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m35s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m35s
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <m/status.h>
|
||||
#include <proc/capability.h>
|
||||
#include <proc/proc.h>
|
||||
#include <proc/suspension_q.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/debug.h>
|
||||
#include <sys/smp.h>
|
||||
@@ -41,6 +42,7 @@
|
||||
|
||||
static struct ringbuffer ps2kb_ringbuffer;
|
||||
static spin_lock_t ps2kb_ringbuffer_lock = SPIN_LOCK_INIT;
|
||||
static struct proc_suspension_q ps2kb_sq;
|
||||
|
||||
static uint8_t shiftcode[0x100] = {
|
||||
[0x1d] = KB_CTL, [0x2a] = KB_SHIFT, [0x36] = KB_SHIFT,
|
||||
@@ -161,35 +163,61 @@ int32_t ps2kb_keycode (void) {
|
||||
return c;
|
||||
}
|
||||
|
||||
void ps2kb_irq (void* arg, void* regs) {
|
||||
bool ps2kb_irq (struct cpu** reschedule_cpu, void* arg, void* regs) {
|
||||
int32_t keycode = ps2kb_keycode ();
|
||||
|
||||
if (keycode >= 0) {
|
||||
spin_lock (&ps2kb_ringbuffer_lock);
|
||||
ringbuffer_push (uint8_t, &ps2kb_ringbuffer, (uint8_t)keycode);
|
||||
if (keycode <= 0)
|
||||
return PROC_NO_RESCHEDULE;
|
||||
|
||||
spin_lock (&ps2kb_ringbuffer_lock);
|
||||
spin_lock (&ps2kb_sq.lock);
|
||||
|
||||
ringbuffer_push (uint8_t, &ps2kb_ringbuffer, (uint8_t)keycode);
|
||||
|
||||
struct list_node_link* node = ps2kb_sq.proc_list;
|
||||
|
||||
if (node) {
|
||||
struct proc_sq_entry* sq_entry = list_entry (node, struct proc_sq_entry, sq_link);
|
||||
struct proc* resumed_proc = sq_entry->proc;
|
||||
|
||||
spin_unlock (&ps2kb_sq.lock);
|
||||
spin_unlock (&ps2kb_ringbuffer_lock);
|
||||
|
||||
return proc_sq_resume (resumed_proc, sq_entry, reschedule_cpu);
|
||||
}
|
||||
|
||||
spin_unlock (&ps2kb_sq.lock);
|
||||
spin_unlock (&ps2kb_ringbuffer_lock);
|
||||
|
||||
return PROC_NO_RESCHEDULE;
|
||||
}
|
||||
|
||||
int ps2kb_read_key (struct proc* proc, void* a1, void* a2, void* a3, void* a4) {
|
||||
if (!(proc->procgroup->capabilities & PROC_CAP_KB))
|
||||
return -ST_PERMISSION_ERROR;
|
||||
bool ps2kb_read_key (struct proc* proc, struct cpu** reschedule_cpu, int* ret, void* a1, void* a2,
|
||||
void* a3, void* a4) {
|
||||
if (!(proc->procgroup->capabilities & PROC_CAP_KB)) {
|
||||
*ret = -ST_PERMISSION_ERROR;
|
||||
return PROC_NO_RESCHEDULE;
|
||||
}
|
||||
|
||||
uint8_t* chbuf = (uint8_t*)a1;
|
||||
|
||||
spin_lock (&ps2kb_ringbuffer_lock);
|
||||
|
||||
size_t prev_count = ps2kb_ringbuffer.count;
|
||||
|
||||
ringbuffer_pop (uint8_t, &ps2kb_ringbuffer, chbuf);
|
||||
|
||||
size_t new_count = ps2kb_ringbuffer.count;
|
||||
|
||||
spin_unlock (&ps2kb_ringbuffer_lock);
|
||||
*ret = ST_OK;
|
||||
|
||||
/* didn't pop anything */
|
||||
if (prev_count == new_count)
|
||||
return -ST_TRY_AGAIN;
|
||||
return proc_sq_suspend (proc, &ps2kb_sq, &ps2kb_ringbuffer_lock, reschedule_cpu);
|
||||
|
||||
return ST_OK;
|
||||
spin_unlock (&ps2kb_ringbuffer_lock);
|
||||
|
||||
return PROC_NO_RESCHEDULE;
|
||||
}
|
||||
|
||||
bool ps2kb_init (void* arg) {
|
||||
|
||||
Reference in New Issue
Block a user