Changes in uspace/lib/usbdev/src/pipesinit.c [365e29e2:b77931d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/pipesinit.c
r365e29e2 rb77931d 68 68 * @return Whether the given descriptor is endpoint descriptor. 69 69 */ 70 static inline bool is_endpoint_descriptor( uint8_t *descriptor)70 static inline bool is_endpoint_descriptor(const uint8_t *descriptor) 71 71 { 72 72 return descriptor[1] == USB_DESCTYPE_ENDPOINT; … … 80 80 */ 81 81 static bool endpoint_fits_description(const usb_endpoint_description_t *wanted, 82 usb_endpoint_description_t *found)82 const usb_endpoint_description_t *found) 83 83 { 84 84 #define _SAME(fieldname) ((wanted->fieldname) == (found->fieldname)) … … 120 120 static usb_endpoint_mapping_t *find_endpoint_mapping( 121 121 usb_endpoint_mapping_t *mapping, size_t mapping_count, 122 usb_endpoint_description_t *found_endpoint,122 const usb_endpoint_description_t *found_endpoint, 123 123 int interface_number, int interface_setting) 124 124 { … … 160 160 usb_device_connection_t *wire) 161 161 { 162 usb_endpoint_description_t description;163 162 164 163 /* … … 167 166 168 167 /* Actual endpoint number is in bits 0..3 */ 169 usb_endpoint_t ep_no = endpoint->endpoint_address & 0x0F; 170 171 /* Endpoint direction is set by bit 7 */ 172 description.direction = (endpoint->endpoint_address & 128) 173 ? USB_DIRECTION_IN : USB_DIRECTION_OUT; 174 /* Transfer type is in bits 0..2 and the enum values corresponds 1:1 */ 175 description.transfer_type = endpoint->attributes & 3; 176 177 /* 178 * Get interface characteristics. 179 */ 180 description.interface_class = interface->interface_class; 181 description.interface_subclass = interface->interface_subclass; 182 description.interface_protocol = interface->interface_protocol; 168 const usb_endpoint_t ep_no = endpoint->endpoint_address & 0x0F; 169 170 const usb_endpoint_description_t description = { 171 /* Endpoint direction is set by bit 7 */ 172 .direction = (endpoint->endpoint_address & 128) 173 ? USB_DIRECTION_IN : USB_DIRECTION_OUT, 174 /* Transfer type is in bits 0..2 and 175 * the enum values corresponds 1:1 */ 176 .transfer_type = endpoint->attributes & 3, 177 178 /* Get interface characteristics. */ 179 .interface_class = interface->interface_class, 180 .interface_subclass = interface->interface_subclass, 181 .interface_protocol = interface->interface_protocol, 182 }; 183 183 184 184 /* … … 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); … … 224 221 static int process_interface( 225 222 usb_endpoint_mapping_t *mapping, size_t mapping_count, 226 usb_dp_parser_t *parser,usb_dp_parser_data_t *parser_data,227 uint8_t *interface_descriptor)228 { 229 uint8_t *descriptor = usb_dp_get_nested_descriptor(parser,223 const usb_dp_parser_t *parser, const usb_dp_parser_data_t *parser_data, 224 const uint8_t *interface_descriptor) 225 { 226 const uint8_t *descriptor = usb_dp_get_nested_descriptor(parser, 230 227 parser_data, interface_descriptor); 231 228 … … 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) … … 284 281 int usb_pipe_initialize_from_configuration( 285 282 usb_endpoint_mapping_t *mapping, size_t mapping_count, 286 uint8_t *configuration_descriptor, size_t configuration_descriptor_size,283 const uint8_t *config_descriptor, size_t config_descriptor_size, 287 284 usb_device_connection_t *connection) 288 285 { 289 286 assert(connection); 290 287 291 if (config uration_descriptor == NULL) {288 if (config_descriptor == NULL) { 292 289 return EBADMEM; 293 290 } 294 if (config uration_descriptor_size291 if (config_descriptor_size 295 292 < sizeof(usb_standard_configuration_descriptor_t)) { 296 293 return ERANGE; 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 */ 312 usb_dp_parser_t dp_parser = { 303 /* Prepare the descriptor parser. */ 304 const usb_dp_parser_t dp_parser = { 313 305 .nesting = descriptor_nesting 314 306 }; 315 usb_dp_parser_data_t dp_data = {316 .data = config uration_descriptor,317 .size = config uration_descriptor_size,307 const usb_dp_parser_data_t dp_data = { 308 .data = config_descriptor, 309 .size = config_descriptor_size, 318 310 .arg = connection 319 311 }; … … 322 314 * Iterate through all interfaces. 323 315 */ 324 uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser,325 &dp_data, config uration_descriptor);316 const uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser, 317 &dp_data, config_descriptor); 326 318 if (interface == NULL) { 327 319 return ENOENT; … … 329 321 do { 330 322 (void) process_interface(mapping, mapping_count, 331 &dp_parser, &dp_data, 332 interface); 323 &dp_parser, &dp_data, interface); 333 324 interface = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data, 334 config uration_descriptor, interface);325 config_descriptor, interface); 335 326 } while (interface != NULL); 336 327 … … 455 446 * @return Error code. 456 447 */ 457 int usb_pipe_register(usb_pipe_t *pipe, 458 unsigned int interval, 459 usb_hc_connection_t *hc_connection) 460 { 461 return usb_pipe_register_with_speed(pipe, USB_SPEED_MAX + 1, 462 interval, hc_connection); 463 } 464 465 /** Register endpoint with a speed at the host controller. 466 * 467 * You will rarely need to use this function because it is needed only 468 * if the registered endpoint is of address 0 and there is no other way 469 * to tell speed of the device at address 0. 470 * 471 * @param pipe Pipe to be registered. 472 * @param speed Speed of the device 473 * (invalid speed means use previously specified one). 474 * @param interval Polling interval. 475 * @param hc_connection Connection to the host controller (must be opened). 476 * @return Error code. 477 */ 478 int usb_pipe_register_with_speed(usb_pipe_t *pipe, usb_speed_t speed, 479 unsigned int interval, 448 int usb_pipe_register(usb_pipe_t *pipe, unsigned interval, 480 449 usb_hc_connection_t *hc_connection) 481 450 { 482 451 assert(pipe); 483 452 assert(hc_connection); 484 453 485 454 if (!usb_hc_connection_is_opened(hc_connection)) 486 455 return EBADF; 487 456 488 457 const usb_target_t target = 489 458 {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }}; 490 #define _PACK2(high, low) (((high) << 16) + (low)) 491 #define _PACK3(high, middle, low) (((((high) << 8) + (middle)) << 8) + (low)) 492 459 #define _PACK2(high, low) (((high & 0xffff) << 16) | (low & 0xffff)) 460 493 461 async_exch_t *exch = async_exchange_begin(hc_connection->hc_sess); 494 462 int rc = async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 495 463 IPC_M_USBHC_REGISTER_ENDPOINT, target.packed, 496 _PACK 3(speed,pipe->transfer_type, pipe->direction),464 _PACK2(pipe->transfer_type, pipe->direction), 497 465 _PACK2(pipe->max_packet_size, interval)); 498 466 async_exchange_end(exch); 499 467 500 468 #undef _PACK2 501 #undef _PACK3502 503 469 return rc; 504 470 } … … 514 480 { 515 481 assert(pipe); 482 assert(pipe->wire); 516 483 assert(hc_connection); 517 484
Note:
See TracChangeset
for help on using the changeset viewer.