Changeset 7aaed09 in mainline for uspace/lib/usbdev/src/pipesinit.c
- Timestamp:
- 2011-12-18T14:02:30Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c868e2d
- Parents:
- 3b71e84d (diff), 1761268 (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/lib/usbdev/src/pipesinit.c
r3b71e84d r7aaed09 54 54 55 55 /** Nesting pairs of standard descriptors. */ 56 static usb_dp_descriptor_nesting_t descriptor_nesting[] = {56 static const usb_dp_descriptor_nesting_t descriptor_nesting[] = { 57 57 NESTING(CONFIGURATION, INTERFACE), 58 58 NESTING(INTERFACE, ENDPOINT), … … 192 192 } 193 193 194 if (ep_mapping->pipe == NULL) {195 return EBADMEM;196 }197 194 if (ep_mapping->present) { 198 195 return EEXISTS; 199 196 } 200 197 201 int rc = usb_pipe_initialize( ep_mapping->pipe, wire,198 int rc = usb_pipe_initialize(&ep_mapping->pipe, wire, 202 199 ep_no, description.transfer_type, endpoint->max_packet_size, 203 200 description.direction); … … 254 251 * 255 252 * The mapping array is expected to conform to following rules: 256 * - @c pipe must point to already allocated structure withuninitialized pipe253 * - @c pipe must be uninitialized pipe 257 254 * - @c description must point to prepared endpoint description 258 255 * - @c descriptor does not need to be initialized (will be overwritten) … … 297 294 } 298 295 299 /* 300 * Go through the mapping and set all endpoints to not present. 301 */ 302 size_t i; 303 for (i = 0; i < mapping_count; i++) { 296 /* Go through the mapping and set all endpoints to not present. */ 297 for (size_t i = 0; i < mapping_count; i++) { 304 298 mapping[i].present = false; 305 299 mapping[i].descriptor = NULL; … … 307 301 } 308 302 309 /* 310 * Prepare the descriptor parser. 311 */ 303 /* Prepare the descriptor parser. */ 312 304 const usb_dp_parser_t dp_parser = { 313 305 .nesting = descriptor_nesting … … 413 405 } 414 406 415 #define TRY_LOOP(attempt_var) \416 for (attempt_var = 0; attempt_var < 3; attempt_var++)417 418 size_t failed_attempts;419 int rc;420 407 421 408 usb_pipe_start_long_transfer(pipe); … … 423 410 uint8_t dev_descr_start[CTRL_PIPE_MIN_PACKET_SIZE]; 424 411 size_t transferred_size; 425 TRY_LOOP(failed_attempts) { 412 int rc; 413 for (size_t attempt_var = 0; attempt_var < 3; ++attempt_var) { 426 414 rc = usb_request_get_descriptor(pipe, USB_REQUEST_TYPE_STANDARD, 427 415 USB_REQUEST_RECIPIENT_DEVICE, USB_DESCTYPE_DEVICE, … … 454 442 * @return Error code. 455 443 */ 456 int usb_pipe_register(usb_pipe_t *pipe, 457 unsigned int interval, 458 usb_hc_connection_t *hc_connection) 459 { 460 return usb_pipe_register_with_speed(pipe, USB_SPEED_MAX + 1, 461 interval, hc_connection); 462 } 463 464 /** Register endpoint with a speed at the host controller. 465 * 466 * You will rarely need to use this function because it is needed only 467 * if the registered endpoint is of address 0 and there is no other way 468 * to tell speed of the device at address 0. 469 * 470 * @param pipe Pipe to be registered. 471 * @param speed Speed of the device 472 * (invalid speed means use previously specified one). 473 * @param interval Polling interval. 474 * @param hc_connection Connection to the host controller (must be opened). 475 * @return Error code. 476 */ 477 int usb_pipe_register_with_speed(usb_pipe_t *pipe, usb_speed_t speed, 478 unsigned int interval, 479 usb_hc_connection_t *hc_connection) 480 { 481 assert(pipe); 482 assert(hc_connection); 483 484 if (!usb_hc_connection_is_opened(hc_connection)) 485 return EBADF; 486 487 const usb_target_t target = 488 {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }}; 489 #define _PACK2(high, low) (((high) << 16) + (low)) 490 #define _PACK3(high, middle, low) (((((high) << 8) + (middle)) << 8) + (low)) 491 492 async_exch_t *exch = async_exchange_begin(hc_connection->hc_sess); 493 int rc = async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 494 IPC_M_USBHC_REGISTER_ENDPOINT, target.packed, 495 _PACK3(speed, pipe->transfer_type, pipe->direction), 496 _PACK2(pipe->max_packet_size, interval)); 497 async_exchange_end(exch); 498 499 #undef _PACK2 500 #undef _PACK3 501 502 return rc; 503 } 504 505 /** Revert endpoint registration with the host controller. 506 * 507 * @param pipe Pipe to be unregistered. 508 * @param hc_connection Connection to the host controller (must be opened). 509 * @return Error code. 510 */ 511 int usb_pipe_unregister(usb_pipe_t *pipe, 444 int usb_pipe_register(usb_pipe_t *pipe, unsigned interval, 512 445 usb_hc_connection_t *hc_connection) 513 446 { … … 515 448 assert(pipe->wire); 516 449 assert(hc_connection); 517 450 518 451 if (!usb_hc_connection_is_opened(hc_connection)) 519 452 return EBADF; 520 521 453 async_exch_t *exch = async_exchange_begin(hc_connection->hc_sess); 522 int rc = async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 523 IPC_M_USBHC_UNREGISTER_ENDPOINT, 454 if (!exch) 455 return ENOMEM; 456 const int ret = usbhc_register_endpoint(exch, 457 pipe->wire->address, pipe->endpoint_no, pipe->transfer_type, 458 pipe->direction, pipe->max_packet_size, interval); 459 460 async_exchange_end(exch); 461 return ret; 462 } 463 464 /** Revert endpoint registration with the host controller. 465 * 466 * @param pipe Pipe to be unregistered. 467 * @param hc_connection Connection to the host controller (must be opened). 468 * @return Error code. 469 */ 470 int usb_pipe_unregister(usb_pipe_t *pipe, 471 usb_hc_connection_t *hc_connection) 472 { 473 assert(pipe); 474 assert(pipe->wire); 475 assert(hc_connection); 476 477 if (!usb_hc_connection_is_opened(hc_connection)) 478 return EBADF; 479 480 async_exch_t *exch = async_exchange_begin(hc_connection->hc_sess); 481 if (!exch) 482 return ENOMEM; 483 const int ret = usbhc_unregister_endpoint(exch, 524 484 pipe->wire->address, pipe->endpoint_no, pipe->direction); 525 485 async_exchange_end(exch); 526 527 return r c;486 487 return ret; 528 488 } 529 489
Note:
See TracChangeset
for help on using the changeset viewer.