Revision 8
Final - macros
lab3.c | ||
---|---|---|
4 | 4 |
#include <lcom/lab3.h> |
5 | 5 |
|
6 | 6 |
#include <stdbool.h> |
7 |
#include "i8254.h" |
|
7 | 8 |
#include <stdint.h> |
8 | 9 |
//#include <timer.c> |
9 | 10 |
|
... | ... | |
48 | 49 |
message msg; |
49 | 50 |
int hook_id = bit_no; |
50 | 51 |
uint8_t scan_arr[2] = {0, 0}; |
51 |
scan_arr[0] = scancode & 0xFF; |
|
52 |
scan_arr[1] = scancode & 0xFF00; |
|
52 |
|
|
53 | 53 |
int flag = 0; |
54 | 54 |
uint32_t cnt=0; |
55 | 55 |
|
... | ... | |
70 | 70 |
//kbc_ih(); |
71 | 71 |
printf("\n"); |
72 | 72 |
while (scancode != |
73 |
EXIT_CODE) { /* You may want to use a different condition */ |
|
73 |
EXIT_CODE) |
|
74 |
{ /* You may want to use a different condition */ |
|
74 | 75 |
/* Get a request message. */ |
75 | 76 |
// printf("1\n"); |
76 | 77 |
// printf("cont:%d, time:%d\n\n",cont/60,time); |
... | ... | |
131 | 132 |
|
132 | 133 |
int(kbd_test_poll)() { |
133 | 134 |
/* To be completed by the students */ |
135 |
uint32_t key=0; |
|
134 | 136 |
uint8_t scan_arr[2] = {0, 0}; |
135 | 137 |
int flag = 0; |
136 | 138 |
uint32_t cnt=0; |
139 |
sys_outb(0x64,0x20); //enable interrupts again |
|
140 |
|
|
141 |
sys_outb(0x64, 0x60); |
|
142 |
sys_inb(0x60,&key); |
|
137 | 143 |
while(scancode != EXIT_CODE) |
138 | 144 |
{ |
139 | 145 |
tickdelay(micros_to_ticks(DELAY_US)); |
... | ... | |
162 | 168 |
flag = 0; |
163 | 169 |
} |
164 | 170 |
} |
165 |
|
|
166 | 171 |
} |
167 | 172 |
kbd_print_no_sysinb(cnt); |
168 |
|
|
169 |
return 1; |
|
173 |
sys_outb(0x64,0x60); //enable interrupts again |
|
174 |
sys_outb(0x60, key | BIT(0)); //enable interrupts again |
|
175 |
return 0; |
|
170 | 176 |
} |
171 | 177 |
|
172 | 178 |
int(kbd_test_timed_scan)(uint8_t n) { |
173 | 179 |
/* To be completed by the students */ |
174 |
printf("%s is not yet implemented!\n", __func__); |
|
180 |
uint8_t scan_arr[2] = {0, 0}; |
|
181 |
int flag=0; |
|
182 |
int ipc_status; |
|
183 |
message msg; |
|
184 |
uint8_t r; |
|
185 |
uint8_t bit_no_timer = 0, bit_no_kbd = 1; |
|
186 |
int hook_id_kbd=bit_no_kbd, hook_id_timer=bit_no_timer; |
|
187 |
int cont=0,cnt=0; |
|
188 |
|
|
189 |
sys_irqsetpolicy(IRQ_TIMER,IRQ_REENABLE,&hook_id_timer); |
|
190 |
sys_irqsetpolicy(IRQ_KB, IRQ_REENABLE | IRQ_EXCLUSIVE, &hook_id_kbd); |
|
191 |
kbc_ih(); |
|
192 |
while( (cont/DEFAULT_FREQ)<n && scancode !=EXIT_CODE) //se não atingir o tempo de espera nem a tecla for ESC |
|
193 |
{ |
|
194 |
/* You may want to use a different condition */ |
|
195 |
/* Get a request message. */ |
|
196 |
// printf("1\n"); |
|
197 |
//printf("cont:%d, time:%d\n\n",cont/60,time); |
|
198 |
if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) |
|
199 |
{ |
|
200 |
printf("driver_receive failed with: %d", r); |
|
201 |
continue; |
|
202 |
} |
|
203 |
if (is_ipc_notify(ipc_status)) { |
|
204 |
switch (_ENDPOINT_P(msg.m_source)) { |
|
205 |
case HARDWARE: |
|
206 |
if (msg.m_notify.interrupts & BIT(bit_no_timer)) { |
|
207 |
cont++; |
|
208 |
if(cont%DEFAULT_FREQ==0) |
|
209 |
timer_print_elapsed_time(); |
|
210 |
//printf("cont:%d\n",cont); |
|
211 |
} |
|
212 |
if (msg.m_notify.interrupts & BIT(bit_no_kbd)) |
|
213 |
{ |
|
214 |
|
|
215 |
#ifdef LAB3 |
|
216 |
cnt++; |
|
217 |
#endif |
|
218 |
sys_inb(0x64, &scancode); |
|
219 |
if (scancode & 0x01) { |
|
220 |
#ifdef LAB3 |
|
221 |
cnt++; |
|
222 |
#endif |
|
223 |
sys_inb(0x60, &scancode); |
|
224 |
if (scancode != 0xe0 && flag == 0) |
|
225 |
{ |
|
226 |
|
|
227 |
scan_arr[0] = scancode; |
|
228 |
kbd_print_scancode(!(scancode & 0x80), 1, scan_arr); |
|
229 |
} |
|
175 | 230 |
|
176 |
return 1; |
|
231 |
else if (scancode == 0xe0) |
|
232 |
{ |
|
233 |
scan_arr[0] = scancode; |
|
234 |
flag = 1; |
|
235 |
} |
|
236 |
|
|
237 |
else if (flag == 1) |
|
238 |
{ |
|
239 |
scan_arr[1] = scancode; |
|
240 |
kbd_print_scancode(!(scancode & 0x80), 2, scan_arr); |
|
241 |
flag = 0; |
|
242 |
} |
|
243 |
cont=0; |
|
244 |
} |
|
245 |
//printf("msg:%x\n",msg.m_notify.interrupts); |
|
246 |
break; |
|
247 |
default: |
|
248 |
//printf("2\n"); |
|
249 |
break; /* no other notifications expected: do nothing */ |
|
250 |
} |
|
251 |
} |
|
252 |
// printf("3\n"); /* received a standard message, not a notification */ |
|
253 |
/* no standard messages expected: do nothing */ |
|
254 |
|
|
255 |
} |
|
256 |
} |
|
257 |
kbd_print_no_sysinb(cnt); |
|
258 |
|
|
259 |
if(sys_irqrmpolicy(&hook_id_timer)!=0) return 1; |
|
260 |
if(sys_irqrmpolicy(&hook_id_kbd)!=0) return 1; |
|
261 |
|
|
262 |
|
|
263 |
return 0; |
|
264 |
|
|
265 |
|
|
266 |
//printf("%s is not yet implemented!\n", __func__); |
|
267 |
|
|
268 |
|
|
177 | 269 |
} |
Also available in: Unified diff