[90fb679] | 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 usb
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * @brief Implementation of pseudo-synchronous transfers.
|
---|
| 34 | */
|
---|
| 35 | #include <usb/usbdrv.h>
|
---|
| 36 | #include <usbhc_iface.h>
|
---|
| 37 | #include <errno.h>
|
---|
| 38 |
|
---|
| 39 | int usb_drv_psync_interrupt_out(int phone, usb_target_t target,
|
---|
| 40 | void *buffer, size_t size)
|
---|
| 41 | {
|
---|
| 42 | usb_handle_t h;
|
---|
| 43 | int rc;
|
---|
| 44 | rc = usb_drv_async_interrupt_out(phone, target, buffer, size, &h);
|
---|
| 45 | if (rc != EOK) {
|
---|
| 46 | return rc;
|
---|
| 47 | }
|
---|
| 48 | return usb_drv_async_wait_for(h);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | int usb_drv_psync_interrupt_in(int phone, usb_target_t target,
|
---|
| 52 | void *buffer, size_t size, size_t *actual_size)
|
---|
| 53 | {
|
---|
| 54 | usb_handle_t h;
|
---|
| 55 | int rc;
|
---|
| 56 | rc = usb_drv_async_interrupt_in(phone, target, buffer, size,
|
---|
| 57 | actual_size, &h);
|
---|
| 58 | if (rc != EOK) {
|
---|
| 59 | return rc;
|
---|
| 60 | }
|
---|
| 61 | return usb_drv_async_wait_for(h);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | int usb_drv_psync_control_write_setup(int phone, usb_target_t target,
|
---|
| 67 | void *buffer, size_t size)
|
---|
| 68 | {
|
---|
| 69 | usb_handle_t h;
|
---|
| 70 | int rc;
|
---|
| 71 | rc = usb_drv_async_control_write_setup(phone, target, buffer, size, &h);
|
---|
| 72 | if (rc != EOK) {
|
---|
| 73 | return rc;
|
---|
| 74 | }
|
---|
| 75 | return usb_drv_async_wait_for(h);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | int usb_drv_psync_control_write_data(int phone, usb_target_t target,
|
---|
| 79 | void *buffer, size_t size)
|
---|
| 80 | {
|
---|
| 81 | usb_handle_t h;
|
---|
| 82 | int rc;
|
---|
| 83 | rc = usb_drv_async_control_write_data(phone, target, buffer, size, &h);
|
---|
| 84 | if (rc != EOK) {
|
---|
| 85 | return rc;
|
---|
| 86 | }
|
---|
| 87 | return usb_drv_async_wait_for(h);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | int usb_drv_psync_control_write_status(int phone, usb_target_t target)
|
---|
| 91 | {
|
---|
| 92 | usb_handle_t h;
|
---|
| 93 | int rc;
|
---|
| 94 | rc = usb_drv_async_control_write_status(phone, target, &h);
|
---|
| 95 | if (rc != EOK) {
|
---|
| 96 | return rc;
|
---|
| 97 | }
|
---|
| 98 | return usb_drv_async_wait_for(h);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 |
|
---|
[11feca8] | 102 | /** Perform complete control write transaction over USB.
|
---|
| 103 | *
|
---|
| 104 | * The DATA stage is performed only when @p data is not NULL and
|
---|
| 105 | * @p data_size is greater than zero.
|
---|
| 106 | *
|
---|
| 107 | * @param phone Open phone to host controller.
|
---|
| 108 | * @param target Target device and endpoint.
|
---|
| 109 | * @param setup_packet Setup packet data.
|
---|
| 110 | * @param setup_packet_size Size of the setup packet.
|
---|
| 111 | * @param data Data to be sent.
|
---|
| 112 | * @param data_size Size of the @p data buffer.
|
---|
| 113 | * @return Error code.
|
---|
| 114 | */
|
---|
| 115 | int usb_drv_psync_control_write(int phone, usb_target_t target,
|
---|
| 116 | void *setup_packet, size_t setup_packet_size,
|
---|
| 117 | void *data, size_t data_size)
|
---|
| 118 | {
|
---|
| 119 | int rc;
|
---|
| 120 |
|
---|
| 121 | rc = usb_drv_psync_control_write_setup(phone, target,
|
---|
| 122 | setup_packet, setup_packet_size);
|
---|
| 123 | if (rc != EOK) {
|
---|
| 124 | return rc;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | if ((data != NULL) && (data_size > 0)) {
|
---|
| 128 | rc = usb_drv_psync_control_write_data(phone, target,
|
---|
| 129 | data, data_size);
|
---|
| 130 | if (rc != EOK) {
|
---|
| 131 | return rc;
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | rc = usb_drv_psync_control_write_status(phone, target);
|
---|
| 136 |
|
---|
| 137 | return rc;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
[90fb679] | 140 |
|
---|
| 141 | int usb_drv_psync_control_read_setup(int phone, usb_target_t target,
|
---|
| 142 | void *buffer, size_t size)
|
---|
| 143 | {
|
---|
| 144 | usb_handle_t h;
|
---|
| 145 | int rc;
|
---|
| 146 | rc = usb_drv_async_control_read_setup(phone, target, buffer, size, &h);
|
---|
| 147 | if (rc != EOK) {
|
---|
| 148 | return rc;
|
---|
| 149 | }
|
---|
| 150 | return usb_drv_async_wait_for(h);
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | int usb_drv_psync_control_read_data(int phone, usb_target_t target,
|
---|
| 154 | void *buffer, size_t size, size_t *actual_size)
|
---|
| 155 | {
|
---|
| 156 | usb_handle_t h;
|
---|
| 157 | int rc;
|
---|
| 158 | rc = usb_drv_async_control_read_data(phone, target, buffer, size,
|
---|
| 159 | actual_size, &h);
|
---|
| 160 | if (rc != EOK) {
|
---|
| 161 | return rc;
|
---|
| 162 | }
|
---|
| 163 | return usb_drv_async_wait_for(h);
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | int usb_drv_psync_control_read_status(int phone, usb_target_t target)
|
---|
| 167 | {
|
---|
| 168 | usb_handle_t h;
|
---|
| 169 | int rc;
|
---|
| 170 | rc = usb_drv_async_control_read_status(phone, target, &h);
|
---|
| 171 | if (rc != EOK) {
|
---|
| 172 | return rc;
|
---|
| 173 | }
|
---|
| 174 | return usb_drv_async_wait_for(h);
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[11feca8] | 177 |
|
---|
| 178 | /** Perform complete control read transaction over USB.
|
---|
| 179 | *
|
---|
| 180 | * @param phone Open phone to host controller.
|
---|
| 181 | * @param target Target device and endpoint.
|
---|
| 182 | * @param setup_packet Setup packet data.
|
---|
| 183 | * @param setup_packet_size Size of the setup packet.
|
---|
| 184 | * @param data Storage for read data.
|
---|
| 185 | * @param data_size Size of the @p data buffer.
|
---|
| 186 | * @param actual_data_size Storage for number of actually transferred data from
|
---|
| 187 | * device.
|
---|
| 188 | * @return Error code.
|
---|
| 189 | */
|
---|
| 190 | int usb_drv_psync_control_read(int phone, usb_target_t target,
|
---|
| 191 | void *setup_packet, size_t setup_packet_size,
|
---|
| 192 | void *data, size_t data_size, size_t *actual_data_size)
|
---|
| 193 | {
|
---|
| 194 | int rc;
|
---|
| 195 |
|
---|
| 196 | rc = usb_drv_psync_control_read_setup(phone, target,
|
---|
| 197 | setup_packet, setup_packet_size);
|
---|
| 198 | if (rc != EOK) {
|
---|
| 199 | return rc;
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | rc = usb_drv_psync_control_read_data(phone, target,
|
---|
| 203 | data, data_size, actual_data_size);
|
---|
| 204 | if (rc != EOK) {
|
---|
| 205 | return rc;
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | rc = usb_drv_psync_control_read_status(phone, target);
|
---|
| 209 |
|
---|
| 210 | return rc;
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 |
|
---|
| 214 |
|
---|
| 215 |
|
---|
[90fb679] | 216 | /**
|
---|
| 217 | * @}
|
---|
| 218 | */
|
---|