Revision 30
Implemented kbd_test_scan
lab3/.depend | ||
---|---|---|
1 |
kbc.d kbc.ln kbc.o: kbc.c /usr/include/lcom/lcf.h /usr/include/stdbool.h \ |
|
2 |
/usr/include/stdio.h /usr/include/sys/cdefs.h \ |
|
3 |
/usr/include/machine/cdefs.h /usr/include/sys/cdefs_elf.h \ |
|
4 |
/usr/include/sys/featuretest.h /usr/include/sys/ansi.h \ |
|
5 |
/usr/include/machine/ansi.h /usr/include/machine/int_types.h \ |
|
6 |
/usr/include/sys/common_int_types.h /usr/include/sys/null.h \ |
|
7 |
/usr/include/stdlib.h /usr/include/sys/types.h \ |
|
8 |
/usr/include/machine/types.h /usr/include/machine/endian.h \ |
|
9 |
/usr/include/sys/endian.h /usr/include/machine/endian_machdep.h \ |
|
10 |
/usr/include/machine/bswap.h /usr/include/machine/byte_swap.h \ |
|
11 |
/usr/include/sys/bswap.h /usr/include/sys/stdint.h \ |
|
12 |
/usr/include/machine/int_mwgwtypes.h \ |
|
13 |
/usr/include/sys/common_int_mwgwtypes.h \ |
|
14 |
/usr/include/machine/int_limits.h /usr/include/sys/common_int_limits.h \ |
|
15 |
/usr/include/machine/int_const.h /usr/include/sys/common_int_const.h \ |
|
16 |
/usr/include/machine/wchar_limits.h /usr/include/sys/fd_set.h \ |
|
17 |
/usr/include/time.h /usr/include/sys/time.h \ |
|
18 |
/usr/include/sys/timespec.h /usr/include/sys/select.h \ |
|
19 |
/usr/include/sys/sigtypes.h /usr/include/unistd.h \ |
|
20 |
/usr/include/sys/unistd.h /usr/include/machine/int86.h \ |
|
21 |
/usr/include/minix/const.h /usr/include/machine/archconst.h \ |
|
22 |
/usr/include/minix/driver.h /usr/include/minix/config.h \ |
|
23 |
/usr/include/minix/sys_config.h /usr/include/minix/type.h \ |
|
24 |
/usr/include/machine/multiboot.h /usr/include/stddef.h \ |
|
25 |
/usr/include/machine/interrupt.h /usr/include/minix/ipc.h \ |
|
26 |
/usr/include/minix/ipcconst.h /usr/include/machine/ipcconst.h \ |
|
27 |
/usr/include/sys/signal.h /usr/include/sys/siginfo.h \ |
|
28 |
/usr/include/machine/signal.h /usr/include/machine/fpu.h \ |
|
29 |
/usr/include/machine/trap.h /usr/include/x86/trap.h \ |
|
30 |
/usr/include/sys/ucontext.h /usr/include/machine/mcontext.h \ |
|
31 |
/usr/include/minix/com.h /usr/include/minix/callnr.h \ |
|
32 |
/usr/include/minix/syslib.h /usr/include/minix/u64.h \ |
|
33 |
/usr/include/minix/devio.h /usr/include/minix/safecopies.h \ |
|
34 |
/usr/include/minix/vm.h /usr/include/minix/endpoint.h \ |
|
35 |
/usr/include/limits.h /usr/include/machine/limits.h \ |
|
36 |
/usr/include/sys/syslimits.h /usr/include/minix/sef.h \ |
|
37 |
/usr/include/minix/sysutil.h /usr/include/string.h \ |
|
38 |
/usr/include/strings.h /usr/include/errno.h /usr/include/sys/errno.h \ |
|
39 |
/usr/include/sys/param.h /usr/include/sys/inttypes.h \ |
|
40 |
/usr/include/machine/int_fmtio.h /usr/include/sys/common_int_fmtio.h \ |
|
41 |
/usr/include/machine/param.h /usr/include/minix/partition.h \ |
|
42 |
/usr/include/sys/mman.h /usr/include/lcom/liblm.h \ |
|
43 |
/usr/include/lcom/lab2.h /usr/include/lcom/timer.h \ |
|
44 |
/usr/include/lcom/utils.h /usr/include/lcom/lab3.h \ |
|
45 |
/usr/include/lcom/types.h kbc.h kbc_func.h |
|
46 |
lab3.d lab3.ln lab3.o: lab3.c /usr/include/lcom/lcf.h /usr/include/stdbool.h \ |
|
47 |
/usr/include/stdio.h /usr/include/sys/cdefs.h \ |
|
48 |
/usr/include/machine/cdefs.h /usr/include/sys/cdefs_elf.h \ |
|
49 |
/usr/include/sys/featuretest.h /usr/include/sys/ansi.h \ |
|
50 |
/usr/include/machine/ansi.h /usr/include/machine/int_types.h \ |
|
51 |
/usr/include/sys/common_int_types.h /usr/include/sys/null.h \ |
|
52 |
/usr/include/stdlib.h /usr/include/sys/types.h \ |
|
53 |
/usr/include/machine/types.h /usr/include/machine/endian.h \ |
|
54 |
/usr/include/sys/endian.h /usr/include/machine/endian_machdep.h \ |
|
55 |
/usr/include/machine/bswap.h /usr/include/machine/byte_swap.h \ |
|
56 |
/usr/include/sys/bswap.h /usr/include/sys/stdint.h \ |
|
57 |
/usr/include/machine/int_mwgwtypes.h \ |
|
58 |
/usr/include/sys/common_int_mwgwtypes.h \ |
|
59 |
/usr/include/machine/int_limits.h /usr/include/sys/common_int_limits.h \ |
|
60 |
/usr/include/machine/int_const.h /usr/include/sys/common_int_const.h \ |
|
61 |
/usr/include/machine/wchar_limits.h /usr/include/sys/fd_set.h \ |
|
62 |
/usr/include/time.h /usr/include/sys/time.h \ |
|
63 |
/usr/include/sys/timespec.h /usr/include/sys/select.h \ |
|
64 |
/usr/include/sys/sigtypes.h /usr/include/unistd.h \ |
|
65 |
/usr/include/sys/unistd.h /usr/include/machine/int86.h \ |
|
66 |
/usr/include/minix/const.h /usr/include/machine/archconst.h \ |
|
67 |
/usr/include/minix/driver.h /usr/include/minix/config.h \ |
|
68 |
/usr/include/minix/sys_config.h /usr/include/minix/type.h \ |
|
69 |
/usr/include/machine/multiboot.h /usr/include/stddef.h \ |
|
70 |
/usr/include/machine/interrupt.h /usr/include/minix/ipc.h \ |
|
71 |
/usr/include/minix/ipcconst.h /usr/include/machine/ipcconst.h \ |
|
72 |
/usr/include/sys/signal.h /usr/include/sys/siginfo.h \ |
|
73 |
/usr/include/machine/signal.h /usr/include/machine/fpu.h \ |
|
74 |
/usr/include/machine/trap.h /usr/include/x86/trap.h \ |
|
75 |
/usr/include/sys/ucontext.h /usr/include/machine/mcontext.h \ |
|
76 |
/usr/include/minix/com.h /usr/include/minix/callnr.h \ |
|
77 |
/usr/include/minix/syslib.h /usr/include/minix/u64.h \ |
|
78 |
/usr/include/minix/devio.h /usr/include/minix/safecopies.h \ |
|
79 |
/usr/include/minix/vm.h /usr/include/minix/endpoint.h \ |
|
80 |
/usr/include/limits.h /usr/include/machine/limits.h \ |
|
81 |
/usr/include/sys/syslimits.h /usr/include/minix/sef.h \ |
|
82 |
/usr/include/minix/sysutil.h /usr/include/string.h \ |
|
83 |
/usr/include/strings.h /usr/include/errno.h /usr/include/sys/errno.h \ |
|
84 |
/usr/include/sys/param.h /usr/include/sys/inttypes.h \ |
|
85 |
/usr/include/machine/int_fmtio.h /usr/include/sys/common_int_fmtio.h \ |
|
86 |
/usr/include/machine/param.h /usr/include/minix/partition.h \ |
|
87 |
/usr/include/sys/mman.h /usr/include/lcom/liblm.h \ |
|
88 |
/usr/include/lcom/lab2.h /usr/include/lcom/timer.h \ |
|
89 |
/usr/include/lcom/utils.h /usr/include/lcom/lab3.h \ |
|
90 |
/usr/include/lcom/types.h kbc.h kbc_func.h |
|
91 |
utils.d utils.ln utils.o: utils.c /usr/include/lcom/lcf.h /usr/include/stdbool.h \ |
|
92 |
/usr/include/stdio.h /usr/include/sys/cdefs.h \ |
|
93 |
/usr/include/machine/cdefs.h /usr/include/sys/cdefs_elf.h \ |
|
94 |
/usr/include/sys/featuretest.h /usr/include/sys/ansi.h \ |
|
95 |
/usr/include/machine/ansi.h /usr/include/machine/int_types.h \ |
|
96 |
/usr/include/sys/common_int_types.h /usr/include/sys/null.h \ |
|
97 |
/usr/include/stdlib.h /usr/include/sys/types.h \ |
|
98 |
/usr/include/machine/types.h /usr/include/machine/endian.h \ |
|
99 |
/usr/include/sys/endian.h /usr/include/machine/endian_machdep.h \ |
|
100 |
/usr/include/machine/bswap.h /usr/include/machine/byte_swap.h \ |
|
101 |
/usr/include/sys/bswap.h /usr/include/sys/stdint.h \ |
|
102 |
/usr/include/machine/int_mwgwtypes.h \ |
|
103 |
/usr/include/sys/common_int_mwgwtypes.h \ |
|
104 |
/usr/include/machine/int_limits.h /usr/include/sys/common_int_limits.h \ |
|
105 |
/usr/include/machine/int_const.h /usr/include/sys/common_int_const.h \ |
|
106 |
/usr/include/machine/wchar_limits.h /usr/include/sys/fd_set.h \ |
|
107 |
/usr/include/time.h /usr/include/sys/time.h \ |
|
108 |
/usr/include/sys/timespec.h /usr/include/sys/select.h \ |
|
109 |
/usr/include/sys/sigtypes.h /usr/include/unistd.h \ |
|
110 |
/usr/include/sys/unistd.h /usr/include/machine/int86.h \ |
|
111 |
/usr/include/minix/const.h /usr/include/machine/archconst.h \ |
|
112 |
/usr/include/minix/driver.h /usr/include/minix/config.h \ |
|
113 |
/usr/include/minix/sys_config.h /usr/include/minix/type.h \ |
|
114 |
/usr/include/machine/multiboot.h /usr/include/stddef.h \ |
|
115 |
/usr/include/machine/interrupt.h /usr/include/minix/ipc.h \ |
|
116 |
/usr/include/minix/ipcconst.h /usr/include/machine/ipcconst.h \ |
|
117 |
/usr/include/sys/signal.h /usr/include/sys/siginfo.h \ |
|
118 |
/usr/include/machine/signal.h /usr/include/machine/fpu.h \ |
|
119 |
/usr/include/machine/trap.h /usr/include/x86/trap.h \ |
|
120 |
/usr/include/sys/ucontext.h /usr/include/machine/mcontext.h \ |
|
121 |
/usr/include/minix/com.h /usr/include/minix/callnr.h \ |
|
122 |
/usr/include/minix/syslib.h /usr/include/minix/u64.h \ |
|
123 |
/usr/include/minix/devio.h /usr/include/minix/safecopies.h \ |
|
124 |
/usr/include/minix/vm.h /usr/include/minix/endpoint.h \ |
|
125 |
/usr/include/limits.h /usr/include/machine/limits.h \ |
|
126 |
/usr/include/sys/syslimits.h /usr/include/minix/sef.h \ |
|
127 |
/usr/include/minix/sysutil.h /usr/include/string.h \ |
|
128 |
/usr/include/strings.h /usr/include/errno.h /usr/include/sys/errno.h \ |
|
129 |
/usr/include/sys/param.h /usr/include/sys/inttypes.h \ |
|
130 |
/usr/include/machine/int_fmtio.h /usr/include/sys/common_int_fmtio.h \ |
|
131 |
/usr/include/machine/param.h /usr/include/minix/partition.h \ |
|
132 |
/usr/include/sys/mman.h /usr/include/lcom/liblm.h \ |
|
133 |
/usr/include/lcom/lab2.h /usr/include/lcom/timer.h \ |
|
134 |
/usr/include/lcom/utils.h /usr/include/lcom/lab3.h \ |
|
135 |
/usr/include/lcom/types.h |
|
0 | 136 |
lab3/Makefile | ||
---|---|---|
1 |
# name of the program (Minix service) |
|
2 |
PROG=lab3 |
|
3 |
|
|
4 |
# source code files to be compiled |
|
5 |
SRCS = lab3.c kbc.c utils.c |
|
6 |
|
|
7 |
# additional compilation flags |
|
8 |
# "-Wall -Wextra -Werror -I . -std=c11 -Wno-unused-parameter" are already set |
|
9 |
CFLAGS += -pedantic |
|
10 |
CPPFLAGS += -D LAB3 |
|
11 |
|
|
12 |
# list of library dependencies (for Lab 2, only LCF library) |
|
13 |
DPADD += ${LIBLCF} |
|
14 |
LDADD += -llcf |
|
15 |
|
|
16 |
# include LCOM's makefile that does all the "heavy lifting" |
|
17 |
.include <minix.lcom.mk> |
|
0 | 18 |
lab3/kbc.c | ||
---|---|---|
1 |
#include <lcom/lcf.h> |
|
2 |
|
|
3 |
#include "kbc.h" |
|
4 |
#include "kbc_func.h" |
|
5 |
|
|
6 |
int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id) { |
|
7 |
if (interrupt_id == NULL) return 1; |
|
8 |
*interrupt_id = interrupt_bit; |
|
9 |
return (sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id)); |
|
10 |
} |
|
11 |
|
|
12 |
int (unsubscribe_kbc_interrupt)(int *interrupt_id) { |
|
13 |
if (interrupt_id == NULL) return 1; |
|
14 |
return sys_irqrmpolicy(interrupt_id); |
|
15 |
} |
|
16 |
|
|
17 |
uint8_t scancode[2]; |
|
18 |
int two_byte_scancode = 0; |
|
19 |
|
|
20 |
void (kbc_ih)(void) { |
|
21 |
uint8_t status = 0; |
|
22 |
|
|
23 |
#ifdef LAB3 |
|
24 |
sys_inb_counter(INCREMENT); |
|
25 |
#endif |
|
26 |
|
|
27 |
if (util_sys_inb(STATUS_REG, &status)) return; |
|
28 |
|
|
29 |
if (status & (TIME_OUT_REC | PARITY_ERROR)) return; |
|
30 |
|
|
31 |
#ifdef LAB3 |
|
32 |
sys_inb_counter(INCREMENT); |
|
33 |
#endif |
|
34 |
|
|
35 |
uint8_t byte = 0; |
|
36 |
|
|
37 |
if (util_sys_inb(OUTPUT_BUF, &byte)) return; |
|
38 |
|
|
39 |
if (two_byte_scancode) { |
|
40 |
scancode[1] = byte; |
|
41 |
two_byte_scancode = 0; |
|
42 |
} else { |
|
43 |
scancode[0] = byte; |
|
44 |
two_byte_scancode = (byte == TWO_BYTE_CODE); |
|
45 |
} |
|
46 |
|
|
47 |
} |
|
48 |
|
|
49 |
uint32_t sys_inb_counter(int increment) { |
|
50 |
static uint32_t counter = 0; |
|
51 |
if (increment) return ++counter; |
|
52 |
return counter; |
|
53 |
} |
|
0 | 54 |
lab3/kbc.d | ||
---|---|---|
1 |
kbc.o: kbc.c /usr/include/lcom/lcf.h /usr/include/stdbool.h \ |
|
2 |
/usr/include/stdio.h /usr/include/sys/cdefs.h \ |
|
3 |
/usr/include/machine/cdefs.h /usr/include/sys/cdefs_elf.h \ |
|
4 |
/usr/include/sys/featuretest.h /usr/include/sys/ansi.h \ |
|
5 |
/usr/include/machine/ansi.h /usr/include/machine/int_types.h \ |
|
6 |
/usr/include/sys/common_int_types.h /usr/include/sys/null.h \ |
|
7 |
/usr/include/stdlib.h /usr/include/sys/types.h \ |
|
8 |
/usr/include/machine/types.h /usr/include/machine/endian.h \ |
|
9 |
/usr/include/sys/endian.h /usr/include/machine/endian_machdep.h \ |
|
10 |
/usr/include/machine/bswap.h /usr/include/machine/byte_swap.h \ |
|
11 |
/usr/include/sys/bswap.h /usr/include/sys/stdint.h \ |
|
12 |
/usr/include/machine/int_mwgwtypes.h \ |
|
13 |
/usr/include/sys/common_int_mwgwtypes.h \ |
|
14 |
/usr/include/machine/int_limits.h /usr/include/sys/common_int_limits.h \ |
|
15 |
/usr/include/machine/int_const.h /usr/include/sys/common_int_const.h \ |
|
16 |
/usr/include/machine/wchar_limits.h /usr/include/sys/fd_set.h \ |
|
17 |
/usr/include/time.h /usr/include/sys/time.h \ |
|
18 |
/usr/include/sys/timespec.h /usr/include/sys/select.h \ |
|
19 |
/usr/include/sys/sigtypes.h /usr/include/unistd.h \ |
|
20 |
/usr/include/sys/unistd.h /usr/include/machine/int86.h \ |
|
21 |
/usr/include/minix/const.h /usr/include/machine/archconst.h \ |
|
22 |
/usr/include/minix/driver.h /usr/include/minix/config.h \ |
|
23 |
/usr/include/minix/sys_config.h /usr/include/minix/type.h \ |
|
24 |
/usr/include/machine/multiboot.h /usr/include/stddef.h \ |
|
25 |
/usr/include/machine/interrupt.h /usr/include/minix/ipc.h \ |
|
26 |
/usr/include/minix/ipcconst.h /usr/include/machine/ipcconst.h \ |
|
27 |
/usr/include/sys/signal.h /usr/include/sys/siginfo.h \ |
|
28 |
/usr/include/machine/signal.h /usr/include/machine/fpu.h \ |
|
29 |
/usr/include/machine/trap.h /usr/include/x86/trap.h \ |
|
30 |
/usr/include/sys/ucontext.h /usr/include/machine/mcontext.h \ |
|
31 |
/usr/include/minix/com.h /usr/include/minix/callnr.h \ |
|
32 |
/usr/include/minix/syslib.h /usr/include/minix/u64.h \ |
|
33 |
/usr/include/minix/devio.h /usr/include/minix/safecopies.h \ |
|
34 |
/usr/include/minix/vm.h /usr/include/minix/endpoint.h \ |
|
35 |
/usr/include/limits.h /usr/include/machine/limits.h \ |
|
36 |
/usr/include/sys/syslimits.h /usr/include/minix/sef.h \ |
|
37 |
/usr/include/minix/sysutil.h /usr/include/string.h \ |
|
38 |
/usr/include/strings.h /usr/include/errno.h /usr/include/sys/errno.h \ |
|
39 |
/usr/include/sys/param.h /usr/include/sys/inttypes.h \ |
|
40 |
/usr/include/machine/int_fmtio.h /usr/include/sys/common_int_fmtio.h \ |
|
41 |
/usr/include/machine/param.h /usr/include/minix/partition.h \ |
|
42 |
/usr/include/sys/mman.h /usr/include/lcom/liblm.h \ |
|
43 |
/usr/include/lcom/lab2.h /usr/include/lcom/timer.h \ |
|
44 |
/usr/include/lcom/utils.h /usr/include/lcom/lab3.h \ |
|
45 |
/usr/include/lcom/types.h kbc.h kbc_func.h |
|
0 | 46 |
lab3/kbc.h | ||
---|---|---|
1 |
#ifndef _KBC_H_ |
|
2 |
#define _KBC_H_ |
|
3 |
|
|
4 |
/* KBC IRQ Line */ |
|
5 |
|
|
6 |
#define KBC_IRQ 1 /* @brief KBC Controller IRQ Line */ |
|
7 |
|
|
8 |
/* I/O Ports Addresses */ |
|
9 |
|
|
10 |
#define KBC_CMD 0x64 /* @brief Address to send commands to KBC */ |
|
11 |
#define KBC_CMD_ARG 0x60 /* @brief Address to write KBC Command Arguments */ |
|
12 |
#define STATUS_REG 0x64 /* @brief KBC Status Register address */ |
|
13 |
|
|
14 |
#define OUTPUT_BUF 0x60 /* @brief Address of Output Buffer of KBC */ |
|
15 |
|
|
16 |
/* KBC Commands */ |
|
17 |
#define READ_KBC_CMD 0x20 /* @brief Read KBC Command Byte */ |
|
18 |
#define WRITE_KBC_CMD 0x60 /* @brief Write KBC Command Byte */ |
|
19 |
#define KBC_SELF_TEST 0xAA /* @brief KBC Diagnostic Tests */ |
|
20 |
#define KBC_INT_TEST 0xAB /* @brief Tests Keyboard Clock and Data lines */ |
|
21 |
#define KBC_INT_DISABLE 0xAD /* @brief Disable KBC Interface */ |
|
22 |
#define KBC_INT_ENABLE 0xAE /* @brief Enable KBC Interface */ |
|
23 |
|
|
24 |
/* Status Byte Masking */ |
|
25 |
|
|
26 |
#define OUT_BUF_FUL BIT(0) /* @brief Output Buffer State */ |
|
27 |
#define IN_BUF_FULL BIT(1) /* @brief Input Buffer State */ |
|
28 |
#define SYS_FLAG BIT(2) /* @brief System Flag */ |
|
29 |
#define DATA_CMD_WRITE BIT(3) /* @brief Identifier of type of byte in input buffer */ |
|
30 |
#define INH_FLAG BIT(4) /* @brief Keyboard inihibited */ |
|
31 |
#define AUX_MOUSE BIT(5) /* @brief Mouse Data */ |
|
32 |
#define TIME_OUT_REC BIT(6) /* @brief Time Out Error - Invalid Data */ |
|
33 |
#define PARITY_ERROR BIT(7) /* @brief Parity Error - Invalid Data */ |
|
34 |
|
|
35 |
/* Scancode Constants */ |
|
36 |
|
|
37 |
#define ESC_BREAK_CODE 0x81 /* @brief ESC Break Code */ |
|
38 |
#define TWO_BYTE_CODE 0xE0 /* @brief First byte of a two byte Scancode */ |
|
39 |
#define BREAK_CODE_BIT BIT(7) /* @brief Bit to distinguish between Make code and Break code */ |
|
40 |
|
|
41 |
#endif |
|
0 | 42 |
lab3/kbc_func.h | ||
---|---|---|
1 |
#ifndef _KBC_FUNC_H_ |
|
2 |
#define _KBC_FUNC_H_ |
|
3 |
|
|
4 |
#include <stdint.h> |
|
5 |
|
|
6 |
#define GET 0 /* @brief Argument to get counter without incrementing */ |
|
7 |
#define INCREMENT 1 /* @brief Argument for incrementing counter */ |
|
8 |
|
|
9 |
/** |
|
10 |
* @brief Subscribes KBC Interrupts and disables Minix Default Keyboard IH |
|
11 |
* @param interrupt_bit Bit of Interrupt Vector that will be set when KBC Interrupt is pending |
|
12 |
* @param interrupt_id KBC Interrupt ID to specify the KBC Interrupt in other calls |
|
13 |
* @return Whether operation was sucessful or not |
|
14 |
*/ |
|
15 |
int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id); |
|
16 |
|
|
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 |
|
21 |
* @return Whether operation was sucessful or not |
|
22 |
*/ |
|
23 |
int (unsubscribe_kbc_interrupt)(int *interrupt_id); |
|
24 |
|
|
25 |
/** |
|
26 |
* @brief KBC Interrupt Handler |
|
27 |
*/ |
|
28 |
void (kbc_ih)(void); |
|
29 |
|
|
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 |
#endif |
|
0 | 38 |
lab3/lab3.c | ||
---|---|---|
1 |
#include <lcom/lcf.h> |
|
2 |
|
|
3 |
#include <lcom/lab3.h> |
|
4 |
|
|
5 |
#include <stdbool.h> |
|
6 |
#include <stdint.h> |
|
7 |
|
|
8 |
#include "kbc.h" |
|
9 |
#include "kbc_func.h" |
|
10 |
|
|
11 |
int main(int argc, char *argv[]) { |
|
12 |
// sets the language of LCF messages (can be either EN-US or PT-PT) |
|
13 |
lcf_set_language("EN-US"); |
|
14 |
|
|
15 |
// enables to log function invocations that are being "wrapped" by LCF |
|
16 |
// [comment this out if you don't want/need it] |
|
17 |
lcf_trace_calls("/home/lcom/labs/lab3/trace.txt"); |
|
18 |
|
|
19 |
// enables to save the output of printf function calls on a file |
|
20 |
// [comment this out if you don't want/need it] |
|
21 |
lcf_log_output("/home/lcom/labs/lab3/output.txt"); |
|
22 |
|
|
23 |
// handles control over to LCF |
|
24 |
// [LCF handles command line arguments and invokes the right function] |
|
25 |
if (lcf_start(argc, argv)) |
|
26 |
return 1; |
|
27 |
|
|
28 |
// LCF clean up tasks |
|
29 |
// [must be the last statement before return] |
|
30 |
lcf_cleanup(); |
|
31 |
|
|
32 |
return 0; |
|
33 |
} |
|
34 |
|
|
35 |
extern uint8_t scancode[2]; |
|
36 |
extern int two_byte_scancode; |
|
37 |
|
|
38 |
int(kbd_test_scan)() { |
|
39 |
|
|
40 |
int ipc_status, r; |
|
41 |
message msg; |
|
42 |
|
|
43 |
uint8_t kbc_irq_bit = BIT(1); |
|
44 |
int kbc_id = 0; |
|
45 |
|
|
46 |
int got_esc_breakcode = 0; |
|
47 |
|
|
48 |
if (subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) return 1; |
|
49 |
|
|
50 |
while (!got_esc_breakcode) { |
|
51 |
/* Get a request message. */ |
|
52 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
|
53 |
printf("driver_receive failed with %d", r); |
|
54 |
continue; |
|
55 |
} |
|
56 |
if (is_ipc_notify(ipc_status)) { /* received notification */ |
|
57 |
switch (_ENDPOINT_P(msg.m_source)) { |
|
58 |
case HARDWARE: /* hardware interrupt notification */ |
|
59 |
if (msg.m_notify.interrupts & kbc_irq_bit) { /* subscribed interrupt */ |
|
60 |
|
|
61 |
kbc_ih(); |
|
62 |
|
|
63 |
if (!two_byte_scancode) { /* finished processing a scancode */ |
|
64 |
if (scancode[0] == TWO_BYTE_CODE) |
|
65 |
kbd_print_scancode(!(scancode[1] & BREAK_CODE_BIT), 2, scancode); |
|
66 |
else |
|
67 |
kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode); |
|
68 |
} |
|
69 |
|
|
70 |
if (scancode[0] == ESC_BREAK_CODE) |
|
71 |
got_esc_breakcode = 1; |
|
72 |
|
|
73 |
} |
|
74 |
break; |
|
75 |
default: |
|
76 |
break; /* no other notifications expected: do nothing */ |
|
77 |
} |
|
78 |
} else { /* received standart message, not a notification */ |
|
79 |
/* no standart message expected: do nothing */ |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
if (unsubscribe_kbc_interrupt(&kbc_id)) return 1; |
|
84 |
|
|
85 |
if (kbd_print_no_sysinb(sys_inb_counter(GET))) return 1; |
|
86 |
|
|
87 |
return 0; |
|
88 |
} |
|
89 |
|
|
90 |
int(kbd_test_poll)() { |
|
91 |
/* To be completed by the students */ |
|
92 |
printf("%s is not yet implemented!\n", __func__); |
|
93 |
|
|
94 |
return 1; |
|
95 |
} |
|
96 |
|
|
97 |
int(kbd_test_timed_scan)(uint8_t n) { |
|
98 |
/* To be completed by the students */ |
|
99 |
printf("%s is not yet implemented!\n", __func__); |
|
100 |
|
|
101 |
return 1; |
|
102 |
} |
|
0 | 103 |
lab3/lab3.d | ||
---|---|---|
1 |
lab3.o: lab3.c /usr/include/lcom/lcf.h /usr/include/stdbool.h \ |
|
2 |
/usr/include/stdio.h /usr/include/sys/cdefs.h \ |
|
3 |
/usr/include/machine/cdefs.h /usr/include/sys/cdefs_elf.h \ |
|
4 |
/usr/include/sys/featuretest.h /usr/include/sys/ansi.h \ |
|
5 |
/usr/include/machine/ansi.h /usr/include/machine/int_types.h \ |
|
6 |
/usr/include/sys/common_int_types.h /usr/include/sys/null.h \ |
|
7 |
/usr/include/stdlib.h /usr/include/sys/types.h \ |
|
8 |
/usr/include/machine/types.h /usr/include/machine/endian.h \ |
|
9 |
/usr/include/sys/endian.h /usr/include/machine/endian_machdep.h \ |
|
10 |
/usr/include/machine/bswap.h /usr/include/machine/byte_swap.h \ |
|
11 |
/usr/include/sys/bswap.h /usr/include/sys/stdint.h \ |
|
12 |
/usr/include/machine/int_mwgwtypes.h \ |
|
13 |
/usr/include/sys/common_int_mwgwtypes.h \ |
|
14 |
/usr/include/machine/int_limits.h /usr/include/sys/common_int_limits.h \ |
|
15 |
/usr/include/machine/int_const.h /usr/include/sys/common_int_const.h \ |
|
16 |
/usr/include/machine/wchar_limits.h /usr/include/sys/fd_set.h \ |
|
17 |
/usr/include/time.h /usr/include/sys/time.h \ |
|
18 |
/usr/include/sys/timespec.h /usr/include/sys/select.h \ |
|
19 |
/usr/include/sys/sigtypes.h /usr/include/unistd.h \ |
|
20 |
/usr/include/sys/unistd.h /usr/include/machine/int86.h \ |
|
21 |
/usr/include/minix/const.h /usr/include/machine/archconst.h \ |
|
22 |
/usr/include/minix/driver.h /usr/include/minix/config.h \ |
|
23 |
/usr/include/minix/sys_config.h /usr/include/minix/type.h \ |
|
24 |
/usr/include/machine/multiboot.h /usr/include/stddef.h \ |
|
25 |
/usr/include/machine/interrupt.h /usr/include/minix/ipc.h \ |
|
26 |
/usr/include/minix/ipcconst.h /usr/include/machine/ipcconst.h \ |
|
27 |
/usr/include/sys/signal.h /usr/include/sys/siginfo.h \ |
|
28 |
/usr/include/machine/signal.h /usr/include/machine/fpu.h \ |
|
29 |
/usr/include/machine/trap.h /usr/include/x86/trap.h \ |
|
30 |
/usr/include/sys/ucontext.h /usr/include/machine/mcontext.h \ |
|
31 |
/usr/include/minix/com.h /usr/include/minix/callnr.h \ |
|
32 |
/usr/include/minix/syslib.h /usr/include/minix/u64.h \ |
|
33 |
/usr/include/minix/devio.h /usr/include/minix/safecopies.h \ |
|
34 |
/usr/include/minix/vm.h /usr/include/minix/endpoint.h \ |
|
35 |
/usr/include/limits.h /usr/include/machine/limits.h \ |
|
36 |
/usr/include/sys/syslimits.h /usr/include/minix/sef.h \ |
|
37 |
/usr/include/minix/sysutil.h /usr/include/string.h \ |
|
38 |
/usr/include/strings.h /usr/include/errno.h /usr/include/sys/errno.h \ |
|
39 |
/usr/include/sys/param.h /usr/include/sys/inttypes.h \ |
|
40 |
/usr/include/machine/int_fmtio.h /usr/include/sys/common_int_fmtio.h \ |
|
41 |
/usr/include/machine/param.h /usr/include/minix/partition.h \ |
|
42 |
/usr/include/sys/mman.h /usr/include/lcom/liblm.h \ |
|
43 |
/usr/include/lcom/lab2.h /usr/include/lcom/timer.h \ |
|
44 |
/usr/include/lcom/utils.h /usr/include/lcom/lab3.h \ |
|
45 |
/usr/include/lcom/types.h kbc.h kbc_func.h |
|
0 | 46 |
lab3/utils.c | ||
---|---|---|
1 |
#include <lcom/lcf.h> |
|
2 |
|
|
3 |
#include <stdint.h> |
|
4 |
|
|
5 |
int (util_sys_inb)(int port, uint8_t *value) { |
|
6 |
if(value == NULL) return 1; |
|
7 |
uint32_t n = 0; |
|
8 |
if(sys_inb(port, &n)) return 1; |
|
9 |
*value = n; |
|
10 |
return 0; |
|
11 |
} |
|
0 | 12 |
lab3/utils.d | ||
---|---|---|
1 |
utils.o: utils.c /usr/include/lcom/lcf.h /usr/include/stdbool.h \ |
|
2 |
/usr/include/stdio.h /usr/include/sys/cdefs.h \ |
|
3 |
/usr/include/machine/cdefs.h /usr/include/sys/cdefs_elf.h \ |
|
4 |
/usr/include/sys/featuretest.h /usr/include/sys/ansi.h \ |
|
5 |
/usr/include/machine/ansi.h /usr/include/machine/int_types.h \ |
|
6 |
/usr/include/sys/common_int_types.h /usr/include/sys/null.h \ |
|
7 |
/usr/include/stdlib.h /usr/include/sys/types.h \ |
|
8 |
/usr/include/machine/types.h /usr/include/machine/endian.h \ |
|
9 |
/usr/include/sys/endian.h /usr/include/machine/endian_machdep.h \ |
|
10 |
/usr/include/machine/bswap.h /usr/include/machine/byte_swap.h \ |
|
11 |
/usr/include/sys/bswap.h /usr/include/sys/stdint.h \ |
|
12 |
/usr/include/machine/int_mwgwtypes.h \ |
|
13 |
/usr/include/sys/common_int_mwgwtypes.h \ |
|
14 |
/usr/include/machine/int_limits.h /usr/include/sys/common_int_limits.h \ |
|
15 |
/usr/include/machine/int_const.h /usr/include/sys/common_int_const.h \ |
|
16 |
/usr/include/machine/wchar_limits.h /usr/include/sys/fd_set.h \ |
|
17 |
/usr/include/time.h /usr/include/sys/time.h \ |
|
18 |
/usr/include/sys/timespec.h /usr/include/sys/select.h \ |
|
19 |
/usr/include/sys/sigtypes.h /usr/include/unistd.h \ |
|
20 |
/usr/include/sys/unistd.h /usr/include/machine/int86.h \ |
|
21 |
/usr/include/minix/const.h /usr/include/machine/archconst.h \ |
|
22 |
/usr/include/minix/driver.h /usr/include/minix/config.h \ |
|
23 |
/usr/include/minix/sys_config.h /usr/include/minix/type.h \ |
|
24 |
/usr/include/machine/multiboot.h /usr/include/stddef.h \ |
|
25 |
/usr/include/machine/interrupt.h /usr/include/minix/ipc.h \ |
|
26 |
/usr/include/minix/ipcconst.h /usr/include/machine/ipcconst.h \ |
|
27 |
/usr/include/sys/signal.h /usr/include/sys/siginfo.h \ |
|
28 |
/usr/include/machine/signal.h /usr/include/machine/fpu.h \ |
|
29 |
/usr/include/machine/trap.h /usr/include/x86/trap.h \ |
|
30 |
/usr/include/sys/ucontext.h /usr/include/machine/mcontext.h \ |
|
31 |
/usr/include/minix/com.h /usr/include/minix/callnr.h \ |
|
32 |
/usr/include/minix/syslib.h /usr/include/minix/u64.h \ |
|
33 |
/usr/include/minix/devio.h /usr/include/minix/safecopies.h \ |
|
34 |
/usr/include/minix/vm.h /usr/include/minix/endpoint.h \ |
|
35 |
/usr/include/limits.h /usr/include/machine/limits.h \ |
|
36 |
/usr/include/sys/syslimits.h /usr/include/minix/sef.h \ |
|
37 |
/usr/include/minix/sysutil.h /usr/include/string.h \ |
|
38 |
/usr/include/strings.h /usr/include/errno.h /usr/include/sys/errno.h \ |
|
39 |
/usr/include/sys/param.h /usr/include/sys/inttypes.h \ |
|
40 |
/usr/include/machine/int_fmtio.h /usr/include/sys/common_int_fmtio.h \ |
|
41 |
/usr/include/machine/param.h /usr/include/minix/partition.h \ |
|
42 |
/usr/include/sys/mman.h /usr/include/lcom/liblm.h \ |
|
43 |
/usr/include/lcom/lab2.h /usr/include/lcom/timer.h \ |
|
44 |
/usr/include/lcom/utils.h /usr/include/lcom/lab3.h \ |
|
45 |
/usr/include/lcom/types.h |
|
0 | 46 |
lab3/utils.h | ||
---|---|---|
1 |
#ifndef _UTILS_H_ |
|
2 |
#define _UTILS_H_ |
|
3 |
|
|
4 |
/** |
|
5 |
* @brief Reads byte from port |
|
6 |
* @param port Adress Port to read from |
|
7 |
* @param value Address to be stored the value read |
|
8 |
* @return Whether operation was sucessful or not |
|
9 |
*/ |
|
10 |
int (util_sys_inb)(int port, uint8_t *value); |
|
11 |
|
|
12 |
#endif |
|
0 | 13 |
Also available in: Unified diff