root / proj / src / interrupts_func.c @ 260
History | View | Annotate | Download (5.56 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 "utils.h" |
9 |
#include "errors.h" |
10 |
|
11 |
static int timer_subscribed = 0, timer_id; |
12 |
|
13 |
static int keyboard_subscribed = 0, kbc_id; |
14 |
|
15 |
static int mouse_subscribed = 0, mouse_id; |
16 |
|
17 |
static void (*const ih[])(void) = { timer_int_handler, |
18 |
kbc_ih, |
19 |
NULL,
|
20 |
NULL,
|
21 |
NULL,
|
22 |
NULL,
|
23 |
NULL,
|
24 |
NULL,
|
25 |
NULL,
|
26 |
NULL,
|
27 |
NULL,
|
28 |
NULL,
|
29 |
mouse_ih, |
30 |
NULL,
|
31 |
NULL,
|
32 |
NULL,
|
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 |
}; |
50 |
|
51 |
int (subscribe_all)(void) { |
52 |
|
53 |
/// Timer interrupt handling
|
54 |
timer_id = 0;
|
55 |
if(subscribe_timer_interrupt(TIMER0_IRQ, &timer_id)) {
|
56 |
printf("%s: failed to subscribe timer interrupts.\n", __func__);
|
57 |
return SBCR_ERROR;
|
58 |
} |
59 |
timer_subscribed = 1;
|
60 |
|
61 |
/// Keyboard interrupt handling
|
62 |
kbc_id = 0;
|
63 |
if (subscribe_kbc_interrupt(KBC_IRQ, &kbc_id)) {
|
64 |
printf("%s: failed to subscribe keyboard interrupts.\n", __func__);
|
65 |
if (unsubscribe_all())
|
66 |
printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
|
67 |
return SBCR_ERROR;
|
68 |
} |
69 |
keyboard_subscribed = 1;
|
70 |
|
71 |
/// Mouse interrupt handling
|
72 |
mouse_id = 0;
|
73 |
if (subscribe_mouse_interrupt(MOUSE_IRQ, &mouse_id)) { // subscribes mouse interrupts in exclusive mode |
74 |
printf("%s: failed to subscribe mouse interrupts.\n", __func__);
|
75 |
if (unsubscribe_all())
|
76 |
printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
|
77 |
return SBCR_ERROR;
|
78 |
} |
79 |
mouse_subscribed = 1;
|
80 |
if (sys_irqdisable(&mouse_id)) { // temporarily disables our interrupts notifications |
81 |
printf("%s: failed to disable mouse interrupts.\n", __func__);
|
82 |
if (unsubscribe_all())
|
83 |
printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
|
84 |
return SBCR_ERROR;
|
85 |
} |
86 |
if (mouse_set_data_report(true)) { // enables mouse data reporting |
87 |
printf("%s: failed to enable mouse data reporting.\n", __func__);
|
88 |
if (unsubscribe_all())
|
89 |
printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
|
90 |
return SBCR_ERROR;
|
91 |
} |
92 |
if (sys_irqenable(&mouse_id)) { // re-enables our interrupts notifications |
93 |
printf("%s: failed to enable mouse interrupts.\n", __func__);
|
94 |
if (unsubscribe_all())
|
95 |
printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
|
96 |
return SBCR_ERROR;
|
97 |
} |
98 |
|
99 |
return SUCCESS;
|
100 |
} |
101 |
|
102 |
int (unsubscribe_all)(void) { |
103 |
int r = SUCCESS;
|
104 |
|
105 |
// Unsubscribe Timer Interrupts
|
106 |
if (timer_subscribed) {
|
107 |
if (unsubscribe_interrupt(&timer_id)) {
|
108 |
printf("%s: failed to unsubcribe timer interrupts.\n");
|
109 |
r = UNSBCR_ERROR; |
110 |
} |
111 |
timer_subscribed = 0;
|
112 |
} |
113 |
|
114 |
// Unsubscribe Keyboard interrupts
|
115 |
if (keyboard_subscribed) {
|
116 |
if (unsubscribe_interrupt(&kbc_id)) {
|
117 |
printf("%s: failed to unsubcribe keyboard interrupts.\n");
|
118 |
r = UNSBCR_ERROR; |
119 |
} |
120 |
keyboard_subscribed = 0;
|
121 |
} |
122 |
|
123 |
// Unsubscribe Mouse Interrupts
|
124 |
if (mouse_subscribed) {
|
125 |
if (sys_irqdisable(&mouse_id)) { // temporarily disables our interrupts notifications |
126 |
printf("%s: failed to disable mouse interrupts.\n");
|
127 |
r = UNSBCR_ERROR; |
128 |
} |
129 |
if (mouse_set_data_report(false)) { // disables mouse data reporting |
130 |
printf("%s: failed to disable mouse data reporting.\n");
|
131 |
r = UNSBCR_ERROR; |
132 |
} |
133 |
if (sys_irqenable(&mouse_id)) { // re-enables our interrupts notifications |
134 |
printf("%s: failed to enable mouse interrupts.\n");
|
135 |
r = UNSBCR_ERROR; |
136 |
} |
137 |
if (unsubscribe_interrupt(&mouse_id)) { // unsubscribes interrupts |
138 |
printf("%s: failed to unsubcribe mouse interrupts.\n");
|
139 |
r = UNSBCR_ERROR; |
140 |
} |
141 |
mouse_subscribed = 0;
|
142 |
} |
143 |
|
144 |
return r;
|
145 |
} |
146 |
|
147 |
void (interrupt_handler)(uint8_t handler) {
|
148 |
if (handler >= 32) return; |
149 |
if ((*ih[handler]) == NULL) return; |
150 |
(*ih[handler])(); |
151 |
} |
152 |
|
153 |
void (timer_manager)() {
|
154 |
|
155 |
} |
156 |
|
157 |
void (mouse_manager)() {
|
158 |
|
159 |
} |