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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a1f83a3 was f9d0a86, checked in by Aearsis <Hlavaty.Ondrej@…>, 8 years ago

Merge tag '0.7.1'

The merge wasn't clean, because of changes in build system. The most
significant change was partial revert of usbhc callback refactoring,
which now does not take usb transfer batch, but few named fields again.

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