Revision 80
reorganized remote
lab4/lab4.c | ||
---|---|---|
35 | 35 |
return 0; |
36 | 36 |
} |
37 | 37 |
|
38 |
extern uint8_t packet[3]; |
|
39 |
extern int counter; |
|
40 |
|
|
41 | 38 |
int (mouse_test_packet)(uint32_t cnt) { |
42 | 39 |
int ret = 0; |
43 | 40 |
/// loop stuff |
... | ... | |
65 | 62 |
case HARDWARE: /* hardware interrupt notification */ |
66 | 63 |
if (msg.m_notify.interrupts & mouse_irq) { /* subscribed interrupt */ |
67 | 64 |
mouse_ih(); |
68 |
if(counter >= 3){ |
|
69 |
struct packet pp = mouse_parse_packet(packet); |
|
65 |
if(counter_mouse_ih >= 3){
|
|
66 |
struct packet pp = mouse_parse_packet(packet_mouse_ih);
|
|
70 | 67 |
mouse_print_packet(&pp); |
71 | 68 |
cnt_now++; |
72 | 69 |
if(cnt == cnt_now) good = 0; |
... | ... | |
86 | 83 |
} |
87 | 84 |
|
88 | 85 |
int (mouse_test_remote)(uint16_t period, uint8_t cnt) { |
89 |
|
|
90 |
// Mouse packets data |
|
91 |
uint8_t packet[3]; |
|
92 |
int sz = 0; |
|
93 |
uint8_t data = 0; |
|
94 |
// Cycle |
|
95 |
int packetCounter = 0; |
|
96 |
int good = 1; |
|
97 |
// return value |
|
98 | 86 |
int ret; |
87 |
//if ((ret = mouse_issue_cmd(SET_REMOTE_MD))) return ret; |
|
88 |
//if ((ret = mouse_set_data_report(true))) return ret; |
|
99 | 89 |
|
100 |
if ((ret = mouse_issue_cmd(SET_REMOTE_MD))) return ret; |
|
101 |
|
|
102 |
if ((ret = mouse_set_data_report(true))) return ret; |
|
103 |
|
|
90 |
struct packet pp; |
|
91 |
while(cnt--){ |
|
92 |
if(mouse_poll(&pp, period)) return 1; |
|
93 |
mouse_print_packet(&pp); |
|
94 |
} |
|
95 |
/* |
|
104 | 96 |
while (good) { |
105 | 97 |
|
106 | 98 |
if ((ret = mouse_read_data(&data))) return ret; |
... | ... | |
118 | 110 |
} |
119 | 111 |
tickdelay(micros_to_ticks(period*1e3)); |
120 | 112 |
} |
121 |
|
|
113 |
*/ |
|
122 | 114 |
// Set Stream mode |
123 | 115 |
if ((ret = mouse_issue_cmd(SET_STREAM_MD))) return ret; |
124 | 116 |
// Disable data reporting |
... | ... | |
167 | 159 |
} |
168 | 160 |
if (msg.m_notify.interrupts & mouse_irq) { /// subscribed interrupt |
169 | 161 |
mouse_ih(); |
170 |
if(counter >= 3){ |
|
171 |
struct packet pp = mouse_parse_packet(packet); |
|
162 |
if(counter_mouse_ih >= 3){
|
|
163 |
struct packet pp = mouse_parse_packet(packet_mouse_ih);
|
|
172 | 164 |
mouse_print_packet(&pp); |
173 | 165 |
time = 0; |
174 | 166 |
no_interrupts = 0; |
... | ... | |
221 | 213 |
case HARDWARE: /* hardware interrupt notification */ |
222 | 214 |
if (msg.m_notify.interrupts & mouse_irq) { /* subscribed interrupt */ |
223 | 215 |
mouse_ih(); |
224 |
if(counter >= 3) { |
|
225 |
pp = mouse_parse_packet(packet); |
|
216 |
if(counter_mouse_ih >= 3) {
|
|
217 |
pp = mouse_parse_packet(packet_mouse_ih);
|
|
226 | 218 |
mouse_print_packet(&pp); |
227 | 219 |
event = mouse_get_event(&pp); |
228 | 220 |
|
lab4/mouse.c | ||
---|---|---|
15 | 15 |
} |
16 | 16 |
|
17 | 17 |
int got_error_mouse_ih = 0; |
18 |
uint8_t packet[3]; |
|
19 |
int counter = 0; |
|
18 |
int counter_mouse_ih = 0; |
|
20 | 19 |
|
21 | 20 |
void (mouse_ih)(void) { |
22 | 21 |
uint8_t status = 0; |
23 | 22 |
got_error_mouse_ih = 0; |
24 |
if(counter >= 3) counter = 0;
|
|
23 |
if(counter_mouse_ih >= 3) counter_mouse_ih = 0;
|
|
25 | 24 |
|
26 | 25 |
if ((got_error_mouse_ih = util_sys_inb(STATUS_REG, &status))) return; |
27 | 26 |
|
... | ... | |
39 | 38 |
if ((got_error_mouse_ih = util_sys_inb(OUTPUT_BUF, &byte))) return; |
40 | 39 |
|
41 | 40 |
/// This does not run if: I was expecting the first one but what I get is definitely not the first byte |
42 |
if((byte & FIRST_BYTE_ID) || counter){ |
|
43 |
packet[counter] = byte;
|
|
44 |
counter++; |
|
41 |
if((byte & FIRST_BYTE_ID) || counter_mouse_ih){
|
|
42 |
packet_mouse_ih[counter_mouse_ih] = byte;
|
|
43 |
counter_mouse_ih++;
|
|
45 | 44 |
} |
46 | 45 |
} |
47 | 46 |
|
... | ... | |
60 | 59 |
return pp; |
61 | 60 |
} |
62 | 61 |
|
63 |
int (mouse_set_data_report)(int on){
|
|
62 |
int mouse_poll(struct packet *pp, uint16_t period){
|
|
64 | 63 |
int ret = 0; |
65 |
if(on){ |
|
66 |
if((ret = mouse_issue_cmd(ENABLE_DATA_REP))) return ret; |
|
64 |
|
|
65 |
int counter = 0; |
|
66 |
uint8_t packet[3]; |
|
67 |
uint8_t byte; |
|
68 |
while(counter < 3){ |
|
69 |
if((ret = mouse_read_data(&byte, period))) return ret; |
|
70 |
if((byte & FIRST_BYTE_ID) || counter){ |
|
71 |
packet[counter] = byte; |
|
72 |
counter++; |
|
73 |
} |
|
67 | 74 |
} |
68 |
else{ |
|
69 |
if((ret = mouse_issue_cmd( DIS_DATA_REP))) return ret; |
|
70 |
} |
|
71 |
return ret; |
|
75 |
*pp = mouse_parse_packet(packet); |
|
76 |
return SUCCESS; |
|
72 | 77 |
} |
73 | 78 |
|
74 |
int (mouse_read_data)(uint8_t *data) { |
|
79 |
int (mouse_set_data_report)(int on){ |
|
80 |
if(on) return mouse_issue_cmd(ENABLE_DATA_REP); |
|
81 |
else return mouse_issue_cmd( DIS_DATA_REP); |
|
82 |
} |
|
83 |
|
|
84 |
int (mouse_read_data)(uint8_t *data, uint16_t period) { |
|
75 | 85 |
int ret; |
76 | 86 |
if ((ret = mouse_issue_cmd(READ_DATA))) return ret; |
77 |
if ((ret = mouse_read_byte(data))) return ret;
|
|
87 |
if ((ret = mouse_poll_byte(data, period))) return ret;
|
|
78 | 88 |
return SUCCESS; |
79 | 89 |
} |
80 | 90 |
|
... | ... | |
123 | 133 |
//return TIMEOUT_ERROR; |
124 | 134 |
} |
125 | 135 |
|
136 |
int (mouse_poll_byte)(uint8_t *byte, uint16_t period) { |
|
137 |
int ret = 0; |
|
138 |
uint8_t stat; |
|
139 |
while(true){ |
|
140 |
if((ret = util_sys_inb(STATUS_REG, &stat))) return ret; |
|
141 |
if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)) { |
|
142 |
if(stat & (PARITY_ERROR | TIME_OUT_REC)) return OTHER_ERROR; |
|
143 |
if((ret = util_sys_inb(OUTPUT_BUF, byte))) return ret; |
|
144 |
else return SUCCESS; |
|
145 |
} |
|
146 |
tickdelay(micros_to_ticks(period*1000)); |
|
147 |
} |
|
148 |
} |
|
149 |
|
|
126 | 150 |
int16_t (sign_extend_byte)(uint8_t sign_bit, uint8_t byte) { |
127 | 151 |
return (int16_t)(((0xFF * sign_bit)<<8) | byte); |
128 | 152 |
} |
lab4/mouse.h | ||
---|---|---|
12 | 12 |
*/ |
13 | 13 |
int (subscribe_mouse_interrupt)(uint8_t interrupt_bit, int *interrupt_id); |
14 | 14 |
|
15 |
int got_error_mouse_ih; |
|
16 |
uint8_t packet_mouse_ih[3]; |
|
17 |
int counter_mouse_ih; |
|
18 |
|
|
15 | 19 |
struct packet (mouse_parse_packet)(const uint8_t *packet_bytes); |
16 | 20 |
|
21 |
int mouse_poll(struct packet *pp, uint16_t period); |
|
22 |
|
|
23 |
/** |
|
24 |
* |
|
25 |
*/ |
|
17 | 26 |
int (mouse_set_data_report)(int on); |
18 | 27 |
|
19 | 28 |
/** |
... | ... | |
25 | 34 |
* @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK |
26 | 35 |
* @see {_ERRORS_H_::errors} |
27 | 36 |
*/ |
28 |
int (mouse_read_data)(uint8_t *data); |
|
37 |
int (mouse_read_data)(uint8_t *data, uint16_t period);
|
|
29 | 38 |
|
30 | 39 |
/** |
31 | 40 |
* @brief Issues command to mouse |
... | ... | |
51 | 60 |
|
52 | 61 |
int (mouse_read_ack)(uint8_t *byte); |
53 | 62 |
|
63 |
int (mouse_poll_byte)(uint8_t *byte, uint16_t period); |
|
64 |
|
|
54 | 65 |
/** |
55 | 66 |
* @brief Converts 9-bit number to 16-bit with sign extension |
56 | 67 |
* @param sign_bit Sign bit identifiying the signal of the number |
Also available in: Unified diff