Ignore:
Timestamp:
2012-12-22T23:20:45Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3c4663e
Parents:
a6a9910
Message:

libusbhost: Use callback wrapper for toggle handling.

File:
1 edited

Legend:

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

    ra6a9910 r1affef2f  
    168168}
    169169
    170 /** Check setup packet data for signs of toggle reset.
    171  *
    172  * @param[in] instance usb_endpoint_manager structure, non-null.
    173  * @param[in] target Device to receive setup packet.
    174  * @param[in] data Setup packet data.
    175  *
    176  * Really ugly one. Resets toggle bit on all endpoints that need it.
    177  * @TODO Use tools from libusbdev requests.h
    178  */
    179 void usb_endpoint_manager_reset_eps_if_need(usb_endpoint_manager_t *instance,
    180     usb_target_t target, const uint8_t data[8])
    181 {
    182         assert(instance);
    183         if (!usb_target_is_valid(target)) {
    184                 usb_log_error("Invalid data when checking for toggle reset.\n");
    185                 return;
    186         }
    187 
    188         assert(data);
    189         switch (data[1])
    190         {
    191         case 0x01: /* Clear Feature -- resets only cleared ep */
    192                 /* Recipient is endpoint, value is zero (ENDPOINT_STALL) */
    193                 // TODO Use macros in libusbdev requests.h
    194                 if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) {
    195                         fibril_mutex_lock(&instance->guard);
    196                         /* endpoint number is < 16, thus first byte is enough */
    197                         list_foreach(*get_list(instance, target.address), it) {
    198                                 endpoint_t *ep = endpoint_get_instance(it);
    199                                 if ((ep->address == target.address)
    200                                     && (ep->endpoint = data[4])) {
    201                                         endpoint_toggle_set(ep,0);
    202                                 }
    203                         }
    204                         fibril_mutex_unlock(&instance->guard);
    205                 }
    206         break;
    207 
    208         case 0x9: /* Set Configuration */
    209         case 0x11: /* Set Interface */
    210                 /* Recipient must be device, this resets all endpoints,
    211                  * In fact there should be no endpoints but EP 0 registered
    212                  * as different interfaces use different endpoints,
    213                  * unless you're changing configuration or alternative
    214                  * interface of an already setup device. */
    215                 if ((data[0] & 0xf) == 0) {
    216                         fibril_mutex_lock(&instance->guard);
    217                         list_foreach(*get_list(instance, target.address), it) {
    218                                 endpoint_t *ep = endpoint_get_instance(it);
    219                                 if (ep->address == target.address) {
    220                                         endpoint_toggle_set(ep,0);
    221                                 }
    222                         }
    223                         fibril_mutex_unlock(&instance->guard);
    224                 }
    225         break;
    226         }
    227 }
    228 
    229170/** Register endpoint structure.
    230171 * Checks for duplicates.
Note: See TracChangeset for help on using the changeset viewer.