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

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

usbhost refactoring: let transfer_batch be initialized by bus

Currently makes older HCs fail, work in progress.

  • Property mode set to 100644
File size: 3.9 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
42#include <stddef.h>
43#include <stdint.h>
44#include <usbhc_iface.h>
45
46#define USB_SETUP_PACKET_SIZE 8
47
48typedef struct endpoint endpoint_t;
49typedef struct bus bus_t;
50typedef struct usb_transfer_batch usb_transfer_batch_t;
51
52/** Callback to be called on transfer. */
53typedef int (*usb_transfer_batch_callback_t)(usb_transfer_batch_t *);
54
55/** Structure stores additional data needed for communication with EP */
56typedef struct usb_transfer_batch {
57 /** Endpoint used for communication */
58 endpoint_t *ep;
59 /** Size reported to be sent */
60 size_t expected_size;
61
62 /** Direction of the transfer */
63 usb_direction_t dir;
64
65 /** Function called on completion */
66 usb_transfer_batch_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 /** Resetting the Toggle */
78 toggle_reset_mode_t toggle_reset_mode;
79
80 /** Place for data to send/receive */
81 char *buffer;
82 /** Size of memory pointed to by buffer member */
83 size_t buffer_size;
84
85 /** Actually used portion of the buffer */
86 size_t transfered_size;
87 /** Indicates success/failure of the communication */
88 int error;
89} usb_transfer_batch_t;
90
91/** Printf formatting string for dumping usb_transfer_batch_t. */
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->target.address, (batch).ep->target.endpoint, \
99 usb_str_speed((batch).ep->speed), \
100 usb_str_transfer_type_short((batch).ep->transfer_type), \
101 usb_str_direction((batch).ep->direction), \
102 (batch).buffer_size, (batch).ep->max_packet_size
103
104void usb_transfer_batch_init(usb_transfer_batch_t *, endpoint_t *);
105void usb_transfer_batch_finish(usb_transfer_batch_t *);
106
107usb_transfer_batch_t *usb_transfer_batch_create(endpoint_t *);
108void usb_transfer_batch_destroy(usb_transfer_batch_t *);
109
110/** Provided to ease the transition. Wraps old-style handlers into a new one.
111 */
112extern void usb_transfer_batch_set_old_handlers(usb_transfer_batch_t *,
113 usbhc_iface_transfer_in_callback_t,
114 usbhc_iface_transfer_out_callback_t, void *);
115
116#endif
117
118/**
119 * @}
120 */
Note: See TracBrowser for help on using the repository browser.