root / proj / src / interrupts_func.c @ 297
History | View | Annotate | Download (6.77 KB)
1 | 178 | up20180642 | #include <lcom/lcf.h> |
---|---|---|---|
2 | |||
3 | 154 | up20180655 | #include "interrupts_func.h" |
4 | #include "timer.h" |
||
5 | #include "keyboard.h" |
||
6 | #include "mouse.h" |
||
7 | 287 | up20180642 | #include "hltp.h" |
8 | 154 | up20180655 | #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 | 263 | up20180642 | static int uart_subscribed = 0, uart_id; |
18 | |||
19 | 154 | up20180655 | static void (*const ih[])(void) = { timer_int_handler, |
20 | kbc_ih, |
||
21 | NULL,
|
||
22 | NULL,
|
||
23 | NULL,
|
||
24 | NULL,
|
||
25 | NULL,
|
||
26 | NULL,
|
||
27 | NULL,
|
||
28 | NULL,
|
||
29 | NULL,
|
||
30 | NULL,
|
||
31 | mouse_ih, |
||
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 | NULL,
|
||
50 | NULL,
|
||
51 | }; |
||
52 | 297 | up20180642 | /*
|
53 | 287 | up20180642 | static void process_received(const uint8_t *p, const size_t sz){
|
54 | void *q = NULL;
|
||
55 | hltp_type t = hltp_interpret(p, sz, &q);
|
||
56 | switch(t){
|
||
57 | case hltp_type_string:{
|
||
58 | char *s = q;
|
||
59 | printf("%s\n", s);
|
||
60 | } break;
|
||
61 | default: break;
|
||
62 | }
|
||
63 | }
|
||
64 | 297 | up20180642 | */
|
65 | 154 | up20180655 | int (subscribe_all)(void) { |
66 | |||
67 | /// Timer interrupt handling
|
||
68 | timer_id = 0;
|
||
69 | if(subscribe_timer_interrupt(TIMER0_IRQ, &timer_id)) {
|
||
70 | printf("%s: failed to subscribe timer interrupts.\n", __func__);
|
||
71 | return SBCR_ERROR;
|
||
72 | } |
||
73 | timer_subscribed = 1;
|
||
74 | |||
75 | /// Keyboard interrupt handling
|
||
76 | kbc_id = 0;
|
||
77 | if (subscribe_kbc_interrupt(KBC_IRQ, &kbc_id)) {
|
||
78 | printf("%s: failed to subscribe keyboard interrupts.\n", __func__);
|
||
79 | if (unsubscribe_all())
|
||
80 | printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
|
||
81 | return SBCR_ERROR;
|
||
82 | } |
||
83 | keyboard_subscribed = 1;
|
||
84 | |||
85 | /// Mouse interrupt handling
|
||
86 | mouse_id = 0;
|
||
87 | if (subscribe_mouse_interrupt(MOUSE_IRQ, &mouse_id)) { // subscribes mouse interrupts in exclusive mode |
||
88 | printf("%s: failed to subscribe mouse interrupts.\n", __func__);
|
||
89 | if (unsubscribe_all())
|
||
90 | printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
|
||
91 | return SBCR_ERROR;
|
||
92 | } |
||
93 | mouse_subscribed = 1;
|
||
94 | if (sys_irqdisable(&mouse_id)) { // temporarily disables our interrupts notifications |
||
95 | printf("%s: failed to disable mouse interrupts.\n", __func__);
|
||
96 | if (unsubscribe_all())
|
||
97 | printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
|
||
98 | return SBCR_ERROR;
|
||
99 | } |
||
100 | if (mouse_set_data_report(true)) { // enables mouse data reporting |
||
101 | printf("%s: failed to enable mouse data reporting.\n", __func__);
|
||
102 | if (unsubscribe_all())
|
||
103 | printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
|
||
104 | return SBCR_ERROR;
|
||
105 | } |
||
106 | if (sys_irqenable(&mouse_id)) { // re-enables our interrupts notifications |
||
107 | printf("%s: failed to enable mouse interrupts.\n", __func__);
|
||
108 | if (unsubscribe_all())
|
||
109 | printf("%s: failed to unsubcribe driver, unexpected behaviour is expected.\n");
|
||
110 | return SBCR_ERROR;
|
||
111 | } |
||
112 | |||
113 | 263 | up20180642 | /// UART interrupt handling
|
114 | uart_id = 0;
|
||
115 | 272 | up20180642 | uart_set_bits_per_character(COM1_ADDR, 8);
|
116 | uart_set_stop_bits (COM1_ADDR, 2);
|
||
117 | uart_set_parity (COM1_ADDR, uart_parity_even); |
||
118 | uart_set_bit_rate (COM1_ADDR, 38400);
|
||
119 | 263 | up20180642 | uart_enable_int_rx (COM1_ADDR); |
120 | 275 | up20180642 | uart_enable_int_tx(COM1_ADDR); |
121 | 263 | up20180642 | if(subscribe_uart_interrupt(COM1_IRQ, &uart_id)) {
|
122 | printf("%s: failed to subscribe UART interrupts.\n", __func__);
|
||
123 | return SBCR_ERROR;
|
||
124 | } |
||
125 | uart_subscribed = 1;
|
||
126 | 297 | up20180642 | nctp_init(); |
127 | 263 | up20180642 | |
128 | 154 | up20180655 | return SUCCESS;
|
129 | } |
||
130 | |||
131 | int (unsubscribe_all)(void) { |
||
132 | int r = SUCCESS;
|
||
133 | |||
134 | // Unsubscribe Timer Interrupts
|
||
135 | if (timer_subscribed) {
|
||
136 | if (unsubscribe_interrupt(&timer_id)) {
|
||
137 | printf("%s: failed to unsubcribe timer interrupts.\n");
|
||
138 | r = UNSBCR_ERROR; |
||
139 | } |
||
140 | timer_subscribed = 0;
|
||
141 | } |
||
142 | |||
143 | // Unsubscribe Keyboard interrupts
|
||
144 | if (keyboard_subscribed) {
|
||
145 | if (unsubscribe_interrupt(&kbc_id)) {
|
||
146 | printf("%s: failed to unsubcribe keyboard interrupts.\n");
|
||
147 | r = UNSBCR_ERROR; |
||
148 | } |
||
149 | keyboard_subscribed = 0;
|
||
150 | } |
||
151 | |||
152 | // Unsubscribe Mouse Interrupts
|
||
153 | if (mouse_subscribed) {
|
||
154 | if (sys_irqdisable(&mouse_id)) { // temporarily disables our interrupts notifications |
||
155 | printf("%s: failed to disable mouse interrupts.\n");
|
||
156 | r = UNSBCR_ERROR; |
||
157 | } |
||
158 | if (mouse_set_data_report(false)) { // disables mouse data reporting |
||
159 | printf("%s: failed to disable mouse data reporting.\n");
|
||
160 | r = UNSBCR_ERROR; |
||
161 | } |
||
162 | if (sys_irqenable(&mouse_id)) { // re-enables our interrupts notifications |
||
163 | printf("%s: failed to enable mouse interrupts.\n");
|
||
164 | r = UNSBCR_ERROR; |
||
165 | } |
||
166 | if (unsubscribe_interrupt(&mouse_id)) { // unsubscribes interrupts |
||
167 | printf("%s: failed to unsubcribe mouse interrupts.\n");
|
||
168 | r = UNSBCR_ERROR; |
||
169 | } |
||
170 | mouse_subscribed = 0;
|
||
171 | } |
||
172 | |||
173 | 263 | up20180642 | // Unsubscribe UART interrupts
|
174 | if (uart_subscribed) {
|
||
175 | if (unsubscribe_interrupt(&uart_id)) {
|
||
176 | printf("%s: failed to unsubcribe UART interrupts.\n");
|
||
177 | r = UNSBCR_ERROR; |
||
178 | } |
||
179 | uart_enable_int_rx(COM1_ADDR); |
||
180 | uart_enable_int_tx(COM1_ADDR); |
||
181 | uart_subscribed = 0;
|
||
182 | } |
||
183 | 275 | up20180642 | nctp_free(); |
184 | 263 | up20180642 | |
185 | 154 | up20180655 | return r;
|
186 | } |
||
187 | |||
188 | 250 | up20180655 | void (interrupt_handler)(uint8_t handler) {
|
189 | 154 | up20180655 | if (handler >= 32) return; |
190 | if ((*ih[handler]) == NULL) return; |
||
191 | (*ih[handler])(); |
||
192 | } |
||
193 | 250 | up20180655 | |
194 | void (timer_manager)() {
|
||
195 | |||
196 | } |
||
197 | |||
198 | void (mouse_manager)() {
|
||
199 | |||
200 | } |