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

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

Switch to new endpoint toggle control.

  • Property mode set to 100644
File size: 6.5 KB
RevLine 
[41b96b4]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 */
[81dce9f]28/** @addtogroup drvusbohci
[41b96b4]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"
[2bf8f8c]41#include "utils/malloc32.h"
[41b96b4]42
[1387692]43static void batch_call_in_and_dispose(usb_transfer_batch_t *instance);
44static void batch_call_out_and_dispose(usb_transfer_batch_t *instance);
[d328172]45
[81dce9f]46#define DEFAULT_ERROR_COUNT 3
[1387692]47usb_transfer_batch_t * batch_get(
[be7950e8]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,
[2bf8f8c]54 size_t buffer_size,
[be7950e8]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,
[68b5ed6e]60 usb_device_keeper_t *manager
[be7950e8]61 )
62{
[2bf8f8c]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
[1387692]72 usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t));
[2bf8f8c]73 CHECK_NULL_DISPOSE_RETURN(instance,
74 "Failed to allocate batch instance.\n");
[f567bcf]75 usb_transfer_batch_init(instance, target, transfer_type, speed,
76 max_packet_size, buffer, NULL, buffer_size, NULL, setup_size,
77 func_in, func_out, arg, fun, NULL, NULL);
[2bf8f8c]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;
[be7950e8]94}
95/*----------------------------------------------------------------------------*/
[1387692]96void batch_dispose(usb_transfer_batch_t *instance)
[be7950e8]97{
[2bf8f8c]98 assert(instance);
[d328172]99 free32(instance->transport_buffer);
100 free32(instance->setup_buffer);
101 free(instance);
[be7950e8]102}
103/*----------------------------------------------------------------------------*/
[1387692]104void batch_control_write(usb_transfer_batch_t *instance)
[be7950e8]105{
[2bf8f8c]106 assert(instance);
[d328172]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);
[be7950e8]113}
114/*----------------------------------------------------------------------------*/
[1387692]115void batch_control_read(usb_transfer_batch_t *instance)
[be7950e8]116{
[2bf8f8c]117 assert(instance);
[d328172]118 instance->next_step = batch_call_in_and_dispose;
119 /* TODO: implement */
[81001f6]120 usb_log_debug("Batch(%p) CONTROL READ initialized.\n", instance);
[be7950e8]121}
122/*----------------------------------------------------------------------------*/
[1387692]123void batch_interrupt_in(usb_transfer_batch_t *instance)
[be7950e8]124{
[2bf8f8c]125 assert(instance);
[d328172]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);
[be7950e8]130}
131/*----------------------------------------------------------------------------*/
[1387692]132void batch_interrupt_out(usb_transfer_batch_t *instance)
[be7950e8]133{
[2bf8f8c]134 assert(instance);
[d328172]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);
[be7950e8]142}
143/*----------------------------------------------------------------------------*/
[1387692]144void batch_bulk_in(usb_transfer_batch_t *instance)
[be7950e8]145{
[2bf8f8c]146 assert(instance);
[d328172]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);
[be7950e8]151}
152/*----------------------------------------------------------------------------*/
[1387692]153void batch_bulk_out(usb_transfer_batch_t *instance)
[be7950e8]154{
[2bf8f8c]155 assert(instance);
[d328172]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 */
[1387692]166void batch_call_in_and_dispose(usb_transfer_batch_t *instance)
[d328172]167{
168 assert(instance);
[1387692]169 usb_transfer_batch_call_in(instance);
[d328172]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 */
[1387692]177void batch_call_out_and_dispose(usb_transfer_batch_t *instance)
[d328172]178{
179 assert(instance);
[1387692]180 usb_transfer_batch_call_out(instance);
[d328172]181 batch_dispose(instance);
[be7950e8]182}
[41b96b4]183/**
184 * @}
185 */
Note: See TracBrowser for help on using the repository browser.