Ignore:
File:
1 edited

Legend:

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

    r3e6a98c5 r956d4281  
    160160        /** I/O registers **/
    161161        ns8250_regs_t *regs;
    162         /** Is there any client conntected to the device? */
    163         bool client_connected;
     162        /** Are there any clients connected to the device? */
     163        unsigned client_connections;
    164164        /** The irq assigned to this device. */
    165165        int irq;
     
    168168        /** The i/o port used to access the serial ports registers. */
    169169        ioport8_t *port;
    170         /** The buffer for incomming data. */
     170        /** The buffer for incoming data. */
    171171        cyclic_buffer_t input_buffer;
    172172        /** The fibril mutex for synchronizing the access to the device. */
     
    190190}
    191191
    192 /** 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.
    193193 *
    194194 * @param port          The base address of the serial port device's ports.
     
    236236 *
    237237 * @param fun           The serial port function
    238  * @param buf           The ouput buffer for read data.
     238 * @param buf           The output buffer for read data.
    239239 * @param count         The number of bytes to be read.
    240240 *
     
    420420                        ns->irq = res->res.interrupt.irq;
    421421                        irq = true;
    422                         ddf_msg(LVL_NOTE, "Device %s was asigned irq = 0x%x.",
     422                        ddf_msg(LVL_NOTE, "Device %s was assigned irq = 0x%x.",
    423423                            ddf_dev_get_name(ns->dev), ns->irq);
    424424                        break;
     
    433433                        }
    434434                        ioport = true;
    435                         ddf_msg(LVL_NOTE, "Device %s was asigned I/O address = "
     435                        ddf_msg(LVL_NOTE, "Device %s was assigned I/O address = "
    436436                            "0x%x.", ddf_dev_get_name(ns->dev), ns->io_addr);
    437437                        break;
     
    753753                        uint8_t val = ns8250_read_8(regs);
    754754                       
    755                         if (ns->client_connected) {
     755                        if (ns->client_connections > 0) {
    756756                                bool buf_was_empty = buf_is_empty(&ns->input_buffer);
    757757                                if (!buf_push_back(&ns->input_buffer, val)) {
     
    827827        ddf_fun_t *fun = NULL;
    828828        bool need_cleanup = false;
     829        bool need_unreg_intr_handler = false;
    829830        int rc;
    830831       
     
    869870                goto fail;
    870871        }
     872        need_unreg_intr_handler = true;
    871873       
    872874        /* Enable interrupt. */
     
    903905        if (fun != NULL)
    904906                ddf_fun_destroy(fun);
     907        if (need_unreg_intr_handler)
     908                ns8250_unregister_interrupt_handler(ns);
    905909        if (need_cleanup)
    906910                ns8250_dev_cleanup(ns);
     
    914918       
    915919        fibril_mutex_lock(&ns->mutex);
    916         if (ns->client_connected) {
     920        if (ns->client_connections > 0) {
    917921                fibril_mutex_unlock(&ns->mutex);
    918922                return EBUSY;
     
    948952       
    949953        fibril_mutex_lock(&ns->mutex);
    950         if (ns->client_connected) {
    951                 res = ELIMIT;
    952         } else if (ns->removed) {
     954        if (ns->removed) {
    953955                res = ENXIO;
    954956        } else {
    955957                res = EOK;
    956                 ns->client_connected = true;
     958                ns->client_connections++;
    957959        }
    958960        fibril_mutex_unlock(&ns->mutex);
     
    974976        fibril_mutex_lock(&data->mutex);
    975977       
    976         assert(data->client_connected);
    977        
    978         data->client_connected = false;
    979         buf_clear(&data->input_buffer);
     978        assert(data->client_connections > 0);
     979       
     980        if (!(--data->client_connections))
     981                buf_clear(&data->input_buffer);
    980982       
    981983        fibril_mutex_unlock(&data->mutex);
Note: See TracChangeset for help on using the changeset viewer.