Project

General

Profile

Revision 74

implemented async. not working properly somehow

View differences:

lab4/Makefile
2 2
PROG=lab4
3 3

  
4 4
# source code files to be compiled
5
SRCS = lab4.c mouse.c utils.c kbc.c keyboard.c
5
SRCS = lab4.c mouse.c utils.c kbc.c keyboard.c timer.c
6 6

  
7 7
# additional compilation flags
8 8
# "-Wall -Wextra -Werror -I . -std=c11 -Wno-unused-parameter" are already set
lab4/lab4.c
7 7
#include "kbc.h"
8 8
#include "errors.h"
9 9
#include "mouse_macros.h"
10
#include "timer.h"
10 11

  
11 12
int main(int argc, char *argv[]) {
12 13
  // sets the language of LCF messages (can be either EN-US or PT-PT)
......
39 40
    /// loop stuff
40 41
    int ipc_status, r;
41 42
    message msg;
42
    /// Keyboard interrupt handling
43
    /// Mouse interrupt handling
43 44
    uint8_t mouse_irq_bit = 12;
44 45
    int mouse_id = 0;
45 46
    int mouse_irq = BIT(mouse_irq_bit);
......
125 126
}
126 127

  
127 128
int (mouse_test_async)(uint8_t idle_time) {
128
    /* To be completed */
129
    printf("%s(%u): under construction\n", __func__, idle_time);
130
    return 1;
129
    /// loop stuff
130
    int ipc_status, r;
131
    message msg;
132
    /// Timer interrupt handling
133
    const uint32_t frequency = sys_hz(); // Frequency asummed at 60Hz
134
    uint8_t timer_irq_bit = 0;
135
    int timer_id = 0;
136
    int timer_irq = BIT(timer_irq_bit);
137
    if(subscribe_timer_interrupt(timer_irq_bit, &timer_id)) return 1;
138

  
139
    no_interrupts = 0;
140
    int time = 0;
141
    /// Mouse interrupt handling
142
    uint8_t mouse_irq_bit = 12;
143
    int mouse_id = 0;
144
    int mouse_irq = BIT(mouse_irq_bit);
145
    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1;
146
    if (mouse_set_data_report(true)) return 1;
147
    /// cycle
148
    int good = 1;
149
    while (good) {
150
        /* Get a request message. */
151
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
152
            printf("driver_receive failed with %d", r);
153
            continue;
154
        }
155
        if (is_ipc_notify(ipc_status)) { /* received notification */
156
            switch (_ENDPOINT_P(msg.m_source)) {
157
                case HARDWARE: /* hardware interrupt notification */
158
                    if (msg.m_notify.interrupts & timer_irq) { /* subscribed interrupt */
159
                        timer_int_handler();
160
                        if (no_interrupts%frequency == 0) time++;
161
                        if(time >= idle_time) good = 0;
162
                    }
163
                    if (msg.m_notify.interrupts & mouse_irq) { /// subscribed interrupt
164
                        mouse_ih();
165
                        if(counter >= 3){
166
                            struct packet pp = mouse_parse_packet(packet);
167
                            mouse_print_packet(&pp);
168
                            time = 0;
169
                            no_interrupts = 0;
170
                        }
171
                    }
172
                    break;
173
                default:
174
                    break; /* no other notifications expected: do nothing */
175
            }
176
        } else { /* received standart message, not a notification */
177
            /* no standart message expected: do nothing */
178
        }
179
    }
180

  
181
    if (unsubscribe_interrupt(&mouse_id)) return 1;
182
    if (mouse_set_data_report(false)) return 1;
183

  
184
    if (unsubscribe_interrupt(&timer_id)) return 1;
185

  
186
    return 0;
131 187
}
132 188

  
133 189
int (mouse_test_gesture)(uint8_t x_len, uint8_t tolerance) {

Also available in: Unified diff