39 lines
911 B
C
39 lines
911 B
C
#include <stdint.h>
|
|
#include "proc/proc.h"
|
|
#include "dlmalloc/malloc.h"
|
|
#include "ipc/pipe/pipe.h"
|
|
#include "kprintf.h"
|
|
#include "rbuf/rbuf.h"
|
|
#include "ps2kbproc.h"
|
|
|
|
Proc *PS2KBPROC = NULL;
|
|
Ps2KbFastBuf PS2KB_BUF;
|
|
|
|
void ps2kbproc_init(Proc *proc) {
|
|
PS2KBPROC = proc;
|
|
|
|
PS2KBPROC->bcast_pipes.list = NULL;
|
|
|
|
uint8_t *buf = dlmalloc(IPC_PIPE_MAX);
|
|
rbuf_init(&PS2KB_BUF.rbuf, buf, IPC_PIPE_MAX);
|
|
spinlock_init(&PS2KB_BUF.spinlock);
|
|
}
|
|
|
|
void ps2kbproc_fn(void) {
|
|
for (;;) {
|
|
uint8_t b = 0;
|
|
spinlock_acquire(&PS2KB_BUF.spinlock);
|
|
if (rbuf_pop(&PS2KB_BUF.rbuf, &b) == 0) {
|
|
spinlock_acquire(&PS2KBPROC->bcast_pipes.spinlock);
|
|
IpcPipe *head = PS2KBPROC->bcast_pipes.list;
|
|
while (head != NULL) {
|
|
ipc_pipewrite(head, &b, 1);
|
|
head = head->next;
|
|
}
|
|
spinlock_release(&PS2KBPROC->bcast_pipes.spinlock);
|
|
}
|
|
spinlock_release(&PS2KB_BUF.spinlock);
|
|
}
|
|
}
|
|
|