root / lab3 / lab3.c @ 32
History | View | Annotate | Download (3.05 KB)
1 |
#include <lcom/lcf.h> |
---|---|
2 |
#include <lcom/lab3.h> |
3 |
|
4 |
#include <stdbool.h> |
5 |
#include <stdint.h> |
6 |
|
7 |
#include "kbc.h" |
8 |
#include "kbc_func.h" |
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 scancode[2]; |
35 |
extern int two_byte_scancode; |
36 |
extern int got_error; |
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 || got_error)) { /* 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 |
} else {
|
69 |
break;
|
70 |
} |
71 |
|
72 |
if (scancode[0] == ESC_BREAK_CODE) |
73 |
got_esc_breakcode = 1;
|
74 |
|
75 |
} |
76 |
break;
|
77 |
default:
|
78 |
break; /* no other notifications expected: do nothing */ |
79 |
} |
80 |
} else { /* received standart message, not a notification */ |
81 |
/* no standart message expected: do nothing */
|
82 |
} |
83 |
} |
84 |
|
85 |
if (unsubscribe_kbc_interrupt(&kbc_id)) return 1; |
86 |
|
87 |
if (kbd_print_no_sysinb(sys_inb_counter(GET))) return 1; |
88 |
|
89 |
return 0; |
90 |
} |
91 |
|
92 |
int(kbd_test_poll)() {
|
93 |
/* To be completed by the students */
|
94 |
printf("%s is not yet implemented!\n", __func__);
|
95 |
|
96 |
return 1; |
97 |
} |
98 |
|
99 |
int(kbd_test_timed_scan)(uint8_t n) {
|
100 |
/* To be completed by the students */
|
101 |
printf("%s is not yet implemented!\n", __func__);
|
102 |
|
103 |
return 1; |
104 |
} |