Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/char/ns8250/ns8250.c

    rc92e30f rc7235d40  
    8282/** Interrupt ID Register definition. */
    8383#define NS8250_IID_ACTIVE       (1 << 0)
    84 #define NS8250_IID_CAUSE_MASK 0x0e
    85 #define NS8250_IID_CAUSE_RXSTATUS 0x06
    8684
    8785/** FIFO Control Register definition. */
     
    181179        /** The fibril mutex for synchronizing the access to the device. */
    182180        fibril_mutex_t mutex;
    183         /** Indicates that some data has become available */
    184         fibril_condvar_t input_buffer_available;
    185181        /** True if device is removed. */
    186182        bool removed;
     
    242238{
    243239        ns8250_t *ns = NS8250(fun);
    244         int ret = 0;
    245        
    246         if (count == 0) return 0;
     240        int ret = EOK;
    247241       
    248242        fibril_mutex_lock(&ns->mutex);
    249         while (buf_is_empty(&ns->input_buffer))
    250                 fibril_condvar_wait(&ns->input_buffer_available, &ns->mutex);
    251243        while (!buf_is_empty(&ns->input_buffer) && (size_t)ret < count) {
    252244                buf[ret] = (char)buf_pop_front(&ns->input_buffer);
     
    468460{
    469461        /* Interrupt when data received. */
    470         pio_write_8(&regs->ier, NS8250_IER_RXREADY | NS8250_IER_RXSTATUS);
     462        pio_write_8(&regs->ier, NS8250_IER_RXREADY);
    471463        pio_write_8(&regs->mcr, NS8250_MCR_DTR | NS8250_MCR_RTS
    472464            | NS8250_MCR_OUT2);
     
    507499        async_exchange_end(exch);
    508500
    509         /* Read LSR to clear possible previous LSR interrupt */
    510         pio_read_8(&ns->regs->lsr);
    511 
    512501        /* Enable interrupt on the serial port. */
    513502        ns8250_port_interrupts_enable(ns->regs);
     
    706695        /* 8 bits, no parity, two stop bits. */
    707696        ns8250_port_set_com_props(ns->regs, SERIAL_NO_PARITY, 8, 2);
    708         /*
    709          * Enable FIFO, clear them, with 4-byte threshold for greater
    710          * reliability.
    711          */
     697        /* Enable FIFO, clear them, with 14-byte threshold. */
    712698        pio_write_8(&ns->regs->iid, NS8250_FCR_FIFOENABLE
    713             | NS8250_FCR_RXFIFORESET | NS8250_FCR_TXFIFORESET
    714             | NS8250_FCR_RXTRIGGERLOW);
     699            | NS8250_FCR_RXFIFORESET | NS8250_FCR_TXFIFORESET 
     700            | NS8250_FCR_RXTRIGGERLOW | NS8250_FCR_RXTRIGGERHI);
    715701        /*
    716702         * RTS/DSR set (Request to Send and Data Terminal Ready lines enabled),
     
    745731        bool cont = true;
    746732       
    747         fibril_mutex_lock(&ns->mutex);
    748733        while (cont) {
     734                fibril_mutex_lock(&ns->mutex);
     735               
    749736                cont = ns8250_received(regs);
    750737                if (cont) {
     
    752739                       
    753740                        if (ns->client_connected) {
    754                                 bool buf_was_empty = buf_is_empty(&ns->input_buffer);
    755741                                if (!buf_push_back(&ns->input_buffer, val)) {
    756742                                        ddf_msg(LVL_WARN, "Buffer overflow on "
    757743                                            "%s.", ns->dev->name);
    758                                         break;
    759744                                } else {
    760745                                        ddf_msg(LVL_DEBUG2, "Character %c saved "
    761746                                            "to the buffer of %s.",
    762747                                            val, ns->dev->name);
    763                                         if (buf_was_empty)
    764                                                 fibril_condvar_broadcast(&ns->input_buffer_available);
    765748                                }
    766749                        }
    767750                }
    768         }
    769         fibril_mutex_unlock(&ns->mutex);
    770         fibril_yield();
     751               
     752                fibril_mutex_unlock(&ns->mutex);
     753                fibril_yield();
     754        }
    771755}
    772756
    773757/** The interrupt handler.
    774758 *
    775  * The serial port is initialized to interrupt when some data come or line
    776  * status register changes, so the interrupt is handled by reading the incoming
    777  * data and reading the line status register.
     759 * The serial port is initialized to interrupt when some data come, so the
     760 * interrupt is handled by reading the incomming data.
    778761 *
    779762 * @param dev           The serial port device.
     
    782765    ipc_call_t *icall)
    783766{
    784         ns8250_t *ns = NS8250_FROM_DEV(dev);
    785 
    786         uint8_t iir = pio_read_8(&ns->regs->iid);
    787         if ((iir & NS8250_IID_CAUSE_MASK) == NS8250_IID_CAUSE_RXSTATUS) {
    788                 uint8_t lsr = pio_read_8(&ns->regs->lsr);
    789                 if (lsr & NS8250_LSR_OE) {
    790                         ddf_msg(LVL_WARN, "Overrun error on %s", ns->dev->name);
    791                 }
    792         }
    793        
    794         ns8250_read_from_device(ns);
     767        ns8250_read_from_device(NS8250_FROM_DEV(dev));
    795768}
    796769
     
    838811       
    839812        fibril_mutex_initialize(&ns->mutex);
    840         fibril_condvar_initialize(&ns->input_buffer_available);
    841813        ns->dev = dev;
    842814       
     
    10811053static void ns8250_init(void)
    10821054{
    1083         ddf_log_init(NAME, LVL_WARN);
     1055        ddf_log_init(NAME, LVL_ERROR);
    10841056       
    10851057        ns8250_dev_ops.open = &ns8250_open;
Note: See TracChangeset for help on using the changeset viewer.