Revision 50
Fixed polling minor issue; refactor code
lab3/kbc_func.c | ||
---|---|---|
37 | 37 |
return; |
38 | 38 |
} |
39 | 39 |
|
40 |
if ((status & OUT_BUF_FUL) == 0 || (status & AUX_MOUSE) != 0) { |
|
41 |
got_error = 1; |
|
42 |
return; |
|
43 |
} |
|
44 |
|
|
40 | 45 |
uint8_t byte = 0; |
41 | 46 |
|
42 | 47 |
if (util_sys_inb(OUTPUT_BUF, &byte)) { |
... | ... | |
73 | 78 |
|
74 | 79 |
int (kbc_change_cmd)(uint8_t cmd){ |
75 | 80 |
if(kbc_issue_cmd(WRITE_KBC_CMD)) return 1; |
76 |
if(sys_outb(KBC_CMD_ARG, cmd)) return 1;
|
|
81 |
if(kbc_issue_arg(cmd)) return 1;
|
|
77 | 82 |
return 0; |
78 | 83 |
} |
79 | 84 |
|
... | ... | |
98 | 103 |
return 1; |
99 | 104 |
} |
100 | 105 |
|
106 |
int (kbc_issue_arg)(uint8_t arg){ |
|
107 |
uint8_t stat; |
|
108 |
for(int i = 0; i < KBC_NUM_TRIES; ++i){ |
|
109 |
if(util_sys_inb(STATUS_REG, &stat)) return 1; |
|
110 |
if((stat&IN_BUF_FULL) == 0){ |
|
111 |
if(sys_outb(KBC_CMD_ARG, arg)) return 1; |
|
112 |
return 0; |
|
113 |
} |
|
114 |
tickdelay(micros_to_ticks(DELAY)); |
|
115 |
} |
|
116 |
return 1; |
|
117 |
} |
|
118 |
|
|
101 | 119 |
int (kbc_read_byte)(uint8_t *byte){ |
102 | 120 |
uint8_t stat; |
103 | 121 |
while(true){ |
lab3/kbc_func.h | ||
---|---|---|
68 | 68 |
int (kbc_issue_cmd)(uint8_t cmd); |
69 | 69 |
|
70 | 70 |
/** |
71 |
* @brief Low-level function to issue an argument of a command |
|
72 |
* @param cmd argument to be issued |
|
73 |
* @return 0 if operation was successful, 1 otherwise |
|
74 |
*/ |
|
75 |
int (kbc_issue_arg)(uint8_t arg); |
|
76 |
|
|
77 |
/** |
|
71 | 78 |
* @brief Low-level function for reading byte from keyboard |
72 | 79 |
* Low-level function for reading byte from keyboard. Waits until output buffer |
73 | 80 |
* is full |
lab3/lab3.c | ||
---|---|---|
85 | 85 |
uint8_t c[2]; uint8_t size; |
86 | 86 |
do{ |
87 | 87 |
if(kbd_poll(c, &size)) return 1; |
88 |
if(kbd_print_scancode((~c[0])&BREAK_CODE_BIT, size, c)) return 1;
|
|
88 |
if(kbd_print_scancode((~c[size-1])&BREAK_CODE_BIT, size, c)) return 1;
|
|
89 | 89 |
}while(!(size == 1 && c[0] == ESC_BREAK_CODE)); |
90 | 90 |
|
91 | 91 |
if(kbc_restore_kbd()) return 1; |
Also available in: Unified diff