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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4e5dabf was c59dbdd5, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

libusbhost: Doxygen. Return NULL on NULL link in endpoint_get_instance.

  • Property mode set to 100644
File size: 5.7 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/** @addtogroup libusbhost
29 * @{
30 */
31/** @file
32 * USB transfer transaction structures.
33 */
34#ifndef LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H
35#define LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H
36
37#include <adt/list.h>
38
39#include <usbhc_iface.h>
40#include <usb/usb.h>
41#include <usb/host/endpoint.h>
42
43#define USB_SETUP_PACKET_SIZE 8
44
45/** Structure stores additional data needed for communication with EP */
46typedef struct usb_transfer_batch {
47 /** Endpoint used for communication */
48 endpoint_t *ep;
49 /** Function called on completion (IN version) */
50 usbhc_iface_transfer_in_callback_t callback_in;
51 /** Function called on completion (OUT version) */
52 usbhc_iface_transfer_out_callback_t callback_out;
53 /** Argument to pass to the completion function */
54 void *arg;
55 /** Place for data to send/receive */
56 char *buffer;
57 /** Size of memory pointed to by buffer member */
58 size_t buffer_size;
59 /** Place to store SETUP data needed by control transfers */
60 char setup_buffer[USB_SETUP_PACKET_SIZE];
61 /** Used portion of setup_buffer member
62 *
63 * SETUP buffer must be 8 bytes for control transfers and is left
64 * unused for all other transfers. Thus, this field is either 0 or 8.
65 */
66 size_t setup_size;
67 /** Host controller function, passed to callback function */
68 ddf_fun_t *fun;
69
70 /** Actually used portion of the buffer
71 * This member is never accessed by functions provided in this header,
72 * with the exception of usb_transfer_batch_finish. For external use.
73 */
74 size_t transfered_size;
75 /** Indicates success/failure of the communication
76 * This member is never accessed by functions provided in this header,
77 * with the exception of usb_transfer_batch_finish. For external use.
78 */
79 int error;
80
81 /** Driver specific data */
82 void *private_data;
83 /** Callback to properly remove driver data during destruction */
84 void (*private_data_dtor)(void *p_data);
85} usb_transfer_batch_t;
86
87/** Printf formatting string for dumping usb_transfer_batch_t. */
88#define USB_TRANSFER_BATCH_FMT "[%d:%d %s %s-%s %zuB/%zu]"
89
90/** Printf arguments for dumping usb_transfer_batch_t.
91 * @param batch USB transfer batch to be dumped.
92 */
93#define USB_TRANSFER_BATCH_ARGS(batch) \
94 (batch).ep->address, (batch).ep->endpoint, \
95 usb_str_speed((batch).ep->speed), \
96 usb_str_transfer_type_short((batch).ep->transfer_type), \
97 usb_str_direction((batch).ep->direction), \
98 (batch).buffer_size, (batch).ep->max_packet_size
99
100
101usb_transfer_batch_t * usb_transfer_batch_create(
102 endpoint_t *ep,
103 char *buffer,
104 size_t buffer_size,
105 uint64_t setup_buffer,
106 usbhc_iface_transfer_in_callback_t func_in,
107 usbhc_iface_transfer_out_callback_t func_out,
108 void *arg,
109 ddf_fun_t *fun,
110 void *private_data,
111 void (*private_data_dtor)(void *p_data)
112);
113void usb_transfer_batch_destroy(const usb_transfer_batch_t *instance);
114
115void usb_transfer_batch_finish_error(const usb_transfer_batch_t *instance,
116 const void* data, size_t size, int error);
117/*----------------------------------------------------------------------------*/
118/** Finish batch using stored error value and transferred size.
119 *
120 * @param[in] instance Batch structure to use.
121 * @param[in] data Data to copy to the output buffer.
122 */
123static inline void usb_transfer_batch_finish(
124 const usb_transfer_batch_t *instance, const void* data)
125{
126 assert(instance);
127 usb_transfer_batch_finish_error(
128 instance, data, instance->transfered_size, instance->error);
129}
130/*----------------------------------------------------------------------------*/
131/** Determine batch direction based on the callbacks present
132 * @param[in] instance Batch structure to use, non-null.
133 * @return USB_DIRECTION_IN, or USB_DIRECTION_OUT.
134 */
135static inline usb_direction_t usb_transfer_batch_direction(
136 const usb_transfer_batch_t *instance)
137{
138 assert(instance);
139 if (instance->callback_in) {
140 assert(instance->callback_out == NULL);
141 assert(instance->ep == NULL
142 || instance->ep->transfer_type == USB_TRANSFER_CONTROL
143 || instance->ep->direction == USB_DIRECTION_IN);
144 return USB_DIRECTION_IN;
145 }
146 if (instance->callback_out) {
147 assert(instance->callback_in == NULL);
148 assert(instance->ep == NULL
149 || instance->ep->transfer_type == USB_TRANSFER_CONTROL
150 || instance->ep->direction == USB_DIRECTION_OUT);
151 return USB_DIRECTION_OUT;
152 }
153 assert(false);
154}
155#endif
156/**
157 * @}
158 */
Note: See TracBrowser for help on using the repository browser.