Changeset 2677758 in mainline for arch/mips32/src/drivers/keyboard.c


Ignore:
Timestamp:
2005-11-22T23:44:38Z (20 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
607c5f9
Parents:
a7fdfe1
Message:

Add chardev_t.
This type is meant to abstract any input character device such as keyboard, serial port etc.
Add stdin.
Add dummy kconsole.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • arch/mips32/src/drivers/keyboard.c

    ra7fdfe1 r2677758  
    11/*
     2 * Copyright (C) 2003 Josef Cejka
    23 * Copyright (C) 2005 Jakub Jermar
    34 * All rights reserved.
     
    2829
    2930#include <arch/drivers/keyboard.h>
     31#include <console/chardev.h>
     32#include <console/console.h>
    3033#include <arch/cp0.h>
    3134#include <putchar.h>
     35#include <synch/spinlock.h>
     36#include <synch/waitq.h>
     37#include <typedefs.h>
    3238
     39static chardev_t kbrd;
     40
     41static void keyboard_enable(void);
     42
     43/** Initialize keyboard subsystem. */
    3344void keyboard_init(void)
    3445{
    35         /* unmask keyboard interrupt */
     46        cp0_unmask_int(KEYBOARD_IRQ);
     47        chardev_initialize(&kbrd, keyboard_enable);
     48        stdin = &kbrd;
     49}
     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 */
     57void keyboard(void)
     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
     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(). */
     77void keyboard_enable(void)
     78{
    3679        cp0_unmask_int(KEYBOARD_IRQ);
    3780}
    38 
    39 void keyboard(void)
    40 {
    41         putchar(*((char *) KEYBOARD_ADDRESS));
    42 }
Note: See TracChangeset for help on using the changeset viewer.