Project

General

Profile

Revision 38

few changes to polling

View differences:

lab3/kbc.c
79 79
    return 0;
80 80
}
81 81

  
82
int (kbd_read_byte)(uint8_t *value){
82
int (kbd_issue_cmd)(uint8_t cmd){
83 83
    uint8_t stat;
84
    while(1){
84
    for(int i = 0; i < 10; ++i){
85 85
        if(util_sys_inb(STATUS_REG, &stat)) return 1;
86
        if((stat&OUT_BUF_FUL) && ((stat&AUX_MOUSE)^AUX_MOUSE)){
86
        if((stat&IN_BUF_FULL) == 0){
87
            if(sys_outb(KBC_CMD, cmd)) return 1;
88
            return 0;
89
        }
90
        tickdelay(micros_to_ticks(DELAY));
91
    }
92
    return 1;
93
}
94

  
95
int (kbd_read_byte)(uint8_t *byte){
96
    uint8_t stat;
97
    while(true){
98
        if(util_sys_inb(STATUS_REG, &stat)) return 1;
99
        if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)==0){
87 100
            if(stat & (PARITY_ERROR | TIME_OUT_REC)) return 1;
88
            else return util_sys_inb(OUTPUT_BUF, value);
101
            if(util_sys_inb(OUTPUT_BUF, byte)) return 1;
102
            else return 0;
89 103
        }
90 104
        tickdelay(micros_to_ticks(DELAY));
91 105
    }
92 106
}
107

  
108
int (kbd_read_cmd)(uint8_t *cmd){
109
    if(kbd_issue_cmd(0x20)) return 1;
110
    if(kbd_read_byte(cmd)) return 1;
111
    return 0;
112
}
lab3/kbc.h
6 6
#define KBC_IRQ     1 /* @brief KBC Controller IRQ Line */
7 7

  
8 8
/* Delay for KBC */
9
#define DELAY   50000 /* @brief KBC Response Delay */
9
#define DELAY   20000 /* @brief KBC Response Delay */
10 10

  
11 11
/* I/O Ports Addresses */
12 12

  
lab3/kbc_func.h
44 44
 */
45 45
int (kbd_poll)(uint8_t bytes[], uint8_t *size);
46 46

  
47
int (kbd_issue_cmd)(uint8_t cmd);
48

  
47 49
/**
48 50
 * @brief Low-level function for reading byte from keyboard
49 51
 * Low-level function for reading byte from keyboard. Waits until output buffer
......
51 53
 * @param value Pointer to variable where byte read from keyboard will be stored
52 54
 * @return 0 if operation was successful, 1 otherwise
53 55
 */
54
int (kbd_read_byte)(uint8_t *value);
56
int (kbd_read_byte)(uint8_t *byte);
55 57

  
58
int (kbd_read_cmd)(uint8_t *cmd);
59

  
56 60
#endif
lab3/lab3.c
96 96
        if(kbd_poll(c, &size)) return 1;
97 97
        if(kbd_print_scancode((~c[0])&BREAK_CODE_BIT, size, c)) return 1;
98 98
    }while(!(size == 1 && c[0] == ESC_BREAK_CODE));
99

  
100
    uint8_t cmd = 0;
101
    if(kbd_read_cmd(&cmd)) return 1;
102
    printf("%x\n", cmd);
103

  
99 104
    return 0;
100 105
}
101 106

  

Also available in: Unified diff