Changeset 9f97ffe in mainline


Ignore:
Timestamp:
2011-12-26T15:44:00Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d56ab85
Parents:
c6c5ff3b
Message:

i8042: Use cyclic buffer to store device data.

Location:
uspace/drv/char/i8042
Files:
1 added
2 edited

Legend:

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

    rc6c5ff3b r9f97ffe  
    142142                return;
    143143        i8042_t *controller = dev->driver_data;
    144         fibril_mutex_lock(&controller->guard);
     144//      fibril_mutex_lock(&controller->guard);
    145145
    146146        const uint8_t status = IPC_GET_ARG1(*call);
    147147        const uint8_t data = IPC_GET_ARG2(*call);
    148         const bool aux = (status & i8042_AUX_DATA);
     148        buffer_t *buffer = (status & i8042_AUX_DATA) ?
     149            &controller->aux_buffer : &controller->kbd_buffer;
     150        buffer_write(buffer, data);
     151#if 0
    149152        char ** buffer =
    150153            aux ? &controller->aux_buffer : &controller->kbd_buffer;
     
    162165
    163166        fibril_mutex_unlock(&controller->guard);
     167#endif
    164168}
    165169/*----------------------------------------------------------------------------*/
     
    203207        dev->mouse_fun->driver_data = dev;
    204208
    205         fibril_mutex_initialize(&dev->guard);
    206         fibril_condvar_initialize(&dev->data_avail);
    207         dev->kbd_buffer = NULL;
    208         dev->kbd_buffer_end = NULL;
    209         dev->aux_buffer = NULL;
    210         dev->aux_buffer_end = NULL;
     209        buffer_init(&dev->kbd_buffer, dev->kbd_data, BUFFER_SIZE);
     210        buffer_init(&dev->aux_buffer, dev->aux_data, BUFFER_SIZE);
     211        fibril_mutex_initialize(&dev->write_guard);
    211212
    212213#define CHECK_RET_DESTROY(ret, msg...) \
     
    300301        assert(fun->driver_data);
    301302        i8042_t *controller = fun->driver_data;
    302         fibril_mutex_lock(&controller->guard);
     303        fibril_mutex_lock(&controller->write_guard);
    303304        for (size_t i = 0; i < size; ++i) {
    304305                wait_ready_write(controller);
    305306                pio_write_8(&controller->regs->data, buffer[i]);
    306307        }
    307         fibril_mutex_unlock(&controller->guard);
     308        fibril_mutex_unlock(&controller->write_guard);
    308309        return size;
    309310}
     
    316317
    317318        i8042_t *controller = fun->driver_data;
    318         fibril_mutex_lock(&controller->guard);
    319         /* There is someone else reading from the device. */
    320         if (controller->kbd_buffer) {
    321                 fibril_mutex_unlock(&controller->guard);
    322                 return EBUSY;
    323         }
    324         controller->kbd_buffer = buffer;
    325         controller->kbd_buffer_end = buffer + size;
    326 
    327         /* Wait for buffer to be filled */
    328         while (controller->kbd_buffer != controller->kbd_buffer_end)
    329                 fibril_condvar_wait(
    330                     &controller->data_avail, &controller->guard);
    331 
    332         controller->kbd_buffer = NULL;
    333         controller->kbd_buffer_end = NULL;
    334         fibril_mutex_unlock(&controller->guard);
     319
     320        for (size_t i = 0; i < size; ++i) {
     321                *buffer++ = buffer_read(&controller->kbd_buffer);
     322        }
    335323        return size;
    336324}
     
    341329        assert(fun->driver_data);
    342330        i8042_t *controller = fun->driver_data;
    343         fibril_mutex_lock(&controller->guard);
     331        fibril_mutex_lock(&controller->write_guard);
    344332        for (size_t i = 0; i < size; ++i) {
    345333                wait_ready_write(controller);
     
    347335                pio_write_8(&controller->regs->data, buffer[i]);
    348336        }
    349         fibril_mutex_unlock(&controller->guard);
     337        fibril_mutex_unlock(&controller->write_guard);
    350338        return size;
    351339}
     
    358346
    359347        i8042_t *controller = fun->driver_data;
    360         fibril_mutex_lock(&controller->guard);
    361         /* There is someone else reading from the device. */
    362         if (controller->aux_buffer) {
    363                 fibril_mutex_unlock(&controller->guard);
    364                 return EBUSY;
    365         }
    366         controller->aux_buffer = buffer;
    367         controller->aux_buffer_end = buffer + size;
    368 
    369         /* Wait for buffer to be filled */
    370         while (controller->aux_buffer != controller->aux_buffer_end)
    371                 fibril_condvar_wait(
    372                     &controller->data_avail, &controller->guard);
    373 
    374         controller->aux_buffer = NULL;
    375         controller->aux_buffer_end = NULL;
    376         fibril_mutex_unlock(&controller->guard);
     348        for (size_t i = 0; i < size; ++i) {
     349                *buffer++ = buffer_read(&controller->aux_buffer);
     350        }
    377351        return size;
    378352}
  • uspace/drv/char/i8042/i8042.h

    rc6c5ff3b r9f97ffe  
    11/*
    22 * Copyright (c) 2006 Josef Cejka
     3 * Copyright (c) 2011 Jan Vesely
    34 * All rights reserved.
    45 *
     
    2627 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2728 */
    28 
    2929/** @addtogroup kbd_port
    3030 * @ingroup  kbd
    3131 * @{
    3232 */
    33 
    3433/** @file
    3534 * @brief i8042 port driver.
     
    4544#include <ddf/driver.h>
    4645
     46#include "buffer.h"
     47
     48#define BUFFER_SIZE 12
     49
    4750/** i8042 HW I/O interface */
    4851typedef struct {
     
    5255} __attribute__ ((packed)) i8042_regs_t;
    5356
    54 /** Softstate structure, one for each serial port (primary and aux). */
    55 /*
    56 typedef struct {
    57         service_id_t service_id;
    58         async_sess_t *client_sess;
    59 } i8042_port_t;
    60 */
    61 
    6257typedef struct i8042 i8042_t;
    63 
    64 enum {
    65         DEVID_PRI = 0, /**< primary device */
    66         DEVID_AUX = 1, /**< AUX device */
    67         MAX_DEVS  = 2
    68 };
    6958
    7059struct i8042 {
    7160        i8042_regs_t *regs;
    72 //      i8042_port_t port[MAX_DEVS];
    7361        ddf_fun_t *kbd_fun;
    7462        ddf_fun_t *mouse_fun;
    75         char * kbd_buffer;
    76         char * kbd_buffer_end;
    77         char * aux_buffer;
    78         char * aux_buffer_end;
    79         fibril_mutex_t guard;
    80         fibril_condvar_t data_avail;
     63        buffer_t aux_buffer;
     64        buffer_t kbd_buffer;
     65        uint8_t aux_data[BUFFER_SIZE];
     66        uint8_t kbd_data[BUFFER_SIZE];
     67        fibril_mutex_t write_guard;
    8168};
    8269
Note: See TracChangeset for help on using the changeset viewer.