Changeset 2e85b3c in mainline for uspace/lib
- Timestamp:
- 2011-02-16T18:22:43Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f4c87aa9
- Parents:
- 600733e (diff), ec59693 (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. - Location:
- uspace/lib
- Files:
-
- 5 added
- 6 deleted
- 17 edited
-
c/generic/str_error.c (modified) (2 diffs)
-
c/include/errno.h (modified) (1 diff)
-
drv/generic/remote_usbhc.c (modified) (13 diffs)
-
drv/include/usbhc_iface.h (modified) (2 diffs)
-
usb/Makefile (modified) (1 diff)
-
usb/include/usb/addrkeep.h (modified) (1 diff, 1 prop)
-
usb/include/usb/classes/hub.h (modified) (3 diffs)
-
usb/include/usb/hcd.h (deleted)
-
usb/include/usb/hcdhubd.h (deleted)
-
usb/include/usb/hub.h (added)
-
usb/include/usb/pipes.h (modified) (4 diffs)
-
usb/include/usb/recognise.h (modified) (1 diff)
-
usb/include/usb/usb.h (modified) (1 diff)
-
usb/include/usb/usbdevice.h (added)
-
usb/src/addrkeep.c (modified) (1 diff)
-
usb/src/dump.c (modified) (1 diff)
-
usb/src/hcdhubd.c (deleted)
-
usb/src/hcdrv.c (deleted)
-
usb/src/hub.c (added)
-
usb/src/localdrv.c (deleted)
-
usb/src/pipes.c (modified) (4 diffs)
-
usb/src/pipesinit.c (modified) (1 diff)
-
usb/src/pipesio.c (added)
-
usb/src/remotedrv.c (deleted)
-
usb/src/usb.c (modified) (1 diff)
-
usb/src/usbdevice.c (added)
-
usb/src/usbdrv.c (modified) (2 diffs)
-
usbvirt/Makefile (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/str_error.c
r600733e r2e85b3c 33 33 */ 34 34 35 #include <errno.h> 35 36 #include <str_error.h> 36 37 #include <stdio.h> … … 63 64 static fibril_local char noerr[NOERR_LEN]; 64 65 65 const char *str_error(const int e rrno)66 const char *str_error(const int e) 66 67 { 67 if ((e rrno <= 0) && (errno>= MIN_ERRNO))68 return err_desc[-e rrno];68 if ((e <= 0) && (e >= MIN_ERRNO)) 69 return err_desc[-e]; 69 70 70 snprintf(noerr, NOERR_LEN, "Unkown error code %d", errno); 71 /* Ad hoc descriptions of error codes interesting for USB. */ 72 switch (e) { 73 case EBADCHECKSUM: 74 return "Bad checksum"; 75 case EAGAIN: 76 return "Resource temporarily unavailable"; 77 default: 78 break; 79 } 80 81 snprintf(noerr, NOERR_LEN, "Unkown error code %d", e); 71 82 return noerr; 72 83 } -
uspace/lib/c/include/errno.h
r600733e r2e85b3c 56 56 #define EMLINK (-266) 57 57 58 /** Bad checksum. */ 59 #define EBADCHECKSUM (-300) 60 58 61 /** An API function is called while another blocking function is in progress. */ 59 62 #define EINPROGRESS (-10036) -
uspace/lib/drv/generic/remote_usbhc.c
r600733e r2e85b3c 40 40 41 41 #define USB_MAX_PAYLOAD_SIZE 1020 42 #define HACK_MAX_PACKET_SIZE 8 43 #define HACK_MAX_PACKET_SIZE_INTERRUPT_IN 4 42 44 43 45 static void remote_usbhc_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *); … … 240 242 241 243 static void callback_out(device_t *device, 242 usb_transaction_outcome_t outcome, void *arg)244 int outcome, void *arg) 243 245 { 244 246 async_transaction_t *trans = (async_transaction_t *)arg; … … 250 252 251 253 static void callback_in(device_t *device, 252 usb_transaction_outcome_t outcome, size_t actual_size, void *arg)254 int outcome, size_t actual_size, void *arg) 253 255 { 254 256 async_transaction_t *trans = (async_transaction_t *)arg; 255 257 256 if (outcome != USB_OUTCOME_OK) {258 if (outcome != EOK) { 257 259 async_answer_0(trans->caller, outcome); 258 260 if (trans->data_caller) { … … 270 272 } 271 273 272 async_answer_0(trans->caller, USB_OUTCOME_OK);274 async_answer_0(trans->caller, EOK); 273 275 274 276 async_transaction_destroy(trans); … … 322 324 trans->size = len; 323 325 324 int rc = transfer_func(device, target, buffer, len, 326 int rc = transfer_func(device, target, HACK_MAX_PACKET_SIZE, 327 buffer, len, 325 328 callback_out, trans); 326 329 … … 368 371 trans->size = len; 369 372 370 int rc = transfer_func(device, target, trans->buffer, len, 373 int rc = transfer_func(device, target, HACK_MAX_PACKET_SIZE_INTERRUPT_IN, 374 trans->buffer, len, 371 375 callback_in, trans); 372 376 … … 540 544 .endpoint = DEV_IPC_GET_ARG2(*call) 541 545 }; 546 size_t data_buffer_len = DEV_IPC_GET_ARG3(*call); 542 547 543 548 int rc; … … 546 551 void *data_buffer = NULL; 547 552 size_t setup_packet_len = 0; 548 size_t data_buffer_len = 0;549 553 550 554 rc = async_data_write_accept(&setup_packet, false, … … 554 558 return; 555 559 } 556 rc = async_data_write_accept(&data_buffer, false, 557 1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len); 558 if (rc != EOK) { 559 async_answer_0(callid, rc); 560 free(setup_packet); 561 return; 560 561 if (data_buffer_len > 0) { 562 rc = async_data_write_accept(&data_buffer, false, 563 1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len); 564 if (rc != EOK) { 565 async_answer_0(callid, rc); 566 free(setup_packet); 567 return; 568 } 562 569 } 563 570 … … 573 580 trans->size = data_buffer_len; 574 581 575 rc = usb_iface->control_write(device, target, 582 rc = usb_iface->control_write(device, target, HACK_MAX_PACKET_SIZE, 576 583 setup_packet, setup_packet_len, 577 584 data_buffer, data_buffer_len, … … 596 603 } 597 604 598 size_t data_len = DEV_IPC_GET_ARG3(*call);599 605 usb_target_t target = { 600 606 .address = DEV_IPC_GET_ARG1(*call), … … 606 612 void *setup_packet = NULL; 607 613 size_t setup_packet_len = 0; 614 size_t data_len = 0; 608 615 609 616 rc = async_data_write_accept(&setup_packet, false, … … 637 644 } 638 645 639 rc = usb_iface->control_read(device, target, 646 rc = usb_iface->control_read(device, target, HACK_MAX_PACKET_SIZE, 640 647 setup_packet, setup_packet_len, 641 648 trans->buffer, trans->size, -
uspace/lib/drv/include/usbhc_iface.h
r600733e r2e85b3c 207 207 /** Callback for outgoing transfer. */ 208 208 typedef void (*usbhc_iface_transfer_out_callback_t)(device_t *, 209 usb_transaction_outcome_t, void *);209 int, void *); 210 210 211 211 /** Callback for incoming transfer. */ 212 212 typedef void (*usbhc_iface_transfer_in_callback_t)(device_t *, 213 usb_transaction_outcome_t, size_t, void *);213 int, size_t, void *); 214 214 215 215 216 216 /** Out transfer processing function prototype. */ 217 typedef int (*usbhc_iface_transfer_out_t)(device_t *, usb_target_t, 217 typedef int (*usbhc_iface_transfer_out_t)(device_t *, usb_target_t, size_t, 218 218 void *, size_t, 219 219 usbhc_iface_transfer_out_callback_t, void *); 220 220 221 /** Setup transfer processing function prototype. */221 /** Setup transfer processing function prototype. @deprecated */ 222 222 typedef usbhc_iface_transfer_out_t usbhc_iface_transfer_setup_t; 223 223 224 224 /** In transfer processing function prototype. */ 225 typedef int (*usbhc_iface_transfer_in_t)(device_t *, usb_target_t, 225 typedef int (*usbhc_iface_transfer_in_t)(device_t *, usb_target_t, size_t, 226 226 void *, size_t, 227 227 usbhc_iface_transfer_in_callback_t, void *); … … 251 251 252 252 int (*control_write)(device_t *, usb_target_t, 253 size_t, 253 254 void *, size_t, void *, size_t, 254 255 usbhc_iface_transfer_out_callback_t, void *); 255 256 256 257 int (*control_read)(device_t *, usb_target_t, 258 size_t, 257 259 void *, size_t, void *, size_t, 258 260 usbhc_iface_transfer_in_callback_t, void *); -
uspace/lib/usb/Makefile
r600733e r2e85b3c 39 39 src/drvpsync.c \ 40 40 src/dump.c \ 41 src/hcdhubd.c \42 src/hcdrv.c \43 41 src/hidparser.c \ 44 src/ localdrv.c \42 src/hub.c \ 45 43 src/pipes.c \ 46 44 src/pipesinit.c \ 45 src/pipesio.c \ 47 46 src/recognise.c \ 48 src/remotedrv.c \49 47 src/request.c \ 50 48 src/usb.c \ 49 src/usbdevice.c \ 51 50 src/usbdrvreq.c \ 52 51 src/usbdrv.c \ -
uspace/lib/usb/include/usb/addrkeep.h
-
Property mode
changed from
120000to100644
r600733e r2e85b3c 1 hcd.h 1 /* 2 * Copyright (c) 2010 Vojtech Horky 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** @addtogroup libusb 30 * @{ 31 */ 32 /** @file 33 * USB address keeping for host controller drivers. 34 */ 35 #ifndef LIBUSB_ADDRKEEP_H_ 36 #define LIBUSB_ADDRKEEP_H_ 37 38 #include <usb/usb.h> 39 #include <fibril_synch.h> 40 #include <devman.h> 41 42 /** Info about used address. */ 43 typedef struct { 44 /** Linked list member. */ 45 link_t link; 46 /** Address. */ 47 usb_address_t address; 48 /** Corresponding devman handle. */ 49 devman_handle_t devman_handle; 50 } usb_address_keeping_used_t; 51 52 /** Structure for keeping track of free and used USB addresses. */ 53 typedef struct { 54 /** Head of list of used addresses. */ 55 link_t used_addresses; 56 /** Upper bound for USB addresses. */ 57 usb_address_t max_address; 58 /** Mutex protecting used address. */ 59 fibril_mutex_t used_addresses_guard; 60 /** Condition variable for used addresses. */ 61 fibril_condvar_t used_addresses_condvar; 62 63 /** Condition variable mutex for default address. */ 64 fibril_mutex_t default_condvar_guard; 65 /** Condition variable for default address. */ 66 fibril_condvar_t default_condvar; 67 /** Whether is default address available. */ 68 bool default_available; 69 } usb_address_keeping_t; 70 71 void usb_address_keeping_init(usb_address_keeping_t *, usb_address_t); 72 73 void usb_address_keeping_reserve_default(usb_address_keeping_t *); 74 void usb_address_keeping_release_default(usb_address_keeping_t *); 75 76 usb_address_t usb_address_keeping_request(usb_address_keeping_t *); 77 int usb_address_keeping_release(usb_address_keeping_t *, usb_address_t); 78 void usb_address_keeping_devman_bind(usb_address_keeping_t *, usb_address_t, 79 devman_handle_t); 80 usb_address_t usb_address_keeping_find(usb_address_keeping_t *, 81 devman_handle_t); 82 83 #endif 84 /** 85 * @} 86 */ -
Property mode
changed from
-
uspace/lib/usb/include/usb/classes/hub.h
r600733e r2e85b3c 37 37 38 38 #include <sys/types.h> 39 #include <usb/hcdhubd.h>40 41 39 42 40 /** Hub class feature selector. … … 80 78 /** 81 79 D1...D0: Logical Power Switching Mode 82 00: Ganged power switching (all ports ’power at80 00: Ganged power switching (all ports power at 83 81 once) 84 82 01: Individual port power switching … … 91 89 00: Global Over-current Protection. The hub 92 90 reports over-current as a summation of all 93 ports ’current draw, without a breakdown of91 ports current draw, without a breakdown of 94 92 individual port over-current status. 95 93 01: Individual Port Over-current Protection. The -
uspace/lib/usb/include/usb/pipes.h
r600733e r2e85b3c 31 31 */ 32 32 /** @file 33 * Communication between device drivers and host controller driver.33 * USB pipes representation. 34 34 */ 35 35 #ifndef LIBUSB_PIPES_H_ … … 38 38 #include <sys/types.h> 39 39 #include <usb/usb.h> 40 #include <usb/usbdevice.h> 40 41 #include <usb/descriptor.h> 41 42 #include <ipc/devman.h> … … 114 115 } usb_endpoint_mapping_t; 115 116 117 int usb_device_connection_initialize_on_default_address( 118 usb_device_connection_t *, usb_hc_connection_t *); 116 119 int usb_device_connection_initialize_from_device(usb_device_connection_t *, 117 120 device_t *); … … 139 142 void *, size_t); 140 143 141 142 143 int usb_endpoint_pipe_async_read(usb_endpoint_pipe_t *, void *, size_t,144 size_t *, usb_handle_t *);145 int usb_endpoint_pipe_async_write(usb_endpoint_pipe_t *, void *, size_t,146 usb_handle_t *);147 148 int usb_endpoint_pipe_async_control_read(usb_endpoint_pipe_t *, void *, size_t,149 void *, size_t, size_t *, usb_handle_t *);150 int usb_endpoint_pipe_async_control_write(usb_endpoint_pipe_t *, void *, size_t,151 void *, size_t, usb_handle_t *);152 153 int usb_endpoint_pipe_wait_for(usb_endpoint_pipe_t *, usb_handle_t);154 155 144 #endif 156 145 /** -
uspace/lib/usb/include/usb/recognise.h
r600733e r2e85b3c 39 39 #include <usb/usb.h> 40 40 #include <usb/pipes.h> 41 #include <ipc/devman.h> 41 42 42 43 int usb_device_create_match_ids(usb_endpoint_pipe_t *, match_id_list_t *); -
uspace/lib/usb/include/usb/usb.h
r600733e r2e85b3c 83 83 } usb_request_recipient_t; 84 84 85 /** USB transaction outcome. */86 typedef enum {87 USB_OUTCOME_OK,88 USB_OUTCOME_CRCERROR,89 USB_OUTCOME_BABBLE90 } usb_transaction_outcome_t;91 92 const char * usb_str_transaction_outcome(usb_transaction_outcome_t o);93 94 85 /** USB address type. 95 86 * Negative values could be used to indicate error. -
uspace/lib/usb/src/addrkeep.c
r600733e r2e85b3c 33 33 * @brief Address keeping. 34 34 */ 35 #include <usb/ hcd.h>35 #include <usb/addrkeep.h> 36 36 #include <errno.h> 37 37 #include <assert.h> -
uspace/lib/usb/src/dump.c
r600733e r2e85b3c 147 147 PRINTLINE("bDeviceProtocol = 0x%02x", d->device_protocol); 148 148 PRINTLINE("bMaxPacketSize0 = %d", d->max_packet_size); 149 PRINTLINE("idVendor = %d", d->vendor_id);150 PRINTLINE("idProduct = %d", d->product_id);149 PRINTLINE("idVendor = 0x%04x", d->vendor_id); 150 PRINTLINE("idProduct = 0x%04x", d->product_id); 151 151 PRINTLINE("bcdDevice = %d", d->device_version); 152 152 PRINTLINE("iManufacturer = %d", d->str_manufacturer); -
uspace/lib/usb/src/pipes.c
r600733e r2e85b3c 31 31 */ 32 32 /** @file 33 * Communication between device drivers and host controller driver. 34 * 35 * Note on synchronousness of the operations: there is ABSOLUTELY NO 36 * guarantee that a call to particular function will not trigger a fibril 37 * switch. 38 * The initialization functions may actually involve contacting some other 39 * task, starting/ending a session might involve asynchronous IPC and since 40 * the transfer functions uses IPC, asynchronous nature of them is obvious. 41 * The pseudo synchronous versions for the transfers internally call the 42 * asynchronous ones and so fibril switch is possible in them as well. 33 * USB endpoint pipes miscellaneous functions. 43 34 */ 44 35 #include <usb/usb.h> … … 47 38 #include <assert.h> 48 39 #include <usb/usbdrv.h> 49 50 #define _PREPARE_TARGET(varname, pipe) \51 usb_target_t varname = { \52 .address = (pipe)->wire->address, \53 .endpoint = (pipe)->endpoint_no \54 }55 40 56 41 /** Initialize connection to USB device. … … 117 102 } 118 103 119 /** Initialize USB endpoint pipe.104 /** Initialize connection to USB device on default address. 120 105 * 121 * @param pipe Endpoint pipe to be initialized. 122 * @param connection Connection to the USB device backing this pipe (the wire). 123 * @param endpoint_no Endpoint number (in USB 1.1 in range 0 to 15). 124 * @param transfer_type Transfer type (e.g. interrupt or bulk). 125 * @param max_packet_size Maximum packet size in bytes. 126 * @param direction Endpoint direction (in/out). 106 * @param dev_connection Device connection structure to be initialized. 107 * @param hc_connection Initialized connection to host controller. 127 108 * @return Error code. 128 109 */ 129 int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *pipe, 130 usb_device_connection_t *connection, usb_endpoint_t endpoint_no, 131 usb_transfer_type_t transfer_type, size_t max_packet_size, 132 usb_direction_t direction) 110 int usb_device_connection_initialize_on_default_address( 111 usb_device_connection_t *dev_connection, 112 usb_hc_connection_t *hc_connection) 133 113 { 134 assert(pipe); 135 assert(connection); 114 assert(dev_connection); 136 115 137 pipe->wire = connection; 138 pipe->hc_phone = -1; 139 pipe->endpoint_no = endpoint_no; 140 pipe->transfer_type = transfer_type; 141 pipe->max_packet_size = max_packet_size; 142 pipe->direction = direction; 116 if (hc_connection == NULL) { 117 return EBADMEM; 118 } 143 119 144 return EOK; 145 } 146 147 148 /** Initialize USB endpoint pipe as the default zero control pipe. 149 * 150 * @param pipe Endpoint pipe to be initialized. 151 * @param connection Connection to the USB device backing this pipe (the wire). 152 * @return Error code. 153 */ 154 int usb_endpoint_pipe_initialize_default_control(usb_endpoint_pipe_t *pipe, 155 usb_device_connection_t *connection) 156 { 157 assert(pipe); 158 assert(connection); 159 160 int rc = usb_endpoint_pipe_initialize(pipe, connection, 161 0, USB_TRANSFER_CONTROL, 8, USB_DIRECTION_BOTH); 162 163 return rc; 120 return usb_device_connection_initialize(dev_connection, 121 hc_connection->hc_handle, (usb_address_t) 0); 164 122 } 165 123 … … 224 182 } 225 183 226 227 /** Request a read (in) transfer on an endpoint pipe.228 *229 * @param[in] pipe Pipe used for the transfer.230 * @param[out] buffer Buffer where to store the data.231 * @param[in] size Size of the buffer (in bytes).232 * @param[out] size_transfered Number of bytes that were actually transfered.233 * @return Error code.234 */235 int usb_endpoint_pipe_read(usb_endpoint_pipe_t *pipe,236 void *buffer, size_t size, size_t *size_transfered)237 {238 assert(pipe);239 240 int rc;241 usb_handle_t handle;242 243 rc = usb_endpoint_pipe_async_read(pipe, buffer, size, size_transfered,244 &handle);245 if (rc != EOK) {246 return rc;247 }248 249 rc = usb_endpoint_pipe_wait_for(pipe, handle);250 return rc;251 }252 253 /** Request a write (out) transfer on an endpoint pipe.254 *255 * @param[in] pipe Pipe used for the transfer.256 * @param[in] buffer Buffer with data to transfer.257 * @param[in] size Size of the buffer (in bytes).258 * @return Error code.259 */260 int usb_endpoint_pipe_write(usb_endpoint_pipe_t *pipe,261 void *buffer, size_t size)262 {263 assert(pipe);264 265 int rc;266 usb_handle_t handle;267 268 rc = usb_endpoint_pipe_async_write(pipe, buffer, size, &handle);269 if (rc != EOK) {270 return rc;271 }272 273 rc = usb_endpoint_pipe_wait_for(pipe, handle);274 return rc;275 }276 277 278 /** Request a control read transfer on an endpoint pipe.279 *280 * This function encapsulates all three stages of a control transfer.281 *282 * @param[in] pipe Pipe used for the transfer.283 * @param[in] setup_buffer Buffer with the setup packet.284 * @param[in] setup_buffer_size Size of the setup packet (in bytes).285 * @param[out] data_buffer Buffer for incoming data.286 * @param[in] data_buffer_size Size of the buffer for incoming data (in bytes).287 * @param[out] data_transfered_size Number of bytes that were actually288 * transfered during the DATA stage.289 * @return Error code.290 */291 int usb_endpoint_pipe_control_read(usb_endpoint_pipe_t *pipe,292 void *setup_buffer, size_t setup_buffer_size,293 void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)294 {295 assert(pipe);296 297 int rc;298 usb_handle_t handle;299 300 rc = usb_endpoint_pipe_async_control_read(pipe,301 setup_buffer, setup_buffer_size,302 data_buffer, data_buffer_size, data_transfered_size,303 &handle);304 if (rc != EOK) {305 return rc;306 }307 308 rc = usb_endpoint_pipe_wait_for(pipe, handle);309 return rc;310 }311 312 313 /** Request a control write transfer on an endpoint pipe.314 *315 * This function encapsulates all three stages of a control transfer.316 *317 * @param[in] pipe Pipe used for the transfer.318 * @param[in] setup_buffer Buffer with the setup packet.319 * @param[in] setup_buffer_size Size of the setup packet (in bytes).320 * @param[in] data_buffer Buffer with data to be sent.321 * @param[in] data_buffer_size Size of the buffer with outgoing data (in bytes).322 * @return Error code.323 */324 int usb_endpoint_pipe_control_write(usb_endpoint_pipe_t *pipe,325 void *setup_buffer, size_t setup_buffer_size,326 void *data_buffer, size_t data_buffer_size)327 {328 assert(pipe);329 330 int rc;331 usb_handle_t handle;332 333 rc = usb_endpoint_pipe_async_control_write(pipe,334 setup_buffer, setup_buffer_size,335 data_buffer, data_buffer_size,336 &handle);337 if (rc != EOK) {338 return rc;339 }340 341 rc = usb_endpoint_pipe_wait_for(pipe, handle);342 return rc;343 }344 345 346 /** Request a read (in) transfer on an endpoint pipe (asynchronous version).347 *348 * @param[in] pipe Pipe used for the transfer.349 * @param[out] buffer Buffer where to store the data.350 * @param[in] size Size of the buffer (in bytes).351 * @param[out] size_transfered Number of bytes that were actually transfered.352 * @param[out] handle Handle of the transfer.353 * @return Error code.354 */355 int usb_endpoint_pipe_async_read(usb_endpoint_pipe_t *pipe,356 void *buffer, size_t size, size_t *size_transfered,357 usb_handle_t *handle)358 {359 assert(pipe);360 361 if (pipe->hc_phone < 0) {362 return EBADF;363 }364 365 if (pipe->direction != USB_DIRECTION_IN) {366 return EBADF;367 }368 369 int rc;370 _PREPARE_TARGET(target, pipe);371 372 switch (pipe->transfer_type) {373 case USB_TRANSFER_INTERRUPT:374 rc = usb_drv_async_interrupt_in(pipe->hc_phone, target,375 buffer, size, size_transfered, handle);376 break;377 case USB_TRANSFER_CONTROL:378 rc = EBADF;379 break;380 default:381 rc = ENOTSUP;382 break;383 }384 385 return rc;386 }387 388 389 /** Request a write (out) transfer on an endpoint pipe (asynchronous version).390 *391 * @param[in] pipe Pipe used for the transfer.392 * @param[in] buffer Buffer with data to transfer.393 * @param[in] size Size of the buffer (in bytes).394 * @param[out] handle Handle of the transfer.395 * @return Error code.396 */397 int usb_endpoint_pipe_async_write(usb_endpoint_pipe_t *pipe,398 void *buffer, size_t size,399 usb_handle_t *handle)400 {401 assert(pipe);402 403 if (pipe->hc_phone < 0) {404 return EBADF;405 }406 407 if (pipe->direction != USB_DIRECTION_OUT) {408 return EBADF;409 }410 411 int rc;412 _PREPARE_TARGET(target, pipe);413 414 switch (pipe->transfer_type) {415 case USB_TRANSFER_INTERRUPT:416 rc = usb_drv_async_interrupt_out(pipe->hc_phone, target,417 buffer, size, handle);418 break;419 case USB_TRANSFER_CONTROL:420 rc = EBADF;421 break;422 default:423 rc = ENOTSUP;424 break;425 }426 427 return rc;428 }429 430 431 /** Request a control read transfer on an endpoint pipe (asynchronous version).432 *433 * This function encapsulates all three stages of a control transfer.434 *435 * @param[in] pipe Pipe used for the transfer.436 * @param[in] setup_buffer Buffer with the setup packet.437 * @param[in] setup_buffer_size Size of the setup packet (in bytes).438 * @param[out] data_buffer Buffer for incoming data.439 * @param[in] data_buffer_size Size of the buffer for incoming data (in bytes).440 * @param[out] data_transfered_size Number of bytes that were actually441 * transfered during the DATA stage.442 * @param[out] handle Handle of the transfer.443 * @return Error code.444 */445 int usb_endpoint_pipe_async_control_read(usb_endpoint_pipe_t *pipe,446 void *setup_buffer, size_t setup_buffer_size,447 void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size,448 usb_handle_t *handle)449 {450 assert(pipe);451 452 if (pipe->hc_phone < 0) {453 return EBADF;454 }455 456 if ((pipe->direction != USB_DIRECTION_BOTH)457 || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {458 return EBADF;459 }460 461 int rc;462 _PREPARE_TARGET(target, pipe);463 464 rc = usb_drv_async_control_read(pipe->hc_phone, target,465 setup_buffer, setup_buffer_size,466 data_buffer, data_buffer_size, data_transfered_size,467 handle);468 469 return rc;470 }471 472 473 /** Request a control write transfer on an endpoint pipe (asynchronous version).474 *475 * This function encapsulates all three stages of a control transfer.476 *477 * @param[in] pipe Pipe used for the transfer.478 * @param[in] setup_buffer Buffer with the setup packet.479 * @param[in] setup_buffer_size Size of the setup packet (in bytes).480 * @param[in] data_buffer Buffer with data to be sent.481 * @param[in] data_buffer_size Size of the buffer with outgoing data (in bytes).482 * @param[out] handle Handle of the transfer.483 * @return Error code.484 */485 int usb_endpoint_pipe_async_control_write(usb_endpoint_pipe_t *pipe,486 void *setup_buffer, size_t setup_buffer_size,487 void *data_buffer, size_t data_buffer_size,488 usb_handle_t *handle)489 {490 assert(pipe);491 492 if (pipe->hc_phone < 0) {493 return EBADF;494 }495 496 if ((pipe->direction != USB_DIRECTION_BOTH)497 || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {498 return EBADF;499 }500 501 int rc;502 _PREPARE_TARGET(target, pipe);503 504 rc = usb_drv_async_control_write(pipe->hc_phone, target,505 setup_buffer, setup_buffer_size,506 data_buffer, data_buffer_size,507 handle);508 509 return rc;510 }511 512 /** Wait for transfer completion.513 *514 * The function blocks the caller fibril until the transfer associated515 * with given @p handle is completed.516 *517 * @param[in] pipe Pipe the transfer executed on.518 * @param[in] handle Transfer handle.519 * @return Error code.520 */521 int usb_endpoint_pipe_wait_for(usb_endpoint_pipe_t *pipe, usb_handle_t handle)522 {523 return usb_drv_async_wait_for(handle);524 }525 526 527 184 /** 528 185 * @} -
uspace/lib/usb/src/pipesinit.c
r600733e r2e85b3c 320 320 } 321 321 322 /** Initialize USB endpoint pipe. 323 * 324 * @param pipe Endpoint pipe to be initialized. 325 * @param connection Connection to the USB device backing this pipe (the wire). 326 * @param endpoint_no Endpoint number (in USB 1.1 in range 0 to 15). 327 * @param transfer_type Transfer type (e.g. interrupt or bulk). 328 * @param max_packet_size Maximum packet size in bytes. 329 * @param direction Endpoint direction (in/out). 330 * @return Error code. 331 */ 332 int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *pipe, 333 usb_device_connection_t *connection, usb_endpoint_t endpoint_no, 334 usb_transfer_type_t transfer_type, size_t max_packet_size, 335 usb_direction_t direction) 336 { 337 assert(pipe); 338 assert(connection); 339 340 pipe->wire = connection; 341 pipe->hc_phone = -1; 342 pipe->endpoint_no = endpoint_no; 343 pipe->transfer_type = transfer_type; 344 pipe->max_packet_size = max_packet_size; 345 pipe->direction = direction; 346 347 return EOK; 348 } 349 350 351 /** Initialize USB endpoint pipe as the default zero control pipe. 352 * 353 * @param pipe Endpoint pipe to be initialized. 354 * @param connection Connection to the USB device backing this pipe (the wire). 355 * @return Error code. 356 */ 357 int usb_endpoint_pipe_initialize_default_control(usb_endpoint_pipe_t *pipe, 358 usb_device_connection_t *connection) 359 { 360 assert(pipe); 361 assert(connection); 362 363 int rc = usb_endpoint_pipe_initialize(pipe, connection, 364 0, USB_TRANSFER_CONTROL, 8, USB_DIRECTION_BOTH); 365 366 return rc; 367 } 368 322 369 /** 323 370 * @} -
uspace/lib/usb/src/usb.c
r600733e r2e85b3c 54 54 } 55 55 56 /** String representation of USB transaction outcome. */57 const char * usb_str_transaction_outcome(usb_transaction_outcome_t o)58 {59 switch (o) {60 case USB_OUTCOME_OK:61 return "ok";62 case USB_OUTCOME_CRCERROR:63 return "CRC error";64 case USB_OUTCOME_BABBLE:65 return "babble";66 default:67 return "unknown";68 }69 }70 71 72 56 /** 73 57 * @} -
uspace/lib/usb/src/usbdrv.c
r600733e r2e85b3c 464 464 assert(setup_packet != NULL); 465 465 assert(setup_packet_size > 0); 466 assert( buffer != NULL);467 assert(buffer_size > 0);466 assert(((buffer != NULL) && (buffer_size > 0)) 467 || ((buffer == NULL) && (buffer_size == 0))); 468 468 assert(handle != NULL); 469 469 … … 494 494 } 495 495 496 rc = async_data_write_start(phone, buffer, buffer_size); 497 if (rc != EOK) { 498 async_wait_for(transfer->request, NULL); 499 return rc; 496 if (buffer_size > 0) { 497 rc = async_data_write_start(phone, buffer, buffer_size); 498 if (rc != EOK) { 499 async_wait_for(transfer->request, NULL); 500 return rc; 501 } 500 502 } 501 503 -
uspace/lib/usbvirt/Makefile
r600733e r2e85b3c 30 30 LIBRARY = libusbvirt 31 31 32 LIBS = $(LIBUSB_PREFIX)/libusb.a33 32 EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -Iinclude 34 33
Note:
See TracChangeset
for help on using the changeset viewer.
