Revision 64
changing
lab4/kbd.c | ||
---|---|---|
1 |
#include <lcom/lcf.h> |
|
2 |
|
|
3 |
#include "kbd.h" |
|
4 |
|
|
5 |
#include "kbc_macros.h" |
|
6 |
#include "kbc.h" |
|
7 |
|
|
8 |
int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id) { |
|
9 |
if (interrupt_id == NULL) return 1; |
|
10 |
*interrupt_id = interrupt_bit; |
|
11 |
return (sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id)); |
|
12 |
} |
|
13 |
|
|
14 |
void (kbc_ih)(void) { |
|
15 |
uint8_t status = 0; |
|
16 |
got_error = 0; |
|
17 |
|
|
18 |
if (util_sys_inb(STATUS_REG, &status)) { |
|
19 |
got_error = 1; |
|
20 |
return; |
|
21 |
} |
|
22 |
|
|
23 |
if (status & (TIME_OUT_REC | PARITY_ERROR)) { |
|
24 |
got_error = 1; |
|
25 |
return; |
|
26 |
} |
|
27 |
|
|
28 |
uint8_t byte = 0; |
|
29 |
|
|
30 |
if (util_sys_inb(OUTPUT_BUF, &byte)) { |
|
31 |
got_error = 1; |
|
32 |
return; |
|
33 |
} |
|
34 |
|
|
35 |
if (two_byte_scancode) { |
|
36 |
scancode[1] = byte; |
|
37 |
two_byte_scancode = 0; |
|
38 |
} else { |
|
39 |
scancode[0] = byte; |
|
40 |
two_byte_scancode = (byte == TWO_BYTE_CODE); |
|
41 |
} |
|
42 |
|
|
43 |
} |
|
44 |
|
|
45 |
int (kbd_poll)(uint8_t bytes[], uint8_t *size){ |
|
46 |
if(bytes == NULL || size == NULL) return 1; |
|
47 |
uint8_t c; |
|
48 |
if(kbc_read_byte(&c)) return 1; |
|
49 |
if(c == TWO_BYTE_CODE){ |
|
50 |
if(kbc_read_byte(&bytes[1])) return 1; |
|
51 |
bytes[0] = c; |
|
52 |
*size = 2; |
|
53 |
}else{ |
|
54 |
bytes[1] = 0; |
|
55 |
bytes[0] = c; |
|
56 |
*size = 1; |
|
57 |
} |
|
58 |
return 0; |
|
59 |
} |
|
60 | 0 |
lab4/kbd.h | ||
---|---|---|
1 |
/** |
|
2 |
* This file concerns everything related to the keyboard |
|
3 |
*/ |
|
4 |
|
|
5 |
#ifndef KBD_H_INCLUDED |
|
6 |
#define KBD_H_INCLUDED |
|
7 |
|
|
8 |
int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id); |
|
9 |
|
|
10 |
uint8_t scancode[2]; |
|
11 |
int two_byte_scancode = 0; |
|
12 |
int got_error = 0; |
|
13 |
|
|
14 |
void (kbc_ih)(void); |
|
15 |
|
|
16 |
int (kbd_poll)(uint8_t bytes[], uint8_t *size); |
|
17 |
|
|
18 |
#endif //KBD_H_INCLUDED |
|
19 | 0 |
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 kbd.c
|
|
5 |
SRCS = lab4.c mouse.c utils.c kbc.c keyboard.c
|
|
6 | 6 |
|
7 | 7 |
# additional compilation flags |
8 | 8 |
# "-Wall -Wextra -Werror -I . -std=c11 -Wno-unused-parameter" are already set |
lab4/utils.c | ||
---|---|---|
1 |
#include "errors.h" |
|
2 |
|
|
3 | 1 |
#include <lcom/lcf.h> |
4 | 2 |
|
5 | 3 |
#include <stdint.h> |
6 | 4 |
|
5 |
int(util_get_LSB)(uint16_t val, uint8_t *lsb) { |
|
6 |
if (lsb == NULL) return 1; |
|
7 |
*lsb = val; |
|
8 |
return 0; |
|
9 |
} |
|
10 |
|
|
11 |
int(util_get_MSB)(uint16_t val, uint8_t *msb) { |
|
12 |
if (msb == NULL) return 1; |
|
13 |
*msb = (val >> 8); |
|
14 |
return 0; |
|
15 |
} |
|
16 |
|
|
17 |
#ifdef LAB3 |
|
18 |
uint32_t sys_inb_counter = 0; |
|
19 |
#endif |
|
20 |
|
|
7 | 21 |
int (util_sys_inb)(int port, uint8_t *value) { |
8 |
if(value == NULL) return NULL_PTR;
|
|
22 |
if(value == NULL) return 1;
|
|
9 | 23 |
uint32_t n = 0; |
10 |
if(sys_inb(port, &n)) return READ_ERROR;
|
|
24 |
if(sys_inb(port, &n)) return 1;
|
|
11 | 25 |
*value = n; |
12 |
return SUCCESS; |
|
26 |
#ifdef LAB3 |
|
27 |
++sys_inb_counter; |
|
28 |
#endif |
|
29 |
return 0; |
|
13 | 30 |
} |
Also available in: Unified diff