Rev 1063 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
519 | mauro | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * Massimiliano Giorgi <massy@gandalf.sssup.it> |
||
11 | * Luca Abeni <luca@gandalf.sssup.it> |
||
12 | * Mauro Marinoni <mauro.marinoni@unipv.it> |
||
13 | * (see the web pages for full authors list) |
||
14 | * |
||
15 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
16 | * |
||
17 | * http://www.sssup.it |
||
18 | * http://retis.sssup.it |
||
19 | * http://shark.sssup.it |
||
20 | */ |
||
21 | |||
1063 | tullio | 22 | /* |
23 | * This program is free software; you can redistribute it and/or modify |
||
24 | * it under the terms of the GNU General Public License as published by |
||
25 | * the Free Software Foundation; either version 2 of the License, or |
||
26 | * (at your option) any later version. |
||
27 | * |
||
28 | * This program is distributed in the hope that it will be useful, |
||
29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
31 | * GNU General Public License for more details. |
||
32 | * |
||
33 | * You should have received a copy of the GNU General Public License |
||
34 | * along with this program; if not, write to the Free Software |
||
35 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
36 | * |
||
37 | */ |
||
38 | |||
519 | mauro | 39 | //#define __KEYB_DEBUG__ |
523 | mauro | 40 | #define KEYB_TASK |
519 | mauro | 41 | |
42 | #include <kernel/kern.h> |
||
1034 | mauro | 43 | #include <kernel/int_sem.h> |
519 | mauro | 44 | #include <signal.h> |
45 | |||
46 | #include "../include/drivers/shark_input26.h" |
||
47 | #include "../include/drivers/shark_keyb26.h" |
||
48 | |||
49 | /* Devices */ |
||
1015 | mauro | 50 | extern int atkbd_init(int soft); |
519 | mauro | 51 | extern int atkbd_exit(void); |
52 | |||
53 | /* Handlers */ |
||
54 | extern int kbd_init(void); |
||
55 | extern int kbd_exit(void); |
||
56 | |||
523 | mauro | 57 | /* Functions */ |
519 | mauro | 58 | extern int kbd_enable(void); |
59 | extern int kbd_disable(void); |
||
60 | extern int kbd_get(unsigned int *data, BYTE access); |
||
61 | extern void kbd_setleds(unsigned int led); |
||
62 | extern int kbd_rate(unsigned int *delay, unsigned int *period); |
||
63 | extern void kbd_mksound(unsigned int hz, unsigned int ticks); |
||
64 | |||
65 | /* |
||
66 | * The following tables contains the ascii code corresponding to the |
||
67 | * scan codes, with shift & no shift... |
||
68 | */ |
||
69 | char keyTable [TABLE_KEY_SIZE]; |
||
70 | char keyShiftTable[TABLE_KEY_SIZE]; |
||
71 | char keyAltGrTable[TABLE_KEY_SIZE]; |
||
72 | |||
73 | BYTE useAltGr = FALSE; |
||
74 | |||
75 | /* Status variables */ |
||
76 | static BYTE shift = FALSE; |
||
77 | static BYTE ctrl = FALSE; |
||
78 | static BYTE alt = FALSE; |
||
79 | static BYTE altgr = FALSE; |
||
80 | |||
81 | static BYTE capslock = FALSE; |
||
82 | static BYTE numlock = TRUE; |
||
83 | static BYTE scrolllock = FALSE; |
||
84 | |||
85 | /* Keyboard Flags (if shift, alt or control are pressed...); */ |
||
86 | static BYTE keyFlag = 0x00; |
||
87 | static BYTE status; |
||
88 | |||
89 | /* Keyboard driver currently installed */ |
||
90 | static int keyb_installed = FALSE; |
||
91 | |||
92 | |||
93 | #define MAX_KEY_EXC 50 |
||
94 | |||
95 | static struct keyexctable |
||
96 | { |
||
97 | KEY_EVT evt; |
||
98 | void (*func) (KEY_EVT * k); |
||
99 | unsigned char lock; |
||
100 | } keyExcTable[MAX_KEY_EXC]; |
||
101 | |||
102 | static int lastExc; |
||
103 | |||
1034 | mauro | 104 | /* Buffer used for the communication between the extern process & the user */ |
519 | mauro | 105 | |
1034 | mauro | 106 | /* Buffer Ssize */ |
107 | #define KEYBUFF_SIZE 256 |
||
108 | /* Buffer Mask ( i=(i+1)&MASK is better than i=(i+1)%SIZE ) */ |
||
109 | #define KEYBUFF_MASK 0xff |
||
110 | |||
111 | static KEY_EVT keybuff[KEYBUFF_SIZE]; |
||
112 | static int keybuff_head = 1; |
||
113 | static int keybuff_tail = 0; |
||
114 | static internal_sem_t keybuff_mutex; |
||
115 | static int keybuff_mutex_init = 0; |
||
116 | |||
522 | mauro | 117 | #ifdef KEYB_TASK |
519 | mauro | 118 | /* keyboard task PID */ |
119 | static PID keybpid; |
||
522 | mauro | 120 | #else |
523 | mauro | 121 | static void keyProc(void); |
522 | mauro | 122 | #endif |
519 | mauro | 123 | |
124 | /* |
||
522 | mauro | 125 | * Start keyProc Task or exec it as function |
519 | mauro | 126 | */ |
522 | mauro | 127 | void shark_kbd_exec(void) |
519 | mauro | 128 | { |
522 | mauro | 129 | #ifdef KEYB_TASK |
519 | mauro | 130 | task_activate(keybpid); |
522 | mauro | 131 | #else |
132 | keyProc(); |
||
133 | #endif |
||
519 | mauro | 134 | } |
135 | |||
136 | /* |
||
137 | * This function get a scan code, return an ascii code and set |
||
138 | * the status vars in order to handle the special keys of the AT keyboard |
||
139 | */ |
||
140 | WORD scanCode(unsigned int c, int d) |
||
141 | { |
||
142 | //printk("scanCode: c (%x) - d (%d)\n", c, d); |
||
143 | |||
144 | /* KEY_EVT status setting */ |
||
749 | mauro | 145 | status = 1 << d; |
519 | mauro | 146 | |
147 | switch (c) { |
||
148 | /* CapsLock pressed*/ |
||
149 | case KEY_CPSLOCK: |
||
150 | if (d == KEY_PRESSED) { |
||
151 | capslock = capslock ? FALSE : TRUE; |
||
152 | /* light the caps lock led */ |
||
153 | kbd_setleds(scrolllock + (numlock << 1) + (capslock << 2)); |
||
154 | } |
||
155 | return 0; |
||
156 | /* NumLock pressed */ |
||
157 | case PAD_NUMLOCK: |
||
158 | if (d == KEY_PRESSED) { |
||
159 | numlock = numlock ? FALSE : TRUE; |
||
160 | /* light the num lock led */ |
||
161 | kbd_setleds(scrolllock + (numlock << 1) + (capslock << 2)); |
||
162 | } |
||
163 | return 0; |
||
164 | /* ScrollLock pressed*/ |
||
165 | case EXT_SCRLOCK: |
||
166 | if (d == KEY_PRESSED) { |
||
167 | scrolllock = scrolllock ? FALSE : TRUE; |
||
168 | /* light the scroll lock led */ |
||
169 | kbd_setleds(scrolllock + (numlock << 1) + (capslock << 2)); |
||
170 | } |
||
171 | return 0; |
||
172 | /* Shift pressed or released */ |
||
173 | case KEY_SHL: |
||
174 | if (d) { |
||
175 | shift = TRUE; |
||
176 | if (c == KEY_SHL) |
||
177 | keyFlag |= SHFL_BIT; |
||
178 | } else { |
||
179 | keyFlag &= (!SHFL_BIT); |
||
180 | if (!(keyFlag & SHFR_BIT)) |
||
181 | shift = FALSE; |
||
182 | } |
||
183 | return 0; |
||
184 | /* Shift pressed or released */ |
||
185 | case KEY_SHR: |
||
186 | if (d) { |
||
187 | shift = TRUE; |
||
188 | if (c == KEY_SHR) |
||
189 | keyFlag |= SHFR_BIT; |
||
190 | } else { |
||
191 | keyFlag &= (!SHFR_BIT); |
||
192 | if (!(keyFlag & SHFL_BIT)) |
||
193 | shift = FALSE; |
||
194 | } |
||
195 | return 0; |
||
196 | /* Control pressed or released */ |
||
197 | case KEY_CTRLL: |
||
198 | if (d) { |
||
199 | ctrl = TRUE; |
||
200 | keyFlag |= CNTL_BIT; |
||
201 | } else { |
||
202 | keyFlag &= (!CNTL_BIT); |
||
203 | if (!(keyFlag & CNTR_BIT)) |
||
204 | ctrl = FALSE; |
||
205 | } |
||
206 | return 0; |
||
207 | /* Control pressed or released */ |
||
208 | case KEY_CTRLR: |
||
209 | if (d) { |
||
210 | ctrl = TRUE; |
||
211 | keyFlag |= CNTR_BIT; |
||
212 | } else { |
||
213 | keyFlag &= (!CNTR_BIT); |
||
214 | if (!(keyFlag & CNTL_BIT)) |
||
215 | ctrl = FALSE; |
||
216 | } |
||
217 | return 0; |
||
218 | /* Alt Left pressed */ |
||
219 | case KEY_ALTL: |
||
220 | if (d) { |
||
221 | alt = TRUE; |
||
222 | keyFlag |= ALTL_BIT; |
||
223 | } else { |
||
224 | alt = FALSE; |
||
225 | keyFlag &= (!ALTL_BIT); |
||
226 | } |
||
227 | return 0; |
||
228 | /* Alt Right (AltGr) pressed */ |
||
229 | case KEY_ALTR: |
||
230 | if (d) { |
||
231 | altgr = TRUE; |
||
232 | keyFlag |= ALTR_BIT; |
||
233 | } else { |
||
234 | altgr = FALSE; |
||
235 | keyFlag &= (!ALTR_BIT); |
||
236 | if ((!useAltGr) && (!(keyFlag & ALTL_BIT))) |
||
237 | alt = FALSE; |
||
238 | } |
||
239 | return 0; |
||
240 | /* Delete */ |
||
241 | case EXT_DEL: |
||
242 | return DELETE; |
||
243 | case PAD_DEL: |
||
244 | if (numlock || shift) |
||
245 | return 0x18; |
||
246 | else |
||
247 | break; |
||
248 | /* Pad Enter */ |
||
249 | case PAD_ENT: |
||
250 | return 0x0d; |
||
251 | /* Pad Add */ |
||
252 | case PAD_PLUS: |
||
253 | return 0x2b; |
||
254 | /* Pad Sub */ |
||
255 | case PAD_SUB: |
||
256 | return 0x2d; |
||
257 | /* Pad Slash */ |
||
258 | case PAD_SLH: |
||
259 | return 0x2f; |
||
260 | /* Numbers & simbols */ |
||
261 | case KEY_1: case KEY_2: case KEY_3: case KEY_4: case KEY_5: |
||
262 | case KEY_6: case KEY_7: case KEY_8: case KEY_9: case KEY_0: |
||
263 | case KEY_SUB: case KEY_PLUS: case KEY_BRL: case KEY_BRR: |
||
264 | case KEY_COL: case KEY_API: case KEY_TIL: case KEY_BSL: |
||
265 | case KEY_LT: case KEY_GT: case KEY_SLH: |
||
266 | /* AlrGR enabled & pressed */ |
||
267 | if (altgr && useAltGr) { |
||
268 | return keyAltGrTable[c]; |
||
269 | } |
||
270 | /* Control Shift status */ |
||
271 | if (shift) |
||
272 | return keyShiftTable[c]; |
||
273 | else |
||
274 | return keyTable[c]; |
||
275 | } |
||
276 | |||
277 | /* Pad Keys */ |
||
278 | if (numlock || shift) |
||
279 | switch (c) { |
||
280 | case PAD_DEL: |
||
281 | return 0x18; |
||
282 | case PAD_INS: |
||
283 | return 0x30; |
||
284 | case PAD_END: |
||
285 | return 0x31; |
||
286 | case PAD_DOWN: |
||
287 | return 0x32; |
||
288 | case PAD_PGDW: |
||
289 | return 0x33; |
||
290 | case PAD_RIGHT: |
||
291 | return 0x34; |
||
292 | case PAD_5: |
||
293 | return 0x35; |
||
294 | case PAD_LEFT: |
||
295 | return 0x36; |
||
296 | case PAD_HOME: |
||
297 | return 0x37; |
||
298 | case PAD_UP: |
||
299 | return 0x38; |
||
300 | case PAD_PGUP: |
||
301 | return 0x39; |
||
302 | } |
||
303 | |||
304 | /* Characters keys */ |
||
305 | if (((c >= KEY_Q) && (c <= KEY_P)) || |
||
306 | ((c >= KEY_A) && (c <= KEY_L)) || |
||
307 | ((c >= KEY_Z) && (c <= KEY_M))) { |
||
308 | /* AlrGR enabled & pressed */ |
||
309 | if (altgr && useAltGr) { |
||
310 | return keyAltGrTable[c]; |
||
311 | } |
||
312 | /* Control CapsLock & Shift status */ |
||
313 | if (capslock) { |
||
314 | if (shift) |
||
315 | return keyTable[c]; |
||
316 | else |
||
317 | return keyShiftTable[c]; |
||
318 | } else { |
||
319 | if (shift) |
||
320 | return keyShiftTable[c]; |
||
321 | else |
||
322 | return keyTable[c]; |
||
323 | } |
||
324 | } |
||
325 | |||
326 | /* Remaining keys */ |
||
327 | if (c < TABLE_KEY_SIZE) |
||
328 | /* Left 'low' keys (Esc, BackSpace, Space, ...) */ |
||
329 | return keyTable[c]; |
||
330 | else |
||
331 | /* Default - Return as keycode */ |
||
332 | return (0xff00 | c); |
||
333 | } |
||
334 | |||
522 | mauro | 335 | #ifdef KEYB_TASK |
519 | mauro | 336 | TASK keyProc(void) |
522 | mauro | 337 | #else |
523 | mauro | 338 | static void keyProc(void) |
522 | mauro | 339 | #endif |
519 | mauro | 340 | { |
341 | WORD code; |
||
342 | BYTE found; |
||
343 | KEY_EVT dt; |
||
344 | int i, res; |
||
345 | unsigned int dato; |
||
346 | |||
522 | mauro | 347 | #ifdef KEYB_TASK |
519 | mauro | 348 | while (1) { |
522 | mauro | 349 | #endif |
519 | mauro | 350 | res = kbd_get(&dato, NON_BLOCK); |
351 | if (res >= 0) { |
||
352 | code = scanCode(dato, res); |
||
353 | if (code != 0) { |
||
354 | if (code & 0xff00) |
||
355 | /* It's a scan code, set the right bit */ |
||
356 | dt.flag = (keyFlag | SCAN_BIT); |
||
357 | else |
||
358 | /* Simply send the keyFlag status */ |
||
359 | dt.flag = keyFlag; |
||
360 | dt.status = status; |
||
361 | dt.ascii = (BYTE) (code & 0x00FF); |
||
362 | dt.scan = dato; |
||
363 | #ifdef __KEYB_DEBUG__ |
||
364 | printk("shark_keyb.c: KEY_EVT ( %2x - %c - %2x - %1d)\n", dt.scan, dt.ascii, dt.flag, dt.status); |
||
365 | #endif |
||
366 | found = FALSE; |
||
1034 | mauro | 367 | for (i = 0; i < MAX_KEY_EXC; i++) { |
368 | if (keyExcTable[i].func == NULL) |
||
369 | continue; |
||
666 | mauro | 370 | if (((keyExcTable[i].evt.flag & ~SCAN_BIT) == (dt.flag & ~SCAN_BIT)) && |
749 | mauro | 371 | ((keyExcTable[i].evt.status & dt.status) != 0)) { |
1034 | mauro | 372 | if ((dt.flag & SCAN_BIT) != 0) { |
373 | if ((keyExcTable[i].evt.scan == dt.scan) && (keyExcTable[i].evt.scan != 0)) { |
||
519 | mauro | 374 | #ifdef __KEYB_DEBUG__ |
1034 | mauro | 375 | printk("shark_keyb.c: Key_Hook ( %2x - %2x - %1d) -> ( %2x - %2x - %1d)\n", |
376 | dt.scan, dt.ascii, dt.flag, dt.status, |
||
377 | keyExcTable[i].evt.scan, keyExcTable[i].evt.ascii, keyExcTable[i].evt.flag, keyExcTable[i].evt.status); |
||
519 | mauro | 378 | #endif |
1034 | mauro | 379 | keyExcTable[i].func(&dt); |
380 | if (keyExcTable[i].lock == TRUE) |
||
381 | found = TRUE; |
||
382 | } |
||
383 | } else { |
||
384 | if ( ((keyExcTable[i].evt.scan == dt.scan) || (keyExcTable[i].evt.scan == 0)) && |
||
385 | ((keyExcTable[i].evt.ascii == dt.ascii) || (keyExcTable[i].evt.ascii == 0)) ){ |
||
386 | #ifdef __KEYB_DEBUG__ |
||
387 | printk("shark_keyb.c: Key_Hook ( %2x - %2x - %1d) -> ( %2x - %2x - %1d)\n", |
||
388 | dt.scan, dt.ascii, dt.flag, dt.status, |
||
389 | keyExcTable[i].evt.scan, keyExcTable[i].evt.ascii, keyExcTable[i].evt.flag, keyExcTable[i].evt.status); |
||
390 | #endif |
||
391 | keyExcTable[i].func(&dt); |
||
392 | if (keyExcTable[i].lock == TRUE) |
||
393 | found = TRUE; |
||
394 | } |
||
666 | mauro | 395 | } |
523 | mauro | 396 | } |
1034 | mauro | 397 | } |
519 | mauro | 398 | /* when the port is full, data is lost */ |
1034 | mauro | 399 | if (!found) { |
400 | if (keybuff_tail != keybuff_head) { |
||
401 | internal_sem_wait(&keybuff_mutex); |
||
402 | memcpy(&keybuff[keybuff_head], &dt, sizeof(KEY_EVT)); |
||
403 | keybuff_head = (keybuff_head+1) & KEYBUFF_MASK; |
||
404 | internal_sem_post(&keybuff_mutex); |
||
405 | } |
||
406 | } |
||
519 | mauro | 407 | } |
408 | } |
||
522 | mauro | 409 | #ifdef KEYB_TASK |
519 | mauro | 410 | task_endcycle(); |
411 | } |
||
522 | mauro | 412 | #endif |
519 | mauro | 413 | } |
414 | |||
415 | /* default function called on ctrl-c */ |
||
416 | void default_ctrlChandler(KEY_EVT * k) { |
||
1034 | mauro | 417 | /* Useful or not to set the page to 0? */ |
418 | /*set_active_page(0); |
||
519 | mauro | 419 | set_visual_page(0); |
1034 | mauro | 420 | cputs("Ctrl-C pressed!\n");*/ |
421 | exit(0); |
||
519 | mauro | 422 | } |
423 | |||
424 | /**** Start User Functions ****/ |
||
425 | |||
426 | /* Function that returns the ascii code */ |
||
427 | BYTE keyb_getch(BYTE wait) |
||
428 | { |
||
523 | mauro | 429 | KEY_EVT ev; |
519 | mauro | 430 | |
1034 | mauro | 431 | while(1) { |
432 | if ( ((keybuff_tail+1) & KEYBUFF_MASK) != ((keybuff_head) & KEYBUFF_MASK) ) { |
||
433 | internal_sem_wait(&keybuff_mutex); |
||
434 | keybuff_tail = (keybuff_tail+1) & KEYBUFF_MASK; |
||
435 | memcpy(&ev, &keybuff[keybuff_tail], sizeof(KEY_EVT)); |
||
436 | internal_sem_post(&keybuff_mutex); |
||
437 | |||
523 | mauro | 438 | #ifdef __KEYB_DEBUG__ |
1034 | mauro | 439 | printk("shark_keyb.c: GetChar ( %2x - %c - %2x - %1d)\n", ev.scan, ev.ascii, ev.flag, ev.status); |
523 | mauro | 440 | #endif |
1034 | mauro | 441 | if (!isScanCode(&ev) && !isReleased(&ev)) { |
442 | return (ev.ascii); |
||
443 | } else { |
||
444 | if (wait != BLOCK) |
||
445 | return 0; |
||
446 | } |
||
447 | } else { |
||
448 | if (wait != BLOCK) |
||
449 | return 0; |
||
450 | } |
||
451 | } |
||
519 | mauro | 452 | } |
453 | |||
454 | /* |
||
455 | * Function that returns a structure containing the flags status, the ascii |
||
456 | * code, and the scan code |
||
457 | */ |
||
1034 | mauro | 458 | int keyb_getcode(KEY_EVT * k, BYTE wait) |
519 | mauro | 459 | { |
1034 | mauro | 460 | while (1) { |
461 | if ( ((keybuff_tail+1) & KEYBUFF_MASK) != ((keybuff_head) & KEYBUFF_MASK) ) { |
||
462 | internal_sem_wait(&keybuff_mutex); |
||
463 | keybuff_tail = (keybuff_tail+1) & KEYBUFF_MASK; |
||
464 | memcpy(k, &keybuff[keybuff_tail], sizeof(KEY_EVT)); |
||
465 | internal_sem_post(&keybuff_mutex); |
||
466 | |||
467 | return(TRUE); |
||
468 | } else { |
||
469 | if (wait != BLOCK) |
||
470 | return(FALSE); |
||
471 | } |
||
472 | } |
||
519 | mauro | 473 | } |
474 | |||
1034 | mauro | 475 | /* |
476 | * This call is used to link a function to a KEY_EVT |
||
477 | */ |
||
478 | int keyb_hook(KEY_EVT k, void (*f) (KEY_EVT * k), unsigned char l) |
||
519 | mauro | 479 | { |
1034 | mauro | 480 | int id = 0; |
481 | |||
482 | if ((k.ascii == 0) && (k.scan == 0)) |
||
483 | return -1; |
||
484 | |||
485 | while (keyExcTable[id].func != NULL) { |
||
486 | id++; |
||
487 | if (id >= MAX_KEY_EXC) |
||
488 | return -1; |
||
489 | } |
||
490 | |||
491 | keyExcTable[lastExc].func = f; |
||
519 | mauro | 492 | keyExcTable[lastExc].evt = k; |
1034 | mauro | 493 | if (keyExcTable[lastExc].evt.status == 0) |
494 | keyExcTable[lastExc].evt.status = KEY_PRESSED; |
||
495 | |||
519 | mauro | 496 | keyExcTable[lastExc++].lock = l; |
497 | |||
1034 | mauro | 498 | return (lastExc-1); |
519 | mauro | 499 | } |
500 | |||
1034 | mauro | 501 | /* Free a keyb_hook slot */ |
502 | int keyb_unhook(int index) |
||
503 | { |
||
504 | if (keyExcTable[index].func != NULL) { |
||
505 | keyExcTable[index].func = NULL; |
||
506 | return 0; |
||
507 | } |
||
508 | return -1; |
||
509 | } |
||
510 | |||
523 | mauro | 511 | /* This function disable the keyboard */ |
826 | mauro | 512 | void inline keyb_disable(void) |
519 | mauro | 513 | { |
514 | kbd_disable(); |
||
515 | } |
||
516 | |||
523 | mauro | 517 | /* This function enable the keyboard */ |
826 | mauro | 518 | void inline keyb_enable(void) |
519 | mauro | 519 | { |
520 | kbd_enable(); |
||
521 | } |
||
522 | |||
523 | mauro | 523 | /**** End User Functions ****/ |
826 | mauro | 524 | int inline KEYB26_installed(void) |
549 | mauro | 525 | { |
526 | return keyb_installed; |
||
527 | } |
||
519 | mauro | 528 | |
529 | int KEYB26_init(KEYB_PARMS *s) |
||
530 | { |
||
531 | KEYB_PARMS kparms = BASE_KEYB; |
||
532 | WORD i; |
||
533 | int status = 0; |
||
534 | |||
522 | mauro | 535 | #ifdef KEYB_TASK |
519 | mauro | 536 | SOFT_TASK_MODEL base_m; |
537 | TASK_MODEL *m; |
||
522 | mauro | 538 | #endif |
519 | mauro | 539 | |
540 | if (keyb_installed == TRUE) return 0; |
||
541 | |||
542 | /* if a NULL is passed */ |
||
543 | if (s == NULL) |
||
544 | s = &kparms; |
||
545 | |||
1034 | mauro | 546 | /* Reset keymap structures */ |
519 | mauro | 547 | for (i = 0; i < TABLE_KEY_SIZE; i++) { |
548 | keyTable[i] = 0; |
||
549 | keyShiftTable[i] = 0; |
||
550 | keyAltGrTable[i] = 0; |
||
551 | } |
||
552 | |||
553 | /* keymap */ |
||
554 | if (s->keymap == (unsigned char)KEYB_DEFAULT) s->keymap = KEYMAP_US; |
||
555 | keyb_set_map(s->keymap); |
||
556 | |||
1034 | mauro | 557 | /* KeyEvt Buffer Initialization */ |
558 | keybuff_head = 1; |
||
559 | keybuff_tail = 0; |
||
560 | if (keybuff_mutex_init==0) { |
||
561 | internal_sem_init(&keybuff_mutex, 1); |
||
562 | keybuff_mutex_init = 1; |
||
519 | mauro | 563 | } |
564 | |||
565 | /* remove all key pressed handlers */ |
||
566 | lastExc = 0; |
||
567 | |||
568 | /* and add a ctrl-c handler if requested */ |
||
569 | if (s->ctrlcfunc == (void *) KEYB_DEFAULT) |
||
570 | s->ctrlcfunc = (void *) default_ctrlChandler; |
||
571 | if (s->ctrlcfunc != NULL) { |
||
572 | KEY_EVT emerg; |
||
523 | mauro | 573 | emerg.ascii = 'c'; |
574 | emerg.scan = KEY_C; |
||
575 | emerg.status = KEY_PRESSED; |
||
576 | emerg.flag = CNTL_BIT; |
||
1034 | mauro | 577 | keyb_hook (emerg, s->ctrlcfunc, FALSE); |
523 | mauro | 578 | emerg.flag = CNTR_BIT; |
1034 | mauro | 579 | keyb_hook (emerg, s->ctrlcfunc, FALSE); |
519 | mauro | 580 | } |
581 | |||
522 | mauro | 582 | #ifdef KEYB_TASK |
519 | mauro | 583 | /* keyb task */ |
584 | if (s->tm == (TASK_MODEL *) KEYB_DEFAULT) { |
||
585 | soft_task_default_model (base_m); |
||
586 | soft_task_def_wcet (base_m, 2000); |
||
587 | soft_task_def_met (base_m, 800); |
||
1034 | mauro | 588 | soft_task_def_period (base_m, 30000); |
519 | mauro | 589 | soft_task_def_system (base_m); |
826 | mauro | 590 | soft_task_def_nokill (base_m); |
519 | mauro | 591 | soft_task_def_aperiodic (base_m); |
592 | m = (TASK_MODEL *) & base_m; |
||
593 | } else |
||
594 | m = s->tm; |
||
595 | |||
596 | #ifdef __KEYB_DEBUG__ |
||
1034 | mauro | 597 | printk(KERN_DEBUG "keyb task: %li %li %li %li\n", (long)s->pclass, (long)APERIODIC, (long)s->dline, (long)s->wcet); |
519 | mauro | 598 | #endif |
599 | |||
600 | keybpid = task_create ("KeyTask", keyProc, m, NULL); |
||
1034 | mauro | 601 | if (keybpid == -1) |
519 | mauro | 602 | return -1; |
522 | mauro | 603 | #endif |
519 | mauro | 604 | |
549 | mauro | 605 | if (INPUT26_installed() == FALSE) |
519 | mauro | 606 | if (INPUT26_init()) { |
607 | printk(KERN_ERR "shark_keyb.c: Unable to open Input SubSystem.\n"); |
||
544 | giacomo | 608 | #ifdef KEYB_TASK |
523 | mauro | 609 | task_kill (keybpid); |
544 | giacomo | 610 | #endif |
519 | mauro | 611 | return -1; |
612 | } |
||
613 | |||
549 | mauro | 614 | status = kbd_init(); |
519 | mauro | 615 | if (status) { |
549 | mauro | 616 | printk(KERN_ERR "shark_keyb.c: Kbd_Init return: %d\n", status); |
544 | giacomo | 617 | #ifdef KEYB_TASK |
523 | mauro | 618 | task_kill (keybpid); |
544 | giacomo | 619 | #endif |
519 | mauro | 620 | return -1; |
621 | } |
||
549 | mauro | 622 | |
1015 | mauro | 623 | |
624 | if (s->softrepeat == (int) KEYB_DEFAULT) { |
||
625 | status = atkbd_init(1); |
||
626 | } else { |
||
627 | status = atkbd_init(s->softrepeat); |
||
628 | } |
||
519 | mauro | 629 | if (status) { |
549 | mauro | 630 | printk(KERN_ERR "shark_keyb.c: AtKbd_Init return: %d\n", status); |
544 | giacomo | 631 | #ifdef KEYB_TASK |
523 | mauro | 632 | task_kill (keybpid); |
544 | giacomo | 633 | #endif |
519 | mauro | 634 | return -1; |
635 | } |
||
636 | |||
637 | kbd_setleds(scrolllock + (numlock << 1) + (capslock << 2)); |
||
638 | kbd_enable(); |
||
639 | |||
640 | keyb_installed = TRUE; |
||
641 | return status; |
||
642 | } |
||
643 | |||
644 | /* |
||
645 | * KEYB module cleanup |
||
646 | * (must be called if it's needed to re-call keyb_init() with other parameters) |
||
647 | * -1 -> ERROR |
||
648 | */ |
||
649 | int KEYB26_close(void) |
||
650 | { |
||
522 | mauro | 651 | #ifdef KEYB_TASK |
519 | mauro | 652 | int free; |
653 | SYS_FLAGS f; |
||
522 | mauro | 654 | #endif |
519 | mauro | 655 | |
656 | if (!keyb_installed) |
||
657 | return -1; |
||
549 | mauro | 658 | |
519 | mauro | 659 | kbd_disable(); |
549 | mauro | 660 | |
661 | atkbd_exit(); |
||
519 | mauro | 662 | kbd_exit(); |
663 | |||
522 | mauro | 664 | #ifdef KEYB_TASK |
519 | mauro | 665 | f = kern_fsave(); |
666 | free = (proc_table[keybpid].status == FREE); |
||
667 | kern_frestore(f); |
||
668 | #ifdef __KEYB_DEBUG__ |
||
669 | printk(KERN_DEBUG "shark_keyb.c: KeyTask is %s.\n", free ? "killed" : "alive"); |
||
670 | #endif |
||
671 | if (free) |
||
672 | task_kill (keybpid); |
||
522 | mauro | 673 | #endif |
519 | mauro | 674 | |
675 | keyb_installed = FALSE; |
||
676 | |||
677 | return 0; |
||
678 | } |