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 libusb
|
---|
29 | * @{
|
---|
30 | */
|
---|
31 | /** @file
|
---|
32 | * @brief OHCI driver USB transaction structure
|
---|
33 | */
|
---|
34 | #include <errno.h>
|
---|
35 | #include <str_error.h>
|
---|
36 |
|
---|
37 | #include <usb/usb.h>
|
---|
38 | #include <usb/debug.h>
|
---|
39 | #include <usb/host/batch.h>
|
---|
40 |
|
---|
41 | void batch_init(
|
---|
42 | batch_t *instance,
|
---|
43 | usb_target_t target,
|
---|
44 | usb_transfer_type_t transfer_type,
|
---|
45 | usb_speed_t speed,
|
---|
46 | size_t max_packet_size,
|
---|
47 | char *buffer,
|
---|
48 | char *transport_buffer,
|
---|
49 | size_t buffer_size,
|
---|
50 | char *setup_buffer,
|
---|
51 | size_t setup_size,
|
---|
52 | usbhc_iface_transfer_in_callback_t func_in,
|
---|
53 | usbhc_iface_transfer_out_callback_t func_out,
|
---|
54 | void *arg,
|
---|
55 | ddf_fun_t *fun,
|
---|
56 | void *private_data
|
---|
57 | )
|
---|
58 | {
|
---|
59 | assert(instance);
|
---|
60 | link_initialize(&instance->link);
|
---|
61 | instance->target = target;
|
---|
62 | instance->transfer_type = transfer_type;
|
---|
63 | instance->speed = speed;
|
---|
64 | instance->callback_in = func_in;
|
---|
65 | instance->callback_out = func_out;
|
---|
66 | instance->arg = arg;
|
---|
67 | instance->buffer = buffer;
|
---|
68 | instance->transport_buffer = transport_buffer;
|
---|
69 | instance->buffer_size = buffer_size;
|
---|
70 | instance->setup_buffer = setup_buffer;
|
---|
71 | instance->setup_size = setup_size;
|
---|
72 | instance->max_packet_size = max_packet_size;
|
---|
73 | instance->fun = fun;
|
---|
74 | instance->private_data = private_data;
|
---|
75 | instance->transfered_size = 0;
|
---|
76 | instance->next_step = NULL;
|
---|
77 | instance->error = EOK;
|
---|
78 |
|
---|
79 | }
|
---|
80 | /*----------------------------------------------------------------------------*/
|
---|
81 | /** Mark batch as finished and continue with next step.
|
---|
82 | *
|
---|
83 | * @param[in] instance Batch structure to use.
|
---|
84 | *
|
---|
85 | */
|
---|
86 | void batch_finish(batch_t *instance, int error)
|
---|
87 | {
|
---|
88 | assert(instance);
|
---|
89 | instance->error = error;
|
---|
90 | instance->next_step(instance);
|
---|
91 | }
|
---|
92 | /*----------------------------------------------------------------------------*/
|
---|
93 | /** Prepare data, get error status and call callback in.
|
---|
94 | *
|
---|
95 | * @param[in] instance Batch structure to use.
|
---|
96 | * Copies data from transport buffer, and calls callback with appropriate
|
---|
97 | * parameters.
|
---|
98 | */
|
---|
99 | void batch_call_in(batch_t *instance)
|
---|
100 | {
|
---|
101 | assert(instance);
|
---|
102 | assert(instance->callback_in);
|
---|
103 |
|
---|
104 | /* We are data in, we need data */
|
---|
105 | memcpy(instance->buffer, instance->transport_buffer,
|
---|
106 | instance->buffer_size);
|
---|
107 |
|
---|
108 | int err = instance->error;
|
---|
109 | usb_log_debug("Batch(%p) callback IN(type:%d): %s(%d), %zu.\n",
|
---|
110 | instance, instance->transfer_type, str_error(err), err,
|
---|
111 | instance->transfered_size);
|
---|
112 |
|
---|
113 | instance->callback_in(
|
---|
114 | instance->fun, err, instance->transfered_size, instance->arg);
|
---|
115 | }
|
---|
116 | /*----------------------------------------------------------------------------*/
|
---|
117 | /** Get error status and call callback out.
|
---|
118 | *
|
---|
119 | * @param[in] instance Batch structure to use.
|
---|
120 | */
|
---|
121 | void batch_call_out(batch_t *instance)
|
---|
122 | {
|
---|
123 | assert(instance);
|
---|
124 | assert(instance->callback_out);
|
---|
125 |
|
---|
126 | int err = instance->error;
|
---|
127 | usb_log_debug("Batch(%p) callback OUT(type:%d): %s(%d).\n",
|
---|
128 | instance, instance->transfer_type, str_error(err), err);
|
---|
129 | instance->callback_out(instance->fun,
|
---|
130 | err, instance->arg);
|
---|
131 | }
|
---|
132 | /**
|
---|
133 | * @}
|
---|
134 | */
|
---|