source: mainline/uspace/drv/ohci/batch.c@ 68b5ed6e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 68b5ed6e was 68b5ed6e, checked in by Vojtech Horky <vojtechhorky@…>, 14 years ago

Rename device_keeper* ⇒ usb_device_keeper*

Also extended some device keeper functions names to be more descriptive.

No change in functionality.

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