Changeset c657bd7 in mainline for uspace/drv/char


Ignore:
Timestamp:
2017-11-20T10:06:59Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
19ea61d
Parents:
5d50c419
git-author:
Jiri Svoboda <jiri@…> (2017-11-19 22:05:26)
git-committer:
Jiri Svoboda <jiri@…> (2017-11-20 10:06:59)
Message:

Less is sometimes more. Need chardev_read to be able to return less bytes than requested if less is available. Otherwise cannot read variable-sized packets except yte-by-byte.

Location:
uspace/drv/char
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/char/i8042/buffer.h

    r5d50c419 rc657bd7  
    113113 *
    114114 * @param buffer Cyclic buffer to read from.
     115 * @param rb Place to store byte read
     116 * @param wait @c True to wait until byte is available
    115117 *
    116  * @return Byte read.
     118 * @return EOK on success, EAGAIN if @c wait is false and no data is available
    117119 *
    118120 */
    119 static inline uint8_t buffer_read(buffer_t *buffer)
     121static inline int buffer_read(buffer_t *buffer, uint8_t *rb, bool wait)
    120122{
    121123        fibril_mutex_lock(&buffer->guard);
    122124       
    123125        /* Buffer is empty. */
    124         while (buffer->write_head == buffer->read_head)
     126        while (wait && buffer->write_head == buffer->read_head)
    125127                fibril_condvar_wait(&buffer->change, &buffer->guard);
     128       
     129        if (buffer->write_head == buffer->read_head) {
     130                fibril_mutex_unlock(&buffer->guard);
     131                return EAGAIN;
     132        }
    126133       
    127134        /* Next position. */
     
    144151       
    145152        fibril_mutex_unlock(&buffer->guard);
    146         return data;
     153        *rb = data;
     154        return EOK;
    147155}
    148156
  • uspace/drv/char/i8042/i8042.c

    r5d50c419 rc657bd7  
    374374        i8042_t *i8042 = port->ctl;
    375375        uint8_t *destp = (uint8_t *)dest;
     376        int rc;
     377        size_t i;
    376378       
    377379        buffer_t *buffer = (port == i8042->aux) ?
    378380            &i8042->aux_buffer : &i8042->kbd_buffer;
    379381       
    380         for (size_t i = 0; i < size; ++i)
    381                 *destp++ = buffer_read(buffer);
    382        
    383         return size;
     382        for (i = 0; i < size; ++i) {
     383                rc = buffer_read(buffer, destp, i == 0);
     384                if (rc != EOK)
     385                        break;
     386                ++destp;
     387        }
     388       
     389        return i;
    384390}
    385391
  • uspace/drv/char/pl050/pl050.c

    r5d50c419 rc657bd7  
    246246        left = size;
    247247        while (left > 0) {
    248                 while (pl050->buf_rp == pl050->buf_wp)
     248                while (left == size && pl050->buf_rp == pl050->buf_wp)
    249249                        fibril_condvar_wait(&pl050->buf_cv, &pl050->buf_lock);
     250                if (pl050->buf_rp == pl050->buf_wp)
     251                        break;
    250252                *bp++ = pl050->buffer[pl050->buf_rp];
    251253                --left;
     
    255257        fibril_mutex_unlock(&pl050->buf_lock);
    256258
    257         return size;
     259        return size - left;
    258260}
    259261
Note: See TracChangeset for help on using the changeset viewer.