source: mainline/uspace/drv/ohci/batch.c@ 344925c

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

Port transfer_list from UHCI

  • Property mode set to 100644
File size: 6.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 drvusbohci
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
40#include "batch.h"
41#include "utils/malloc32.h"
42
43static void batch_call_in_and_dispose(usb_transfer_batch_t *instance);
44static void batch_call_out_and_dispose(usb_transfer_batch_t *instance);
45
46#define DEFAULT_ERROR_COUNT 3
47usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep,
48 char *buffer, size_t buffer_size, char* setup_buffer, size_t setup_size,
49 usbhc_iface_transfer_in_callback_t func_in,
50 usbhc_iface_transfer_out_callback_t func_out, void *arg)
51{
52#define CHECK_NULL_DISPOSE_RETURN(ptr, message...) \
53 if (ptr == NULL) { \
54 usb_log_error(message); \
55 if (instance) { \
56 batch_dispose(instance); \
57 } \
58 return NULL; \
59 } else (void)0
60
61 usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t));
62 CHECK_NULL_DISPOSE_RETURN(instance,
63 "Failed to allocate batch instance.\n");
64 usb_target_t target =
65 { .address = ep->address, .endpoint = ep->endpoint };
66 usb_transfer_batch_init(instance, target, ep->transfer_type, ep->speed,
67 ep->max_packet_size, buffer, NULL, buffer_size, NULL, setup_size,
68 func_in, func_out, arg, fun, ep, NULL);
69
70 if (buffer_size > 0) {
71 instance->transport_buffer = malloc32(buffer_size);
72 CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer,
73 "Failed to allocate device accessible buffer.\n");
74 }
75
76 if (setup_size > 0) {
77 instance->setup_buffer = malloc32(setup_size);
78 CHECK_NULL_DISPOSE_RETURN(instance->setup_buffer,
79 "Failed to allocate device accessible setup buffer.\n");
80 memcpy(instance->setup_buffer, setup_buffer, setup_size);
81 }
82
83
84 return instance;
85}
86/*----------------------------------------------------------------------------*/
87void batch_dispose(usb_transfer_batch_t *instance)
88{
89 assert(instance);
90 free32(instance->transport_buffer);
91 free32(instance->setup_buffer);
92 free(instance);
93}
94/*----------------------------------------------------------------------------*/
95bool batch_is_complete(usb_transfer_batch_t *instance)
96{
97 // TODO: implement
98 return false;
99}
100/*----------------------------------------------------------------------------*/
101void batch_control_write(usb_transfer_batch_t *instance)
102{
103 assert(instance);
104 /* We are data out, we are supposed to provide data */
105 memcpy(instance->transport_buffer, instance->buffer,
106 instance->buffer_size);
107 instance->next_step = batch_call_out_and_dispose;
108 /* TODO: implement */
109 usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);
110}
111/*----------------------------------------------------------------------------*/
112void batch_control_read(usb_transfer_batch_t *instance)
113{
114 assert(instance);
115 instance->next_step = batch_call_in_and_dispose;
116 /* TODO: implement */
117 usb_log_debug("Batch(%p) CONTROL READ initialized.\n", instance);
118}
119/*----------------------------------------------------------------------------*/
120void batch_interrupt_in(usb_transfer_batch_t *instance)
121{
122 assert(instance);
123 instance->direction = USB_DIRECTION_IN;
124 instance->next_step = batch_call_in_and_dispose;
125 /* TODO: implement */
126 usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance);
127}
128/*----------------------------------------------------------------------------*/
129void batch_interrupt_out(usb_transfer_batch_t *instance)
130{
131 assert(instance);
132 instance->direction = USB_DIRECTION_OUT;
133 /* We are data out, we are supposed to provide data */
134 memcpy(instance->transport_buffer, instance->buffer,
135 instance->buffer_size);
136 instance->next_step = batch_call_out_and_dispose;
137 /* TODO: implement */
138 usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance);
139}
140/*----------------------------------------------------------------------------*/
141void batch_bulk_in(usb_transfer_batch_t *instance)
142{
143 assert(instance);
144 instance->direction = USB_DIRECTION_IN;
145 instance->next_step = batch_call_in_and_dispose;
146 /* TODO: implement */
147 usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
148}
149/*----------------------------------------------------------------------------*/
150void batch_bulk_out(usb_transfer_batch_t *instance)
151{
152 assert(instance);
153 instance->direction = USB_DIRECTION_IN;
154 instance->next_step = batch_call_in_and_dispose;
155 /* TODO: implement */
156 usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
157}
158/*----------------------------------------------------------------------------*/
159ed_t * batch_ed(usb_transfer_batch_t *instance)
160{
161 return NULL;
162}
163/*----------------------------------------------------------------------------*/
164/** Helper function calls callback and correctly disposes of batch structure.
165 *
166 * @param[in] instance Batch structure to use.
167 */
168void batch_call_in_and_dispose(usb_transfer_batch_t *instance)
169{
170 assert(instance);
171 usb_transfer_batch_call_in(instance);
172 batch_dispose(instance);
173}
174/*----------------------------------------------------------------------------*/
175/** Helper function calls callback and correctly disposes of batch structure.
176 *
177 * @param[in] instance Batch structure to use.
178 */
179void batch_call_out_and_dispose(usb_transfer_batch_t *instance)
180{
181 assert(instance);
182 usb_transfer_batch_call_out(instance);
183 batch_dispose(instance);
184}
185/**
186 * @}
187 */
Note: See TracBrowser for help on using the repository browser.