Ignore:
File:
1 edited

Legend:

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

    r267f235 r956d4281  
    4040#include <stdio.h>
    4141#include <errno.h>
    42 #include <bool.h>
     42#include <stdbool.h>
    4343#include <fibril_synch.h>
    4444#include <stdlib.h>
     
    5151#include <sys/stat.h>
    5252#include <ddi.h>
    53 #include <libarch/ddi.h>
    5453
    5554#include <ddf/driver.h>
     
    161160        /** I/O registers **/
    162161        ns8250_regs_t *regs;
    163         /** Is there any client conntected to the device? */
    164         bool client_connected;
     162        /** Are there any clients connected to the device? */
     163        unsigned client_connections;
    165164        /** The irq assigned to this device. */
    166165        int irq;
     
    169168        /** The i/o port used to access the serial ports registers. */
    170169        ioport8_t *port;
    171         /** The buffer for incomming data. */
     170        /** The buffer for incoming data. */
    172171        cyclic_buffer_t input_buffer;
    173172        /** The fibril mutex for synchronizing the access to the device. */
     
    191190}
    192191
    193 /** Find out if there is some incomming data available on the serial port.
     192/** Find out if there is some incoming data available on the serial port.
    194193 *
    195194 * @param port          The base address of the serial port device's ports.
     
    237236 *
    238237 * @param fun           The serial port function
    239  * @param buf           The ouput buffer for read data.
     238 * @param buf           The output buffer for read data.
    240239 * @param count         The number of bytes to be read.
    241240 *
     
    421420                        ns->irq = res->res.interrupt.irq;
    422421                        irq = true;
    423                         ddf_msg(LVL_NOTE, "Device %s was asigned irq = 0x%x.",
     422                        ddf_msg(LVL_NOTE, "Device %s was assigned irq = 0x%x.",
    424423                            ddf_dev_get_name(ns->dev), ns->irq);
    425424                        break;
     
    434433                        }
    435434                        ioport = true;
    436                         ddf_msg(LVL_NOTE, "Device %s was asigned I/O address = "
     435                        ddf_msg(LVL_NOTE, "Device %s was assigned I/O address = "
    437436                            "0x%x.", ddf_dev_get_name(ns->dev), ns->io_addr);
    438437                        break;
     
    754753                        uint8_t val = ns8250_read_8(regs);
    755754                       
    756                         if (ns->client_connected) {
     755                        if (ns->client_connections > 0) {
    757756                                bool buf_was_empty = buf_is_empty(&ns->input_buffer);
    758757                                if (!buf_push_back(&ns->input_buffer, val)) {
     
    828827        ddf_fun_t *fun = NULL;
    829828        bool need_cleanup = false;
     829        bool need_unreg_intr_handler = false;
    830830        int rc;
    831831       
     
    870870                goto fail;
    871871        }
     872        need_unreg_intr_handler = true;
    872873       
    873874        /* Enable interrupt. */
     
    904905        if (fun != NULL)
    905906                ddf_fun_destroy(fun);
     907        if (need_unreg_intr_handler)
     908                ns8250_unregister_interrupt_handler(ns);
    906909        if (need_cleanup)
    907910                ns8250_dev_cleanup(ns);
     
    915918       
    916919        fibril_mutex_lock(&ns->mutex);
    917         if (ns->client_connected) {
     920        if (ns->client_connections > 0) {
    918921                fibril_mutex_unlock(&ns->mutex);
    919922                return EBUSY;
     
    949952       
    950953        fibril_mutex_lock(&ns->mutex);
    951         if (ns->client_connected) {
    952                 res = ELIMIT;
    953         } else if (ns->removed) {
     954        if (ns->removed) {
    954955                res = ENXIO;
    955956        } else {
    956957                res = EOK;
    957                 ns->client_connected = true;
     958                ns->client_connections++;
    958959        }
    959960        fibril_mutex_unlock(&ns->mutex);
     
    975976        fibril_mutex_lock(&data->mutex);
    976977       
    977         assert(data->client_connected);
    978        
    979         data->client_connected = false;
    980         buf_clear(&data->input_buffer);
     978        assert(data->client_connections > 0);
     979       
     980        if (!(--data->client_connections))
     981                buf_clear(&data->input_buffer);
    981982       
    982983        fibril_mutex_unlock(&data->mutex);
Note: See TracChangeset for help on using the changeset viewer.