source: mainline/uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h@ db51a6a6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since db51a6a6 was db51a6a6, checked in by Ondřej Hlavatý <aearsis@…>, 7 years ago

typo: transferred is spelled with two r

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * Copyright (c) 2011 Jan Vesely
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 libusbhost
30 * @{
31 */
32/** @file
33 * USB transfer transaction structures.
34 */
35
36#ifndef LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H
37#define LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H
38
39#include <atomic.h>
40#include <errno.h>
41#include <stddef.h>
42#include <stdint.h>
43#include <usb/request.h>
44#include <usb/usb.h>
45#include <usbhc_iface.h>
46
47#include <usb/host/hcd.h>
48#include <usb/host/endpoint.h>
49#include <usb/host/bus.h>
50
51typedef struct endpoint endpoint_t;
52typedef struct bus bus_t;
53
54/** Structure stores additional data needed for communication with EP */
55typedef struct usb_transfer_batch {
56 /** Target for communication */
57 usb_target_t target;
58
59 /** Endpoint used for communication */
60 endpoint_t *ep;
61
62 /** Direction of the transfer */
63 usb_direction_t dir;
64
65 /** Function called on completion */
66 usbhc_iface_transfer_callback_t on_complete;
67 /** Arbitrary data for the handler */
68 void *on_complete_data;
69
70 /** Place to store SETUP data needed by control transfers */
71 union {
72 char buffer [USB_SETUP_PACKET_SIZE];
73 usb_device_request_setup_packet_t packet;
74 uint64_t packed;
75 } setup;
76
77 /** Place for data to send/receive */
78 char *buffer;
79 /** Size of memory pointed to by buffer member */
80 size_t buffer_size;
81 /** Actually used portion of the buffer */
82 size_t transferred_size;
83
84 /** Indicates success/failure of the communication */
85 int error;
86} usb_transfer_batch_t;
87
88/**
89 * Printf formatting string for dumping usb_transfer_batch_t.
90 * [address:endpoint speed transfer_type-direction buffer_sizeB/max_packet_size]
91 * */
92#define USB_TRANSFER_BATCH_FMT "[%d:%d %s %s-%s %zuB/%zu]"
93
94/** Printf arguments for dumping usb_transfer_batch_t.
95 * @param batch USB transfer batch to be dumped.
96 */
97#define USB_TRANSFER_BATCH_ARGS(batch) \
98 ((batch).ep->device->address), ((batch).ep->endpoint), \
99 usb_str_speed((batch).ep->device->speed), \
100 usb_str_transfer_type_short((batch).ep->transfer_type), \
101 usb_str_direction((batch).dir), \
102 (batch).buffer_size, (batch).ep->max_packet_size
103
104/** Wrapper for bus operation. */
105usb_transfer_batch_t *usb_transfer_batch_create(endpoint_t *);
106
107/** Batch initializer. */
108void usb_transfer_batch_init(usb_transfer_batch_t *, endpoint_t *);
109
110/** Batch finalization. */
111void usb_transfer_batch_finish(usb_transfer_batch_t *);
112
113/** To be called from outside only when the transfer is not going to be finished
114 * (i.o.w. until successfuly scheduling)
115 */
116void usb_transfer_batch_destroy(usb_transfer_batch_t *);
117
118#endif
119
120/**
121 * @}
122 */
Note: See TracBrowser for help on using the repository browser.