root / proj / src / interrupts_func.c @ 271
History | View | Annotate | Download (6.26 KB)
1 |
#include <lcom/lcf.h> |
---|---|
2 |
|
3 |
#include "interrupts_func.h" |
4 |
#include "timer.h" |
5 |
#include "i8254.h" |
6 |
#include "keyboard.h" |
7 |
#include "mouse.h" |
8 |
#include "uart.h" |
9 |
#include "utils.h" |
10 |
#include "errors.h" |
11 |
|
12 |
static int timer_subscribed = 0, timer_id; |
13 |
|
14 |
static int keyboard_subscribed = 0, kbc_id; |
15 |
|
16 |
static int mouse_subscribed = 0, mouse_id; |
17 |
|
18 |
static int uart_subscribed = 0, uart_id; |
19 |
|
20 |
static void (*const ih[])(void) = { timer_int_handler, |
21 |
kbc_ih, |
22 |
NULL,
|
23 |
NULL,
|
24 |
NULL,
|
25 |
NULL,
|
26 |
NULL,
|
27 |
NULL,
|
28 |
NULL,
|
29 |
NULL,
|
30 |
NULL,
|
31 |
NULL,
|
32 |
mouse_ih, |
33 |
NULL,
|
34 |
NULL,
|
35 |
NULL,
|
36 |
NULL,
|
37 |
NULL,
|
38 |
NULL,
|
39 |
NULL,
|
40 |
NULL,
|
41 |
NULL,
|
42 |
NULL,
|
43 |
NULL,
|
44 |
NULL,
|
45 |
NULL,
|
46 |
NULL,
|
47 |
NULL,
|
48 |
NULL,
|
49 |
NULL,
|
50 |
NULL,
|
51 |
NULL,
|
52 |
}; |
53 |
|
54 |
int (subscribe_all)(void) { |
55 |
|
56 |
/// Timer interrupt handling
|
57 |
timer_id = 0;
|
58 |
if(subscribe_timer_interrupt(TIMER0_IRQ, &timer_id)) {
|
59 |
printf("%s: failed to subscribe timer interrupts.\n", __func__);
|
60 |
return SBCR_ERROR;
|
61 |
} |
62 |
timer_subscribed = 1;
|
63 |
|
64 |
/// Keyboard interrupt handling
|
65 |
kbc_id = 0;
|
66 |
if (subscribe_kbc_interrupt(KBC_IRQ, &kbc_id)) {
|
67 |
printf("%s: failed to subscribe keyboard interrupts.\n", __func__);
|
68 |
if (unsubscribe_all())
|
69 |
printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
|
70 |
return SBCR_ERROR;
|
71 |
} |
72 |
keyboard_subscribed = 1;
|
73 |
|
74 |
/// Mouse interrupt handling
|
75 |
mouse_id = 0;
|
76 |
if (subscribe_mouse_interrupt(MOUSE_IRQ, &mouse_id)) { // subscribes mouse interrupts in exclusive mode |
77 |
printf("%s: failed to subscribe mouse interrupts.\n", __func__);
|
78 |
if (unsubscribe_all())
|
79 |
printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
|
80 |
return SBCR_ERROR;
|
81 |
} |
82 |
mouse_subscribed = 1;
|
83 |
if (sys_irqdisable(&mouse_id)) { // temporarily disables our interrupts notifications |
84 |
printf("%s: failed to disable mouse interrupts.\n", __func__);
|
85 |
if (unsubscribe_all())
|
86 |
printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
|
87 |
return SBCR_ERROR;
|
88 |
} |
89 |
if (mouse_set_data_report(true)) { // enables mouse data reporting |
90 |
printf("%s: failed to enable mouse data reporting.\n", __func__);
|
91 |
if (unsubscribe_all())
|
92 |
printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
|
93 |
return SBCR_ERROR;
|
94 |
} |
95 |
if (sys_irqenable(&mouse_id)) { // re-enables our interrupts notifications |
96 |
printf("%s: failed to enable mouse interrupts.\n", __func__);
|
97 |
if (unsubscribe_all())
|
98 |
printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
|
99 |
return SBCR_ERROR;
|
100 |
} |
101 |
|
102 |
/// UART interrupt handling
|
103 |
uart_id = 0;
|
104 |
uart_enable_int_rx (COM1_ADDR); |
105 |
uart_disable_int_tx(COM1_ADDR); |
106 |
if(subscribe_uart_interrupt(COM1_IRQ, &uart_id)) {
|
107 |
printf("%s: failed to subscribe UART interrupts.\n", __func__);
|
108 |
return SBCR_ERROR;
|
109 |
} |
110 |
uart_subscribed = 1;
|
111 |
|
112 |
return SUCCESS;
|
113 |
} |
114 |
|
115 |
int (unsubscribe_all)(void) { |
116 |
int r = SUCCESS;
|
117 |
|
118 |
// Unsubscribe Timer Interrupts
|
119 |
if (timer_subscribed) {
|
120 |
if (unsubscribe_interrupt(&timer_id)) {
|
121 |
printf("%s: failed to unsubcribe timer interrupts.\n");
|
122 |
r = UNSBCR_ERROR; |
123 |
} |
124 |
timer_subscribed = 0;
|
125 |
} |
126 |
|
127 |
// Unsubscribe Keyboard interrupts
|
128 |
if (keyboard_subscribed) {
|
129 |
if (unsubscribe_interrupt(&kbc_id)) {
|
130 |
printf("%s: failed to unsubcribe keyboard interrupts.\n");
|
131 |
r = UNSBCR_ERROR; |
132 |
} |
133 |
keyboard_subscribed = 0;
|
134 |
} |
135 |
|
136 |
// Unsubscribe Mouse Interrupts
|
137 |
if (mouse_subscribed) {
|
138 |
if (sys_irqdisable(&mouse_id)) { // temporarily disables our interrupts notifications |
139 |
printf("%s: failed to disable mouse interrupts.\n");
|
140 |
r = UNSBCR_ERROR; |
141 |
} |
142 |
if (mouse_set_data_report(false)) { // disables mouse data reporting |
143 |
printf("%s: failed to disable mouse data reporting.\n");
|
144 |
r = UNSBCR_ERROR; |
145 |
} |
146 |
if (sys_irqenable(&mouse_id)) { // re-enables our interrupts notifications |
147 |
printf("%s: failed to enable mouse interrupts.\n");
|
148 |
r = UNSBCR_ERROR; |
149 |
} |
150 |
if (unsubscribe_interrupt(&mouse_id)) { // unsubscribes interrupts |
151 |
printf("%s: failed to unsubcribe mouse interrupts.\n");
|
152 |
r = UNSBCR_ERROR; |
153 |
} |
154 |
mouse_subscribed = 0;
|
155 |
} |
156 |
|
157 |
// Unsubscribe UART interrupts
|
158 |
if (uart_subscribed) {
|
159 |
if (unsubscribe_interrupt(&uart_id)) {
|
160 |
printf("%s: failed to unsubcribe UART interrupts.\n");
|
161 |
r = UNSBCR_ERROR; |
162 |
} |
163 |
uart_enable_int_rx(COM1_ADDR); |
164 |
uart_enable_int_tx(COM1_ADDR); |
165 |
uart_subscribed = 0;
|
166 |
} |
167 |
|
168 |
return r;
|
169 |
} |
170 |
|
171 |
void (interrupt_handler)(uint8_t handler) {
|
172 |
if (handler >= 32) return; |
173 |
if ((*ih[handler]) == NULL) return; |
174 |
(*ih[handler])(); |
175 |
} |
176 |
|
177 |
void (timer_manager)() {
|
178 |
|
179 |
} |
180 |
|
181 |
void (mouse_manager)() {
|
182 |
|
183 |
} |