root / lab3 / kbc.c @ 30
History | View | Annotate | Download (1.19 KB)
1 | 30 | up20180655 | #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 | |||
20 | void (kbc_ih)(void) { |
||
21 | uint8_t status = 0;
|
||
22 | |||
23 | #ifdef LAB3
|
||
24 | sys_inb_counter(INCREMENT); |
||
25 | #endif
|
||
26 | |||
27 | if (util_sys_inb(STATUS_REG, &status)) return; |
||
28 | |||
29 | if (status & (TIME_OUT_REC | PARITY_ERROR)) return; |
||
30 | |||
31 | #ifdef LAB3
|
||
32 | sys_inb_counter(INCREMENT); |
||
33 | #endif
|
||
34 | |||
35 | uint8_t byte = 0;
|
||
36 | |||
37 | if (util_sys_inb(OUTPUT_BUF, &byte)) return; |
||
38 | |||
39 | if (two_byte_scancode) {
|
||
40 | scancode[1] = byte;
|
||
41 | two_byte_scancode = 0;
|
||
42 | } else {
|
||
43 | scancode[0] = byte;
|
||
44 | two_byte_scancode = (byte == TWO_BYTE_CODE); |
||
45 | } |
||
46 | |||
47 | } |
||
48 | |||
49 | uint32_t sys_inb_counter(int increment) {
|
||
50 | static uint32_t counter = 0; |
||
51 | if (increment) return ++counter; |
||
52 | return counter;
|
||
53 | } |