Subversion Repositories HelenOS-historic

Rev

Rev 509 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
509 jermar 1
/*
510 jermar 2
 * Copyright (C) 2003 Josef Cejka
509 jermar 3
 * Copyright (C) 2005 Jakub Jermar
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 *
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
14
 *   documentation and/or other materials provided with the distribution.
15
 * - The name of the author may not be used to endorse or promote products
16
 *   derived from this software without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29
 
30
#include <arch/drivers/keyboard.h>
510 jermar 31
#include <console/chardev.h>
32
#include <console/console.h>
509 jermar 33
#include <arch/cp0.h>
34
#include <putchar.h>
510 jermar 35
#include <synch/spinlock.h>
36
#include <synch/waitq.h>
37
#include <typedefs.h>
509 jermar 38
 
510 jermar 39
static chardev_t kbrd;
40
 
41
static void keyboard_enable(void);
42
 
43
/** Initialize keyboard subsystem. */
509 jermar 44
void keyboard_init(void)
45
{
46
    cp0_unmask_int(KEYBOARD_IRQ);
510 jermar 47
    chardev_initialize(&kbrd, keyboard_enable);
48
    stdin = &kbrd;
509 jermar 49
}
50
 
510 jermar 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
 */
509 jermar 57
void keyboard(void)
58
{
510 jermar 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
 
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);
509 jermar 74
}
510 jermar 75
 
76
/* Called from getc(). */
77
void keyboard_enable(void)
78
{
79
    cp0_unmask_int(KEYBOARD_IRQ);
80
}