Project

General

Profile

Revision 44

implemented 3rd function. something is wrong

View differences:

lab3/Makefile
2 2
PROG=lab3
3 3

  
4 4
# source code files to be compiled
5
SRCS = lab3.c kbc.c utils.c
5
SRCS = lab3.c kbc_func.c timer_func.c utils.c
6 6

  
7 7
# additional compilation flags
8 8
# "-Wall -Wextra -Werror -I . -std=c11 -Wno-unused-parameter" are already set
lab3/kbc_func.h
15 15
int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
16 16

  
17 17
/**
18
 * @brief Unsubcribes KBC Interrupts
19
 * @param interrupt_id KBC Interrupt ID, value via arguments on subscription of the interrupt_id
20
 * @see subscribe_kbc_interrupt
18
 * @brief Unsubcribes Interrupts
19
 * @param interrupt_id Interrupt ID, value via arguments on subscription of the interrupt_id
20
 * @see subscribe_kbc_interrupt, subscribe_timer_interrupt
21 21
 * @return Whether operation was sucessful or not
22 22
 */
23
int (unsubscribe_kbc_interrupt)(int *interrupt_id);
23
int (unsubscribe_interrupt)(int *interrupt_id);
24 24

  
25 25
/**
26 26
 * @brief KBC Interrupt Handler
lab3/lab3.c
6 6

  
7 7
#include "kbc.h"
8 8
#include "kbc_func.h"
9
#include "timer_func.h"
9 10

  
10 11
int main(int argc, char *argv[]) {
11 12
  // sets the language of LCF messages (can be either EN-US or PT-PT)
......
37 38
extern uint32_t sys_inb_counter;
38 39

  
39 40
int(kbd_test_scan)() {
40

  
41
    /// loop stuff
41 42
    int ipc_status, r;
42 43
    message msg;
43

  
44
    /// Keyboard interrupt handling
44 45
    uint8_t kbc_irq_bit = 1;
45 46
    int kbc_id = 0;
46 47
    int kbc_irq = BIT(kbc_irq_bit);
47

  
48
    int got_esc_breakcode = 0;
49

  
50 48
    if (subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) return 1;
51

  
52
    while (!got_esc_breakcode) {
49
    /// cycle
50
    int good = 1;
51
    while (good) {
53 52
        /* Get a request message. */
54 53
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
55 54
            printf("driver_receive failed with %d", r);
......
59 58
            switch (_ENDPOINT_P(msg.m_source)) {
60 59
                case HARDWARE: /* hardware interrupt notification */
61 60
                    if (msg.m_notify.interrupts & kbc_irq) { /* subscribed interrupt */
62

  
63 61
                        kbc_ih();
64

  
65 62
                        if (!(two_byte_scancode || got_error)) { /* finished processing a scancode */
66
                            if (scancode[0] == TWO_BYTE_CODE)
67
                                kbd_print_scancode(!(scancode[1] & BREAK_CODE_BIT), 2, scancode);
68
                            else
69
                                kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode);
70
                        } else {
71
                            break;
72
                        }
73

  
74
                        if (scancode[0] == ESC_BREAK_CODE)
75
                            got_esc_breakcode = 1;
76

  
63
                            if (scancode[0] == TWO_BYTE_CODE) kbd_print_scancode(!(scancode[1] & BREAK_CODE_BIT), 2, scancode);
64
                            else                              kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode);
65
                        } else { break; }
66
                        if (scancode[0] == ESC_BREAK_CODE) good = 0;
77 67
                    }
78 68
                    break;
79 69
                default:
......
84 74
        }
85 75
    }
86 76

  
87
    if (unsubscribe_kbc_interrupt(&kbc_id)) return 1;
77
    if (unsubscribe_interrupt(&kbc_id)) return 1;
88 78

  
89 79
    if (kbd_print_no_sysinb(sys_inb_counter)) return 1;
90 80

  
......
105 95
    return 0;
106 96
}
107 97

  
108
int(kbd_test_timed_scan)(uint8_t n) {
109
  /* To be completed by the students */
110
  printf("%s is not yet implemented!\n", __func__);
98
extern int no_interrupts;
111 99

  
112
  return 1;
100
int(kbd_test_timed_scan)(uint8_t idle) {
101
    /// loop stuff
102
    int ipc_status, r;
103
    message msg;
104
    /// Timer interrupt handling
105
    const uint32_t frequency = 60; // Frequency asummed at 60Hz
106
    uint8_t timer_irq_bit = 0;
107
    int timer_id = 0;
108
    int timer_irq = BIT(timer_irq_bit);
109
    if(subscribe_timer_interrupt(timer_irq_bit, &timer_id)) return 1;
110

  
111
    no_interrupts = 0;
112
    int time = 0;
113
    /// Keyboard interrupt handling
114
    uint8_t kbc_irq_bit = 1;
115
    int kbc_id = 0;
116
    int kbc_irq = BIT(kbc_irq_bit);
117
    if(subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) return 1;
118
    /// cycle
119
    int good = 1;
120
    while (good) {
121
        /* Get a request message. */
122
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
123
            printf("driver_receive failed with %d", r);
124
            continue;
125
        }
126
        if (is_ipc_notify(ipc_status)) { /* received notification */
127
            switch (_ENDPOINT_P(msg.m_source)) {
128
                case HARDWARE: /* hardware interrupt notification */
129
                    if (msg.m_notify.interrupts & timer_irq) { /* subscribed interrupt */
130
                        timer_int_handler();
131
                        //printf("no_interrupts: %d\n", no_interrupts);
132
                        if (no_interrupts%frequency == 0) time++;
133
                        if(time >= idle) good = 0;
134
                    }
135
                    if (msg.m_notify.interrupts & kbc_irq) { /// subscribed interrupt
136
                        kbc_ih();
137
                        if (!(two_byte_scancode || got_error)) { /// finished processing a scancode
138
                            if (scancode[0] == TWO_BYTE_CODE) kbd_print_scancode(!(scancode[1] & BREAK_CODE_BIT), 2, scancode);
139
                            else                              kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode);
140
                            time = 0;
141
                            if (scancode[0] == ESC_BREAK_CODE) good = 0;
142
                        }
143
                    }
144
                    break;
145
                default:
146
                    break; /* no other notifications expected: do nothing */
147
            }
148
        } else { /* received standart message, not a notification */
149
            /* no standart message expected: do nothing */
150
        }
151
    }
152

  
153
    if (unsubscribe_interrupt(&kbc_id)) return 1;
154
    if (unsubscribe_interrupt(&timer_id)) return 1;
155

  
156
    return 0;
113 157
}

Also available in: Unified diff