Ignore:
Timestamp:
2014-12-08T19:34:48Z (9 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f42adef
Parents:
7785ebd7 (diff), 21b6307 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~martin-sucha/helenos/kernel-serial

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/drivers/ns16550/ns16550.c

    r7785ebd7 r3da166f0  
    4141#include <mm/slab.h>
    4242#include <ddi/device.h>
     43#include <str.h>
    4344
    4445#define LSR_DATA_READY  0x01
     46#define LSR_TH_READY    0x20
    4547
    4648static irq_ownership_t ns16550_claim(irq_t *irq)
     
    6264        if (pio_read_8(&dev->lsr) & LSR_DATA_READY) {
    6365                uint8_t data = pio_read_8(&dev->rbr);
    64                 indev_push_character(instance->kbrdin, data);
     66                indev_push_character(instance->input, data);
    6567        }
    6668}
     
    7375}
    7476
     77static void ns16550_sendb(ns16550_t *dev, uint8_t byte)
     78{
     79        while (!(pio_read_8(&dev->lsr) & LSR_TH_READY))
     80                ;
     81        pio_write_8(&dev->thr, byte);
     82}
     83
     84static void ns16550_putchar(outdev_t *dev, wchar_t ch)
     85{
     86        ns16550_instance_t *instance = (ns16550_instance_t *) dev->data;
     87       
     88        if ((!instance->parea.mapped) || (console_override)) {
     89                if (ascii_check(ch))
     90                        ns16550_sendb(instance->ns16550, (uint8_t) ch);
     91                else
     92                        ns16550_sendb(instance->ns16550, U_SPECIAL);
     93        }
     94}
     95
     96static outdev_operations_t ns16550_ops = {
     97        .write = ns16550_putchar,
     98        .redraw = NULL
     99};
     100
    75101/** Initialize ns16550.
    76102 *
    77103 * @param dev      Addrress of the beginning of the device in I/O space.
    78  * @param devno    Device number.
    79104 * @param inr      Interrupt number.
    80105 * @param cir      Clear interrupt function.
    81106 * @param cir_arg  First argument to cir.
     107 * @param output   Where to store pointer to the output device
     108 *                 or NULL if the caller is not interested in
     109 *                 writing to the serial port.
    82110 *
    83111 * @return Keyboard instance or NULL on failure.
    84112 *
    85113 */
    86 ns16550_instance_t *ns16550_init(ns16550_t *dev, inr_t inr, cir_t cir, void *cir_arg)
     114ns16550_instance_t *ns16550_init(ns16550_t *dev, inr_t inr, cir_t cir,
     115    void *cir_arg, outdev_t **output)
    87116{
    88117        ns16550_instance_t *instance
     
    90119        if (instance) {
    91120                instance->ns16550 = dev;
    92                 instance->kbrdin = NULL;
     121                instance->input = NULL;
     122                instance->output = NULL;
     123               
     124                if (output) {
     125                        instance->output = malloc(sizeof(outdev_t),
     126                            FRAME_ATOMIC);
     127                        if (!instance->output) {
     128                                free(instance);
     129                                return NULL;
     130                        }
     131                       
     132                        outdev_initialize("ns16550", instance->output,
     133                            &ns16550_ops);
     134                        instance->output->data = instance;
     135                        *output = instance->output;
     136                }
    93137               
    94138                irq_initialize(&instance->irq);
     
    100144                instance->irq.cir = cir;
    101145                instance->irq.cir_arg = cir_arg;
     146               
     147                instance->parea.pbase = (uintptr_t) dev;
     148                instance->parea.frames = 1;
     149                instance->parea.unpriv = false;
     150                instance->parea.mapped = false;
     151                ddi_parea_register(&instance->parea);
    102152        }
    103153       
     
    105155}
    106156
    107 void ns16550_wire(ns16550_instance_t *instance, indev_t *kbrdin)
     157void ns16550_wire(ns16550_instance_t *instance, indev_t *input)
    108158{
    109159        ASSERT(instance);
    110         ASSERT(kbrdin);
     160        ASSERT(input);
    111161       
    112         instance->kbrdin = kbrdin;
     162        instance->input = input;
    113163        irq_register(&instance->irq);
    114164       
Note: See TracChangeset for help on using the changeset viewer.