43,6 → 43,10 |
|
#define LSR_DATA_READY 0x01 |
|
static indev_operations_t kbrdin_ops = { |
.poll = NULL |
}; |
|
static irq_ownership_t ns16550_claim(irq_t *irq) |
{ |
ns16550_instance_t *instance = irq->instance; |
60,18 → 64,11 |
ns16550_t *dev = instance->ns16550; |
|
if (pio_read_8(&dev->lsr) & LSR_DATA_READY) { |
uint8_t data = pio_read_8(&dev->rbr); |
indev_push_character(instance->kbrdin, data); |
uint8_t x = pio_read_8(&dev->rbr); |
indev_push_character(&instance->kbrdin, x); |
} |
} |
|
/**< Clear input buffer. */ |
static void ns16550_clear_buffer(ns16550_t *dev) |
{ |
while ((pio_read_8(&dev->lsr) & LSR_DATA_READY)) |
(void) pio_read_8(&dev->rbr); |
} |
|
/** Initialize ns16550. |
* |
* @param dev Addrress of the beginning of the device in I/O space. |
80,16 → 77,19 |
* @param cir Clear interrupt function. |
* @param cir_arg First argument to cir. |
* |
* @return Keyboard instance or NULL on failure. |
* @return Keyboard device pointer or NULL on failure. |
* |
*/ |
ns16550_instance_t *ns16550_init(ns16550_t *dev, inr_t inr, cir_t cir, void *cir_arg) |
indev_t *ns16550_init(ns16550_t *dev, inr_t inr, cir_t cir, void *cir_arg) |
{ |
ns16550_instance_t *instance |
= malloc(sizeof(ns16550_instance_t), FRAME_ATOMIC); |
if (instance) { |
if (!instance) |
return NULL; |
|
indev_initialize("ns16550", &instance->kbrdin, &kbrdin_ops); |
|
instance->ns16550 = dev; |
instance->kbrdin = NULL; |
|
irq_initialize(&instance->irq); |
instance->irq.devno = device_assign_devno(); |
99,24 → 99,16 |
instance->irq.instance = instance; |
instance->irq.cir = cir; |
instance->irq.cir_arg = cir_arg; |
} |
|
return instance; |
} |
|
void ns16550_wire(ns16550_instance_t *instance, indev_t *kbrdin) |
{ |
ASSERT(instance); |
ASSERT(kbrdin); |
|
instance->kbrdin = kbrdin; |
irq_register(&instance->irq); |
|
ns16550_clear_buffer(instance->ns16550); |
while ((pio_read_8(&dev->lsr) & LSR_DATA_READY)) |
(void) pio_read_8(&dev->rbr); |
|
/* Enable interrupts */ |
pio_write_8(&instance->ns16550->ier, IER_ERBFI); |
pio_write_8(&instance->ns16550->mcr, MCR_OUT2); |
pio_write_8(&dev->ier, IER_ERBFI); |
pio_write_8(&dev->mcr, MCR_OUT2); |
|
return &instance->kbrdin; |
} |
|
/** @} |