Changeset 434ef65 in mainline for uspace/lib/usb/src


Ignore:
Timestamp:
2011-03-21T16:54:36Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
41ef5b9, ce794342
Parents:
5287502 (diff), 625f1ba (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Small improvements of libusb

Below is a summary of changes

  • added usb_str_speed() function for nicer outputs
  • USB framework remembers configuration descriptor
  • some refactoring (hub driver, messages of transfer batch API)
Location:
uspace/lib/usb/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/devdrv.c

    r5287502 r434ef65  
    137137        }
    138138
    139         void *config_descriptor;
    140         size_t config_descriptor_size;
    141         rc = usb_request_get_full_configuration_descriptor_alloc(
    142             &dev->ctrl_pipe, 0, &config_descriptor, &config_descriptor_size);
    143         if (rc != EOK) {
    144                 usb_log_error("Failed retrieving configuration of `%s': %s.\n",
    145                     dev->ddf_dev->name, str_error(rc));
    146                 goto rollback;
    147         }
    148 
    149         rc = usb_pipe_initialize_from_configuration(dev->pipes,
    150            pipe_count, config_descriptor, config_descriptor_size, &dev->wire);
     139        rc = usb_pipe_initialize_from_configuration(dev->pipes, pipe_count,
     140            dev->descriptors.configuration, dev->descriptors.configuration_size,
     141            &dev->wire);
    151142        if (rc != EOK) {
    152143                usb_log_error("Failed initializing USB endpoints: %s.\n",
     
    237228
    238229        /*
    239          * Initialization of other pipes requires open session on
    240          * default control pipe.
     230         * For further actions, we need open session on default control pipe.
    241231         */
    242232        rc = usb_pipe_start_session(&dev->ctrl_pipe);
     
    247237        }
    248238
     239        /* Get the device descriptor. */
     240        rc = usb_request_get_device_descriptor(&dev->ctrl_pipe,
     241            &dev->descriptors.device);
     242        if (rc != EOK) {
     243                usb_log_error("Failed to retrieve device descriptor: %s.\n",
     244                    str_error(rc));
     245                return rc;
     246        }
     247
     248        /* Get the full configuration descriptor. */
     249        rc = usb_request_get_full_configuration_descriptor_alloc(
     250            &dev->ctrl_pipe, 0, (void **) &dev->descriptors.configuration,
     251            &dev->descriptors.configuration_size);
     252        if (rc != EOK) {
     253                usb_log_error("Failed retrieving configuration descriptor: %s.\n",
     254                    dev->ddf_dev->name, str_error(rc));
     255                return rc;
     256        }
     257
    249258        if (driver->endpoints != NULL) {
    250259                rc = initialize_other_pipes(driver, dev);
     
    253262        /* No checking here. */
    254263        usb_pipe_end_session(&dev->ctrl_pipe);
     264
     265        /* Rollback actions. */
     266        if (rc != EOK) {
     267                if (dev->descriptors.configuration != NULL) {
     268                        free(dev->descriptors.configuration);
     269                }
     270        }
    255271
    256272        return rc;
     
    283299        dev->ddf_dev->driver_data = dev;
    284300        dev->driver_data = NULL;
     301        dev->descriptors.configuration = NULL;
    285302
    286303        rc = initialize_pipes(dev);
  • uspace/lib/usb/src/host/batch.c

    r5287502 r434ef65  
    107107            instance->buffer_size);
    108108
    109         int err = instance->error;
    110         usb_log_debug("Batch(%p) callback IN(type:%d): %s(%d), %zu.\n",
    111             instance, instance->transfer_type, str_error(err), err,
    112             instance->transfered_size);
     109        usb_log_debug("Batch %p done (T%d.%d, %s %s in, %zuB): %s (%d).\n",
     110            instance,
     111            instance->target.address, instance->target.endpoint,
     112            usb_str_speed(instance->speed),
     113            usb_str_transfer_type_short(instance->transfer_type),
     114            instance->transfered_size,
     115            str_error(instance->error), instance->error);
    113116
    114         instance->callback_in(
    115             instance->fun, err, instance->transfered_size, instance->arg);
     117        instance->callback_in(instance->fun, instance->error,
     118            instance->transfered_size, instance->arg);
    116119}
    117120/*----------------------------------------------------------------------------*/
     
    125128        assert(instance->callback_out);
    126129
    127         int err = instance->error;
    128         usb_log_debug("Batch(%p) callback OUT(type:%d): %s(%d).\n",
    129             instance, instance->transfer_type, str_error(err), err);
     130        usb_log_debug("Batch %p done (T%d.%d, %s %s out): %s (%d).\n",
     131            instance,
     132            instance->target.address, instance->target.endpoint,
     133            usb_str_speed(instance->speed),
     134            usb_str_transfer_type_short(instance->transfer_type),
     135            str_error(instance->error), instance->error);
     136
    130137        instance->callback_out(instance->fun,
    131             err, instance->arg);
     138            instance->error, instance->arg);
    132139}
    133140/**
  • uspace/lib/usb/src/usb.c

    r5287502 r434ef65  
    3636#include <errno.h>
    3737
     38#define ARR_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
     39
     40static const char *str_speed[] = {
     41        "low",
     42        "full",
     43        "high"
     44};
     45
     46static const char *str_transfer_type[] = {
     47        "control",
     48        "isochronous",
     49        "bulk",
     50        "interrupt"
     51};
     52
     53static const char *str_transfer_type_short[] = {
     54        "ctrl",
     55        "iso",
     56        "bulk",
     57        "intr"
     58};
    3859
    3960/** String representation for USB transfer type.
     
    4263 * @return Transfer type as a string (in English).
    4364 */
    44 const char * usb_str_transfer_type(usb_transfer_type_t t)
     65const char *usb_str_transfer_type(usb_transfer_type_t t)
    4566{
    46         switch (t) {
    47                 case USB_TRANSFER_ISOCHRONOUS:
    48                         return "isochronous";
    49                 case USB_TRANSFER_INTERRUPT:
    50                         return "interrupt";
    51                 case USB_TRANSFER_CONTROL:
    52                         return "control";
    53                 case USB_TRANSFER_BULK:
    54                         return "bulk";
    55                 default:
    56                         return "unknown";
     67        if (t >= ARR_SIZE(str_transfer_type)) {
     68                return "invalid";
    5769        }
     70        return str_transfer_type[t];
     71}
     72
     73/** String representation for USB transfer type (short version).
     74 *
     75 * @param t Transfer type.
     76 * @return Transfer type as a short string for debugging messages.
     77 */
     78const char *usb_str_transfer_type_short(usb_transfer_type_t t)
     79{
     80        if (t >= ARR_SIZE(str_transfer_type_short)) {
     81                return "invl";
     82        }
     83        return str_transfer_type_short[t];
     84}
     85
     86/** String representation of USB speed.
     87 *
     88 * @param s The speed.
     89 * @return USB speed as a string (in English).
     90 */
     91const char *usb_str_speed(usb_speed_t s)
     92{
     93        if (s >= ARR_SIZE(str_speed)) {
     94                return "invalid";
     95        }
     96        return str_speed[s];
    5897}
    5998
Note: See TracChangeset for help on using the changeset viewer.