Changes in kernel/genarch/src/drivers/ns16550/ns16550.c [448e093:24abb85d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/drivers/ns16550/ns16550.c
r448e093 r24abb85d 1 1 /* 2 2 * Copyright (c) 2009 Jakub Jermar 3 * Copyright (c) 2018 CZ.NIC, z.s.p.o.4 3 * All rights reserved. 5 4 * … … 47 46 #define LSR_TH_READY 0x20 48 47 49 static uint8_t ns16550_reg_read(ns16550_instance_t *inst, ns16550_reg_t reg)50 {51 return pio_read_8(&inst->ns16550[reg << inst->reg_shift]);52 }53 54 static void ns16550_reg_write(ns16550_instance_t *inst, ns16550_reg_t reg,55 uint8_t val)56 {57 pio_write_8(&inst->ns16550[reg << inst->reg_shift], val);58 }59 60 48 static irq_ownership_t ns16550_claim(irq_t *irq) 61 49 { 62 50 ns16550_instance_t *instance = irq->instance; 63 64 if (ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_DATA_READY) 51 ns16550_t *dev = instance->ns16550; 52 53 if (pio_read_8(&dev->lsr) & LSR_DATA_READY) 65 54 return IRQ_ACCEPT; 66 55 else … … 71 60 { 72 61 ns16550_instance_t *instance = irq->instance; 62 ns16550_t *dev = instance->ns16550; 73 63 74 while (ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_DATA_READY) {75 uint8_t data = ns16550_reg_read(instance, NS16550_REG_RBR);64 if (pio_read_8(&dev->lsr) & LSR_DATA_READY) { 65 uint8_t data = pio_read_8(&dev->rbr); 76 66 indev_push_character(instance->input, data); 77 67 } … … 79 69 80 70 /**< Clear input buffer. */ 81 static void ns16550_clear_buffer(ns16550_ instance_t *instance)71 static void ns16550_clear_buffer(ns16550_t *dev) 82 72 { 83 while ( ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_DATA_READY)84 (void) ns16550_reg_read(instance, NS16550_REG_RBR);73 while ((pio_read_8(&dev->lsr) & LSR_DATA_READY)) 74 (void) pio_read_8(&dev->rbr); 85 75 } 86 76 87 static void ns16550_sendb(ns16550_ instance_t *instance, uint8_t byte)77 static void ns16550_sendb(ns16550_t *dev, uint8_t byte) 88 78 { 89 while (!( ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_TH_READY))79 while (!(pio_read_8(&dev->lsr) & LSR_TH_READY)) 90 80 ; 91 ns16550_reg_write(instance, NS16550_REG_THR, byte);81 pio_write_8(&dev->thr, byte); 92 82 } 93 83 … … 98 88 if ((!instance->parea.mapped) || (console_override)) { 99 89 if (ascii_check(ch)) 100 ns16550_sendb(instance , (uint8_t) ch);90 ns16550_sendb(instance->ns16550, (uint8_t) ch); 101 91 else 102 ns16550_sendb(instance , U_SPECIAL);92 ns16550_sendb(instance->ns16550, U_SPECIAL); 103 93 } 104 94 } … … 111 101 /** Initialize ns16550. 112 102 * 113 * @param dev Address of the beginning of the device in I/O space. 114 * @param reg_shift Spacing between individual register addresses, in log2. 115 * The individual register location is calculated as 116 * `base + (register offset << reg_shift)`. 117 * @param inr Interrupt number. 118 * @param cir Clear interrupt function. 119 * @param cir_arg First argument to cir. 120 * @param output Where to store pointer to the output device 121 * or NULL if the caller is not interested in 122 * writing to the serial port. 103 * @param dev Addrress of the beginning of the device in I/O space. 104 * @param inr Interrupt number. 105 * @param cir Clear interrupt function. 106 * @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. 123 110 * 124 111 * @return Keyboard instance or NULL on failure. 125 112 * 126 113 */ 127 ns16550_instance_t *ns16550_init( ioport8_t *dev, unsigned reg_shift, inr_t inr,128 cir_t cir,void *cir_arg, outdev_t **output)114 ns16550_instance_t *ns16550_init(ns16550_t *dev, inr_t inr, cir_t cir, 115 void *cir_arg, outdev_t **output) 129 116 { 130 117 ns16550_instance_t *instance … … 132 119 if (instance) { 133 120 instance->ns16550 = dev; 134 instance->reg_shift = reg_shift;135 121 instance->input = NULL; 136 122 instance->output = NULL; … … 176 162 irq_register(&instance->irq); 177 163 178 ns16550_clear_buffer(instance );164 ns16550_clear_buffer(instance->ns16550); 179 165 180 166 /* Enable interrupts */ 181 ns16550_reg_write(instance, NS16550_REG_IER, IER_ERBFI);182 ns16550_reg_write(instance, NS16550_REG_MCR, MCR_OUT2);167 pio_write_8(&instance->ns16550->ier, IER_ERBFI); 168 pio_write_8(&instance->ns16550->mcr, MCR_OUT2); 183 169 } 184 170
Note:
See TracChangeset
for help on using the changeset viewer.