Changeset a35b458 in mainline for uspace/drv/char/ns8250


Ignore:
Timestamp:
2018-03-02T20:10:49Z (8 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

Location:
uspace/drv/char/ns8250
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/char/ns8250/cyclic_buffer.h

    r3061bc1 ra35b458  
    6565{
    6666        assert(!buf_is_empty(buf));
    67        
     67
    6868        uint8_t res = buf->buf[buf->start];
    6969        buf->start = (buf->start + 1) % BUF_LEN;
  • uspace/drv/char/ns8250/ns8250.c

    r3061bc1 ra35b458  
    238238        while (!is_transmit_empty(regs))
    239239                ;
    240        
     240
    241241        pio_write_8(&regs->data, c);
    242242}
     
    256256        char *bp = (char *) buf;
    257257        size_t pos = 0;
    258        
     258
    259259        if (count == 0) {
    260260                *nread = 0;
    261261                return EOK;
    262262        }
    263        
     263
    264264        fibril_mutex_lock(&ns->mutex);
    265265        while (buf_is_empty(&ns->input_buffer))
     
    270270        }
    271271        fibril_mutex_unlock(&ns->mutex);
    272        
     272
    273273        *nread = pos;
    274274        return EOK;
     
    301301        size_t idx;
    302302        uint8_t *bp = (uint8_t *) buf;
    303        
     303
    304304        for (idx = 0; idx < count; idx++)
    305305                ns8250_putchar(ns, bp[idx]);
    306        
     306
    307307        *nwritten = count;
    308308        return EOK;
     
    355355{
    356356        ddf_msg(LVL_DEBUG, "ns8250_pio_enable %s", ddf_dev_get_name(ns->dev));
    357        
     357
    358358        /* Gain control over port's registers. */
    359359        if (pio_enable((void *) ns->io_addr, REG_COUNT,
     
    365365
    366366        ns->regs = (ns8250_regs_t *)ns->port;
    367        
     367
    368368        return true;
    369369}
     
    377377{
    378378        ddf_msg(LVL_DEBUG, "ns8250_dev_probe %s", ddf_dev_get_name(ns->dev));
    379        
     379
    380380        bool res = true;
    381381        uint8_t olddata;
    382        
     382
    383383        olddata = pio_read_8(&ns->regs->mcr);
    384        
     384
    385385        pio_write_8(&ns->regs->mcr, NS8250_MCR_LOOPBACK);
    386386        if (pio_read_8(&ns->regs->msr) & NS8250_MSR_SIGNALS)
    387387                res = false;
    388        
     388
    389389        pio_write_8(&ns->regs->mcr, NS8250_MCR_ALL);
    390390        if ((pio_read_8(&ns->regs->msr) & NS8250_MSR_SIGNALS)
    391391            != NS8250_MSR_SIGNALS)
    392392                res = false;
    393        
     393
    394394        pio_write_8(&ns->regs->mcr, olddata);
    395        
     395
    396396        if (!res) {
    397397                ddf_msg(LVL_DEBUG, "Device %s is not present.",
    398398                    ddf_dev_get_name(ns->dev));
    399399        }
    400        
     400
    401401        return res;
    402402}
     
    410410{
    411411        errno_t ret = EOK;
    412        
     412
    413413        ddf_msg(LVL_DEBUG, "ns8250_dev_initialize %s", ddf_dev_get_name(ns->dev));
    414        
     414
    415415        hw_resource_list_t hw_resources;
    416416        memset(&hw_resources, 0, sizeof(hw_resource_list_t));
    417        
     417
    418418        /* Get hw resources. */
    419419        ret = hw_res_get_resource_list(ns->parent_sess, &hw_resources);
     
    423423                goto failed;
    424424        }
    425        
     425
    426426        size_t i;
    427427        hw_resource_t *res;
    428428        bool irq = false;
    429429        bool ioport = false;
    430        
     430
    431431        for (i = 0; i < hw_resources.count; i++) {
    432432                res = &hw_resources.resources[i];
     
    438438                            ddf_dev_get_name(ns->dev), ns->irq);
    439439                        break;
    440                        
     440
    441441                case IO_RANGE:
    442442                        ns->io_addr = res->res.io_range.address;
     
    451451                            "0x%#" PRIxn ".", ddf_dev_get_name(ns->dev), ns->io_addr);
    452452                        break;
    453                        
     453
    454454                default:
    455455                        break;
    456456                }
    457457        }
    458        
     458
    459459        if (!irq || !ioport) {
    460460                ddf_msg(LVL_ERROR, "Missing HW resource(s) for device %s.",
     
    463463                goto failed;
    464464        }
    465        
     465
    466466        hw_res_clean_resource_list(&hw_resources);
    467467        return ret;
    468        
     468
    469469failed:
    470470        ns8250_dev_cleanup(ns);
     
    507507        if (rc != EOK)
    508508                return EIO;
    509        
     509
    510510        /* Read LSR to clear possible previous LSR interrupt */
    511511        pio_read_8(&ns->regs->lsr);
    512        
     512
    513513        /* Enable interrupt on the serial port. */
    514514        ns8250_port_interrupts_enable(ns->regs);
    515        
     515
    516516        return EOK;
    517517}
     
    551551        uint16_t divisor;
    552552        uint8_t div_low, div_high;
    553        
     553
    554554        if (baud_rate < 50 || MAX_BAUD_RATE % baud_rate != 0) {
    555555                ddf_msg(LVL_ERROR, "Invalid baud rate %d requested.",
     
    557557                return EINVAL;
    558558        }
    559        
     559
    560560        divisor = MAX_BAUD_RATE / baud_rate;
    561561        div_low = (uint8_t)divisor;
    562562        div_high = (uint8_t)(divisor >> 8);
    563        
     563
    564564        /* Enable DLAB to be able to access baud rate divisor. */
    565565        enable_dlab(regs);
    566        
     566
    567567        /* Set divisor low byte. */
    568568        pio_write_8(&regs->data, div_low);
    569569        /* Set divisor high byte. */
    570570        pio_write_8(&regs->ier, div_high);
    571        
     571
    572572        clear_dlab(regs);
    573        
     573
    574574        return EOK;
    575575}
     
    584584        uint16_t divisor;
    585585        uint8_t div_low, div_high;
    586        
     586
    587587        /* Enable DLAB to be able to access baud rate divisor. */
    588588        enable_dlab(regs);
    589        
     589
    590590        /* Get divisor low byte. */
    591591        div_low = pio_read_8(&regs->data);
    592592        /* Get divisor high byte. */
    593593        div_high = pio_read_8(&regs->ier);
    594        
     594
    595595        clear_dlab(regs);
    596        
     596
    597597        divisor = (div_high << 8) | div_low;
    598598        return MAX_BAUD_RATE / divisor;
     
    610610{
    611611        uint8_t val;
    612        
     612
    613613        val = pio_read_8(&regs->lcr);
    614614        *parity = ((val >> NS8250_LCR_PARITY) & 7);
    615        
     615
    616616        /* Silence warnings */
    617617        *word_length = 0;
     
    631631                break;
    632632        }
    633        
     633
    634634        if ((val >> NS8250_LCR_STOPBITS) & 1)
    635635                *stop_bits = 2;
     
    650650{
    651651        uint8_t val;
    652        
     652
    653653        switch (word_length) {
    654654        case 5:
     
    667667                return EINVAL;
    668668        }
    669        
     669
    670670        switch (stop_bits) {
    671671        case 1:
     
    678678                return EINVAL;
    679679        }
    680        
     680
    681681        switch (parity) {
    682682        case SERIAL_NO_PARITY:
     
    690690                return EINVAL;
    691691        }
    692        
     692
    693693        pio_write_8(&regs->lcr, val);
    694        
     694
    695695        return EOK;
    696696}
     
    748748        ns8250_regs_t *regs = ns->regs;
    749749        bool cont = true;
    750        
     750
    751751        fibril_mutex_lock(&ns->mutex);
    752752        while (cont) {
     
    754754                if (cont) {
    755755                        uint8_t val = ns8250_read_8(regs);
    756                        
     756
    757757                        if (ns->client_connections > 0) {
    758758                                bool buf_was_empty = buf_is_empty(&ns->input_buffer);
     
    794794                }
    795795        }
    796        
     796
    797797        ns8250_read_from_device(ns);
    798798        hw_res_clear_interrupt(ns->parent_sess, ns->irq);
     
    832832        bool need_unreg_intr_handler = false;
    833833        errno_t rc;
    834        
     834
    835835        ddf_msg(LVL_DEBUG, "ns8250_dev_add %s (handle = %d)",
    836836            ddf_dev_get_name(dev), (int) ddf_dev_get_handle(dev));
    837        
     837
    838838        /* Allocate soft-state for the device */
    839839        ns = ddf_dev_data_alloc(dev, sizeof(ns8250_t));
     
    842842                goto fail;
    843843        }
    844        
     844
    845845        fibril_mutex_initialize(&ns->mutex);
    846846        fibril_condvar_initialize(&ns->input_buffer_available);
    847847        ns->dev = dev;
    848        
     848
    849849        ns->parent_sess = ddf_dev_parent_sess_get(ns->dev);
    850850        if (ns->parent_sess == NULL) {
     
    854854                goto fail;
    855855        }
    856        
     856
    857857        rc = ns8250_dev_initialize(ns);
    858858        if (rc != EOK)
    859859                goto fail;
    860        
     860
    861861        need_cleanup = true;
    862        
     862
    863863        if (!ns8250_pio_enable(ns)) {
    864864                rc = EADDRNOTAVAIL;
    865865                goto fail;
    866866        }
    867        
     867
    868868        /* Find out whether the device is present. */
    869869        if (!ns8250_dev_probe(ns)) {
     
    871871                goto fail;
    872872        }
    873        
     873
    874874        /* Serial port initialization (baud rate etc.). */
    875875        ns8250_initialize_port(ns);
    876        
     876
    877877        /* Register interrupt handler. */
    878878        rc = ns8250_register_interrupt_handler(ns, &ns->irq_cap);
     
    891891                goto fail;
    892892        }
    893        
     893
    894894        fun = ddf_fun_create(dev, fun_exposed, "a");
    895895        if (fun == NULL) {
     
    897897                goto fail;
    898898        }
    899        
     899
    900900        ddf_fun_set_conn_handler(fun, ns8250_char_conn);
    901        
     901
    902902        chardev_srvs_init(&ns->cds);
    903903        ns->cds.ops = &ns8250_chardev_ops;
    904904        ns->cds.sarg = ns;
    905        
     905
    906906        rc = ddf_fun_bind(fun);
    907907        if (rc != EOK) {
     
    911911
    912912        ns->fun = fun;
    913        
     913
    914914        ddf_fun_add_to_category(fun, "serial");
    915        
     915
    916916        ddf_msg(LVL_NOTE, "Device %s successfully initialized.",
    917917            ddf_dev_get_name(dev));
    918        
     918
    919919        return EOK;
    920920fail:
     
    932932        ns8250_t *ns = dev_ns8250(dev);
    933933        errno_t rc;
    934        
     934
    935935        fibril_mutex_lock(&ns->mutex);
    936936        if (ns->client_connections > 0) {
     
    940940        ns->removed = true;
    941941        fibril_mutex_unlock(&ns->mutex);
    942        
     942
    943943        rc = ddf_fun_unbind(ns->fun);
    944944        if (rc != EOK) {
     
    946946                return rc;
    947947        }
    948        
     948
    949949        ddf_fun_destroy(ns->fun);
    950        
     950
    951951        ns8250_port_cleanup(ns);
    952952        ns8250_unregister_interrupt_handler(ns);
     
    967967        ns8250_t *ns = srv_ns8250(srv);
    968968        errno_t res;
    969        
     969
    970970        fibril_mutex_lock(&ns->mutex);
    971971        if (ns->removed) {
     
    976976        }
    977977        fibril_mutex_unlock(&ns->mutex);
    978        
     978
    979979        return res;
    980980}
     
    990990{
    991991        ns8250_t *data = srv_ns8250(srv);
    992        
     992
    993993        fibril_mutex_lock(&data->mutex);
    994        
     994
    995995        assert(data->client_connections > 0);
    996        
     996
    997997        if (!(--data->client_connections))
    998998                buf_clear(&data->input_buffer);
    999        
     999
    10001000        fibril_mutex_unlock(&data->mutex);
    1001        
     1001
    10021002        return EOK;
    10031003}
     
    10181018        ns8250_t *data = dev_ns8250(dev);
    10191019        ns8250_regs_t *regs = data->regs;
    1020        
     1020
    10211021        fibril_mutex_lock(&data->mutex);
    10221022        ns8250_port_interrupts_disable(regs);
     
    10251025        ns8250_port_interrupts_enable(regs);
    10261026        fibril_mutex_unlock(&data->mutex);
    1027        
     1027
    10281028        ddf_msg(LVL_DEBUG, "ns8250_get_props: baud rate %d, parity 0x%x, word "
    10291029            "length %d, stop bits %d", *baud_rate, *parity, *word_length,
     
    10461046            "length %d, stop bits %d", baud_rate, parity, word_length,
    10471047            stop_bits);
    1048        
     1048
    10491049        ns8250_t *data = dev_ns8250(dev);
    10501050        ns8250_regs_t *regs = data->regs;
    10511051        errno_t ret;
    1052        
     1052
    10531053        fibril_mutex_lock(&data->mutex);
    10541054        ns8250_port_interrupts_disable(regs);
     
    10581058        ns8250_port_interrupts_enable(regs);
    10591059        fibril_mutex_unlock(&data->mutex);
    1060        
     1060
    10611061        return ret;
    10621062}
     
    10741074        errno_t ret;
    10751075        unsigned int baud_rate, parity, word_length, stop_bits;
    1076        
     1076
    10771077        switch (method) {
    10781078        case SERIAL_GET_COM_PROPS:
     
    10821082                    stop_bits);
    10831083                break;
    1084                
     1084
    10851085        case SERIAL_SET_COM_PROPS:
    10861086                baud_rate = IPC_GET_ARG1(*call);
     
    10921092                async_answer_0(callid, ret);
    10931093                break;
    1094                
     1094
    10951095        default:
    10961096                async_answer_0(callid, ENOTSUP);
Note: See TracChangeset for help on using the changeset viewer.