root / lab3 / kbc.c @ 32
History | View | Annotate | Download (1.35 KB)
1 |
#include <lcom/lcf.h> |
---|---|
2 |
|
3 |
#include "kbc.h" |
4 |
#include "kbc_func.h" |
5 |
|
6 |
int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id) { |
7 |
if (interrupt_id == NULL) return 1; |
8 |
*interrupt_id = interrupt_bit; |
9 |
return (sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id));
|
10 |
} |
11 |
|
12 |
int (unsubscribe_kbc_interrupt)(int *interrupt_id) { |
13 |
if (interrupt_id == NULL) return 1; |
14 |
return sys_irqrmpolicy(interrupt_id);
|
15 |
} |
16 |
|
17 |
uint8_t scancode[2];
|
18 |
int two_byte_scancode = 0; |
19 |
int got_error = 0; |
20 |
|
21 |
void (kbc_ih)(void) { |
22 |
uint8_t status = 0;
|
23 |
got_error = 0;
|
24 |
|
25 |
#ifdef LAB3
|
26 |
sys_inb_counter(INCREMENT); |
27 |
#endif
|
28 |
|
29 |
if (util_sys_inb(STATUS_REG, &status)) {
|
30 |
got_error = 1;
|
31 |
return;
|
32 |
} |
33 |
|
34 |
if (status & (TIME_OUT_REC | PARITY_ERROR)) {
|
35 |
got_error = 1;
|
36 |
return;
|
37 |
} |
38 |
|
39 |
#ifdef LAB3
|
40 |
sys_inb_counter(INCREMENT); |
41 |
#endif
|
42 |
|
43 |
uint8_t byte = 0;
|
44 |
|
45 |
if (util_sys_inb(OUTPUT_BUF, &byte)) {
|
46 |
got_error = 1;
|
47 |
return;
|
48 |
} |
49 |
|
50 |
if (two_byte_scancode) {
|
51 |
scancode[1] = byte;
|
52 |
two_byte_scancode = 0;
|
53 |
} else {
|
54 |
scancode[0] = byte;
|
55 |
two_byte_scancode = (byte == TWO_BYTE_CODE); |
56 |
} |
57 |
|
58 |
} |
59 |
|
60 |
uint32_t (sys_inb_counter)(int increment) {
|
61 |
static uint32_t counter = 0; |
62 |
if (increment) return ++counter; |
63 |
return counter;
|
64 |
} |