Rev 509 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 509 | Rev 510 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* |
1 | /* |
- | 2 | * Copyright (C) 2003 Josef Cejka |
|
2 | * Copyright (C) 2005 Jakub Jermar |
3 | * Copyright (C) 2005 Jakub Jermar |
3 | * All rights reserved. |
4 | * All rights reserved. |
4 | * |
5 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
Line 25... | Line 26... | ||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
28 | */ |
28 | 29 | ||
29 | #include <arch/drivers/keyboard.h> |
30 | #include <arch/drivers/keyboard.h> |
- | 31 | #include <console/chardev.h> |
|
- | 32 | #include <console/console.h> |
|
30 | #include <arch/cp0.h> |
33 | #include <arch/cp0.h> |
31 | #include <putchar.h> |
34 | #include <putchar.h> |
- | 35 | #include <synch/spinlock.h> |
|
- | 36 | #include <synch/waitq.h> |
|
- | 37 | #include <typedefs.h> |
|
32 | 38 | ||
- | 39 | static chardev_t kbrd; |
|
- | 40 | ||
- | 41 | static void keyboard_enable(void); |
|
- | 42 | ||
- | 43 | /** Initialize keyboard subsystem. */ |
|
33 | void keyboard_init(void) |
44 | void keyboard_init(void) |
34 | { |
45 | { |
35 | /* unmask keyboard interrupt */ |
- | |
36 | cp0_unmask_int(KEYBOARD_IRQ); |
46 | cp0_unmask_int(KEYBOARD_IRQ); |
- | 47 | chardev_initialize(&kbrd, keyboard_enable); |
|
- | 48 | stdin = &kbrd; |
|
37 | } |
49 | } |
38 | 50 | ||
- | 51 | /** Process keyboard interrupt. |
|
- | 52 | * |
|
- | 53 | * This function is called directly from the interrupt handler. |
|
- | 54 | * It feeds the keyboard buffer with characters read. When the buffer |
|
- | 55 | * is full, it simply masks the keyboard interrupt signal. |
|
- | 56 | */ |
|
39 | void keyboard(void) |
57 | void keyboard(void) |
40 | { |
58 | { |
- | 59 | char ch; |
|
- | 60 | ||
- | 61 | spinlock_lock(&kbrd.lock); |
|
- | 62 | kbrd.counter++; |
|
- | 63 | if (kbrd.counter == CHARDEV_BUFLEN - 1) { |
|
- | 64 | /* buffer full => disable keyboard interrupt */ |
|
- | 65 | cp0_mask_int(KEYBOARD_IRQ); |
|
- | 66 | } |
|
- | 67 | ||
41 | putchar(*((char *) KEYBOARD_ADDRESS)); |
68 | ch = *((char *) KEYBOARD_ADDRESS); |
- | 69 | putchar(ch); |
|
- | 70 | kbrd.buffer[kbrd.index++] = ch; |
|
- | 71 | kbrd.index = kbrd.index % CHARDEV_BUFLEN; /* index modulo size of buffer */ |
|
- | 72 | waitq_wakeup(&kbrd.wq, WAKEUP_FIRST); |
|
- | 73 | spinlock_unlock(&kbrd.lock); |
|
- | 74 | } |
|
- | 75 | ||
- | 76 | /* Called from getc(). */ |
|
- | 77 | void keyboard_enable(void) |
|
- | 78 | { |
|
- | 79 | cp0_unmask_int(KEYBOARD_IRQ); |
|
42 | } |
80 | } |