Project

General

Profile

Revision 42

changed counter

View differences:

lab3/kbc.c
22 22
    uint8_t status = 0;
23 23
    got_error = 0;
24 24

  
25
    #ifdef LAB3
26
    sys_inb_counter(INCREMENT);
27
    #endif
28

  
29 25
    if (util_sys_inb(STATUS_REG, &status)) {
30 26
        got_error = 1;
31 27
        return;
......
36 32
        return;
37 33
    }
38 34

  
39
    #ifdef LAB3
40
    sys_inb_counter(INCREMENT);
41
    #endif
42

  
43 35
    uint8_t byte = 0;
44 36

  
45 37
    if (util_sys_inb(OUTPUT_BUF, &byte)) {
......
57 49

  
58 50
}
59 51

  
60
uint32_t (sys_inb_counter)(int increment) {
61
    static uint32_t counter = 0;
62
    if (increment) return ++counter;
63
    return counter;
64
}
65

  
66 52
int (kbd_poll)(uint8_t bytes[], uint8_t *size){
67 53
    if(bytes == NULL || size == NULL) return 1;
68 54
    uint8_t c;
lab3/kbc_func.h
28 28
void (kbc_ih)(void);
29 29

  
30 30
/**
31
 * @brief Counter for sys_inb calls
32
 * @param increment Whether the value should be incremented or not
33
 * @return The current value of the counter
34
 */
35
uint32_t (sys_inb_counter)(int get_increment);
36

  
37
/**
38 31
 * @brief High-level function that polls keyboard for scancode
39 32
 * High-level function that polls keyboard for scancode of up to 2 bytes. If
40 33
 * scancode has only 1 byte, the second byte is set to 0x00.
lab3/lab3.c
34 34
extern uint8_t scancode[2];
35 35
extern int two_byte_scancode;
36 36
extern int got_error;
37
extern uint32_t sys_inb_counter;
37 38

  
38 39
int(kbd_test_scan)() {
39 40

  
......
85 86

  
86 87
    if (unsubscribe_kbc_interrupt(&kbc_id)) return 1;
87 88

  
88
    if (kbd_print_no_sysinb(sys_inb_counter(GET))) return 1;
89
    if (kbd_print_no_sysinb(sys_inb_counter)) return 1;
89 90

  
90 91
    return 0;
91 92
}
......
102 103
    cmd = (cmd | INT_KBD) & (~DIS_KBD);
103 104
    if(kbc_change_cmd(cmd)) return 1;
104 105

  
106
    if (kbd_print_no_sysinb(sys_inb_counter)) return 1;
107

  
105 108
    return 0;
106 109
}
107 110

  
lab3/utils.c
2 2

  
3 3
#include <stdint.h>
4 4

  
5
#ifdef LAB3
6
    uint32_t sys_inb_counter = 0;
7
#endif
8

  
5 9
int (util_sys_inb)(int port, uint8_t *value) {
6 10
    if(value == NULL) return 1;
7 11
    uint32_t n = 0;
8 12
    if(sys_inb(port, &n)) return 1;
9 13
    *value = n;
14
    #ifdef LAB3
15
        ++sys_inb_counter;
16
    #endif
10 17
    return 0;
11 18
}

Also available in: Unified diff