Revision 11
Added function 5.2, must check for errors
lab3.c | ||
---|---|---|
45 | 45 |
return 1; |
46 | 46 |
} |
47 | 47 |
|
48 |
while(scan_code!=ESC_BREAK){ //looping until scann_code is the breakcode of ESC key
|
|
48 |
while(scan_code!=ESC_BREAK){ //looping until scan_code is the breakcode of ESC key |
|
49 | 49 |
if ((r = driver_receive(ANY, &msg, &ipc_status))==1){ |
50 | 50 |
printf("driver_receive failed with: %d",r); |
51 | 51 |
continue; |
52 | 52 |
} |
53 | 53 |
if (is_ipc_notify(ipc_status)){ //received notification |
54 | 54 |
switch (_ENDPOINT_P(msg.m_source)){ |
55 |
case HARDWARE: //hardware interrupt notification
|
|
55 |
case HARDWARE: //hardware interrupt notification |
|
56 | 56 |
if (msg.m_notify.interrupts &keyboard_irq){ // subscribed interrupt |
57 | 57 |
|
58 | 58 |
kbc_ih(); |
... | ... | |
72 | 72 |
else { |
73 | 73 |
make = true; //make code |
74 | 74 |
} |
75 |
kbd_print_scancode(make, size, bytes); //prints the code |
|
75 |
|
|
76 |
if(kbd_print_scancode(make, size, bytes)!=0){ //prints the code |
|
77 |
printf("Error printing scan code\n"); |
|
78 |
return 1; |
|
79 |
} |
|
76 | 80 |
} |
77 | 81 |
break; |
78 | 82 |
default: |
... | ... | |
89 | 93 |
return 1; |
90 | 94 |
} |
91 | 95 |
|
92 |
kbd_print_no_sysinb(cnt); |
|
96 |
if(kbd_print_no_sysinb(cnt)!=0){ |
|
97 |
printf("Error printing number of sys used\n"); |
|
98 |
return 1; |
|
99 |
} |
|
93 | 100 |
|
101 |
cnt=0; |
|
102 |
scan_code=0; |
|
103 |
|
|
94 | 104 |
return 0; |
95 | 105 |
} |
96 | 106 |
|
97 | 107 |
int(kbd_test_poll)() { |
98 |
/* To be completed by the students */
|
|
99 |
printf("%s is not yet implemented!\n", __func__);
|
|
108 |
uint8_t status, size, bytes[2]; //size of scancode can be 2 byte long
|
|
109 |
bool make=false; //to check if code is make or break
|
|
100 | 110 |
|
101 |
return 1; |
|
111 |
while(scan_code!=ESC_BREAK){ //looping until scan_code is the breakcode of ESC key, can't do interruptions |
|
112 |
if(util_sys_inb(STATUS_REG, &status)!=0){ //checks the status register |
|
113 |
printf("Error reading status register\n"); |
|
114 |
return 1; |
|
115 |
} |
|
116 |
|
|
117 |
if ((status & STAT_REG_OBF) && !(status & STAT_REG_AUX) && !(status & STAT_REG_PAR || status & STAT_REG_TIMEOUT)) { //checks if there is no parity ot timeout error, if the output buffer is full and if there is mouse data |
|
118 |
|
|
119 |
if(util_sys_inb(OUTPUT_BUF, &scan_code)!=0){ |
|
120 |
printf("Error reading output buffer\n"); |
|
121 |
return 1; |
|
122 |
} |
|
123 |
|
|
124 |
bytes[0]=scan_code; |
|
125 |
bytes[1]=scan_code; |
|
126 |
|
|
127 |
if(bytes[0]==TWO_BYTE_SCANCODE){ |
|
128 |
size=2; |
|
129 |
} |
|
130 |
else{ |
|
131 |
size=1; |
|
132 |
} |
|
133 |
|
|
134 |
if (scan_code & MAKE_CODE){ //checks if code is make or break |
|
135 |
make = false; //break code |
|
136 |
} |
|
137 |
else { |
|
138 |
make = true; //make code |
|
139 |
} |
|
140 |
|
|
141 |
if(kbd_print_scancode(make, size, bytes)!=0){ //prints the code |
|
142 |
printf("Error printing scan code\n"); |
|
143 |
return 1; |
|
144 |
} |
|
145 |
|
|
146 |
} |
|
147 |
else { //if the output buffer is not full wait |
|
148 |
tickdelay(micros_to_ticks(DELAY_US)); //makes keyboard respond to a command in 20 ms |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 |
if(kbd_print_no_sysinb(cnt)!=0){ |
|
153 |
printf("Error printing number of sys used\n"); |
|
154 |
return 1; |
|
155 |
} |
|
156 |
|
|
157 |
if(enable_interrupt()!=0){ |
|
158 |
printf("Coulnd re-enable the interruptions\n"); |
|
159 |
return 1; |
|
160 |
|
|
161 |
} |
|
162 |
cnt=0; |
|
163 |
scan_code=0; |
|
164 |
|
|
165 |
return 0; |
|
102 | 166 |
} |
103 | 167 |
|
104 | 168 |
int(kbd_test_timed_scan)(uint8_t n) { |
Also available in: Unified diff