Changes in uspace/lib/usb/src/host/device_keeper.c [c4e3b1f7:ba038f4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/host/device_keeper.c
rc4e3b1f7 rba038f4 48 48 { 49 49 assert(instance); 50 fibril_mutex_initialize(&instance->guard); 51 fibril_condvar_initialize(&instance->change); 52 instance->last_address = 0; 50 53 unsigned i = 0; 51 54 for (; i < USB_ADDRESS_COUNT; ++i) { … … 57 60 // (it is needed to allow smooth registration at default address) 58 61 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 */ 69 void 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 */ 87 void 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 /*----------------------------------------------------------------------------*/ 62 96 /*----------------------------------------------------------------------------*/ 63 97 /** Get a free USB address … … 86 120 assert(new_address != USB_ADDRESS_DEFAULT); 87 121 assert(instance->devices[new_address].occupied == false); 88 89 122 instance->devices[new_address].occupied = true; 90 123 instance->devices[new_address].speed = speed; 91 124 instance->last_address = new_address; 92 93 125 fibril_mutex_unlock(&instance->guard); 94 126 return new_address; … … 106 138 assert(instance); 107 139 fibril_mutex_lock(&instance->guard); 108 109 140 assert(address > 0); 110 141 assert(address <= USB11_ADDRESS_MAX); 111 142 assert(instance->devices[address].occupied); 112 113 143 instance->devices[address].handle = handle; 114 144 fibril_mutex_unlock(&instance->guard); … … 129 159 fibril_mutex_lock(&instance->guard); 130 160 assert(instance->devices[address].occupied); 131 132 161 instance->devices[address].occupied = false; 133 162 fibril_mutex_unlock(&instance->guard); … … 148 177 while (address <= USB11_ADDRESS_MAX) { 149 178 if (instance->devices[address].handle == handle) { 150 assert(instance->devices[address].occupied);151 179 fibril_mutex_unlock(&instance->guard); 152 180 return address; … … 170 198 assert(address >= 0); 171 199 assert(address <= USB11_ADDRESS_MAX); 172 173 200 return instance->devices[address].speed; 174 201 }
Note:
See TracChangeset
for help on using the changeset viewer.