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

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

Use per endpoint communication mutex

  • Property mode set to 100644
File size: 4.8 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 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 endpoint_t *ep,
57 void *private_data
58 )
59{
60 assert(instance);
61 link_initialize(&instance->link);
62 instance->target = target;
63 instance->transfer_type = transfer_type;
64 instance->speed = speed;
65 instance->direction = USB_DIRECTION_BOTH;
66 instance->callback_in = func_in;
67 instance->callback_out = func_out;
68 instance->arg = arg;
69 instance->buffer = buffer;
70 instance->transport_buffer = transport_buffer;
71 instance->buffer_size = buffer_size;
72 instance->setup_buffer = setup_buffer;
73 instance->setup_size = setup_size;
74 instance->max_packet_size = max_packet_size;
75 instance->fun = fun;
76 instance->private_data = private_data;
77 instance->transfered_size = 0;
78 instance->next_step = NULL;
79 instance->error = EOK;
80 instance->ep = ep;
81 endpoint_use(instance->ep);
82}
83/*----------------------------------------------------------------------------*/
84/** Mark batch as finished and continue with next step.
85 *
86 * @param[in] instance Batch structure to use.
87 *
88 */
89void usb_transfer_batch_finish(usb_transfer_batch_t *instance)
90{
91 assert(instance);
92 assert(instance->ep);
93 endpoint_release(instance->ep);
94 instance->next_step(instance);
95}
96/*----------------------------------------------------------------------------*/
97/** Prepare data, get error status and call callback in.
98 *
99 * @param[in] instance Batch structure to use.
100 * Copies data from transport buffer, and calls callback with appropriate
101 * parameters.
102 */
103void usb_transfer_batch_call_in(usb_transfer_batch_t *instance)
104{
105 assert(instance);
106 assert(instance->callback_in);
107
108 /* We are data in, we need data */
109 memcpy(instance->buffer, instance->transport_buffer,
110 instance->buffer_size);
111
112 usb_log_debug("Batch %p done (T%d.%d, %s %s in, %zuB): %s (%d).\n",
113 instance,
114 instance->target.address, instance->target.endpoint,
115 usb_str_speed(instance->speed),
116 usb_str_transfer_type_short(instance->transfer_type),
117 instance->transfered_size,
118 str_error(instance->error), instance->error);
119
120 instance->callback_in(instance->fun, instance->error,
121 instance->transfered_size, instance->arg);
122}
123/*----------------------------------------------------------------------------*/
124/** Get error status and call callback out.
125 *
126 * @param[in] instance Batch structure to use.
127 */
128void usb_transfer_batch_call_out(usb_transfer_batch_t *instance)
129{
130 assert(instance);
131 assert(instance->callback_out);
132
133 usb_log_debug("Batch %p done (T%d.%d, %s %s out): %s (%d).\n",
134 instance,
135 instance->target.address, instance->target.endpoint,
136 usb_str_speed(instance->speed),
137 usb_str_transfer_type_short(instance->transfer_type),
138 str_error(instance->error), instance->error);
139
140 instance->callback_out(instance->fun,
141 instance->error, instance->arg);
142}
143/**
144 * @}
145 */
Note: See TracBrowser for help on using the repository browser.