Changeset 72af8da in mainline for uspace/drv/uhci-hcd/utils/device_keeper.c
- Timestamp:
- 2011-03-16T18:50:17Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 42a3a57
- Parents:
- 3e7b7cd (diff), fcf07e6 (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
r3e7b7cd r72af8da 27 27 */ 28 28 29 /** @addtogroup drvusbuhci 29 /** @addtogroup drvusbuhcihc 30 30 * @{ 31 31 */ … … 35 35 #include <assert.h> 36 36 #include <errno.h> 37 #include <usb/debug.h> 37 38 38 39 #include "device_keeper.h" 39 40 40 41 /*----------------------------------------------------------------------------*/ 42 /** Initialize device keeper structure. 43 * 44 * @param[in] instance Memory place to initialize. 45 * 46 * Set all values to false/0. 47 */ 41 48 void device_keeper_init(device_keeper_t *instance) 42 49 { … … 49 56 instance->devices[i].occupied = false; 50 57 instance->devices[i].handle = 0; 51 } 52 } 53 /*----------------------------------------------------------------------------*/ 54 void device_keeper_reserve_default( 55 device_keeper_t *instance, usb_speed_t speed) 58 instance->devices[i].toggle_status = 0; 59 } 60 } 61 /*----------------------------------------------------------------------------*/ 62 /** Attempt to obtain address 0, blocks. 63 * 64 * @param[in] instance Device keeper structure to use. 65 * @param[in] speed Speed of the device requesting default address. 66 */ 67 void device_keeper_reserve_default(device_keeper_t *instance, usb_speed_t speed) 56 68 { 57 69 assert(instance); … … 66 78 } 67 79 /*----------------------------------------------------------------------------*/ 80 /** Attempt to obtain address 0, blocks. 81 * 82 * @param[in] instance Device keeper structure to use. 83 * @param[in] speed Speed of the device requesting default address. 84 */ 68 85 void device_keeper_release_default(device_keeper_t *instance) 69 86 { … … 75 92 } 76 93 /*----------------------------------------------------------------------------*/ 94 /** Check setup packet data for signs of toggle reset. 95 * 96 * @param[in] instance Device keeper structure to use. 97 * @param[in] target Device to receive setup packet. 98 * @param[in] data Setup packet data. 99 * 100 * Really ugly one. 101 */ 102 void device_keeper_reset_if_need( 103 device_keeper_t *instance, usb_target_t target, const unsigned char *data) 104 { 105 assert(instance); 106 fibril_mutex_lock(&instance->guard); 107 if (target.endpoint > 15 || target.endpoint < 0 108 || target.address >= USB_ADDRESS_COUNT || target.address < 0 109 || !instance->devices[target.address].occupied) { 110 fibril_mutex_unlock(&instance->guard); 111 usb_log_error("Invalid data when checking for toggle reset.\n"); 112 return; 113 } 114 115 switch (data[1]) 116 { 117 case 0x01: /*clear feature*/ 118 /* recipient is endpoint, value is zero (ENDPOINT_STALL) */ 119 if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) { 120 /* endpoint number is < 16, thus first byte is enough */ 121 instance->devices[target.address].toggle_status &= 122 ~(1 << data[4]); 123 } 124 break; 125 126 case 0x9: /* set configuration */ 127 case 0x11: /* set interface */ 128 /* target must be device */ 129 if ((data[0] & 0xf) == 0) { 130 instance->devices[target.address].toggle_status = 0; 131 } 132 break; 133 } 134 fibril_mutex_unlock(&instance->guard); 135 } 136 /*----------------------------------------------------------------------------*/ 137 /** Get current value of endpoint toggle. 138 * 139 * @param[in] instance Device keeper structure to use. 140 * @param[in] target Device and endpoint used. 141 * @return Error code 142 */ 143 int device_keeper_get_toggle(device_keeper_t *instance, usb_target_t target) 144 { 145 assert(instance); 146 int ret; 147 fibril_mutex_lock(&instance->guard); 148 if (target.endpoint > 15 || target.endpoint < 0 149 || target.address >= USB_ADDRESS_COUNT || target.address < 0 150 || !instance->devices[target.address].occupied) { 151 usb_log_error("Invalid data when asking for toggle value.\n"); 152 ret = EINVAL; 153 } else { 154 ret = (instance->devices[target.address].toggle_status 155 >> target.endpoint) & 1; 156 } 157 fibril_mutex_unlock(&instance->guard); 158 return ret; 159 } 160 /*----------------------------------------------------------------------------*/ 161 /** Set current value of endpoint toggle. 162 * 163 * @param[in] instance Device keeper structure to use. 164 * @param[in] target Device and endpoint used. 165 * @param[in] toggle Toggle value. 166 * @return Error code. 167 */ 168 int device_keeper_set_toggle( 169 device_keeper_t *instance, usb_target_t target, bool toggle) 170 { 171 assert(instance); 172 int ret; 173 fibril_mutex_lock(&instance->guard); 174 if (target.endpoint > 15 || target.endpoint < 0 175 || target.address >= USB_ADDRESS_COUNT || target.address < 0 176 || !instance->devices[target.address].occupied) { 177 usb_log_error("Invalid data when setting toggle value.\n"); 178 ret = EINVAL; 179 } else { 180 if (toggle) { 181 instance->devices[target.address].toggle_status |= (1 << target.endpoint); 182 } else { 183 instance->devices[target.address].toggle_status &= ~(1 << target.endpoint); 184 } 185 ret = EOK; 186 } 187 fibril_mutex_unlock(&instance->guard); 188 return ret; 189 } 190 /*----------------------------------------------------------------------------*/ 191 /** Get a free USB address 192 * 193 * @param[in] instance Device keeper structure to use. 194 * @param[in] speed Speed of the device requiring address. 195 * @return Free address, or error code. 196 */ 77 197 usb_address_t device_keeper_request( 78 198 device_keeper_t *instance, usb_speed_t speed) … … 96 216 instance->devices[new_address].occupied = true; 97 217 instance->devices[new_address].speed = speed; 218 instance->devices[new_address].toggle_status = 0; 98 219 instance->last_address = new_address; 99 220 fibril_mutex_unlock(&instance->guard); … … 101 222 } 102 223 /*----------------------------------------------------------------------------*/ 224 /** Bind USB address to devman handle. 225 * 226 * @param[in] instance Device keeper structure to use. 227 * @param[in] address Device address 228 * @param[in] handle Devman handle of the device. 229 */ 103 230 void device_keeper_bind( 104 231 device_keeper_t *instance, usb_address_t address, devman_handle_t handle) … … 113 240 } 114 241 /*----------------------------------------------------------------------------*/ 242 /** Release used USB address. 243 * 244 * @param[in] instance Device keeper structure to use. 245 * @param[in] address Device address 246 */ 115 247 void device_keeper_release(device_keeper_t *instance, usb_address_t address) 116 248 { … … 125 257 } 126 258 /*----------------------------------------------------------------------------*/ 259 /** Find USB address associated with the device 260 * 261 * @param[in] instance Device keeper structure to use. 262 * @param[in] handle Devman handle of the device seeking its address. 263 * @return USB Address, or error code. 264 */ 127 265 usb_address_t device_keeper_find( 128 266 device_keeper_t *instance, devman_handle_t handle) … … 142 280 } 143 281 /*----------------------------------------------------------------------------*/ 282 /** Get speed associated with the address 283 * 284 * @param[in] instance Device keeper structure to use. 285 * @param[in] address Address of the device. 286 * @return USB speed. 287 */ 144 288 usb_speed_t device_keeper_speed( 145 289 device_keeper_t *instance, usb_address_t address)
Note:
See TracChangeset
for help on using the changeset viewer.