Ignore:
Timestamp:
2011-09-19T16:31:00Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a347a11
Parents:
3842a955 (diff), 086290d (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:

Merge mainline changes

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/usb_transfer_batch.c

    r3842a955 r26e7d6d  
    3737#include <usb/usb.h>
    3838#include <usb/debug.h>
    39 #include <usb/host/batch.h>
     39#include <usb/host/usb_transfer_batch.h>
     40#include <usb/host/hcd.h>
    4041
    41 void usb_transfer_batch_call_in(usb_transfer_batch_t *instance);
    42 void usb_transfer_batch_call_out(usb_transfer_batch_t *instance);
    43 
    44 void usb_transfer_batch_init(
    45     usb_transfer_batch_t *instance,
     42usb_transfer_batch_t * usb_transfer_batch_get(
    4643    endpoint_t *ep,
    4744    char *buffer,
    48     char *data_buffer,
    4945    size_t buffer_size,
    50     char *setup_buffer,
    51     size_t setup_size,
     46    uint64_t setup_buffer,
    5247    usbhc_iface_transfer_in_callback_t func_in,
    5348    usbhc_iface_transfer_out_callback_t func_out,
     
    5550    ddf_fun_t *fun,
    5651    void *private_data,
    57     void (*private_data_dtor)(void *p_data)
     52    void (*private_data_dtor)(void *)
    5853    )
    5954{
    60         assert(instance);
    61         link_initialize(&instance->link);
    62         instance->ep = ep;
    63         instance->callback_in = func_in;
    64         instance->callback_out = func_out;
    65         instance->arg = arg;
    66         instance->buffer = buffer;
    67         instance->data_buffer = data_buffer;
    68         instance->buffer_size = buffer_size;
    69         instance->setup_buffer = setup_buffer;
    70         instance->setup_size = setup_size;
    71         instance->fun = fun;
    72         instance->private_data = private_data;
    73         instance->private_data_dtor = private_data_dtor;
    74         instance->transfered_size = 0;
    75         instance->next_step = NULL;
    76         instance->error = EOK;
    77         endpoint_use(instance->ep);
     55        usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t));
     56        if (instance) {
     57                instance->ep = ep;
     58                instance->callback_in = func_in;
     59                instance->callback_out = func_out;
     60                instance->arg = arg;
     61                instance->buffer = buffer;
     62                instance->buffer_size = buffer_size;
     63                instance->setup_size = 0;
     64                instance->fun = fun;
     65                instance->private_data = private_data;
     66                instance->private_data_dtor = private_data_dtor;
     67                instance->transfered_size = 0;
     68                instance->error = EOK;
     69                if (ep && ep->transfer_type == USB_TRANSFER_CONTROL) {
     70                        memcpy(instance->setup_buffer, &setup_buffer,
     71                            USB_SETUP_PACKET_SIZE);
     72                        instance->setup_size = USB_SETUP_PACKET_SIZE;
     73                }
     74                if (instance->ep)
     75                        endpoint_use(instance->ep);
     76        }
     77        return instance;
    7878}
    7979/*----------------------------------------------------------------------------*/
    80 /** Helper function, calls callback and correctly destroys batch structure.
     80/** Mark batch as finished and run callback.
    8181 *
    8282 * @param[in] instance Batch structure to use.
     83 * @param[in] data Data to copy to the output buffer.
     84 * @param[in] size Size of @p data.
    8385 */
    84 void 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  */
    95 void 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);
    100 }
    101 /*----------------------------------------------------------------------------*/
    102 /** Mark batch as finished and continue with next step.
    103  *
    104  * @param[in] instance Batch structure to use.
    105  *
    106  */
    107 void usb_transfer_batch_finish(usb_transfer_batch_t *instance)
     86void usb_transfer_batch_finish(
     87    usb_transfer_batch_t *instance, const void *data, size_t size)
    10888{
    10989        assert(instance);
    11090        assert(instance->ep);
    111         endpoint_release(instance->ep);
    112         instance->next_step(instance);
     91        /* we care about the data and there are some to copy */
     92        if (instance->ep->direction != USB_DIRECTION_OUT
     93            && data) {
     94                const size_t min_size =
     95                    size < instance->buffer_size ? size : instance->buffer_size;
     96                memcpy(instance->buffer, data, min_size);
     97        }
     98        if (instance->callback_out)
     99                usb_transfer_batch_call_out(instance);
     100        if (instance->callback_in)
     101                usb_transfer_batch_call_in(instance);
     102
    113103}
    114104/*----------------------------------------------------------------------------*/
     
    123113        assert(instance);
    124114        assert(instance->callback_in);
    125         assert(instance->ep);
    126115
    127         /* We are data in, we need data */
    128         memcpy(instance->buffer, instance->data_buffer, instance->buffer_size);
    129 
    130         usb_log_debug("Batch %p " USB_TRANSFER_BATCH_FMT " completed (%zuB): %s.\n",
     116        usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " completed (%zuB): %s.\n",
    131117            instance, USB_TRANSFER_BATCH_ARGS(*instance),
    132118            instance->transfered_size, str_error(instance->error));
     
    145131        assert(instance->callback_out);
    146132
    147         usb_log_debug("Batch %p " USB_TRANSFER_BATCH_FMT " completed: %s.\n",
     133        usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " completed: %s.\n",
    148134            instance, USB_TRANSFER_BATCH_ARGS(*instance),
    149135            str_error(instance->error));
     136
     137        if (instance->ep->transfer_type == USB_TRANSFER_CONTROL
     138            && instance->error == EOK) {
     139                const usb_target_t target =
     140                    {{ instance->ep->address, instance->ep->endpoint }};
     141                reset_ep_if_need(
     142                    fun_to_hcd(instance->fun), target, instance->setup_buffer);
     143        }
    150144
    151145        instance->callback_out(instance->fun,
     
    159153void usb_transfer_batch_dispose(usb_transfer_batch_t *instance)
    160154{
    161         assert(instance);
     155        if (!instance)
     156                return;
    162157        usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " disposing.\n",
    163158            instance, USB_TRANSFER_BATCH_ARGS(*instance));
     159        if (instance->ep) {
     160                endpoint_release(instance->ep);
     161        }
    164162        if (instance->private_data) {
    165163                assert(instance->private_data_dtor);
Note: See TracChangeset for help on using the changeset viewer.