Ignore:
Timestamp:
2011-09-16T14:50:20Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
432a269, d1e18573
Parents:
47fecbb (diff), 82a31261 (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 USB changes from bzr://krabicka.net/orome/helenos/usb/

  • Move common HC code from uhci/ohci drivers to libusbhost
  • Rewrite USB HC interface to have common read/write functions for all transfer types.
  • Restructure hc drivers to avoid some hooks and void* casts
  • Cleanup the code and remove unnecessary mallocs.
File:
1 moved

Legend:

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

    r47fecbb rfd07e526  
    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         assert(instance->next_step);
    112         endpoint_release(instance->ep);
    113         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
    114103}
    115104/*----------------------------------------------------------------------------*/
     
    124113        assert(instance);
    125114        assert(instance->callback_in);
    126         assert(instance->ep);
    127 
    128         /* We are data in, we need data */
    129         memcpy(instance->buffer, instance->data_buffer, instance->buffer_size);
    130115
    131116        usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " completed (%zuB): %s.\n",
     
    150135            str_error(instance->error));
    151136
     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        }
     144
    152145        instance->callback_out(instance->fun,
    153146            instance->error, instance->arg);
     
    160153void usb_transfer_batch_dispose(usb_transfer_batch_t *instance)
    161154{
    162         assert(instance);
     155        if (!instance)
     156                return;
    163157        usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " disposing.\n",
    164158            instance, USB_TRANSFER_BATCH_ARGS(*instance));
     159        if (instance->ep) {
     160                endpoint_release(instance->ep);
     161        }
    165162        if (instance->private_data) {
    166163                assert(instance->private_data_dtor);
Note: See TracChangeset for help on using the changeset viewer.