source: mainline/uspace/lib/usb/src/host/batch.c@ d017cea

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

Remove EP information stored in usb_transfer_batch_t

rename usb_transfer_batch_t.transport_buffer ⇒ data_buffer

  • Property mode set to 100644
File size: 4.5 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 libusb
29 * @{
30 */
31/** @file
32 * USB transfer transaction structures (implementation).
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
41void usb_transfer_batch_init(
42 usb_transfer_batch_t *instance,
43 endpoint_t *ep,
44 char *buffer,
45 char *data_buffer,
46 size_t buffer_size,
47 char *setup_buffer,
48 size_t setup_size,
49 usbhc_iface_transfer_in_callback_t func_in,
50 usbhc_iface_transfer_out_callback_t func_out,
51 void *arg,
52 ddf_fun_t *fun,
53 void *private_data
54 )
55{
56 assert(instance);
57 link_initialize(&instance->link);
58 instance->ep = ep;
59 instance->callback_in = func_in;
60 instance->callback_out = func_out;
61 instance->arg = arg;
62 instance->buffer = buffer;
63 instance->data_buffer = data_buffer;
64 instance->buffer_size = buffer_size;
65 instance->setup_buffer = setup_buffer;
66 instance->setup_size = setup_size;
67 instance->fun = fun;
68 instance->private_data = private_data;
69 instance->transfered_size = 0;
70 instance->next_step = NULL;
71 instance->error = EOK;
72 endpoint_use(instance->ep);
73}
74/*----------------------------------------------------------------------------*/
75/** Mark batch as finished and continue with next step.
76 *
77 * @param[in] instance Batch structure to use.
78 *
79 */
80void usb_transfer_batch_finish(usb_transfer_batch_t *instance)
81{
82 assert(instance);
83 assert(instance->ep);
84 endpoint_release(instance->ep);
85 instance->next_step(instance);
86}
87/*----------------------------------------------------------------------------*/
88/** Prepare data, get error status and call callback in.
89 *
90 * @param[in] instance Batch structure to use.
91 * Copies data from transport buffer, and calls callback with appropriate
92 * parameters.
93 */
94void usb_transfer_batch_call_in(usb_transfer_batch_t *instance)
95{
96 assert(instance);
97 assert(instance->callback_in);
98 assert(instance->ep);
99
100 /* We are data in, we need data */
101 memcpy(instance->buffer, instance->data_buffer, instance->buffer_size);
102
103 usb_log_debug("Batch %p done (T%d.%d, %s %s in, %zuB): %s (%d).\n",
104 instance, instance->ep->address, instance->ep->endpoint,
105 usb_str_speed(instance->ep->speed),
106 usb_str_transfer_type_short(instance->ep->transfer_type),
107 instance->transfered_size, str_error(instance->error), instance->error);
108
109 instance->callback_in(instance->fun, instance->error,
110 instance->transfered_size, instance->arg);
111}
112/*----------------------------------------------------------------------------*/
113/** Get error status and call callback out.
114 *
115 * @param[in] instance Batch structure to use.
116 */
117void usb_transfer_batch_call_out(usb_transfer_batch_t *instance)
118{
119 assert(instance);
120 assert(instance->callback_out);
121
122 usb_log_debug("Batch %p done (T%d.%d, %s %s out): %s (%d).\n",
123 instance, instance->ep->address, instance->ep->endpoint,
124 usb_str_speed(instance->ep->speed),
125 usb_str_transfer_type_short(instance->ep->transfer_type),
126 str_error(instance->error), instance->error);
127
128 instance->callback_out(instance->fun,
129 instance->error, instance->arg);
130}
131/**
132 * @}
133 */
Note: See TracBrowser for help on using the repository browser.