Revision 67
not working
lab3/errors.h | ||
---|---|---|
1 |
#ifndef _ERRORS_H_
|
|
2 |
#define _ERRORS_H_
|
|
1 |
#ifndef ERRORS_H_INCLUDED
|
|
2 |
#define ERRORS_H_INCLUDED
|
|
3 | 3 |
|
4 | 4 |
enum errors { |
5 | 5 |
SUCCESS = 0, /* @brief Sucessful */ |
... | ... | |
12 | 12 |
TIMEOUT_ERROR, /* @brief Timeout error */ |
13 | 13 |
}; |
14 | 14 |
|
15 |
#endif /* end of include guard: _ERRORS_H_ */ |
|
15 |
#endif // ERRORS_H_INCLUDED |
lab3/kbc.c | ||
---|---|---|
4 | 4 |
|
5 | 5 |
#include "kbc_macros.h" |
6 | 6 |
#include "utils.h" |
7 |
#include "errors.h" |
|
7 | 8 |
|
8 | 9 |
int (unsubscribe_interrupt)(int *interrupt_id) { |
9 |
if (interrupt_id == NULL) return 1; |
|
10 |
return sys_irqrmpolicy(interrupt_id); |
|
10 |
if (interrupt_id == NULL) return NULL_PTR; |
|
11 |
if(sys_irqrmpolicy(interrupt_id)) return UNSBCR_ERROR; |
|
12 |
return SUCCESS; |
|
11 | 13 |
} |
12 | 14 |
|
13 | 15 |
int (kbc_read_cmd)(uint8_t *cmd){ |
14 |
if(kbc_issue_cmd(READ_KBC_CMD)) return 1; |
|
15 |
if(kbc_read_byte(cmd)) return 1; |
|
16 |
return 0; |
|
16 |
int ret = 0; |
|
17 |
if((ret = kbc_issue_cmd(READ_KBC_CMD))) return ret; |
|
18 |
if((ret = kbc_read_byte(cmd))) return ret; |
|
19 |
return SUCCESS; |
|
17 | 20 |
} |
18 | 21 |
|
19 | 22 |
int (kbc_change_cmd)(uint8_t cmd){ |
20 |
if(kbc_issue_cmd(WRITE_KBC_CMD)) return 1; |
|
21 |
if(sys_outb(KBC_CMD_ARG, cmd)) return 1; |
|
22 |
return 0; |
|
23 |
int ret = 0; |
|
24 |
if((ret = kbc_issue_cmd(WRITE_KBC_CMD))) return ret; |
|
25 |
if((ret = kbc_issue_arg(cmd))) return ret; |
|
26 |
return SUCCESS; |
|
23 | 27 |
} |
24 | 28 |
|
25 | 29 |
int (kbc_restore_keyboard)(){ |
30 |
int ret = 0; |
|
26 | 31 |
uint8_t cmd = 0; |
27 |
if(kbc_read_cmd(&cmd)) return 1;
|
|
32 |
if((ret = kbc_read_cmd(&cmd))) return ret;
|
|
28 | 33 |
cmd = (cmd | INT_KBD) & (~DIS_KBD) ; |
29 |
if(kbc_change_cmd(cmd)) return 1;
|
|
30 |
return 0;
|
|
34 |
if((ret = kbc_change_cmd(cmd))) return ret;
|
|
35 |
return SUCCESS;
|
|
31 | 36 |
} |
32 | 37 |
|
33 | 38 |
int (kbc_issue_cmd)(uint8_t cmd){ |
39 |
int ret = 0; |
|
34 | 40 |
uint8_t stat; |
35 | 41 |
for(int i = 0; i < KBC_NUM_TRIES; ++i){ |
36 |
if(util_sys_inb(STATUS_REG, &stat)) return 1;
|
|
42 |
if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
|
|
37 | 43 |
if((stat&IN_BUF_FULL) == 0){ |
38 |
if(sys_outb(KBC_CMD, cmd)) return 1;
|
|
39 |
return 0;
|
|
44 |
if(sys_outb(KBC_CMD, cmd)) return WRITE_ERROR;
|
|
45 |
return SUCCESS;
|
|
40 | 46 |
} |
41 | 47 |
tickdelay(micros_to_ticks(DELAY)); |
42 | 48 |
} |
43 |
return 1;
|
|
49 |
return TIMEOUT_ERROR;
|
|
44 | 50 |
} |
45 | 51 |
|
46 | 52 |
int (kbc_issue_arg)(uint8_t arg){ |
53 |
int ret = 0; |
|
47 | 54 |
uint8_t stat; |
48 | 55 |
for(int i = 0; i < KBC_NUM_TRIES; ++i){ |
49 |
if(util_sys_inb(STATUS_REG, &stat)) return 1;
|
|
56 |
if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
|
|
50 | 57 |
if((stat&IN_BUF_FULL) == 0){ |
51 |
if(sys_outb(KBC_CMD_ARG, arg)) return 1;
|
|
52 |
return 0;
|
|
58 |
if(sys_outb(KBC_CMD_ARG, arg)) return WRITE_ERROR;
|
|
59 |
return SUCCESS;
|
|
53 | 60 |
} |
54 | 61 |
tickdelay(micros_to_ticks(DELAY)); |
55 | 62 |
} |
56 |
return 1;
|
|
63 |
return TIMEOUT_ERROR;
|
|
57 | 64 |
} |
58 | 65 |
|
59 | 66 |
int (kbc_read_byte)(uint8_t *byte){ |
67 |
int ret = 0; |
|
60 | 68 |
uint8_t stat; |
61 | 69 |
while(true){ |
62 |
if(util_sys_inb(STATUS_REG, &stat)) return 1;
|
|
70 |
if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
|
|
63 | 71 |
if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)==0){ |
64 | 72 |
if(stat & (PARITY_ERROR | TIME_OUT_REC)) return 1; |
65 |
if(util_sys_inb(OUTPUT_BUF, byte)) return 1;
|
|
66 |
else return 0;
|
|
73 |
if((ret = util_sys_inb(OUTPUT_BUF, byte))) return ret;
|
|
74 |
else return SUCCESS;
|
|
67 | 75 |
} |
68 | 76 |
tickdelay(micros_to_ticks(DELAY)); |
69 | 77 |
} |
78 |
return TIMEOUT_ERROR; |
|
70 | 79 |
} |
lab3/kbc.h | ||
---|---|---|
3 | 3 |
* actually also manages the mouse) |
4 | 4 |
*/ |
5 | 5 |
|
6 |
#ifndef _KBC_FUNC_H_
|
|
7 |
#define _KBC_FUNC_H_
|
|
6 |
#ifndef KBC_H_INCLUDED
|
|
7 |
#define KBC_H_INCLUDED
|
|
8 | 8 |
|
9 | 9 |
/** |
10 | 10 |
* @brief Unsubcribes Interrupts |
... | ... | |
60 | 60 |
*/ |
61 | 61 |
int (kbc_read_byte)(uint8_t *byte); |
62 | 62 |
|
63 |
|
|
64 |
#endif |
|
63 |
#endif //KBC_H_INCLUDED |
lab3/kbc_macros.h | ||
---|---|---|
1 |
#ifndef _KBC_H_
|
|
2 |
#define _KBC_H_
|
|
1 |
#ifndef KBC_MACROS_H_INCLUDED
|
|
2 |
#define KBC_MACROS_H_INCLUDED
|
|
3 | 3 |
|
4 | 4 |
/* KBC IRQ Line */ |
5 | 5 |
|
... | ... | |
53 | 53 |
#define DIS_KBD BIT(4) /* @brief Disable Keyboard */ |
54 | 54 |
#define DIS_MOU BIT(5) /* @brief Disable Mouse */ |
55 | 55 |
|
56 |
#endif |
|
56 |
#endif //KBC_MACROS_H_INCLUDED |
lab3/keyboard.c | ||
---|---|---|
14 | 14 |
return SUCCESS; |
15 | 15 |
} |
16 | 16 |
|
17 |
int done = 1; |
|
18 |
int sz = 1; |
|
17 |
int keyboard_done = 1;
|
|
18 |
int scancode_sz = 1;
|
|
19 | 19 |
int got_error_keyboard = 0; |
20 | 20 |
|
21 | 21 |
void (kbc_ih)(void) { |
22 |
if(done) sz = 1; |
|
23 |
else sz++; |
|
22 |
if(keyboard_done) scancode_sz = 0; |
|
24 | 23 |
uint8_t status = 0; |
25 | 24 |
got_error_keyboard = 0; |
26 | 25 |
if (util_sys_inb(STATUS_REG, &status)) { |
... | ... | |
40 | 39 |
got_error_keyboard = 1; |
41 | 40 |
return; |
42 | 41 |
} |
43 |
scancode[sz-1] = byte; |
|
44 |
done = !(TWO_BYTE_CODE == byte); |
|
42 |
scancode[scancode_sz] = byte; |
|
43 |
scancode_sz++; |
|
44 |
keyboard_done = !(TWO_BYTE_CODE == byte); |
|
45 | 45 |
} |
46 | 46 |
|
47 | 47 |
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 done; |
|
18 |
int sz; |
|
17 |
int keyboard_done;
|
|
18 |
int scancode_sz;
|
|
19 | 19 |
int got_error_keyboard; |
20 | 20 |
|
21 | 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(done) |
|
60 |
kbd_print_scancode(!(scancode[sz-1] & BREAK_CODE_BIT), sz, scancode);
|
|
59 |
if(keyboard_done)
|
|
60 |
kbd_print_scancode(!(scancode[scancode_sz-1] & BREAK_CODE_BIT), scancode_sz, scancode);
|
|
61 | 61 |
if (scancode[0] == ESC_BREAK_CODE) good = 0; |
62 | 62 |
} |
63 | 63 |
break; |
... | ... | |
126 | 126 |
} |
127 | 127 |
if (msg.m_notify.interrupts & kbc_irq) { /// subscribed interrupt |
128 | 128 |
kbc_ih(); |
129 |
if(done) { |
|
130 |
kbd_print_scancode(!(scancode[sz-1] & BREAK_CODE_BIT), sz, scancode);
|
|
129 |
if(keyboard_done) {
|
|
130 |
kbd_print_scancode(!(scancode[scancode_sz-1] & BREAK_CODE_BIT), scancode_sz, scancode);
|
|
131 | 131 |
time = 0; |
132 | 132 |
no_interrupts = 0; |
133 | 133 |
if (scancode[0] == ESC_BREAK_CODE) good = 0; |
Also available in: Unified diff