Changeset e50cd7f in mainline for uspace/lib/usb/src/host/batch.c


Ignore:
Timestamp:
2011-04-17T19:17:55Z (13 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
63517c2, cfbbe1d3
Parents:
ef354b6 (diff), 8595577b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

new report structure fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/host/batch.c

    ref354b6 re50cd7f  
    3939#include <usb/host/batch.h>
    4040
     41void usb_transfer_batch_call_in(usb_transfer_batch_t *instance);
     42void usb_transfer_batch_call_out(usb_transfer_batch_t *instance);
     43
    4144void usb_transfer_batch_init(
    4245    usb_transfer_batch_t *instance,
    43     usb_target_t target,
    44     usb_transfer_type_t transfer_type,
    45     usb_speed_t speed,
    46     size_t max_packet_size,
     46    endpoint_t *ep,
    4747    char *buffer,
    48     char *transport_buffer,
     48    char *data_buffer,
    4949    size_t buffer_size,
    5050    char *setup_buffer,
     
    5454    void *arg,
    5555    ddf_fun_t *fun,
    56                 endpoint_t *ep,
    57     void *private_data
     56    void *private_data,
     57    void (*private_data_dtor)(void *p_data)
    5858    )
    5959{
    6060        assert(instance);
    6161        link_initialize(&instance->link);
    62         instance->target = target;
    63         instance->transfer_type = transfer_type;
    64         instance->speed = speed;
    65         instance->direction = USB_DIRECTION_BOTH;
     62        instance->ep = ep;
    6663        instance->callback_in = func_in;
    6764        instance->callback_out = func_out;
    6865        instance->arg = arg;
    6966        instance->buffer = buffer;
    70         instance->transport_buffer = transport_buffer;
     67        instance->data_buffer = data_buffer;
    7168        instance->buffer_size = buffer_size;
    7269        instance->setup_buffer = setup_buffer;
    7370        instance->setup_size = setup_size;
    74         instance->max_packet_size = max_packet_size;
    7571        instance->fun = fun;
    7672        instance->private_data = private_data;
     73        instance->private_data_dtor = private_data_dtor;
    7774        instance->transfered_size = 0;
    7875        instance->next_step = NULL;
    7976        instance->error = EOK;
    80         instance->ep = ep;
     77        endpoint_use(instance->ep);
     78}
     79/*----------------------------------------------------------------------------*/
     80/** Helper function, calls callback and correctly destroys batch structure.
     81 *
     82 * @param[in] instance Batch structure to use.
     83 */
     84void usb_transfer_batch_call_in_and_dispose(usb_transfer_batch_t *instance)
     85{
     86        assert(instance);
     87        usb_transfer_batch_call_in(instance);
     88        usb_transfer_batch_dispose(instance);
     89}
     90/*----------------------------------------------------------------------------*/
     91/** Helper function calls callback and correctly destroys batch structure.
     92 *
     93 * @param[in] instance Batch structure to use.
     94 */
     95void usb_transfer_batch_call_out_and_dispose(usb_transfer_batch_t *instance)
     96{
     97        assert(instance);
     98        usb_transfer_batch_call_out(instance);
     99        usb_transfer_batch_dispose(instance);
    81100}
    82101/*----------------------------------------------------------------------------*/
     
    86105 *
    87106 */
    88 void usb_transfer_batch_finish(usb_transfer_batch_t *instance, int error)
     107void usb_transfer_batch_finish(usb_transfer_batch_t *instance)
    89108{
    90109        assert(instance);
    91         instance->error = error;
     110        assert(instance->ep);
     111        endpoint_release(instance->ep);
    92112        instance->next_step(instance);
    93113}
     
    103123        assert(instance);
    104124        assert(instance->callback_in);
     125        assert(instance->ep);
    105126
    106127        /* We are data in, we need data */
    107         memcpy(instance->buffer, instance->transport_buffer,
    108             instance->buffer_size);
     128        memcpy(instance->buffer, instance->data_buffer, instance->buffer_size);
    109129
    110130        usb_log_debug("Batch %p done (T%d.%d, %s %s in, %zuB): %s (%d).\n",
    111             instance,
    112             instance->target.address, instance->target.endpoint,
    113             usb_str_speed(instance->speed),
    114             usb_str_transfer_type_short(instance->transfer_type),
    115             instance->transfered_size,
    116             str_error(instance->error), instance->error);
     131            instance, instance->ep->address, instance->ep->endpoint,
     132            usb_str_speed(instance->ep->speed),
     133            usb_str_transfer_type_short(instance->ep->transfer_type),
     134            instance->transfered_size, str_error(instance->error), instance->error);
    117135
    118136        instance->callback_in(instance->fun, instance->error,
     
    130148
    131149        usb_log_debug("Batch %p done (T%d.%d, %s %s out): %s (%d).\n",
    132             instance,
    133             instance->target.address, instance->target.endpoint,
    134             usb_str_speed(instance->speed),
    135             usb_str_transfer_type_short(instance->transfer_type),
     150            instance, instance->ep->address, instance->ep->endpoint,
     151            usb_str_speed(instance->ep->speed),
     152            usb_str_transfer_type_short(instance->ep->transfer_type),
    136153            str_error(instance->error), instance->error);
    137154
     
    139156            instance->error, instance->arg);
    140157}
     158/*----------------------------------------------------------------------------*/
     159/** Correctly dispose all used data structures.
     160 *
     161 * @param[in] instance Batch structure to use.
     162 */
     163void usb_transfer_batch_dispose(usb_transfer_batch_t *instance)
     164{
     165        assert(instance);
     166        usb_log_debug("Batch(%p) disposing.\n", instance);
     167        if (instance->private_data) {
     168                assert(instance->private_data_dtor);
     169                instance->private_data_dtor(instance->private_data);
     170        }
     171        free(instance);
     172}
    141173/**
    142174 * @}
Note: See TracChangeset for help on using the changeset viewer.