Changeset 2fd1f0c6 in mainline
- Timestamp:
- 2011-10-29T11:36:54Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5400606
- Parents:
- 57e06ef
- Location:
- uspace/lib/usbhost
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/usb_device_manager.h
r57e06ef r2fd1f0c6 69 69 usb_device_manager_t *instance, usb_speed_t speed); 70 70 71 voidusb_device_manager_bind(usb_device_manager_t *instance,71 int usb_device_manager_bind(usb_device_manager_t *instance, 72 72 usb_address_t address, devman_handle_t handle); 73 73 74 voidusb_device_manager_release(usb_device_manager_t *instance,74 int usb_device_manager_release(usb_device_manager_t *instance, 75 75 usb_address_t address); 76 76 -
uspace/lib/usbhost/src/iface.c
r57e06ef r2fd1f0c6 128 128 129 129 usb_log_debug("Address bind %d-%" PRIun ".\n", address, handle); 130 usb_device_manager_bind(&hcd->dev_manager, address, handle); 131 return EOK; 130 return usb_device_manager_bind(&hcd->dev_manager, address, handle); 132 131 } 133 132 /*----------------------------------------------------------------------------*/ -
uspace/lib/usbhost/src/usb_device_manager.c
r57e06ef r2fd1f0c6 47 47 { 48 48 assert(instance); 49 unsigned i = 0; 50 for (; i < USB_ADDRESS_COUNT; ++i) { 49 for (unsigned i = 0; i < USB_ADDRESS_COUNT; ++i) { 51 50 instance->devices[i].occupied = false; 52 51 instance->devices[i].handle = 0; … … 101 100 * @param[in] address Device address 102 101 * @param[in] handle Devman handle of the device. 103 */ 104 void usb_device_manager_bind(usb_device_manager_t *instance, 102 * @return Error code. 103 */ 104 int usb_device_manager_bind(usb_device_manager_t *instance, 105 105 usb_address_t address, devman_handle_t handle) 106 106 { 107 assert(instance); 108 fibril_mutex_lock(&instance->guard); 109 110 assert(address > 0); 111 assert(address <= USB11_ADDRESS_MAX); 112 assert(instance->devices[address].occupied); 113 107 if ((address <= 0) || (address >= USB_ADDRESS_COUNT)) { 108 return EINVAL; 109 } 110 assert(instance); 111 112 fibril_mutex_lock(&instance->guard); 113 /* Not reserved */ 114 if (!instance->devices[address].occupied) { 115 fibril_mutex_unlock(&instance->guard); 116 return ENOENT; 117 } 118 /* Already bound */ 119 if (instance->devices[address].handle != 0) { 120 fibril_mutex_unlock(&instance->guard); 121 return EEXISTS; 122 } 114 123 instance->devices[address].handle = handle; 115 124 fibril_mutex_unlock(&instance->guard); 125 return EOK; 116 126 } 117 127 /*----------------------------------------------------------------------------*/ … … 120 130 * @param[in] instance Device manager structure to use. 121 131 * @param[in] address Device address 122 */ 123 void usb_device_manager_release( 132 * @return Error code. 133 */ 134 int usb_device_manager_release( 124 135 usb_device_manager_t *instance, usb_address_t address) 125 136 { 126 assert(instance); 127 assert(address > 0); 128 assert(address <= USB11_ADDRESS_MAX); 129 130 fibril_mutex_lock(&instance->guard); 131 assert(instance->devices[address].occupied); 137 if ((address <= 0) || (address >= USB_ADDRESS_COUNT)) { 138 return EINVAL; 139 } 140 assert(instance); 141 142 fibril_mutex_lock(&instance->guard); 143 if (!instance->devices[address].occupied) { 144 fibril_mutex_unlock(&instance->guard); 145 return ENOENT; 146 } 132 147 133 148 instance->devices[address].occupied = false; 134 149 instance->devices[address].handle = 0; 135 150 fibril_mutex_unlock(&instance->guard); 151 return EOK; 136 152 } 137 153 /*----------------------------------------------------------------------------*/ … … 147 163 assert(instance); 148 164 fibril_mutex_lock(&instance->guard); 149 usb_address_t address = 1;150 while (address <= USB11_ADDRESS_MAX){165 for (usb_address_t address = 1; address <= USB11_ADDRESS_MAX; ++address) 166 { 151 167 if (instance->devices[address].handle == handle) { 152 168 assert(instance->devices[address].occupied); … … 154 170 return address; 155 171 } 156 ++address;157 172 } 158 173 fibril_mutex_unlock(&instance->guard);
Note:
See TracChangeset
for help on using the changeset viewer.