Changeset 361e61b in mainline for uspace/lib/usb/src/host/device_keeper.c
- Timestamp:
- 2011-03-21T14:23:15Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 55e388a1
- Parents:
- c32688d (diff), 48fe0c9 (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 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/host/device_keeper.c
rc32688d r361e61b 27 27 */ 28 28 29 /** @addtogroup drvusbuhci29 /** @addtogroup libusb 30 30 * @{ 31 31 */ … … 36 36 #include <errno.h> 37 37 #include <usb/debug.h> 38 39 #include "device_keeper.h" 40 41 /*----------------------------------------------------------------------------*/ 42 /** Initializes device keeper structure. 38 #include <usb/host/device_keeper.h> 39 40 /*----------------------------------------------------------------------------*/ 41 /** Initialize device keeper structure. 43 42 * 44 43 * @param[in] instance Memory place to initialize. 44 * 45 * Set all values to false/0. 45 46 */ 46 47 void device_keeper_init(device_keeper_t *instance) … … 54 55 instance->devices[i].occupied = false; 55 56 instance->devices[i].handle = 0; 56 instance->devices[i].toggle_status = 0; 57 } 58 } 59 /*----------------------------------------------------------------------------*/ 60 /** Attempts to obtain address 0, blocks. 57 instance->devices[i].toggle_status[0] = 0; 58 instance->devices[i].toggle_status[1] = 0; 59 } 60 } 61 /*----------------------------------------------------------------------------*/ 62 /** Attempt to obtain address 0, blocks. 61 63 * 62 64 * @param[in] instance Device keeper structure to use. … … 76 78 } 77 79 /*----------------------------------------------------------------------------*/ 78 /** Attempt sto obtain address 0, blocks.80 /** Attempt to obtain address 0, blocks. 79 81 * 80 82 * @param[in] instance Device keeper structure to use. … … 90 92 } 91 93 /*----------------------------------------------------------------------------*/ 92 /** Check s setupdata for signs of toggle reset.94 /** Check setup packet data for signs of toggle reset. 93 95 * 94 96 * @param[in] instance Device keeper structure to use. 95 97 * @param[in] target Device to receive setup packet. 96 98 * @param[in] data Setup packet data. 99 * 100 * Really ugly one. 97 101 */ 98 102 void device_keeper_reset_if_need( … … 105 109 || !instance->devices[target.address].occupied) { 106 110 fibril_mutex_unlock(&instance->guard); 111 usb_log_error("Invalid data when checking for toggle reset.\n"); 107 112 return; 108 113 } … … 114 119 if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) { 115 120 /* endpoint number is < 16, thus first byte is enough */ 116 instance->devices[target.address].toggle_status &= 121 instance->devices[target.address].toggle_status[0] &= 122 ~(1 << data[4]); 123 instance->devices[target.address].toggle_status[1] &= 117 124 ~(1 << data[4]); 118 125 } … … 123 130 /* target must be device */ 124 131 if ((data[0] & 0xf) == 0) { 125 instance->devices[target.address].toggle_status = 0; 132 instance->devices[target.address].toggle_status[0] = 0; 133 instance->devices[target.address].toggle_status[1] = 0; 126 134 } 127 135 break; … … 130 138 } 131 139 /*----------------------------------------------------------------------------*/ 132 /** Get scurrent value of endpoint toggle.140 /** Get current value of endpoint toggle. 133 141 * 134 142 * @param[in] instance Device keeper structure to use. … … 136 144 * @return Error code 137 145 */ 138 int device_keeper_get_toggle(device_keeper_t *instance, usb_target_t target) 139 { 140 assert(instance); 146 int device_keeper_get_toggle( 147 device_keeper_t *instance, usb_target_t target, usb_direction_t direction) 148 { 149 assert(instance); 150 /* only control pipes are bi-directional and those do not need toggle */ 151 if (direction == USB_DIRECTION_BOTH) 152 return ENOENT; 141 153 int ret; 142 154 fibril_mutex_lock(&instance->guard); … … 144 156 || target.address >= USB_ADDRESS_COUNT || target.address < 0 145 157 || !instance->devices[target.address].occupied) { 158 usb_log_error("Invalid data when asking for toggle value.\n"); 146 159 ret = EINVAL; 147 160 } else { 148 ret = 149 (instance->devices[target.address].toggle_status 161 ret = (instance->devices[target.address].toggle_status[direction] 150 162 >> target.endpoint) & 1; 151 163 } … … 154 166 } 155 167 /*----------------------------------------------------------------------------*/ 156 /** Set scurrent value of endpoint toggle.168 /** Set current value of endpoint toggle. 157 169 * 158 170 * @param[in] instance Device keeper structure to use. 159 171 * @param[in] target Device and endpoint used. 160 * @param[in] toggle Current toggle value.172 * @param[in] toggle Toggle value. 161 173 * @return Error code. 162 174 */ 163 int device_keeper_set_toggle( 164 device_keeper_t *instance, usb_target_t target, bool toggle) 165 { 166 assert(instance); 175 int device_keeper_set_toggle(device_keeper_t *instance, 176 usb_target_t target, usb_direction_t direction, bool toggle) 177 { 178 assert(instance); 179 /* only control pipes are bi-directional and those do not need toggle */ 180 if (direction == USB_DIRECTION_BOTH) 181 return ENOENT; 167 182 int ret; 168 183 fibril_mutex_lock(&instance->guard); … … 170 185 || target.address >= USB_ADDRESS_COUNT || target.address < 0 171 186 || !instance->devices[target.address].occupied) { 187 usb_log_error("Invalid data when setting toggle value.\n"); 172 188 ret = EINVAL; 173 189 } else { 174 190 if (toggle) { 175 instance->devices[target.address].toggle_status |= (1 << target.endpoint); 191 instance->devices[target.address].toggle_status[direction] 192 |= (1 << target.endpoint); 176 193 } else { 177 instance->devices[target.address].toggle_status &= ~(1 << target.endpoint); 194 instance->devices[target.address].toggle_status[direction] 195 &= ~(1 << target.endpoint); 178 196 } 179 197 ret = EOK; … … 183 201 } 184 202 /*----------------------------------------------------------------------------*/ 185 /** Get sa free USB address203 /** Get a free USB address 186 204 * 187 205 * @param[in] instance Device keeper structure to use. … … 210 228 instance->devices[new_address].occupied = true; 211 229 instance->devices[new_address].speed = speed; 212 instance->devices[new_address].toggle_status = 0; 230 instance->devices[new_address].toggle_status[0] = 0; 231 instance->devices[new_address].toggle_status[1] = 0; 213 232 instance->last_address = new_address; 214 233 fibril_mutex_unlock(&instance->guard); … … 216 235 } 217 236 /*----------------------------------------------------------------------------*/ 218 /** Bind sUSB address to devman handle.237 /** Bind USB address to devman handle. 219 238 * 220 239 * @param[in] instance Device keeper structure to use. … … 234 253 } 235 254 /*----------------------------------------------------------------------------*/ 236 /** Release sused USB address.255 /** Release used USB address. 237 256 * 238 257 * @param[in] instance Device keeper structure to use. … … 251 270 } 252 271 /*----------------------------------------------------------------------------*/ 253 /** Find sUSB address associated with the device272 /** Find USB address associated with the device 254 273 * 255 274 * @param[in] instance Device keeper structure to use. … … 274 293 } 275 294 /*----------------------------------------------------------------------------*/ 276 /** Get sspeed associated with the address295 /** Get speed associated with the address 277 296 * 278 297 * @param[in] instance Device keeper structure to use.
Note:
See TracChangeset
for help on using the changeset viewer.