Revision 61
changes
lab3/kbc.c | ||
---|---|---|
43 | 43 |
return 1; |
44 | 44 |
} |
45 | 45 |
|
46 |
int (kbc_issue_arg)(uint8_t arg){ |
|
47 |
uint8_t stat; |
|
48 |
for(int i = 0; i < KBC_NUM_TRIES; ++i){ |
|
49 |
if(util_sys_inb(STATUS_REG, &stat)) return 1; |
|
50 |
if((stat&IN_BUF_FULL) == 0){ |
|
51 |
if(sys_outb(KBC_CMD_ARG, arg)) return 1; |
|
52 |
return 0; |
|
53 |
} |
|
54 |
tickdelay(micros_to_ticks(DELAY)); |
|
55 |
} |
|
56 |
return 1; |
|
57 |
} |
|
58 |
|
|
46 | 59 |
int (kbc_read_byte)(uint8_t *byte){ |
47 | 60 |
uint8_t stat; |
48 | 61 |
while(true){ |
lab3/kbc.h | ||
---|---|---|
45 | 45 |
int (kbc_issue_cmd)(uint8_t cmd); |
46 | 46 |
|
47 | 47 |
/** |
48 |
* @brief Low-level function to issue an argument of a command |
|
49 |
* @param cmd argument to be issued |
|
50 |
* @return 0 if operation was successful, 1 otherwise |
|
51 |
*/ |
|
52 |
int (kbc_issue_arg)(uint8_t arg); |
|
53 |
|
|
54 |
/** |
|
48 | 55 |
* @brief Low-level function for reading byte from keyboard |
49 | 56 |
* Low-level function for reading byte from keyboard. Waits until output buffer |
50 | 57 |
* is full |
lab3/keyboard.c | ||
---|---|---|
12 | 12 |
return (sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id)); |
13 | 13 |
} |
14 | 14 |
|
15 |
int done = 1; |
|
16 |
int sz = 1; |
|
15 | 17 |
int got_error_keyboard = 0; |
16 |
int two_byte_scancode = 0; |
|
17 | 18 |
|
18 | 19 |
void (kbc_ih)(void) { |
20 |
if(done) sz = 1; |
|
21 |
else sz++; |
|
19 | 22 |
uint8_t status = 0; |
20 | 23 |
got_error_keyboard = 0; |
21 |
|
|
22 | 24 |
if (util_sys_inb(STATUS_REG, &status)) { |
23 | 25 |
got_error_keyboard = 1; |
24 | 26 |
return; |
25 | 27 |
} |
26 |
|
|
27 | 28 |
if (status & (TIME_OUT_REC | PARITY_ERROR)) { |
28 | 29 |
got_error_keyboard = 1; |
29 | 30 |
return; |
30 | 31 |
} |
31 |
|
|
32 |
if ((status & OUT_BUF_FUL) == 0 || (status & AUX_MOUSE) != 0) { |
|
33 |
got_error_keyboard = 1; |
|
34 |
return; |
|
35 |
} |
|
32 | 36 |
uint8_t byte = 0; |
33 |
|
|
34 | 37 |
if (util_sys_inb(OUTPUT_BUF, &byte)) { |
35 | 38 |
got_error_keyboard = 1; |
36 | 39 |
return; |
37 | 40 |
} |
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 |
|
|
41 |
scancode[sz-1] = byte; |
|
42 |
done = !(TWO_BYTE_CODE == byte); |
|
47 | 43 |
} |
48 | 44 |
|
49 | 45 |
int (keyboard_poll)(uint8_t bytes[], uint8_t *size){ |
lab3/keyboard.h | ||
---|---|---|
14 | 14 |
int (subscribe_keyboard_interrupt)(uint8_t interrupt_bit, int *interrupt_id); |
15 | 15 |
|
16 | 16 |
uint8_t scancode[2]; |
17 |
int two_byte_scancode; |
|
17 |
int done; |
|
18 |
int sz; |
|
18 | 19 |
int got_error_keyboard; |
19 | 20 |
|
20 | 21 |
/** |
lab3/lab3.c | ||
---|---|---|
56 | 56 |
case HARDWARE: /* hardware interrupt notification */ |
57 | 57 |
if (msg.m_notify.interrupts & kbc_irq) { /* subscribed interrupt */ |
58 | 58 |
kbc_ih(); |
59 |
if (!(two_byte_scancode || got_error_keyboard)) { /* finished processing a scancode */ |
|
60 |
if (scancode[0] == TWO_BYTE_CODE) kbd_print_scancode(!(scancode[1] & BREAK_CODE_BIT), 2, scancode); |
|
61 |
else kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode); |
|
62 |
} else { break; } |
|
63 | 59 |
if(done) |
64 | 60 |
kbd_print_scancode(!(scancode[sz-1] & BREAK_CODE_BIT), sz, scancode); |
65 | 61 |
if (scancode[0] == ESC_BREAK_CODE) good = 0; |
... | ... | |
131 | 127 |
} |
132 | 128 |
if (msg.m_notify.interrupts & kbc_irq) { /// subscribed interrupt |
133 | 129 |
kbc_ih(); |
134 |
|
|
135 |
if (!(two_byte_scancode || got_error_keyboard)) { /// finished processing a scancode |
|
136 |
if (scancode[0] == TWO_BYTE_CODE) kbd_print_scancode(!(scancode[1] & BREAK_CODE_BIT), 2, scancode); |
|
137 |
else kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode); |
|
138 | 130 |
if(done) { |
139 | 131 |
kbd_print_scancode(!(scancode[sz-1] & BREAK_CODE_BIT), sz, scancode); |
140 | 132 |
time = 0; |
Also available in: Unified diff