Revision 70
implemented remote, working on fixing issues
lab4/errors.h | ||
---|---|---|
2 | 2 |
#define ERRORS_H_INCLUDED |
3 | 3 |
|
4 | 4 |
enum errors { |
5 |
SUCCESS = 0, /* @brief Sucessful */ |
|
6 |
NULL_PTR, /* @brief Null Pointer Error */ |
|
7 |
LCF_ERROR, /* @brief Error originated on LCF */ |
|
8 |
SBCR_ERROR, /* @brief Error on Subscribing Interrupt */ |
|
9 |
UNSBCR_ERROR, /* @brief Error on Unsubscring Interrupt*/ |
|
10 |
READ_ERROR, /* @brief Error on Reading from Port */ |
|
11 |
WRITE_ERROR, /* @brief Error on Writing to Port */ |
|
12 |
TIMEOUT_ERROR, /* @brief Timeout error */ |
|
13 |
OTHER_ERROR, /* @brief Unspecified error */ |
|
5 |
SUCCESS = 0, /* @brief Sucessful */ |
|
6 |
NULL_PTR, /* @brief Null Pointer Error */ |
|
7 |
LCF_ERROR, /* @brief Error originated on LCF */ |
|
8 |
SBCR_ERROR, /* @brief Error on Subscribing Interrupt */ |
|
9 |
UNSBCR_ERROR, /* @brief Error on Unsubscring Interrupt*/ |
|
10 |
READ_ERROR, /* @brief Error on Reading from Port */ |
|
11 |
WRITE_ERROR, /* @brief Error on Writing to Port */ |
|
12 |
TIMEOUT_ERROR, /* @brief Timeout error */ |
|
13 |
INVALID_COMMAND, /* @brief Invalid Command issued */ |
|
14 |
OTHER_ERROR, /* @brief Unspecified error */ |
|
14 | 15 |
}; |
15 | 16 |
|
16 | 17 |
#endif //ERRORS_H_INCLUDED |
lab4/lab4.c | ||
---|---|---|
5 | 5 |
|
6 | 6 |
#include "mouse.h" |
7 | 7 |
#include "kbc.h" |
8 |
#include "errors.h" |
|
9 |
#include "mouse_macros.h" |
|
8 | 10 |
|
9 | 11 |
int main(int argc, char *argv[]) { |
10 | 12 |
// sets the language of LCF messages (can be either EN-US or PT-PT) |
... | ... | |
80 | 82 |
} |
81 | 83 |
|
82 | 84 |
int (mouse_test_remote)(uint16_t period, uint8_t cnt) { |
83 |
/* To be completed */ |
|
84 |
printf("%s(%u, %u): under construction\n", __func__, period, cnt); |
|
85 |
return 1; |
|
85 |
|
|
86 |
// Mouse packets data |
|
87 |
uint8_t packet[3]; |
|
88 |
int sz = 0; |
|
89 |
uint8_t data = 0; |
|
90 |
// Cycle |
|
91 |
int packetCounter = 0; |
|
92 |
int good = 1; |
|
93 |
// return value |
|
94 |
int ret; |
|
95 |
|
|
96 |
while (good) { |
|
97 |
|
|
98 |
if ((ret = mouse_read_data(&data))) return ret; |
|
99 |
|
|
100 |
if ((data & FIRST_BYTE_ID) || sz) { |
|
101 |
packet[sz] = data; |
|
102 |
sz++; |
|
103 |
} |
|
104 |
|
|
105 |
if (sz == 3) { |
|
106 |
struct packet pp = mouse_parse_packet(packet); |
|
107 |
mouse_print_packet(&pp); |
|
108 |
packetCounter++; |
|
109 |
sz = 0; |
|
110 |
if (packetCounter == cnt) good = 0; |
|
111 |
} |
|
112 |
|
|
113 |
tickdelay(micros_to_ticks(period*1e3)); |
|
114 |
} |
|
115 |
|
|
116 |
// Set Stream mode |
|
117 |
if ((ret = mouse_issue_cmd(SET_STREAM_MD))) return ret; |
|
118 |
// Disable data reporting |
|
119 |
if ((ret = mouse_issue_cmd(DIS_DATA_REP))) return ret; |
|
120 |
|
|
121 |
uint8_t cmd_byte = minix_get_dflt_kbc_cmd_byte(); |
|
122 |
if ((ret = kbc_change_cmd(cmd_byte))) return ret; |
|
123 |
|
|
124 |
return SUCCESS; |
|
86 | 125 |
} |
87 | 126 |
|
88 | 127 |
int (mouse_test_async)(uint8_t idle_time) { |
lab4/mouse.c | ||
---|---|---|
66 | 66 |
printf("ACK: %x\n", ack); |
67 | 67 |
return SUCCESS; |
68 | 68 |
} |
69 |
|
|
70 |
int (mouse_read_data)(uint8_t *data) { |
|
71 |
int ret; |
|
72 |
if ((ret = mouse_issue_cmd(READ_DATA))) return ret; |
|
73 |
if ((ret = mouse_read_byte(data))) return ret; |
|
74 |
return SUCCESS; |
|
75 |
} |
|
76 |
|
|
77 |
int (mouse_issue_cmd)(uint32_t cmd) { |
|
78 |
int ret; |
|
79 |
uint8_t ack = 0; |
|
80 |
while (ack != ACK_ERROR) { |
|
81 |
if ((ret = kbc_issue_cmd(MOUSE_WRITE_B))) return ret; |
|
82 |
if ((ret = kbc_issue_arg(cmd))) return ret; |
|
83 |
if ((ret = mouse_read_byte(&ack))) return ret; |
|
84 |
if (ack == ACK_OK) return SUCCESS; |
|
85 |
tickdelay(micros_to_ticks(DELAY)); |
|
86 |
} |
|
87 |
return INVALID_COMMAND; |
|
88 |
} |
|
89 |
|
|
90 |
int (mouse_read_byte)(uint8_t *byte) { |
|
91 |
int ret = 0; |
|
92 |
uint8_t stat; |
|
93 |
for(int i = 0; i < KBC_NUM_TRIES; ++i){ |
|
94 |
if((ret = util_sys_inb(STATUS_REG, &stat))) return ret; |
|
95 |
if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)) { |
|
96 |
if(stat & (PARITY_ERROR | TIME_OUT_REC)) return OTHER_ERROR; |
|
97 |
if((ret = util_sys_inb(OUTPUT_BUF, byte))) return ret; |
|
98 |
else return SUCCESS; |
|
99 |
} |
|
100 |
tickdelay(micros_to_ticks(DELAY)); |
|
101 |
} |
|
102 |
return TIMEOUT_ERROR; |
|
103 |
} |
lab4/mouse.h | ||
---|---|---|
16 | 16 |
|
17 | 17 |
int (mouse_set_data_report)(int on); |
18 | 18 |
|
19 |
/** |
|
20 |
* @brief Reads data byte from mouse |
|
21 |
* <summary> |
|
22 |
* Polls the mouse till data is available for reading |
|
23 |
* </summary> |
|
24 |
* @param data Pointer to variable where byte read from mouse will be stored |
|
25 |
* @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK |
|
26 |
* @see {_ERRORS_H_::errors} |
|
27 |
*/ |
|
28 |
int (mouse_read_data)(uint8_t *data); |
|
29 |
|
|
30 |
/** |
|
31 |
* @brief Issues command to mouse |
|
32 |
* <summary> |
|
33 |
* Issues command to mouse, returns error after two consecutive errors reported by the acknowledgment byte |
|
34 |
* </summary> |
|
35 |
* @param cmd Command to be issued |
|
36 |
* @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK |
|
37 |
* @see {_ERRORS_H_::errors} |
|
38 |
*/ |
|
39 |
int (mouse_issue_cmd)(uint32_t cmd); |
|
40 |
|
|
41 |
/** |
|
42 |
* @brief Reads byte from mouse |
|
43 |
* <summary> |
|
44 |
* Reads byte from mouse, giving error if exceeds number of tries to read |
|
45 |
* @param byte Pointer to variable where byte read from mouse will be stored |
|
46 |
* @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK |
|
47 |
* @see {_ERRORS_H_::errors} |
|
48 |
*/ |
|
49 |
int (mouse_read_byte)(uint8_t *byte); |
|
50 |
|
|
19 | 51 |
#endif //MOUSE_H_INCLUDED |
Also available in: Unified diff