root / lab3 / lab3.c @ 7
History | View | Annotate | Download (4.37 KB)
1 | 4 | up20180614 | #include <lcom/lcf.h> |
---|---|---|---|
2 | #include <minix/sysutil.h> |
||
3 | |||
4 | #include <lcom/lab3.h> |
||
5 | |||
6 | #include <stdbool.h> |
||
7 | #include <stdint.h> |
||
8 | //#include <timer.c>
|
||
9 | |||
10 | 7 | up20180614 | |
11 | 4 | up20180614 | #define IRQ_KB 1 |
12 | #define DELAY_US 20000 |
||
13 | #define EXIT_CODE 0x81 |
||
14 | #define I_O_BUFFER 0x60 |
||
15 | |||
16 | static uint32_t scancode;
|
||
17 | |||
18 | int main(int argc, char *argv[]) { |
||
19 | // sets the language of LCF messages (can be either EN-US or PT-PT)
|
||
20 | lcf_set_language("EN-US");
|
||
21 | |||
22 | // enables to log function invocations that are being "wrapped" by LCF
|
||
23 | // [comment this out if you don't want/need it]
|
||
24 | lcf_trace_calls("/home/lcom/labs/lab3/trace.txt");
|
||
25 | |||
26 | // enables to save the output of printf function calls on a file
|
||
27 | // [comment this out if you don't want/need it]
|
||
28 | lcf_log_output("/home/lcom/labs/lab3/output.txt");
|
||
29 | |||
30 | // handles control over to LCF
|
||
31 | // [LCF handles command line arguments and invokes the right function]
|
||
32 | if (lcf_start(argc, argv))
|
||
33 | 6 | up20180614 | return 1; |
34 | 4 | up20180614 | |
35 | // LCF clean up tasks
|
||
36 | // [must be the last statement before return]
|
||
37 | lcf_cleanup(); |
||
38 | |||
39 | return 0; |
||
40 | } |
||
41 | |||
42 | 5 | up20180614 | void(kbc_ih)() {}
|
43 | 4 | up20180614 | |
44 | int(kbd_test_scan)() {
|
||
45 | /* To be completed by the students */
|
||
46 | int ipc_status;
|
||
47 | 5 | up20180614 | uint8_t r, bit_no = 0;
|
48 | 4 | up20180614 | message msg; |
49 | 5 | up20180614 | int hook_id = bit_no;
|
50 | uint8_t scan_arr[2] = {0, 0}; |
||
51 | scan_arr[0] = scancode & 0xFF; |
||
52 | scan_arr[1] = scancode & 0xFF00; |
||
53 | 6 | up20180614 | int flag = 0; |
54 | 7 | up20180614 | uint32_t cnt=0;
|
55 | 4 | up20180614 | |
56 | 5 | up20180614 | printf("%d\n",
|
57 | sys_irqsetpolicy(IRQ_KB, IRQ_REENABLE | IRQ_EXCLUSIVE, &hook_id)); |
||
58 | /* sys_outb(0x64, 0x20);
|
||
59 | sys_inb(0x64, &scancode);
|
||
60 | printf("%x\n", scancode);
|
||
61 | if (scancode & 0x10) {
|
||
62 | scancode = (scancode & 0xEF);
|
||
63 | }
|
||
64 | |||
65 | printf("%x\n", scancode);
|
||
66 | sys_outb(0x64, 0x60);
|
||
67 | sys_outb(0x64, scancode); */
|
||
68 | |||
69 | printf("%x\n", scancode);
|
||
70 | 7 | up20180614 | //kbc_ih();
|
71 | 5 | up20180614 | printf("\n");
|
72 | 6 | up20180614 | while (scancode !=
|
73 | 5 | up20180614 | EXIT_CODE) { /* You may want to use a different condition */
|
74 | /* Get a request message. */
|
||
75 | // printf("1\n");
|
||
76 | // printf("cont:%d, time:%d\n\n",cont/60,time);
|
||
77 | if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
||
78 | printf("driver_receive failed with: %d", r);
|
||
79 | continue;
|
||
80 | 4 | up20180614 | } |
81 | if (is_ipc_notify(ipc_status)) { /* received notification */ |
||
82 | 5 | up20180614 | switch (_ENDPOINT_P(msg.m_source)) {
|
83 | case HARDWARE: /* hardware interrupt notification */ |
||
84 | if (msg.m_notify.interrupts & BIT(0)) { /* subscribed interrupt */ |
||
85 | |||
86 | 7 | up20180614 | #ifdef LAB3
|
87 | cnt++; |
||
88 | #endif
|
||
89 | 5 | up20180614 | sys_inb(0x64, &scancode);
|
90 | if (scancode & 0x01) { |
||
91 | 7 | up20180614 | #ifdef LAB3
|
92 | cnt++; |
||
93 | #endif
|
||
94 | 5 | up20180614 | sys_inb(0x60, &scancode);
|
95 | 6 | up20180614 | if (scancode != 0xe0 && flag == 0) { |
96 | // tickdelay(micros_to_ticks(DELAY_US));
|
||
97 | 5 | up20180614 | scan_arr[0] = scancode;
|
98 | kbd_print_scancode(!(scancode & 0x80), 1, scan_arr); |
||
99 | } |
||
100 | |||
101 | 6 | up20180614 | else if (scancode == 0xe0) { |
102 | scan_arr[0] = scancode;
|
||
103 | flag = 1;
|
||
104 | 5 | up20180614 | } |
105 | |||
106 | 6 | up20180614 | else if (flag == 1) { |
107 | 5 | up20180614 | scan_arr[1] = scancode;
|
108 | kbd_print_scancode(!(scancode & 0x80), 2, scan_arr); |
||
109 | 6 | up20180614 | flag = 0;
|
110 | 5 | up20180614 | } |
111 | 6 | up20180614 | } |
112 | 5 | up20180614 | |
113 | 4 | up20180614 | } |
114 | 5 | up20180614 | // printf("msg:%x\n",msg.m_notify.interrupts);
|
115 | break;
|
||
116 | default:
|
||
117 | // printf("2\n");
|
||
118 | break; /* no other notifications expected: do nothing */ |
||
119 | } |
||
120 | 4 | up20180614 | } else {
|
121 | 5 | up20180614 | // printf("3\n"); /* received a standard message, not a notification */
|
122 | /* no standard messages expected: do nothing */
|
||
123 | 4 | up20180614 | } |
124 | 5 | up20180614 | } |
125 | 7 | up20180614 | kbd_print_no_sysinb(cnt); |
126 | 5 | up20180614 | if (sys_irqrmpolicy(&hook_id) != 0) |
127 | return 1; |
||
128 | 4 | up20180614 | |
129 | return 0; |
||
130 | } |
||
131 | |||
132 | int(kbd_test_poll)() {
|
||
133 | /* To be completed by the students */
|
||
134 | 6 | up20180614 | uint8_t scan_arr[2] = {0, 0}; |
135 | int flag = 0; |
||
136 | 7 | up20180614 | uint32_t cnt=0;
|
137 | 6 | up20180614 | while(scancode != EXIT_CODE)
|
138 | { |
||
139 | tickdelay(micros_to_ticks(DELAY_US)); |
||
140 | 7 | up20180614 | #ifdef LAB3
|
141 | cnt++; |
||
142 | #endif
|
||
143 | 6 | up20180614 | sys_inb(0x64, &scancode);
|
144 | if (scancode & 0x01) { |
||
145 | 7 | up20180614 | #ifdef LAB3
|
146 | cnt++; |
||
147 | #endif
|
||
148 | 6 | up20180614 | sys_inb(0x60, &scancode);
|
149 | if (scancode != 0xe0 && flag == 0) { |
||
150 | scan_arr[0] = scancode;
|
||
151 | kbd_print_scancode(!(scancode & 0x80), 1, scan_arr); |
||
152 | } |
||
153 | 4 | up20180614 | |
154 | 6 | up20180614 | else if (scancode == 0xe0) { |
155 | scan_arr[0] = scancode;
|
||
156 | flag = 1;
|
||
157 | } |
||
158 | |||
159 | else if (flag == 1) { |
||
160 | scan_arr[1] = scancode;
|
||
161 | kbd_print_scancode(!(scancode & 0x80), 2, scan_arr); |
||
162 | flag = 0;
|
||
163 | } |
||
164 | } |
||
165 | |||
166 | } |
||
167 | 7 | up20180614 | kbd_print_no_sysinb(cnt); |
168 | 6 | up20180614 | |
169 | 4 | up20180614 | return 1; |
170 | } |
||
171 | |||
172 | int(kbd_test_timed_scan)(uint8_t n) {
|
||
173 | /* To be completed by the students */
|
||
174 | printf("%s is not yet implemented!\n", __func__);
|
||
175 | |||
176 | return 1; |
||
177 | } |