Revision 16
added function 1 and 2, working
lab4.c | ||
---|---|---|
4 | 4 |
#include <stdint.h> |
5 | 5 |
#include <stdio.h> |
6 | 6 |
#include "mouse.h" |
7 |
#include "timer.h" |
|
7 | 8 |
|
8 | 9 |
// Any header files included below this line should have been created by you |
9 | 10 |
|
... | ... | |
32 | 33 |
} |
33 | 34 |
|
34 | 35 |
extern uint8_t byte; |
36 |
extern int mouse_id; |
|
35 | 37 |
|
36 | 38 |
int (mouse_test_packet)(uint32_t cnt) { |
37 | 39 |
int r, ipc_status; |
38 |
uint8_t mouse_irq, size=0; //size of mouse packet is 3 byte long |
|
40 |
uint8_t mouse_irq; |
|
41 |
unsigned int size=0; //size of mouse packet is 3 byte long |
|
39 | 42 |
message msg; |
40 |
uint32_t counter_copy=cnt;
|
|
43 |
uint32_t counter_pp=0;
|
|
41 | 44 |
|
42 | 45 |
struct packet pp; |
43 | 46 |
|
44 |
if(mouse_enable_data_reporting()!=0){ //check if disabling stream mode worked |
|
47 |
|
|
48 |
//mouse_enable_data_reporting(); |
|
49 |
|
|
50 |
//sys_irqdisable(&mouse_id); |
|
51 |
if(write_cmd_mouse(0xF4)!=0){ //check if disabling stream mode worked (0xF4 is the byte to disable data report) |
|
45 | 52 |
printf("Error disabling stream mode\n"); |
46 | 53 |
return 1; |
47 | 54 |
} |
55 |
//sys_irqenable(&mouse_id); |
|
48 | 56 |
|
49 |
if(mouse_subscribe_int(&kmouse_irq)!=0){ //check if subscription worked
|
|
57 |
if(mouse_subscribe_int(&mouse_irq)!=0){ //check if subscription worked |
|
50 | 58 |
printf("Error subscribing int\n"); |
51 | 59 |
return 1; |
52 | 60 |
} |
61 |
|
|
53 | 62 |
|
54 |
while(counter_copy>0){ //looping until counter>0 |
|
63 |
while (cnt > counter_pp) |
|
64 |
{ /* ends when it has printed the number in ctn */ |
|
65 |
/*Get a request message.*/ |
|
66 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) |
|
67 |
{ |
|
68 |
printf("ERROR: driver_receive failed with: %d", r); |
|
69 |
continue; |
|
70 |
} |
|
71 |
if (is_ipc_notify(ipc_status)) |
|
72 |
{ // received notification |
|
73 |
switch (_ENDPOINT_P(msg.m_source)) |
|
74 |
{ |
|
75 |
case HARDWARE: // hardware interrupt notification |
|
76 |
if (msg.m_notify.interrupts & mouse_irq) |
|
77 |
{ // subscribed interrupt |
|
78 |
mouse_ih(); //must read only one byte |
|
79 |
if ((size == 0 && (BIT(3) & byte)) || size == 1 ||size ==2) |
|
80 |
{ //access the struct bytes |
|
81 |
pp.bytes[size] = byte; // bytes 0, 1 or 2 |
|
82 |
size++; // increments the counter to know in the next interrupt |
|
83 |
} |
|
84 |
if (size == 3) // 3 bytes haven been read and there's no error |
|
85 |
{ |
|
86 |
size = 0; // reset to start counting new packets |
|
87 |
parse_packet(&pp); // parses packet |
|
88 |
mouse_print_packet(&pp); // prints packet |
|
89 |
counter_pp++; //counts the prints for the end of the loop |
|
90 |
} |
|
91 |
} |
|
92 |
break; |
|
93 |
default: |
|
94 |
break; // no other notifications expected: do nothing |
|
95 |
} |
|
96 |
} |
|
97 |
else |
|
98 |
{ // received a standard message, not a notification |
|
99 |
// no standard messages expected: do nothing |
|
100 |
} |
|
101 |
} |
|
55 | 102 |
|
56 |
if ((r = driver_receive(ANY, &msg, &ipc_status))==1){ |
|
57 |
printf("driver_receive failed with: %d",r); |
|
58 |
continue; |
|
103 |
if (mouse_unsubscribe_int() != 0) { //check if unsubscription worked |
|
104 |
printf("Error unsubscribing int \n"); |
|
105 |
return 1; |
|
106 |
} |
|
107 |
|
|
108 |
if(write_cmd_mouse(0xF5)!=0){ //check if disabling stream mode worked (0xF5 is the byte to disable data report) |
|
109 |
printf("Error disabling stream mode\n"); |
|
110 |
return 1; |
|
111 |
} |
|
112 |
|
|
113 |
|
|
114 |
byte=0; |
|
115 |
|
|
116 |
return 0; |
|
117 |
} |
|
118 |
|
|
119 |
int (mouse_test_remote)(uint16_t period, uint8_t cnt) { |
|
120 |
uint8_t counter_pp=0, status; |
|
121 |
|
|
122 |
struct packet pp; |
|
123 |
|
|
124 |
/*if(write_cmd_mouse(0xF5)!=0){ //check if disabling stream mode worked (0xF5 is the byte to disable data report) |
|
125 |
printf("Error disabling stream mode\n"); |
|
126 |
return 1; |
|
127 |
} |
|
128 |
|
|
129 |
if(write_cmd_mouse(0xF0)!=0){ //check if enabling remote mode worked (0xF0 is the byte to enable remote mode) |
|
130 |
printf("Error disabling stream mode\n"); |
|
131 |
return 1; |
|
132 |
}*/ |
|
133 |
|
|
134 |
|
|
135 |
while (cnt > counter_pp) |
|
136 |
{ /* ends when it has printed the number in ctn */ |
|
137 |
if(write_cmd_mouse(0xEB)!=0){ //check if enabling remote mode worked (0xF0 is the byte to enable remote mode) |
|
138 |
printf("Error disabling stream mode\n"); |
|
139 |
return 1; |
|
59 | 140 |
} |
60 |
if (is_ipc_notify(ipc_status)){ //received notification |
|
61 |
switch (_ENDPOINT_P(msg.m_source)){ |
|
62 |
case HARDWARE: //hardware interrupt notification |
|
63 |
if (msg.m_notify.interrupts &mouse_irq){ // subscribed interrupt |
|
64 |
|
|
65 |
mouse_ih(); |
|
66 |
if((size==0 && ((byte&0x08)==0x08)) || size==1 ||size==2){ //0x08 is the mask to check if the 3rd bit of the first byte is set |
|
67 |
pp.bytes[size]=byte; |
|
68 |
size++; |
|
69 |
} |
|
70 |
if(size==3){ |
|
71 |
size=0; |
|
72 |
parse_packet(&pp); |
|
73 |
mouse_print_packet(&pp); |
|
74 |
counter_copy--; |
|
75 |
} |
|
76 |
} |
|
77 |
break; |
|
78 |
default: |
|
79 |
break; //no other notifications expected: do nothing |
|
141 |
|
|
142 |
if(util_sys_inb(STATUS_REG,&status)!=0){ |
|
143 |
printf("Error verifying the status of buffer\n"); |
|
144 |
return 1; |
|
145 |
} |
|
146 |
|
|
147 |
if((status & 0x01)==0x01){ |
|
148 |
|
|
149 |
if((status & (STAT_REG_PAR|STAT_REG_TIMEOUT))==0){ |
|
150 |
|
|
151 |
for(int size=0;size<3;size++){ |
|
152 |
|
|
153 |
if(util_sys_inb(OUTPUT_BUF,&byte)!=0){ |
|
154 |
printf("Error reading output_buf\n"); |
|
155 |
return 1; |
|
156 |
} |
|
157 |
|
|
158 |
if (size == 0 && (BIT(3) & byte)){ // access the struct bytes |
|
159 |
pp.bytes[size] = byte; // bytes 0, 1 or 2 |
|
160 |
//continue; |
|
161 |
} |
|
162 |
if(size==1){ |
|
163 |
pp.bytes[size] = byte; // bytes 0, 1 or 2 |
|
164 |
//continue; |
|
165 |
} |
|
166 |
if(size==2){ |
|
167 |
pp.bytes[size] = byte; |
|
168 |
|
|
169 |
} |
|
80 | 170 |
} |
81 |
} |
|
82 |
else { //received a standard message, not a notification |
|
83 |
//no standard messages expected: do nothing |
|
171 |
parse_packet(&pp); // parses packet |
|
172 |
mouse_print_packet(&pp); // prints packet |
|
173 |
|
|
174 |
} |
|
84 | 175 |
} |
85 |
} |
|
176 |
counter_pp++; //counts the prints for the end of the loop |
|
177 |
tickdelay(micros_to_ticks(period*1000)); |
|
178 |
|
|
179 |
} |
|
86 | 180 |
|
87 |
if (mouse_unsubscribe_int() != 0) { //check if unsubscription worked
|
|
181 |
if (write_cmd_mouse(0xEA)!=0) { //check if set stream mode worked (0xEA is the byte to enable)
|
|
88 | 182 |
printf("Error unsubscribing int \n"); |
89 | 183 |
return 1; |
90 | 184 |
} |
91 |
scan_code=0; |
|
92 | 185 |
|
186 |
if(write_cmd_mouse(0xF5)!=0){ //check if disabling data report worked (0xF5 is the byte to disable data report) |
|
187 |
printf("Error disabling stream mode\n"); |
|
188 |
return 1; |
|
189 |
} |
|
190 |
|
|
191 |
if (sys_outb(0X64,0x60)!=0) |
|
192 |
{ // Sends Write Command |
|
193 |
printf("Could not reset KBC command byte to default!"); |
|
194 |
return 1; |
|
195 |
} |
|
196 |
uint8_t default_cmd=minix_get_dflt_kbc_cmd_byte(); |
|
197 |
if (sys_outb(0x60,default_cmd)!=0) |
|
198 |
{ // Writes Command Byte |
|
199 |
printf("Could not reset KBC command byte to default!"); |
|
200 |
return 1; |
|
201 |
} |
|
202 |
|
|
203 |
byte=0; |
|
204 |
|
|
93 | 205 |
return 0; |
94 | 206 |
} |
95 | 207 |
|
96 |
int (mouse_test_remote)(uint16_t period, uint8_t cnt) { |
|
97 |
/* To be completed */ |
|
98 |
printf("%s(%u, %u): under construction\n", __func__, period, cnt); |
|
99 |
return 1; |
|
100 |
} |
|
101 |
|
|
102 | 208 |
int (mouse_test_async)(uint8_t idle_time) { |
103 | 209 |
/* To be completed */ |
104 | 210 |
printf("%s(%u): under construction\n", __func__, idle_time); |
105 | 211 |
return 1; |
106 | 212 |
} |
107 | 213 |
|
108 |
int (mouse_test_gesture)() { |
|
214 |
int (mouse_test_gesture)(uint8_t x_len, uint8_t tolerance) {
|
|
109 | 215 |
/* To be completed */ |
110 | 216 |
printf("%s: under construction\n", __func__); |
111 | 217 |
return 1; |
Also available in: Unified diff