Changeset 4267908 in mainline for uspace/lib/usbhost/src/usb_device_manager.c
- Timestamp:
- 2011-10-27T10:45:08Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 83c3123
- Parents:
- 069b80d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/usb_device_manager.c
r069b80d r4267908 38 38 #include <usb/host/usb_device_manager.h> 39 39 40 /*----------------------------------------------------------------------------*/41 40 /** Initialize device manager structure. 42 41 * … … 77 76 ++new_address; 78 77 if (new_address > USB11_ADDRESS_MAX) 79 new_address = 1; 78 new_address = 1; // NOTE it should be safe to put 0 here 79 // TODO Use mod 80 80 if (new_address == instance->last_address) { 81 81 fibril_mutex_unlock(&instance->guard); … … 86 86 assert(new_address != USB_ADDRESS_DEFAULT); 87 87 assert(instance->devices[new_address].occupied == false); 88 assert(instance->devices[new_address].handle == 0); 88 89 89 90 instance->devices[new_address].occupied = true; … … 131 132 132 133 instance->devices[address].occupied = false; 134 instance->devices[address].handle = 0; 133 135 fibril_mutex_unlock(&instance->guard); 134 136 } … … 140 142 * @return USB Address, or error code. 141 143 */ 142 usb_address_t usb_device_manager_find (144 usb_address_t usb_device_manager_find_address( 143 145 usb_device_manager_t *instance, devman_handle_t handle) 144 146 { … … 157 159 return ENOENT; 158 160 } 159 160 /** Find devman handle a ssigned to USB address.161 * Intentionally refuse to find handle ofdefault address.161 /*----------------------------------------------------------------------------*/ 162 /** Find devman handle and speed assigned to USB address. 163 * Intentionally refuse to work on default address. 162 164 * 163 165 * @param[in] instance Device manager structure to use. 164 166 * @param[in] address Address the caller wants to find. 165 167 * @param[out] handle Where to store found handle. 166 * @return Whether such address is currently occupied. 168 * @param[out] speed Assigned speed. 169 * @return Error code. 167 170 */ 168 bool usb_device_manager_find_by_address(usb_device_manager_t *instance,169 usb_address_t address, devman_handle_t *handle )171 int usb_device_manager_get_info_by_address(usb_device_manager_t *instance, 172 usb_address_t address, devman_handle_t *handle, usb_speed_t *speed) 170 173 { 171 174 assert(instance); 175 if ((address <= 0) || (address >= USB_ADDRESS_COUNT)) { 176 return EINVAL; 177 } 178 172 179 fibril_mutex_lock(&instance->guard); 173 if ((address <= 0) || (address >= USB_ADDRESS_COUNT)) {174 fibril_mutex_unlock(&instance->guard);175 return false;176 }177 180 if (!instance->devices[address].occupied) { 178 181 fibril_mutex_unlock(&instance->guard); 179 return false;182 return ENOENT; 180 183 } 181 184 … … 183 186 *handle = instance->devices[address].handle; 184 187 } 188 if (speed != NULL) { 189 *speed = instance->devices[address].speed; 190 } 185 191 186 192 fibril_mutex_unlock(&instance->guard); 187 return true; 188 } 189 190 /*----------------------------------------------------------------------------*/ 191 /** Get speed associated with the address 192 * 193 * @param[in] instance Device manager structure to use. 194 * @param[in] address Address of the device. 195 * @return USB speed. 196 */ 197 usb_speed_t usb_device_manager_get_speed( 198 usb_device_manager_t *instance, usb_address_t address) 199 { 200 assert(instance); 201 assert(address >= 0); 202 assert(address <= USB11_ADDRESS_MAX); 203 204 return instance->devices[address].speed; 193 return EOK; 205 194 } 206 195 /**
Note:
See TracChangeset
for help on using the changeset viewer.