Ignore:
Timestamp:
2011-03-06T19:01:09Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
960bee9, c867a216
Parents:
24d5432 (diff), 8a20380 (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:

Fix toggle protocol implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/utils/device_keeper.c

    r24d5432 rd4beec3  
    4949                instance->devices[i].occupied = false;
    5050                instance->devices[i].handle = 0;
     51                instance->devices[i].toggle_status = 0;
    5152        }
    5253}
     
    7374        fibril_mutex_unlock(&instance->guard);
    7475        fibril_condvar_signal(&instance->default_address_occupied);
     76}
     77/*----------------------------------------------------------------------------*/
     78void device_keeper_reset_if_need(
     79    device_keeper_t *instance, usb_target_t target, const unsigned char *data)
     80{
     81        assert(instance);
     82        fibril_mutex_lock(&instance->guard);
     83        if (target.endpoint > 15 || target.endpoint < 0
     84            || target.address >= USB_ADDRESS_COUNT || target.address < 0
     85            || !instance->devices[target.address].occupied) {
     86                goto the_end;
     87        }
     88
     89        switch (data[1])
     90        {
     91        case 0x01: /*clear feature*/
     92                /* recipient is enpoint, value is zero (ENDPOINT_STALL) */
     93                if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) {
     94                        /* enpoint number is < 16, thus first byte is enough */
     95                        instance->devices[target.address].toggle_status &= ~(1 << data[4]);
     96                }
     97        break;
     98
     99        case 0x9: /* set configuration */
     100        case 0x11: /* set interface */
     101                instance->devices[target.address].toggle_status = 0;
     102        break;
     103        }
     104the_end:
     105        fibril_mutex_unlock(&instance->guard);
     106}
     107/*----------------------------------------------------------------------------*/
     108int device_keeper_get_toggle(device_keeper_t *instance, usb_target_t target)
     109{
     110        assert(instance);
     111        int ret;
     112        fibril_mutex_lock(&instance->guard);
     113        if (target.endpoint > 15 || target.endpoint < 0
     114            || target.address >= USB_ADDRESS_COUNT || target.address < 0
     115            || !instance->devices[target.address].occupied) {
     116                ret = EINVAL;
     117        } else {
     118                ret = (instance->devices[target.address].toggle_status >> target.endpoint) & 1;
     119        }
     120        fibril_mutex_unlock(&instance->guard);
     121        return ret;
     122}
     123/*----------------------------------------------------------------------------*/
     124int device_keeper_set_toggle(
     125    device_keeper_t *instance, usb_target_t target, bool toggle)
     126{
     127        assert(instance);
     128        int ret;
     129        fibril_mutex_lock(&instance->guard);
     130        if (target.endpoint > 15 || target.endpoint < 0
     131            || target.address >= USB_ADDRESS_COUNT || target.address < 0
     132            || !instance->devices[target.address].occupied) {
     133                ret = EINVAL;
     134        } else {
     135                if (toggle) {
     136                        instance->devices[target.address].toggle_status |= (1 << target.endpoint);
     137                } else {
     138                        instance->devices[target.address].toggle_status &= ~(1 << target.endpoint);
     139                }
     140                ret = EOK;
     141        }
     142        fibril_mutex_unlock(&instance->guard);
     143        return ret;
    75144}
    76145/*----------------------------------------------------------------------------*/
     
    96165        instance->devices[new_address].occupied = true;
    97166        instance->devices[new_address].speed = speed;
     167        instance->devices[new_address].toggle_status = 0;
    98168        instance->last_address = new_address;
    99169        fibril_mutex_unlock(&instance->guard);
Note: See TracChangeset for help on using the changeset viewer.