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