Changeset 1ed3eb4 in mainline for uspace/lib/usbhost/src/bus.c


Ignore:
Timestamp:
2018-01-13T19:13:04Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2489353
Parents:
001778c
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-13 19:12:34)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-13 19:13:04)
Message:

usbhost: endpoint is identified also by its direction

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/bus.c

    r001778c r1ed3eb4  
    307307err:
    308308        return rc;
     309}
     310
     311/**
     312 * Calculate an index to the endpoint array.
     313 * For the default control endpoint 0, it must return 0.
     314 * For different arguments, the result is stable but not defined.
     315 */
     316static int bus_endpoint_index(usb_endpoint_t ep, usb_direction_t dir)
     317{
     318        return 2 * ep + (dir == USB_DIRECTION_OUT);
    309319}
    310320
     
    357367            ep->max_transfer_size);
    358368
     369        const int idx = bus_endpoint_index(ep->endpoint, ep->direction);
     370
    359371        fibril_mutex_lock(&device->guard);
    360372        if (!device->online && ep->endpoint != 0) {
    361373                err = EAGAIN;
    362         } else if (device->endpoints[ep->endpoint] != NULL) {
     374        } else if (device->endpoints[idx] != NULL) {
    363375                err = EEXIST;
    364376        } else {
    365377                err = register_ops->endpoint_register(ep);
    366378                if (!err)
    367                         device->endpoints[ep->endpoint] = ep;
     379                        device->endpoints[idx] = ep;
    368380        }
    369381        fibril_mutex_unlock(&device->guard);
     
    385397 * Search for an endpoint. Returns a reference.
    386398 */
    387 endpoint_t *bus_find_endpoint(device_t *device, usb_endpoint_t endpoint)
     399endpoint_t *bus_find_endpoint(device_t *device, usb_endpoint_t endpoint, usb_direction_t dir)
    388400{
    389401        assert(device);
    390402
     403        const int idx = bus_endpoint_index(endpoint, dir);
     404        const int ctrl_idx = bus_endpoint_index(endpoint, USB_DIRECTION_BOTH);
     405
    391406        fibril_mutex_lock(&device->guard);
    392         endpoint_t *ep = device->endpoints[endpoint];
     407        endpoint_t *ep = device->endpoints[idx];
     408        /*
     409         * If the endpoint was not found, it's still possible it is a control
     410         * endpoint having direction BOTH.
     411         */
     412        if (!ep) {
     413                ep = device->endpoints[ctrl_idx];
     414                if (ep && ep->transfer_type != USB_TRANSFER_CONTROL)
     415                        ep = NULL;
     416        }
    393417        if (ep) {
    394418                /* Exporting reference */
     
    423447            ep->max_transfer_size);
    424448
     449        const int idx = bus_endpoint_index(ep->endpoint, ep->direction);
     450
    425451        fibril_mutex_lock(&device->guard);
    426452        ops->endpoint_unregister(ep);
    427         device->endpoints[ep->endpoint] = NULL;
     453        device->endpoints[idx] = NULL;
    428454        fibril_mutex_unlock(&device->guard);
    429455
     
    489515
    490516        /* Temporary reference */
    491         endpoint_t *ep = bus_find_endpoint(device, target.endpoint);
     517        endpoint_t *ep = bus_find_endpoint(device, target.endpoint, direction);
    492518        if (ep == NULL) {
    493519                usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
Note: See TracChangeset for help on using the changeset viewer.