Changeset 4c03793 in mainline


Ignore:
Timestamp:
2018-01-19T22:17:23Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b5c92d7
Parents:
726af29
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-19 22:17:21)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-19 22:17:23)
Message:

libusbhost: fix resetting endpoints

Because apparently, I had no idea what I was doing.

File:
1 edited

Legend:

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

    r726af29 r4c03793  
    211211}
    212212
    213 /** How many toggles need to be reset */
    214 typedef enum {
    215         RESET_NONE,
    216         RESET_EP,
    217         RESET_ALL
    218 } toggle_reset_mode_t;
    219 
    220213/**
    221214 * Check setup packet data for signs of toggle reset.
    222215 *
    223216 * @param[in] batch USB batch
    224  */
    225 static toggle_reset_mode_t get_request_toggle_reset_mode(const usb_transfer_batch_t *batch)
     217 * @param[in] reset_cb Callback to reset an endpoint
     218 */
     219void hc_reset_toggles(const usb_transfer_batch_t *batch, endpoint_reset_toggle_t reset_cb)
    226220{
    227221        if (batch->ep->transfer_type != USB_TRANSFER_CONTROL
    228222            || batch->dir != USB_DIRECTION_OUT)
    229                 return RESET_NONE;
     223                return;
    230224
    231225        const usb_device_request_setup_packet_t *request = &batch->setup.packet;
     226        device_t * const dev = batch->ep->device;
    232227
    233228        switch (request->request)
     
    237232                /* 0x2 ( HOST to device | STANDART | TO ENPOINT) */
    238233                if ((request->request_type == 0x2) &&
    239                     (request->value == USB_FEATURE_ENDPOINT_HALT))
    240                         return RESET_EP;
     234                    (request->value == USB_FEATURE_ENDPOINT_HALT)) {
     235                        const unsigned index = uint16_usb2host(request->index);
     236                        const unsigned ep_num = index & 0xf;
     237                        const usb_direction_t dir = (index >> 7) ? USB_DIRECTION_IN : USB_DIRECTION_OUT;
     238
     239                        endpoint_t *ep = bus_find_endpoint(dev, ep_num, dir);
     240                        reset_cb(ep);
     241                }
    241242                break;
    242243        case USB_DEVREQ_SET_CONFIGURATION:
     
    248249                 * interface of an already setup device. */
    249250                if (!(request->request_type & SETUP_REQUEST_TYPE_DEVICE_TO_HOST))
    250                         return RESET_ALL;
     251                        for (usb_endpoint_t i = 0; i < 2 * USB_ENDPOINT_MAX; ++i)
     252                                if (dev->endpoints[i])
     253                                        reset_cb(dev->endpoints[i]);
    251254                break;
    252255        default:
    253256                break;
    254257        }
    255 
    256         return RESET_NONE;
    257 }
    258 
    259 void hc_reset_toggles(const usb_transfer_batch_t *batch, endpoint_reset_toggle_t reset_cb)
    260 {
    261         assert(reset_cb);
    262         assert(batch->ep);
    263         assert(batch->ep->device);
    264 
    265         if (batch->error != EOK)
    266                 return;
    267 
    268         toggle_reset_mode_t mode = get_request_toggle_reset_mode(batch);
    269 
    270         if (mode == RESET_NONE)
    271                 return;
    272 
    273         if (mode == RESET_ALL) {
    274                 const device_t *dev = batch->ep->device;
    275                 for (usb_endpoint_t i = 0; i < 2 * USB_ENDPOINT_MAX; ++i) {
    276                         if (dev->endpoints[i])
    277                                 reset_cb(dev->endpoints[i]);
    278                 }
    279         } else {
    280                 reset_cb(batch->ep);
    281         }
    282258}
    283259
Note: See TracChangeset for help on using the changeset viewer.