Changeset 25d224c6 in mainline
- Timestamp:
- 2011-09-16T10:19:08Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 058fd76
- Parents:
- db2cb04
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/uhci/uhci_batch.c
rdb2cb04 r25d224c6 45 45 #define DEFAULT_ERROR_COUNT 3 46 46 47 static void batch_control(uhci_transfer_batch_t *uhci_batch,48 usb_packet_id data_stage, usb_packet_id status_stage);49 static void batch_data(uhci_transfer_batch_t *uhci_batch);50 /*----------------------------------------------------------------------------*/51 47 static void uhci_transfer_batch_dispose(uhci_transfer_batch_t *uhci_batch) 52 48 { … … 72 68 } 73 69 /*----------------------------------------------------------------------------*/ 74 static void (* const batch_setup[4][3])(uhci_transfer_batch_t*);70 static void (*const batch_setup[4][3])(uhci_transfer_batch_t*, usb_direction_t); 75 71 /*----------------------------------------------------------------------------*/ 76 72 /** Allocate memory and initialize internal data structure. … … 143 139 USB_TRANSFER_BATCH_ARGS(*usb_batch)); 144 140 145 assert(146 batch_setup[usb_batch->ep->transfer_type][usb_batch->ep->direction]); 147 batch_setup[usb_batch->ep->transfer_type][usb_batch->ep->direction](148 uhci_batch);141 const usb_direction_t dir = usb_transfer_batch_direction(usb_batch); 142 143 assert(batch_setup[usb_batch->ep->transfer_type][dir]); 144 batch_setup[usb_batch->ep->transfer_type][dir](uhci_batch, dir); 149 145 150 146 return uhci_batch; … … 204 200 } 205 201 /*----------------------------------------------------------------------------*/ 202 static const usb_packet_id direction_pids[] = { 203 [USB_DIRECTION_IN] = USB_PID_IN, 204 [USB_DIRECTION_OUT] = USB_PID_OUT, 205 }; 206 /*----------------------------------------------------------------------------*/ 206 207 /** Prepare generic data transfer 207 208 * 208 209 * @param[in] uhci_batch Batch structure to use. 209 * @param[in] pid Pid to use for data transactions.210 * @param[in] dir Communication direction. 210 211 * 211 212 * Transactions with alternating toggle bit and supplied pid value. 212 213 * The last transfer is marked with IOC flag. 213 214 */ 214 static void batch_data(uhci_transfer_batch_t *uhci_batch )215 static void batch_data(uhci_transfer_batch_t *uhci_batch, usb_direction_t dir) 215 216 { 216 217 assert(uhci_batch); 217 218 assert(uhci_batch->usb_batch); 218 219 assert(uhci_batch->usb_batch->ep); 219 assert(uhci_batch->usb_batch->ep->direction == USB_DIRECTION_OUT || 220 uhci_batch->usb_batch->ep->direction == USB_DIRECTION_IN); 221 222 static const usb_packet_id pids[] = { 223 [USB_DIRECTION_IN] = USB_PID_IN, 224 [USB_DIRECTION_OUT] = USB_PID_OUT, 225 }; 226 227 const usb_packet_id pid = pids[uhci_batch->usb_batch->ep->direction]; 220 assert(dir == USB_DIRECTION_OUT || dir == USB_DIRECTION_IN); 221 222 223 const usb_packet_id pid = direction_pids[dir]; 228 224 const bool low_speed = 229 225 uhci_batch->usb_batch->ep->speed == USB_SPEED_LOW; … … 270 266 * 271 267 * @param[in] uhci_batch Batch structure to use. 272 * @param[in] data_stage Pid to use for data tds. 273 * @param[in] status_stage Pid to use for data tds. 268 * @param[in] dir Communication direction. 274 269 * 275 270 * Setup stage with toggle 0 and USB_PID_SETUP. 276 * Data stage with alternating toggle and pid supplied by parameter. 277 * Status stage with toggle 1 and pid supplied by parameter. 271 * Data stage with alternating toggle and pid determined by the communication 272 * direction. 273 * Status stage with toggle 1 and pid determined by the communication direction. 278 274 * The last transfer is marked with IOC. 279 275 */ 280 static void batch_control(uhci_transfer_batch_t *uhci_batch, 281 usb_packet_id data_stage_pid, usb_packet_id status_stage_pid) 276 static void batch_control(uhci_transfer_batch_t *uhci_batch, usb_direction_t dir) 282 277 { 283 278 assert(uhci_batch); 284 279 assert(uhci_batch->usb_batch); 285 280 assert(uhci_batch->usb_batch->ep); 281 assert(dir == USB_DIRECTION_OUT || dir == USB_DIRECTION_IN); 286 282 assert(uhci_batch->td_count >= 2); 287 283 static const usb_packet_id status_stage_pids[] = { 284 [USB_DIRECTION_IN] = USB_PID_OUT, 285 [USB_DIRECTION_OUT] = USB_PID_IN, 286 }; 287 288 const usb_packet_id data_stage_pid = direction_pids[dir]; 289 const usb_packet_id status_stage_pid = status_stage_pids[dir]; 288 290 const bool low_speed = 289 291 uhci_batch->usb_batch->ep->speed == USB_SPEED_LOW; … … 334 336 } 335 337 /*----------------------------------------------------------------------------*/ 336 static void batch_setup_control(uhci_transfer_batch_t *uhci_batch) 337 { 338 assert(uhci_batch); 339 assert(uhci_batch->usb_batch); 340 assert(uhci_batch->usb_batch->setup_buffer); 341 // TODO Find a better way to do this 342 /* Check first bit of the first setup request byte 343 * (it signals hc-> dev or dev->hc communication) */ 344 const char *direction = NULL; 345 if (uhci_batch->usb_batch->setup_buffer[0] & (1 << 7)) { 346 batch_control(uhci_batch, USB_PID_IN, USB_PID_OUT); 347 direction = "read"; 348 } else { 349 batch_control(uhci_batch, USB_PID_OUT, USB_PID_IN); 350 direction = "write"; 351 } 352 usb_log_debug2( 353 "Batch %p %s %s " USB_TRANSFER_BATCH_FMT " initialized.\n", \ 354 uhci_batch->usb_batch, 355 usb_str_transfer_type(uhci_batch->usb_batch->ep->transfer_type), 356 direction, USB_TRANSFER_BATCH_ARGS(*uhci_batch->usb_batch)); 357 } 358 /*----------------------------------------------------------------------------*/ 359 static void (* const batch_setup[4][3])(uhci_transfer_batch_t*) = 360 { 361 { NULL, NULL, batch_setup_control }, 338 static void (*const batch_setup[4][3])(uhci_transfer_batch_t*, usb_direction_t) = 339 { 340 { batch_control, batch_control, NULL }, 362 341 { NULL, NULL, NULL }, 363 342 { batch_data, batch_data, NULL },
Note:
See TracChangeset
for help on using the changeset viewer.