root / lab3 / lab3.c @ 10
History | View | Annotate | Download (3.09 KB)
1 |
|
---|---|
2 |
#include <lcom/lcf.h> |
3 |
#include <lcom/lab3.h> |
4 |
#include <stdbool.h> |
5 |
#include <stdint.h> |
6 |
|
7 |
#include "keyboard.h" |
8 |
|
9 |
|
10 |
int main(int argc, char *argv[]) { |
11 |
// sets the language of LCF messages (can be either EN-US or PT-PT)
|
12 |
lcf_set_language("EN-US");
|
13 |
|
14 |
// enables to log function invocations that are being "wrapped" by LCF
|
15 |
// [comment this out if you don't want/need it]
|
16 |
lcf_trace_calls("/home/lcom/labs/lab3/trace.txt");
|
17 |
|
18 |
// enables to save the output of printf function calls on a file
|
19 |
// [comment this out if you don't want/need it]
|
20 |
lcf_log_output("/home/lcom/labs/lab3/output.txt");
|
21 |
|
22 |
// handles control over to LCF
|
23 |
// [LCF handles command line arguments and invokes the right function]
|
24 |
if (lcf_start(argc, argv))
|
25 |
return 1; |
26 |
|
27 |
// LCF clean up tasks
|
28 |
// [must be the last statement before return]
|
29 |
lcf_cleanup(); |
30 |
|
31 |
return 0; |
32 |
} |
33 |
|
34 |
extern uint8_t scan_code;
|
35 |
extern uint32_t cnt;
|
36 |
|
37 |
int(kbd_test_scan)() {
|
38 |
int r, ipc_status;
|
39 |
uint8_t keyboard_irq, size, bytes[2]; //size of scancode can be 2 byte long |
40 |
message msg; |
41 |
bool make=false; //to check if code is make or break |
42 |
|
43 |
if(kbc_subscribe_int(&keyboard_irq)==1){ |
44 |
printf("Error subscribing int\n");
|
45 |
return 1; |
46 |
} |
47 |
|
48 |
while(scan_code!=ESC_BREAK){ //looping until scann_code is the breakcode of ESC key |
49 |
if ((r = driver_receive(ANY, &msg, &ipc_status))==1){ |
50 |
printf("driver_receive failed with: %d",r);
|
51 |
continue;
|
52 |
} |
53 |
if (is_ipc_notify(ipc_status)){ //received notification |
54 |
switch (_ENDPOINT_P(msg.m_source)){
|
55 |
case HARDWARE: //hardware interrupt notification |
56 |
if (msg.m_notify.interrupts &keyboard_irq){ // subscribed interrupt |
57 |
|
58 |
kbc_ih(); |
59 |
bytes[0]=scan_code;
|
60 |
bytes[1]=scan_code;
|
61 |
|
62 |
if(bytes[0]==TWO_BYTE_SCANCODE){ |
63 |
size=2;
|
64 |
} |
65 |
else{
|
66 |
size=1;
|
67 |
} |
68 |
|
69 |
if (scan_code & MAKE_CODE){ //checks if code is make or break |
70 |
make = false; //break code |
71 |
} |
72 |
else {
|
73 |
make = true; //make code |
74 |
} |
75 |
kbd_print_scancode(make, size, bytes); //prints the code
|
76 |
} |
77 |
break;
|
78 |
default:
|
79 |
break; //no other notifications expected: do nothing |
80 |
} |
81 |
} |
82 |
else { //received a standard message, not a notification |
83 |
//no standard messages expected: do nothing
|
84 |
} |
85 |
} |
86 |
|
87 |
if (kbc_unsubscribe_int() != 0) { // Check if subscription worked |
88 |
printf("Error unsubscribing int \n");
|
89 |
return 1; |
90 |
} |
91 |
|
92 |
kbd_print_no_sysinb(cnt); |
93 |
|
94 |
return 0; |
95 |
} |
96 |
|
97 |
int(kbd_test_poll)() {
|
98 |
/* To be completed by the students */
|
99 |
printf("%s is not yet implemented!\n", __func__);
|
100 |
|
101 |
return 1; |
102 |
} |
103 |
|
104 |
int(kbd_test_timed_scan)(uint8_t n) {
|
105 |
/* To be completed by the students */
|
106 |
printf("%s is not yet implemented!\n", __func__);
|
107 |
|
108 |
return 1; |
109 |
} |