Revision 5
Primeira func done
lab3.c | ||
---|---|---|
29 | 29 |
// handles control over to LCF |
30 | 30 |
// [LCF handles command line arguments and invokes the right function] |
31 | 31 |
if (lcf_start(argc, argv)) |
32 |
return 1; |
|
32 |
return 1;
|
|
33 | 33 |
|
34 | 34 |
// LCF clean up tasks |
35 | 35 |
// [must be the last statement before return] |
... | ... | |
38 | 38 |
return 0; |
39 | 39 |
} |
40 | 40 |
|
41 |
void (kbc_ih)() |
|
42 |
{ |
|
43 |
sys_inb(I_O_BUFFER, &scancode); |
|
44 |
} |
|
41 |
void(kbc_ih)() {} |
|
45 | 42 |
|
46 | 43 |
int(kbd_test_scan)() { |
47 | 44 |
/* To be completed by the students */ |
48 | 45 |
int ipc_status; |
49 |
uint8_t r, bit_no=0;
|
|
46 |
uint8_t r, bit_no = 0;
|
|
50 | 47 |
message msg; |
51 |
int hook_id=bit_no;
|
|
52 |
uint8_t scan_arr[2] = {0,0}; |
|
53 |
scan_arr[0]=scancode & 0xFF;
|
|
54 |
scan_arr[1]=scancode & 0xFF00;
|
|
55 |
sys_irqsetpolicy(IRQ_KB,IRQ_REENABLE|IRQ_EXCLUSIVE,&hook_id);
|
|
48 |
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;
|
|
56 | 53 |
|
57 |
//kbc_ih(); |
|
58 |
printf("%x\n",scancode); |
|
59 |
while( 1)//(scancode & 0xFF) != EXIT_CODE ) |
|
60 |
{ /* You may want to use a different condition */ |
|
61 |
/* Get a request message. */ |
|
62 |
// printf("1\n"); |
|
63 |
//printf("cont:%d, time:%d\n\n",cont/60,time); |
|
64 |
if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) |
|
65 |
{ |
|
66 |
printf("driver_receive failed with: %d", r); |
|
67 |
continue; |
|
54 |
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; |
|
68 | 78 |
} |
69 | 79 |
if (is_ipc_notify(ipc_status)) { /* received notification */ |
70 |
switch (_ENDPOINT_P(msg.m_source)) { |
|
71 |
case HARDWARE: /* hardware interrupt notification */ |
|
72 |
if (msg.m_notify.interrupts & BIT(0)) { /* subscribed interrupt */ |
|
73 |
|
|
74 |
kbd_print_scancode((scancode & 0xFF & 0x80),2,scan_arr ); |
|
75 |
} |
|
76 |
//printf("msg:%x\n",msg.m_notify.interrupts); |
|
77 |
break; |
|
78 |
default: |
|
79 |
//printf("2\n"); |
|
80 |
break; /* no other notifications expected: do nothing */ |
|
80 |
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 |
|
|
81 | 109 |
} |
110 |
// 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 |
} |
|
82 | 116 |
} else { |
83 |
// printf("3\n"); /* received a standard message, not a notification */ |
|
84 |
/* no standard messages expected: do nothing */
|
|
117 |
// printf("3\n"); /* received a standard message, not a notification */
|
|
118 |
/* no standard messages expected: do nothing */ |
|
85 | 119 |
} |
86 |
} |
|
87 |
if(timer_unsubscribe_int()!=0) return 1;
|
|
88 |
sys_irqrmpolicy(&hook_id);
|
|
120 |
}
|
|
121 |
if (sys_irqrmpolicy(&hook_id) != 0)
|
|
122 |
return 1;
|
|
89 | 123 |
|
90 |
|
|
91 | 124 |
return 0; |
92 | 125 |
} |
93 | 126 |
|
Also available in: Unified diff