Revision 9
Added Makefile, keyboard files and i8xxx.h files
lab3.c | ||
---|---|---|
4 | 4 |
|
5 | 5 |
#include <stdbool.h> |
6 | 6 |
#include <stdint.h> |
7 |
|
|
7 |
#include "keyboard.h" |
|
8 | 8 |
int main(int argc, char *argv[]) { |
9 | 9 |
// sets the language of LCF messages (can be either EN-US or PT-PT) |
10 | 10 |
lcf_set_language("EN-US"); |
... | ... | |
29 | 29 |
return 0; |
30 | 30 |
} |
31 | 31 |
|
32 |
extern uint8_t scan_reg; |
|
33 |
|
|
32 | 34 |
int(kbd_test_scan)() { |
33 |
/* To be completed by the students */ |
|
34 |
printf("%s is not yet implemented!\n", __func__); |
|
35 |
int r, ipc_status; |
|
36 |
uint8_t keyboard_irq, size, byte[2]; //size of scancode can be 2 byte long |
|
37 |
message msg; |
|
38 |
bool make=false; //to check if code is make or break |
|
35 | 39 |
|
36 |
return 1; |
|
40 |
if(kbc_subscribe_int(keyboard_irq)==1){ |
|
41 |
printf("Error subscribing int\n"); |
|
42 |
return 1; |
|
43 |
} |
|
44 |
|
|
45 |
while(scan_code!=ESC_BREAK){ //looping until status_reg is the breakcode of ESC key |
|
46 |
if ((r = driver_receive(ANY, &msg, &ipc_status))==1){ |
|
47 |
printf("driver_receive failed with: %d",r); |
|
48 |
continue; |
|
49 |
} |
|
50 |
if (is_ipc_notify(ipc_status)){ //received notification |
|
51 |
switch (_ENDPOINT_P(msg.m_source)){ |
|
52 |
case HARDWARE: //hardware interrupt notification |
|
53 |
if (msg.m_notify.interrupts &keyboard_irq){ // subscribed interrupt |
|
54 |
|
|
55 |
kbc_ih(); |
|
56 |
bytes[0]=scan_code; |
|
57 |
bytes[1]=scan_code; |
|
58 |
|
|
59 |
if(bytes[0]==TWO_BYTE_SCANCODE){ |
|
60 |
size=2; |
|
61 |
} |
|
62 |
else{ |
|
63 |
size=1; |
|
64 |
} |
|
65 |
|
|
66 |
if (scan_code & MAKE_CODE){ // 4 - Checks if code is make or break |
|
67 |
make = false; //break code |
|
68 |
} |
|
69 |
else { |
|
70 |
make = true; //make code |
|
71 |
} |
|
72 |
kbd_print_scancode(make, size, bytes); //prints the code |
|
73 |
} |
|
74 |
break; |
|
75 |
default: |
|
76 |
break; //no other notifications expected: do nothing |
|
77 |
} |
|
78 |
} |
|
79 |
else { //received a standard message, not a notification |
|
80 |
//no standard messages expected: do nothing |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
if (kbc_unsubscribe_int() != 0) { // Check if subscription worked |
|
85 |
printf("Error unsubscribing int \n"); |
|
86 |
return 1; |
|
87 |
} |
|
88 |
|
|
89 |
return 0; |
|
37 | 90 |
} |
38 | 91 |
|
39 | 92 |
int(kbd_test_poll)() { |
Also available in: Unified diff