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