root / lab4 / test / lab3 / keyboard.c @ 14
History | View | Annotate | Download (1.36 KB)
1 |
#include "keyboard.h" |
---|---|
2 |
//#include "lab3.c"
|
3 |
#include <lcom/lcf.h> |
4 |
|
5 |
#include <minix/sysutil.h> |
6 |
#include <stdint.h> |
7 |
|
8 |
#include "i8042.h" |
9 |
#include "i8254.h" |
10 |
|
11 |
#include <lcom/lab3.h> |
12 |
#include <stdbool.h> |
13 |
|
14 |
extern uint32_t scancode;
|
15 |
static int hook_id = 1; |
16 |
extern uint32_t cnt;
|
17 |
extern int flag; |
18 |
|
19 |
void(kbc_ih)() {
|
20 |
uint8_t scan_arr[2] = {0, 0}; |
21 |
|
22 |
#ifdef LAB3
|
23 |
cnt++; |
24 |
#endif
|
25 |
sys_inb(IN_BUF, &scancode); |
26 |
if (scancode & O_BUFFER_FULL) {
|
27 |
#ifdef LAB3
|
28 |
cnt++; |
29 |
#endif
|
30 |
sys_inb(I_O_BUFFER, &scancode); |
31 |
if (scancode != TWO_BYTES && flag == 0) { |
32 |
scan_arr[0] = scancode;
|
33 |
kbd_print_scancode(!(scancode & PAR_ERR), 1, scan_arr);
|
34 |
} |
35 |
|
36 |
else if (scancode == TWO_BYTES) { |
37 |
scan_arr[0] = scancode;
|
38 |
flag = 1;
|
39 |
} |
40 |
|
41 |
else if (flag == 1) { |
42 |
scan_arr[1] = scancode;
|
43 |
kbd_print_scancode(!(scancode & PAR_ERR), 2, scan_arr);
|
44 |
flag = 0;
|
45 |
} |
46 |
} |
47 |
|
48 |
} |
49 |
|
50 |
int kbd_subscribe_int(uint8_t *bit_no) {
|
51 |
*bit_no = hook_id; |
52 |
|
53 |
if (sys_irqsetpolicy(IRQ_KB, (IRQ_REENABLE | IRQ_EXCLUSIVE), &hook_id) != OK) {
|
54 |
printf("ERROR kbd subscribe failed");
|
55 |
return 1; |
56 |
} |
57 |
|
58 |
return 0; |
59 |
} |
60 |
|
61 |
int kbd_unsubscribe_int() {
|
62 |
if (sys_irqrmpolicy(&hook_id) != OK) {
|
63 |
printf("ERROR kbd unsubscribe failed");
|
64 |
return 1; |
65 |
} |
66 |
|
67 |
return 0; |
68 |
} |