Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/host/device_keeper.c

    rc4e3b1f7 rba038f4  
    4848{
    4949        assert(instance);
     50        fibril_mutex_initialize(&instance->guard);
     51        fibril_condvar_initialize(&instance->change);
     52        instance->last_address = 0;
    5053        unsigned i = 0;
    5154        for (; i < USB_ADDRESS_COUNT; ++i) {
     
    5760        // (it is needed to allow smooth registration at default address)
    5861        instance->devices[0].occupied = true;
    59         instance->last_address = 0;
    60         fibril_mutex_initialize(&instance->guard);
    61 }
     62}
     63/*----------------------------------------------------------------------------*/
     64/** Attempt to obtain address 0, blocks.
     65 *
     66 * @param[in] instance Device keeper structure to use.
     67 * @param[in] speed Speed of the device requesting default address.
     68 */
     69void usb_device_keeper_reserve_default_address(
     70    usb_device_keeper_t *instance, usb_speed_t speed)
     71{
     72        assert(instance);
     73        fibril_mutex_lock(&instance->guard);
     74        while (instance->devices[USB_ADDRESS_DEFAULT].occupied) {
     75                fibril_condvar_wait(&instance->change, &instance->guard);
     76        }
     77        instance->devices[USB_ADDRESS_DEFAULT].occupied = true;
     78        instance->devices[USB_ADDRESS_DEFAULT].speed = speed;
     79        fibril_mutex_unlock(&instance->guard);
     80}
     81/*----------------------------------------------------------------------------*/
     82/** Attempt to obtain address 0, blocks.
     83 *
     84 * @param[in] instance Device keeper structure to use.
     85 * @param[in] speed Speed of the device requesting default address.
     86 */
     87void usb_device_keeper_release_default_address(usb_device_keeper_t *instance)
     88{
     89        assert(instance);
     90        fibril_mutex_lock(&instance->guard);
     91        instance->devices[USB_ADDRESS_DEFAULT].occupied = false;
     92        fibril_mutex_unlock(&instance->guard);
     93        fibril_condvar_signal(&instance->change);
     94}
     95/*----------------------------------------------------------------------------*/
    6296/*----------------------------------------------------------------------------*/
    6397/** Get a free USB address
     
    86120        assert(new_address != USB_ADDRESS_DEFAULT);
    87121        assert(instance->devices[new_address].occupied == false);
    88 
    89122        instance->devices[new_address].occupied = true;
    90123        instance->devices[new_address].speed = speed;
    91124        instance->last_address = new_address;
    92 
    93125        fibril_mutex_unlock(&instance->guard);
    94126        return new_address;
     
    106138        assert(instance);
    107139        fibril_mutex_lock(&instance->guard);
    108 
    109140        assert(address > 0);
    110141        assert(address <= USB11_ADDRESS_MAX);
    111142        assert(instance->devices[address].occupied);
    112 
    113143        instance->devices[address].handle = handle;
    114144        fibril_mutex_unlock(&instance->guard);
     
    129159        fibril_mutex_lock(&instance->guard);
    130160        assert(instance->devices[address].occupied);
    131 
    132161        instance->devices[address].occupied = false;
    133162        fibril_mutex_unlock(&instance->guard);
     
    148177        while (address <= USB11_ADDRESS_MAX) {
    149178                if (instance->devices[address].handle == handle) {
    150                         assert(instance->devices[address].occupied);
    151179                        fibril_mutex_unlock(&instance->guard);
    152180                        return address;
     
    170198        assert(address >= 0);
    171199        assert(address <= USB11_ADDRESS_MAX);
    172 
    173200        return instance->devices[address].speed;
    174201}
Note: See TracChangeset for help on using the changeset viewer.