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