00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
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 }