Project

General

Profile

Revision 87

fixed stuff

View differences:

lab4/lab4.c
44 44
    uint8_t mouse_irq_bit = 12;
45 45
    int mouse_id = 0;
46 46
    int mouse_irq = BIT(mouse_irq_bit);
47
    if ((ret = mouse_set_data_report(true))) return ret;
48
    //if ((ret = mouse_enable_data_reporting())) return ret;
49 47

  
50
    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1;
48
    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1; // subscribes mouse interrupts in exclusive mode
49
    if (sys_irqdisable(&mouse_id)) return 1; // temporarily disables our interrupts notifications
50
    if ((ret = mouse_set_data_report(true))) return ret; // enables mouse data reporting
51
    if (sys_irqenable(&mouse_id)) return 1; // re-enables our interrupts notifications
52

  
51 53
    /// cycle
52
    int good = cnt != 0;
54
    int good = (cnt != 0);
53 55
    uint32_t cnt_now = 0;
54 56
    while (good) {
55 57
        /* Get a request message. */
......
77 79
            /* no standart message expected: do nothing */
78 80
        }
79 81
    }
80
    if (unsubscribe_interrupt(&mouse_id)) return 1;
81
    if (mouse_set_data_report(false)) return 1;
82
    if (sys_irqdisable(&mouse_id)) return 1; // temporarily disables our interrupts notifications
83
    if (mouse_set_data_report(false)) return 1; // enables mouse data reporting
84
    if (sys_irqenable(&mouse_id)) return 1; // re-enables our interrupts notifications
85
    if (unsubscribe_interrupt(&mouse_id)) return 1; // unsubscribes interrupts
82 86
    return 0;
83 87
}
84 88

  
......
93 97
        mouse_print_packet(&pp);
94 98
        tickdelay(micros_to_ticks(period*1000));
95 99
    }
96
    /*
97
    while (good) {
98

  
99
        if ((ret = mouse_read_data(&data))) return ret;
100

  
101
        if ((data & FIRST_BYTE_ID) || sz) {
102
            packet[sz] = data;
103
            sz++;
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
        tickdelay(micros_to_ticks(period*1e3));
113
    }
114
    */
115 100
    // Set Stream mode
116 101
    if ((ret = mouse_issue_cmd(SET_STREAM_MD))) return ret;
117 102
    // Disable data reporting
......
139 124
    uint8_t mouse_irq_bit = 12;
140 125
    int mouse_id = 0;
141 126
    int mouse_irq = BIT(mouse_irq_bit);
142
    if (mouse_set_data_report(true)) return 1;
143 127

  
144
    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1;
128
    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1; // subscribes mouse interrupts in exclusive mode
129
    if (sys_irqdisable(&mouse_id)) return 1; // temporarily disables our interrupts notifications
130
    if (mouse_set_data_report(true)) return 1; // enables mouse data reporting
131
    if (sys_irqenable(&mouse_id)) return 1; // re-enables our interrupts notifications
132

  
145 133
    /// cycle
146 134
    int good = 1;
147 135
    while (good) {
......
176 164
        }
177 165
    }
178 166

  
179
    if (unsubscribe_interrupt(&mouse_id)) return 1;
180
    if (mouse_set_data_report(false)) return 1;
167
    if (sys_irqdisable(&mouse_id)) return 1; // temporarily disables our interrupts notifications
168
    if (mouse_set_data_report(false)) return 1; // enables mouse data reporting
169
    if (sys_irqenable(&mouse_id)) return 1; // re-enables our interrupts notifications
170
    if (unsubscribe_interrupt(&mouse_id)) return 1; // unsubscribes interrupts
181 171

  
182 172
    if (unsubscribe_interrupt(&timer_id)) return 1;
183 173

  
......
193 183
    uint8_t mouse_irq_bit = 12;
194 184
    int mouse_id = 0;
195 185
    int mouse_irq = BIT(mouse_irq_bit);
196
    if ((ret = mouse_set_data_report(true))) return ret;
197 186

  
198
    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1;
187
    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1; // subscribes mouse interrupts in exclusive mode
188
    if (sys_irqdisable(&mouse_id)) return 1; // temporarily disables our interrupts notifications
189
    if ((ret = mouse_set_data_report(true))) return ret; // enables mouse data reporting
190
    if (sys_irqenable(&mouse_id)) return 1; // re-enables our interrupts notifications
191

  
199 192
    /// cycle
200 193
    int good = 1;
201 194

  
......
235 228
            /* no standart message expected: do nothing */
236 229
        }
237 230
    }
238
    if (unsubscribe_interrupt(&mouse_id)) return 1;
239
    if (mouse_set_data_report(false)) return 1;
240 231

  
232
    if (sys_irqdisable(&mouse_id)) return 1; // temporarily disables our interrupts notifications
233
    if (mouse_set_data_report(false)) return 1; // enables mouse data reporting
234
    if (sys_irqenable(&mouse_id)) return 1; // re-enables our interrupts notifications
235
    if (unsubscribe_interrupt(&mouse_id)) return 1; // unsubscribes interrupts
236

  
241 237
    return 0;
242 238
}
lab4/mouse.c
91 91
    for (unsigned int i = 0; i < KBC_NUM_TRIES; i++) {
92 92
        if ((ret = kbc_issue_cmd(MOUSE_WRITE_B))) return ret;
93 93
        if ((ret = kbc_issue_arg(cmd))) return ret;
94
        if ((ret = mouse_read_ack(&ack))) return ret;
94
        if ((ret = mouse_read_byte(&ack))) return ret;
95 95

  
96 96
        if (ack == ACK_OK) return SUCCESS;
97 97
        if (ack == ACK_ERROR) return INVALID_COMMAND;
......
115 115
    return TIMEOUT_ERROR;
116 116
}
117 117

  
118
int (mouse_read_ack)(uint8_t *byte) {
119
    int ret = 0;
120
    uint8_t stat;
121
    //for(int i = 0; i < KBC_NUM_TRIES; ++i){
122
        if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
123
        //if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)) {
124
            if(stat & (PARITY_ERROR | TIME_OUT_REC)) return OTHER_ERROR;
125
            if((ret = util_sys_inb(OUTPUT_BUF, byte))) return ret;
126
            else return SUCCESS;
127
        //}
128
        //tickdelay(micros_to_ticks(DELAY));
129
    //}
130
    //return TIMEOUT_ERROR;
131
}
132

  
133 118
int (mouse_poll_byte)(uint8_t *byte, uint16_t period) {
134 119
    int ret = 0;
135 120
    uint8_t stat;
lab4/mouse.h
73 73
int (mouse_read_byte)(uint8_t *byte);
74 74

  
75 75
/**
76
 * @brief Same as @ref mouse_read_byte, except it does not wait for output buffer
77
 * to be full, since ACK is considered to arrive instantaneously somehow.
78
 * @param   byte    pointer to byte where ACK will be stored
79
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
80
 */
81
int (mouse_read_ack)(uint8_t *byte);
82

  
83
/**
84 76
 * @brief Polls OUT_BUF for byte coming from mouse.
85 77
 * @param   byte    pointer to byte read from OUT_BUF
86 78
 * @param   period  time (in milliseconds) the poller should wait between pollings of bytes
lab4/state_machine.c
71 71

  
72 72
    if (event == NULL)
73 73
        return response;
74

  
74 75
    switch (state) {
75 76
        case INITIAL:
76 77
            if (event->type == LB_PRESSED)
......
78 79
            break;
79 80
        case DRAG_UP:
80 81
            if (event->type == MOUSE_MOV) {
81
                if (abs(event->delta_x) > tolerance || abs(event->delta_y) > tolerance) {
82
                if (event->delta_x < -tolerance || event->delta_y < -tolerance) {
82 83
                    state = INITIAL;
83 84
                    x_length = 0;
84 85
                    y_length = 0;
......
124 125
            break;
125 126
        case DRAG_DOWN:
126 127
            if (event->type == MOUSE_MOV) {
127
                if (abs(event->delta_x) > tolerance || abs(event->delta_y) > tolerance) {
128
                if (event->delta_x < -tolerance || event->delta_y > tolerance) {
128 129
                    state = INITIAL;
129 130
                    x_length = 0;
130 131
                    y_length = 0;

Also available in: Unified diff