Changeset 567d002 in mainline
- Timestamp:
- 2011-02-14T18:11:21Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 47c573a
- Parents:
- b53ca1e
- Location:
- uspace/lib/usb
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/include/usb/pipes.h
rb53ca1e r567d002 139 139 void *, size_t); 140 140 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 141 #endif 156 142 /** -
uspace/lib/usb/src/pipesio.c
rb53ca1e r567d002 68 68 assert(pipe); 69 69 70 int rc; 71 usb_handle_t handle; 72 73 rc = usb_endpoint_pipe_async_read(pipe, buffer, size, size_transfered, 74 &handle); 75 if (rc != EOK) { 76 return rc; 77 } 78 79 rc = usb_endpoint_pipe_wait_for(pipe, handle); 70 if (pipe->hc_phone < 0) { 71 return EBADF; 72 } 73 74 if (pipe->direction != USB_DIRECTION_IN) { 75 return EBADF; 76 } 77 78 int rc; 79 _PREPARE_TARGET(target, pipe); 80 usb_handle_t handle; 81 82 switch (pipe->transfer_type) { 83 case USB_TRANSFER_INTERRUPT: 84 rc = usb_drv_async_interrupt_in(pipe->hc_phone, target, 85 buffer, size, size_transfered, &handle); 86 break; 87 case USB_TRANSFER_CONTROL: 88 rc = EBADF; 89 break; 90 default: 91 rc = ENOTSUP; 92 break; 93 } 94 95 if (rc != EOK) { 96 return rc; 97 } 98 99 rc = usb_drv_async_wait_for(handle); 100 80 101 return rc; 81 102 } … … 93 114 assert(pipe); 94 115 95 int rc; 96 usb_handle_t handle; 97 98 rc = usb_endpoint_pipe_async_write(pipe, buffer, size, &handle); 99 if (rc != EOK) { 100 return rc; 101 } 102 103 rc = usb_endpoint_pipe_wait_for(pipe, handle); 116 if (pipe->hc_phone < 0) { 117 return EBADF; 118 } 119 120 if (pipe->direction != USB_DIRECTION_OUT) { 121 return EBADF; 122 } 123 124 int rc; 125 _PREPARE_TARGET(target, pipe); 126 usb_handle_t handle; 127 128 switch (pipe->transfer_type) { 129 case USB_TRANSFER_INTERRUPT: 130 rc = usb_drv_async_interrupt_out(pipe->hc_phone, target, 131 buffer, size, &handle); 132 break; 133 case USB_TRANSFER_CONTROL: 134 rc = EBADF; 135 break; 136 default: 137 rc = ENOTSUP; 138 break; 139 } 140 141 if (rc != EOK) { 142 return rc; 143 } 144 145 rc = usb_drv_async_wait_for(handle); 146 104 147 return rc; 105 148 } … … 125 168 assert(pipe); 126 169 127 int rc; 128 usb_handle_t handle; 129 130 rc = usb_endpoint_pipe_async_control_read(pipe, 170 if (pipe->hc_phone < 0) { 171 return EBADF; 172 } 173 174 if ((pipe->direction != USB_DIRECTION_BOTH) 175 || (pipe->transfer_type != USB_TRANSFER_CONTROL)) { 176 return EBADF; 177 } 178 179 int rc; 180 _PREPARE_TARGET(target, pipe); 181 usb_handle_t handle; 182 183 rc = usb_drv_async_control_read(pipe->hc_phone, target, 131 184 setup_buffer, setup_buffer_size, 132 185 data_buffer, data_buffer_size, data_transfered_size, 133 186 &handle); 134 if (rc != EOK) { 135 return rc; 136 } 137 138 rc = usb_endpoint_pipe_wait_for(pipe, handle); 187 188 if (rc != EOK) { 189 return rc; 190 } 191 192 rc = usb_drv_async_wait_for(handle); 193 139 194 return rc; 140 195 } … … 158 213 assert(pipe); 159 214 160 int rc; 161 usb_handle_t handle; 162 163 rc = usb_endpoint_pipe_async_control_write(pipe, 215 if (pipe->hc_phone < 0) { 216 return EBADF; 217 } 218 219 if ((pipe->direction != USB_DIRECTION_BOTH) 220 || (pipe->transfer_type != USB_TRANSFER_CONTROL)) { 221 return EBADF; 222 } 223 224 int rc; 225 _PREPARE_TARGET(target, pipe); 226 usb_handle_t handle; 227 228 rc = usb_drv_async_control_write(pipe->hc_phone, target, 164 229 setup_buffer, setup_buffer_size, 165 230 data_buffer, data_buffer_size, 166 231 &handle); 167 if (rc != EOK) { 168 return rc; 169 } 170 171 rc = usb_endpoint_pipe_wait_for(pipe, handle); 172 return rc; 173 } 174 175 176 /** Request a read (in) transfer on an endpoint pipe (asynchronous version). 177 * 178 * @param[in] pipe Pipe used for the transfer. 179 * @param[out] buffer Buffer where to store the data. 180 * @param[in] size Size of the buffer (in bytes). 181 * @param[out] size_transfered Number of bytes that were actually transfered. 182 * @param[out] handle Handle of the transfer. 183 * @return Error code. 184 */ 185 int usb_endpoint_pipe_async_read(usb_endpoint_pipe_t *pipe, 186 void *buffer, size_t size, size_t *size_transfered, 187 usb_handle_t *handle) 188 { 189 assert(pipe); 190 191 if (pipe->hc_phone < 0) { 192 return EBADF; 193 } 194 195 if (pipe->direction != USB_DIRECTION_IN) { 196 return EBADF; 197 } 198 199 int rc; 200 _PREPARE_TARGET(target, pipe); 201 202 switch (pipe->transfer_type) { 203 case USB_TRANSFER_INTERRUPT: 204 rc = usb_drv_async_interrupt_in(pipe->hc_phone, target, 205 buffer, size, size_transfered, handle); 206 break; 207 case USB_TRANSFER_CONTROL: 208 rc = EBADF; 209 break; 210 default: 211 rc = ENOTSUP; 212 break; 213 } 214 215 return rc; 216 } 217 218 219 /** Request a write (out) transfer on an endpoint pipe (asynchronous version). 220 * 221 * @param[in] pipe Pipe used for the transfer. 222 * @param[in] buffer Buffer with data to transfer. 223 * @param[in] size Size of the buffer (in bytes). 224 * @param[out] handle Handle of the transfer. 225 * @return Error code. 226 */ 227 int usb_endpoint_pipe_async_write(usb_endpoint_pipe_t *pipe, 228 void *buffer, size_t size, 229 usb_handle_t *handle) 230 { 231 assert(pipe); 232 233 if (pipe->hc_phone < 0) { 234 return EBADF; 235 } 236 237 if (pipe->direction != USB_DIRECTION_OUT) { 238 return EBADF; 239 } 240 241 int rc; 242 _PREPARE_TARGET(target, pipe); 243 244 switch (pipe->transfer_type) { 245 case USB_TRANSFER_INTERRUPT: 246 rc = usb_drv_async_interrupt_out(pipe->hc_phone, target, 247 buffer, size, handle); 248 break; 249 case USB_TRANSFER_CONTROL: 250 rc = EBADF; 251 break; 252 default: 253 rc = ENOTSUP; 254 break; 255 } 256 257 return rc; 258 } 259 260 261 /** Request a control read transfer on an endpoint pipe (asynchronous version). 262 * 263 * This function encapsulates all three stages of a control transfer. 264 * 265 * @param[in] pipe Pipe used for the transfer. 266 * @param[in] setup_buffer Buffer with the setup packet. 267 * @param[in] setup_buffer_size Size of the setup packet (in bytes). 268 * @param[out] data_buffer Buffer for incoming data. 269 * @param[in] data_buffer_size Size of the buffer for incoming data (in bytes). 270 * @param[out] data_transfered_size Number of bytes that were actually 271 * transfered during the DATA stage. 272 * @param[out] handle Handle of the transfer. 273 * @return Error code. 274 */ 275 int usb_endpoint_pipe_async_control_read(usb_endpoint_pipe_t *pipe, 276 void *setup_buffer, size_t setup_buffer_size, 277 void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size, 278 usb_handle_t *handle) 279 { 280 assert(pipe); 281 282 if (pipe->hc_phone < 0) { 283 return EBADF; 284 } 285 286 if ((pipe->direction != USB_DIRECTION_BOTH) 287 || (pipe->transfer_type != USB_TRANSFER_CONTROL)) { 288 return EBADF; 289 } 290 291 int rc; 292 _PREPARE_TARGET(target, pipe); 293 294 rc = usb_drv_async_control_read(pipe->hc_phone, target, 295 setup_buffer, setup_buffer_size, 296 data_buffer, data_buffer_size, data_transfered_size, 297 handle); 298 299 return rc; 300 } 301 302 303 /** Request a control write transfer on an endpoint pipe (asynchronous version). 304 * 305 * This function encapsulates all three stages of a control transfer. 306 * 307 * @param[in] pipe Pipe used for the transfer. 308 * @param[in] setup_buffer Buffer with the setup packet. 309 * @param[in] setup_buffer_size Size of the setup packet (in bytes). 310 * @param[in] data_buffer Buffer with data to be sent. 311 * @param[in] data_buffer_size Size of the buffer with outgoing data (in bytes). 312 * @param[out] handle Handle of the transfer. 313 * @return Error code. 314 */ 315 int usb_endpoint_pipe_async_control_write(usb_endpoint_pipe_t *pipe, 316 void *setup_buffer, size_t setup_buffer_size, 317 void *data_buffer, size_t data_buffer_size, 318 usb_handle_t *handle) 319 { 320 assert(pipe); 321 322 if (pipe->hc_phone < 0) { 323 return EBADF; 324 } 325 326 if ((pipe->direction != USB_DIRECTION_BOTH) 327 || (pipe->transfer_type != USB_TRANSFER_CONTROL)) { 328 return EBADF; 329 } 330 331 int rc; 332 _PREPARE_TARGET(target, pipe); 333 334 rc = usb_drv_async_control_write(pipe->hc_phone, target, 335 setup_buffer, setup_buffer_size, 336 data_buffer, data_buffer_size, 337 handle); 338 339 return rc; 340 } 341 342 /** Wait for transfer completion. 343 * 344 * The function blocks the caller fibril until the transfer associated 345 * with given @p handle is completed. 346 * 347 * @param[in] pipe Pipe the transfer executed on. 348 * @param[in] handle Transfer handle. 349 * @return Error code. 350 */ 351 int usb_endpoint_pipe_wait_for(usb_endpoint_pipe_t *pipe, usb_handle_t handle) 352 { 353 return usb_drv_async_wait_for(handle); 232 233 if (rc != EOK) { 234 return rc; 235 } 236 237 rc = usb_drv_async_wait_for(handle); 238 239 return rc; 354 240 } 355 241
Note:
See TracChangeset
for help on using the changeset viewer.