batch.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011 Jan Vesely
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00034 #include <errno.h>
00035 #include <str_error.h>
00036 
00037 #include <usb/usb.h>
00038 #include <usb/debug.h>
00039 #include <usb/host/batch.h>
00040 
00041 void usb_transfer_batch_call_in(usb_transfer_batch_t *instance);
00042 void usb_transfer_batch_call_out(usb_transfer_batch_t *instance);
00043 
00044 void usb_transfer_batch_init(
00045     usb_transfer_batch_t *instance,
00046     endpoint_t *ep,
00047     char *buffer,
00048     char *data_buffer,
00049     size_t buffer_size,
00050     char *setup_buffer,
00051     size_t setup_size,
00052     usbhc_iface_transfer_in_callback_t func_in,
00053     usbhc_iface_transfer_out_callback_t func_out,
00054     void *arg,
00055     ddf_fun_t *fun,
00056     void *private_data,
00057     void (*private_data_dtor)(void *p_data)
00058     )
00059 {
00060         assert(instance);
00061         link_initialize(&instance->link);
00062         instance->ep = ep;
00063         instance->callback_in = func_in;
00064         instance->callback_out = func_out;
00065         instance->arg = arg;
00066         instance->buffer = buffer;
00067         instance->data_buffer = data_buffer;
00068         instance->buffer_size = buffer_size;
00069         instance->setup_buffer = setup_buffer;
00070         instance->setup_size = setup_size;
00071         instance->fun = fun;
00072         instance->private_data = private_data;
00073         instance->private_data_dtor = private_data_dtor;
00074         instance->transfered_size = 0;
00075         instance->next_step = NULL;
00076         instance->error = EOK;
00077         endpoint_use(instance->ep);
00078 }
00079 /*----------------------------------------------------------------------------*/
00084 void usb_transfer_batch_call_in_and_dispose(usb_transfer_batch_t *instance)
00085 {
00086         assert(instance);
00087         usb_transfer_batch_call_in(instance);
00088         usb_transfer_batch_dispose(instance);
00089 }
00090 /*----------------------------------------------------------------------------*/
00095 void usb_transfer_batch_call_out_and_dispose(usb_transfer_batch_t *instance)
00096 {
00097         assert(instance);
00098         usb_transfer_batch_call_out(instance);
00099         usb_transfer_batch_dispose(instance);
00100 }
00101 /*----------------------------------------------------------------------------*/
00107 void usb_transfer_batch_finish(usb_transfer_batch_t *instance)
00108 {
00109         assert(instance);
00110         assert(instance->ep);
00111         endpoint_release(instance->ep);
00112         instance->next_step(instance);
00113 }
00114 /*----------------------------------------------------------------------------*/
00121 void usb_transfer_batch_call_in(usb_transfer_batch_t *instance)
00122 {
00123         assert(instance);
00124         assert(instance->callback_in);
00125         assert(instance->ep);
00126 
00127         /* We are data in, we need data */
00128         memcpy(instance->buffer, instance->data_buffer, instance->buffer_size);
00129 
00130         usb_log_debug("Batch(%p) done (T%d.%d, %s %s in, %zuB): %s (%d).\n",
00131             instance, instance->ep->address, instance->ep->endpoint,
00132             usb_str_speed(instance->ep->speed),
00133             usb_str_transfer_type_short(instance->ep->transfer_type),
00134             instance->transfered_size, str_error(instance->error),
00135             instance->error);
00136 
00137         instance->callback_in(instance->fun, instance->error,
00138             instance->transfered_size, instance->arg);
00139 }
00140 /*----------------------------------------------------------------------------*/
00145 void usb_transfer_batch_call_out(usb_transfer_batch_t *instance)
00146 {
00147         assert(instance);
00148         assert(instance->callback_out);
00149 
00150         usb_log_debug("Batch(%p) done (T%d.%d, %s %s out): %s (%d).\n",
00151             instance, instance->ep->address, instance->ep->endpoint,
00152             usb_str_speed(instance->ep->speed),
00153             usb_str_transfer_type_short(instance->ep->transfer_type),
00154             str_error(instance->error), instance->error);
00155 
00156         instance->callback_out(instance->fun,
00157             instance->error, instance->arg);
00158 }
00159 /*----------------------------------------------------------------------------*/
00164 void usb_transfer_batch_dispose(usb_transfer_batch_t *instance)
00165 {
00166         assert(instance);
00167         usb_log_debug("Batch(%p) disposing.\n", instance);
00168         if (instance->private_data) {
00169                 assert(instance->private_data_dtor);
00170                 instance->private_data_dtor(instance->private_data);
00171         }
00172         free(instance);
00173 }

Generated on Thu Jun 2 07:45:44 2011 for HelenOS/USB by  doxygen 1.4.7