Changeset d2fc1c2 in mainline for uspace/drv/uhci-hcd/utils/device_keeper.c
- Timestamp:
- 2011-03-08T18:18:05Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 48d2765, 8e9becf6
- Parents:
- d477734 (diff), a8e98498 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/utils/device_keeper.c
rd477734 rd2fc1c2 39 39 40 40 /*----------------------------------------------------------------------------*/ 41 /** Initializes device keeper structure. 42 * 43 * @param[in] instance Memory place to initialize. 44 */ 41 45 void device_keeper_init(device_keeper_t *instance) 42 46 { … … 49 53 instance->devices[i].occupied = false; 50 54 instance->devices[i].handle = 0; 51 } 52 } 53 /*----------------------------------------------------------------------------*/ 54 void device_keeper_reserve_default( 55 device_keeper_t *instance, usb_speed_t speed) 55 instance->devices[i].toggle_status = 0; 56 } 57 } 58 /*----------------------------------------------------------------------------*/ 59 /** Attempts to obtain address 0, blocks. 60 * 61 * @param[in] instance Device keeper structure to use. 62 * @param[in] speed Speed of the device requesting default address. 63 */ 64 void device_keeper_reserve_default(device_keeper_t *instance, usb_speed_t speed) 56 65 { 57 66 assert(instance); … … 66 75 } 67 76 /*----------------------------------------------------------------------------*/ 77 /** Attempts to obtain address 0, blocks. 78 * 79 * @param[in] instance Device keeper structure to use. 80 * @param[in] speed Speed of the device requesting default address. 81 */ 68 82 void device_keeper_release_default(device_keeper_t *instance) 69 83 { … … 75 89 } 76 90 /*----------------------------------------------------------------------------*/ 91 /** Checks setup data for signs of toggle reset. 92 * 93 * @param[in] instance Device keeper structure to use. 94 * @param[in] target Device to receive setup packet. 95 * @param[in] data Setup packet data. 96 */ 97 void device_keeper_reset_if_need( 98 device_keeper_t *instance, usb_target_t target, const unsigned char *data) 99 { 100 assert(instance); 101 fibril_mutex_lock(&instance->guard); 102 if (target.endpoint > 15 || target.endpoint < 0 103 || target.address >= USB_ADDRESS_COUNT || target.address < 0 104 || !instance->devices[target.address].occupied) { 105 fibril_mutex_unlock(&instance->guard); 106 return; 107 } 108 109 switch (data[1]) 110 { 111 case 0x01: /*clear feature*/ 112 /* recipient is endpoint, value is zero (ENDPOINT_STALL) */ 113 if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) { 114 /* endpoint number is < 16, thus first byte is enough */ 115 instance->devices[target.address].toggle_status &= 116 ~(1 << data[4]); 117 } 118 break; 119 120 case 0x9: /* set configuration */ 121 case 0x11: /* set interface */ 122 instance->devices[target.address].toggle_status = 0; 123 break; 124 } 125 fibril_mutex_unlock(&instance->guard); 126 } 127 /*----------------------------------------------------------------------------*/ 128 /** Gets current value of endpoint toggle. 129 * 130 * @param[in] instance Device keeper structure to use. 131 * @param[in] target Device and endpoint used. 132 * @return Error code 133 */ 134 int device_keeper_get_toggle(device_keeper_t *instance, usb_target_t target) 135 { 136 assert(instance); 137 int ret; 138 fibril_mutex_lock(&instance->guard); 139 if (target.endpoint > 15 || target.endpoint < 0 140 || target.address >= USB_ADDRESS_COUNT || target.address < 0 141 || !instance->devices[target.address].occupied) { 142 ret = EINVAL; 143 } else { 144 ret = 145 (instance->devices[target.address].toggle_status 146 >> target.endpoint) & 1; 147 } 148 fibril_mutex_unlock(&instance->guard); 149 return ret; 150 } 151 /*----------------------------------------------------------------------------*/ 152 /** Sets current value of endpoint toggle. 153 * 154 * @param[in] instance Device keeper structure to use. 155 * @param[in] target Device and endpoint used. 156 * @param[in] toggle Current toggle value. 157 * @return Error code. 158 */ 159 int device_keeper_set_toggle( 160 device_keeper_t *instance, usb_target_t target, bool toggle) 161 { 162 assert(instance); 163 int ret; 164 fibril_mutex_lock(&instance->guard); 165 if (target.endpoint > 15 || target.endpoint < 0 166 || target.address >= USB_ADDRESS_COUNT || target.address < 0 167 || !instance->devices[target.address].occupied) { 168 ret = EINVAL; 169 } else { 170 if (toggle) { 171 instance->devices[target.address].toggle_status |= (1 << target.endpoint); 172 } else { 173 instance->devices[target.address].toggle_status &= ~(1 << target.endpoint); 174 } 175 ret = EOK; 176 } 177 fibril_mutex_unlock(&instance->guard); 178 return ret; 179 } 180 /*----------------------------------------------------------------------------*/ 181 /** Gets a free USB address 182 * 183 * @param[in] instance Device keeper structure to use. 184 * @param[in] speed Speed of the device requiring address. 185 * @return Free address, or error code. 186 */ 77 187 usb_address_t device_keeper_request( 78 188 device_keeper_t *instance, usb_speed_t speed) … … 96 206 instance->devices[new_address].occupied = true; 97 207 instance->devices[new_address].speed = speed; 208 instance->devices[new_address].toggle_status = 0; 98 209 instance->last_address = new_address; 99 210 fibril_mutex_unlock(&instance->guard); … … 101 212 } 102 213 /*----------------------------------------------------------------------------*/ 214 /** Binds USB address to devman handle. 215 * 216 * @param[in] instance Device keeper structure to use. 217 * @param[in] address Device address 218 * @param[in] handle Devman handle of the device. 219 */ 103 220 void device_keeper_bind( 104 221 device_keeper_t *instance, usb_address_t address, devman_handle_t handle) … … 113 230 } 114 231 /*----------------------------------------------------------------------------*/ 232 /** Releases used USB address. 233 * 234 * @param[in] instance Device keeper structure to use. 235 * @param[in] address Device address 236 */ 115 237 void device_keeper_release(device_keeper_t *instance, usb_address_t address) 116 238 { … … 125 247 } 126 248 /*----------------------------------------------------------------------------*/ 249 /** Finds USB address associated with the device 250 * 251 * @param[in] instance Device keeper structure to use. 252 * @param[in] handle Devman handle of the device seeking its address. 253 * @return USB Address, or error code. 254 */ 127 255 usb_address_t device_keeper_find( 128 256 device_keeper_t *instance, devman_handle_t handle) … … 142 270 } 143 271 /*----------------------------------------------------------------------------*/ 272 /** Gets speed associated with the address 273 * 274 * @param[in] instance Device keeper structure to use. 275 * @param[in] address Address of the device. 276 * @return USB speed. 277 */ 144 278 usb_speed_t device_keeper_speed( 145 279 device_keeper_t *instance, usb_address_t address)
Note:
See TracChangeset
for help on using the changeset viewer.