Changeset 9a884ed in mainline


Ignore:
Timestamp:
2011-05-06T10:12:25Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
42d47f8
Parents:
30f9f8f
Message:

Virtual HID terminates with last interface

Also it is not possible to turn on the same interface twice.

Location:
uspace/app/vuhid
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/vuhid/device.c

    r30f9f8f r9a884ed  
    7777{
    7878        vuhid_interface_t *iface = arg;
     79        vuhid_data_t *hid_data = iface->vuhid_data;
    7980
    8081        if (iface->live != NULL) {
    8182                iface->live(iface);
    8283        }
     84
     85        fibril_mutex_lock(&hid_data->iface_count_mutex);
     86        hid_data->iface_died_count++;
     87        fibril_condvar_broadcast(&hid_data->iface_count_cv);
     88        fibril_mutex_unlock(&hid_data->iface_count_mutex);
    8389
    8490        return EOK;
     
    110116        if ((iface->in_data_size == 0) && (iface->out_data_size == 0)) {
    111117                return EEMPTY;
     118        }
     119
     120        // FIXME - we shall set vuhid_data to NULL in the main() rather
     121        // than to depend on individual interfaces
     122        /* Already used interface. */
     123        if (iface->vuhid_data != NULL) {
     124                return EEXISTS;
    112125        }
    113126
     
    252265
    253266        /* Launch the "life" fibril. */
     267        iface->vuhid_data = hid_data;
    254268        fid_t life_fibril = fibril_create(interface_life_fibril, iface);
    255269        if (life_fibril == 0) {
     
    310324            += total_descr_size;
    311325
     326        hid_data->iface_count++;
    312327        fibril_add_ready(life_fibril);
    313328
     
    331346}
    332347
     348void wait_for_interfaces_death(usbvirt_device_t *dev)
     349{
     350        vuhid_data_t *hid_data = dev->device_data;
     351
     352        fibril_mutex_lock(&hid_data->iface_count_mutex);
     353        while (hid_data->iface_died_count < hid_data->iface_count) {
     354                fibril_condvar_wait(&hid_data->iface_count_cv,
     355                    &hid_data->iface_count_mutex);
     356        }
     357        fibril_mutex_unlock(&hid_data->iface_count_mutex);
     358}
    333359
    334360/** @}
  • uspace/app/vuhid/hids/bootkbd.c

    r30f9f8f r9a884ed  
    169169        .on_data_out = on_data_out,
    170170
    171         .live = live
     171        .live = live,
     172
     173        .vuhid_data = NULL
    172174};
    173175
  • uspace/app/vuhid/main.c

    r30f9f8f r9a884ed  
    132132        .in_endpoint_first_free = 1,
    133133        .out_endpoints_mapping = { NULL },
    134         .out_endpoint_first_free = 1
    135 };
     134        .out_endpoint_first_free = 1,
     135
     136        .iface_count = 0,
     137        .iface_died_count = 0
     138        // mutex and CV must be initialized elsewhere
     139};
     140
    136141
    137142/** Keyboard device.
     
    151156
    152157        usb_log_enable(USB_LOG_LEVEL_DEBUG2, "vusbhid");
     158
     159        fibril_mutex_initialize(&vuhid_data.iface_count_mutex);
     160        fibril_condvar_initialize(&vuhid_data.iface_count_cv);
    153161
    154162        /* Determine which interfaces to initialize. */
     
    182190        printf("Connected to VHCD...\n");
    183191
    184         while (true) {
    185                 async_usleep(10 * 1000 * 1000);
    186         }
     192        wait_for_interfaces_death(&hid_dev);
    187193       
    188194        printf("Terminating...\n");
  • uspace/app/vuhid/virthid.h

    r30f9f8f r9a884ed  
    3838#include <usb/usb.h>
    3939#include <usbvirt/device.h>
     40#include <fibril_synch.h>
    4041
    4142#define VUHID_ENDPOINT_MAX USB11_ENDPOINT_MAX
     
    4344
    4445typedef struct vuhid_interface vuhid_interface_t;
     46
     47typedef struct {
     48        vuhid_interface_t *in_endpoints_mapping[VUHID_ENDPOINT_MAX];
     49        size_t in_endpoint_first_free;
     50        vuhid_interface_t *out_endpoints_mapping[VUHID_ENDPOINT_MAX];
     51        size_t out_endpoint_first_free;
     52        vuhid_interface_t *interface_mapping[VUHID_INTERFACE_MAX];
     53
     54        fibril_mutex_t iface_count_mutex;
     55        fibril_condvar_t iface_count_cv;
     56        size_t iface_count;
     57        size_t iface_died_count;
     58} vuhid_data_t;
    4559
    4660struct vuhid_interface {
     
    6377
    6478        void *interface_data;
     79
     80        vuhid_data_t *vuhid_data;
    6581};
    66 
    67 typedef struct {
    68         vuhid_interface_t *in_endpoints_mapping[VUHID_ENDPOINT_MAX];
    69         size_t in_endpoint_first_free;
    70         vuhid_interface_t *out_endpoints_mapping[VUHID_ENDPOINT_MAX];
    71         size_t out_endpoint_first_free;
    72         vuhid_interface_t *interface_mapping[VUHID_INTERFACE_MAX];
    73 } vuhid_data_t;
    7482
    7583typedef struct {
     
    8492
    8593int add_interface_by_id(vuhid_interface_t **, const char *, usbvirt_device_t *);
     94void wait_for_interfaces_death(usbvirt_device_t *);
    8695
    8796#endif
Note: See TracChangeset for help on using the changeset viewer.