[81dce9f] | 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 | */
|
---|
[160b75e] | 28 | /** @addtogroup libusbhost
|
---|
[81dce9f] | 29 | * @{
|
---|
| 30 | */
|
---|
| 31 | /** @file
|
---|
[c92c13f] | 32 | * USB transfer transaction structures.
|
---|
[81dce9f] | 33 | */
|
---|
[160b75e] | 34 | #ifndef LIBUSBHOST_HOST_BATCH_H
|
---|
| 35 | #define LIBUSBHOST_HOST_BATCH_H
|
---|
[81dce9f] | 36 |
|
---|
| 37 | #include <adt/list.h>
|
---|
| 38 |
|
---|
| 39 | #include <usbhc_iface.h>
|
---|
| 40 | #include <usb/usb.h>
|
---|
[f567bcf] | 41 | #include <usb/host/endpoint.h>
|
---|
[81dce9f] | 42 |
|
---|
[1387692] | 43 | typedef struct usb_transfer_batch usb_transfer_batch_t;
|
---|
| 44 | struct usb_transfer_batch {
|
---|
[d017cea] | 45 | endpoint_t *ep;
|
---|
[81dce9f] | 46 | link_t link;
|
---|
| 47 | usbhc_iface_transfer_in_callback_t callback_in;
|
---|
| 48 | usbhc_iface_transfer_out_callback_t callback_out;
|
---|
[d017cea] | 49 | void *arg;
|
---|
[81dce9f] | 50 | char *buffer;
|
---|
[d017cea] | 51 | char *data_buffer;
|
---|
[81dce9f] | 52 | size_t buffer_size;
|
---|
| 53 | char *setup_buffer;
|
---|
| 54 | size_t setup_size;
|
---|
| 55 | size_t transfered_size;
|
---|
[1387692] | 56 | void (*next_step)(usb_transfer_batch_t *);
|
---|
[81dce9f] | 57 | int error;
|
---|
| 58 | ddf_fun_t *fun;
|
---|
| 59 | void *private_data;
|
---|
[2cc6e97] | 60 | void (*private_data_dtor)(void *p_data);
|
---|
[1387692] | 61 | };
|
---|
[81dce9f] | 62 |
|
---|
[c4fb5ecd] | 63 | /** Printf formatting string for dumping usb_transfer_batch_t. */
|
---|
| 64 | #define USB_TRANSFER_BATCH_FMT "[%d:%d %s %s-%s %zuB/%zu]"
|
---|
| 65 |
|
---|
| 66 | /** Printf arguments for dumping usb_transfer_batch_t.
|
---|
| 67 | * @param batch USB transfer batch to be dumped.
|
---|
| 68 | */
|
---|
| 69 | #define USB_TRANSFER_BATCH_ARGS(batch) \
|
---|
| 70 | (batch).ep->address, (batch).ep->endpoint, \
|
---|
| 71 | usb_str_speed((batch).ep->speed), \
|
---|
| 72 | usb_str_transfer_type_short((batch).ep->transfer_type), \
|
---|
| 73 | usb_str_direction((batch).ep->direction), \
|
---|
| 74 | (batch).buffer_size, (batch).ep->max_packet_size
|
---|
| 75 |
|
---|
| 76 |
|
---|
[70fb822] | 77 | usb_transfer_batch_t * usb_transfer_batch_get(
|
---|
[2cc6e97] | 78 | endpoint_t *ep,
|
---|
[81dce9f] | 79 | char *buffer,
|
---|
[d017cea] | 80 | char *data_buffer,
|
---|
[81dce9f] | 81 | size_t buffer_size,
|
---|
| 82 | char *setup_buffer,
|
---|
| 83 | size_t setup_size,
|
---|
| 84 | usbhc_iface_transfer_in_callback_t func_in,
|
---|
| 85 | usbhc_iface_transfer_out_callback_t func_out,
|
---|
| 86 | void *arg,
|
---|
| 87 | ddf_fun_t *fun,
|
---|
[2cc6e97] | 88 | void *private_data,
|
---|
| 89 | void (*private_data_dtor)(void *p_data)
|
---|
[81dce9f] | 90 | );
|
---|
| 91 |
|
---|
[f18d82f0] | 92 | void usb_transfer_batch_finish(usb_transfer_batch_t *instance,
|
---|
| 93 | const void* data, size_t size);
|
---|
[96e2d01] | 94 | void usb_transfer_batch_call_in(usb_transfer_batch_t *instance);
|
---|
| 95 | void usb_transfer_batch_call_out(usb_transfer_batch_t *instance);
|
---|
[2cc6e97] | 96 | void usb_transfer_batch_dispose(usb_transfer_batch_t *instance);
|
---|
[cd1cec3b] | 97 |
|
---|
[96e2d01] | 98 | /** Helper function, calls callback and correctly destroys batch structure.
|
---|
| 99 | *
|
---|
| 100 | * @param[in] instance Batch structure to use.
|
---|
| 101 | */
|
---|
| 102 | static inline void usb_transfer_batch_call_in_and_dispose(
|
---|
| 103 | usb_transfer_batch_t *instance)
|
---|
| 104 | {
|
---|
| 105 | assert(instance);
|
---|
| 106 | usb_transfer_batch_call_in(instance);
|
---|
| 107 | usb_transfer_batch_dispose(instance);
|
---|
| 108 | }
|
---|
| 109 | /*----------------------------------------------------------------------------*/
|
---|
| 110 | /** Helper function calls callback and correctly destroys batch structure.
|
---|
| 111 | *
|
---|
| 112 | * @param[in] instance Batch structure to use.
|
---|
| 113 | */
|
---|
| 114 | static inline void usb_transfer_batch_call_out_and_dispose(
|
---|
| 115 | usb_transfer_batch_t *instance)
|
---|
| 116 | {
|
---|
| 117 | assert(instance);
|
---|
| 118 | usb_transfer_batch_call_out(instance);
|
---|
| 119 | usb_transfer_batch_dispose(instance);
|
---|
| 120 | }
|
---|
| 121 | /*----------------------------------------------------------------------------*/
|
---|
[cd1cec3b] | 122 | static inline void usb_transfer_batch_finish_error(
|
---|
[f18d82f0] | 123 | usb_transfer_batch_t *instance, const void* data, size_t size, int error)
|
---|
[cd1cec3b] | 124 | {
|
---|
| 125 | assert(instance);
|
---|
| 126 | instance->error = error;
|
---|
[f18d82f0] | 127 | usb_transfer_batch_finish(instance, data, size);
|
---|
[cd1cec3b] | 128 | }
|
---|
[96e2d01] | 129 | /*----------------------------------------------------------------------------*/
|
---|
[2cc6e97] | 130 | static inline usb_transfer_batch_t *usb_transfer_batch_from_link(link_t *l)
|
---|
| 131 | {
|
---|
| 132 | assert(l);
|
---|
| 133 | return list_get_instance(l, usb_transfer_batch_t, link);
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[81dce9f] | 136 | #endif
|
---|
| 137 | /**
|
---|
| 138 | * @}
|
---|
| 139 | */
|
---|