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