Ignore:
Timestamp:
2011-10-30T19:50:54Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3ce78580, 48902fa
Parents:
4c3ad56 (diff), 45bf63c (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 edited

Legend:

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

    r4c3ad56 r20a3465  
    3737#include <usb/usb.h>
    3838#include <usb/debug.h>
     39
    3940#include <usb/host/usb_transfer_batch.h>
    4041#include <usb/host/hcd.h>
    4142
    42 usb_transfer_batch_t * usb_transfer_batch_get(
     43/** Allocate and initialize usb_transfer_batch structure.
     44 * @param ep endpoint used by the transfer batch.
     45 * @param buffer data to send/recieve.
     46 * @param buffer_size Size of data buffer.
     47 * @param setup_buffer Data to send in SETUP stage of control transfer.
     48 * @param func_in callback on IN transfer completion.
     49 * @param func_out callback on OUT transfer completion.
     50 * @param arg Argument to pass to the callback function.
     51 * @param private_data driver specific per batch data.
     52 * @param private_data_dtor Function to properly destroy private_data.
     53 * @return Pointer to valid usb_transfer_batch_t structure, NULL on failure.
     54 */
     55usb_transfer_batch_t * usb_transfer_batch_create(
    4356    endpoint_t *ep,
    4457    char *buffer,
     
    5366    )
    5467{
     68        if (func_in == NULL && func_out == NULL)
     69                return NULL;
     70        if (func_in != NULL && func_out != NULL)
     71                return NULL;
     72
    5573        usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t));
    5674        if (instance) {
     
    7896}
    7997/*----------------------------------------------------------------------------*/
    80 /** Mark batch as finished and run callback.
    81  *
    82  * @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.
    85  */
    86 void usb_transfer_batch_finish(
    87     usb_transfer_batch_t *instance, const void *data, size_t size)
    88 {
    89         assert(instance);
    90         assert(instance->ep);
    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 
    103 }
    104 /*----------------------------------------------------------------------------*/
    105 /** Prepare data, get error status and call callback in.
    106  *
    107  * @param[in] instance Batch structure to use.
    108  * Copies data from transport buffer, and calls callback with appropriate
    109  * parameters.
    110  */
    111 void usb_transfer_batch_call_in(usb_transfer_batch_t *instance)
    112 {
    113         assert(instance);
    114         assert(instance->callback_in);
    115 
    116         usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " completed (%zuB): %s.\n",
    117             instance, USB_TRANSFER_BATCH_ARGS(*instance),
    118             instance->transfered_size, str_error(instance->error));
    119 
    120         instance->callback_in(instance->fun, instance->error,
    121             instance->transfered_size, instance->arg);
    122 }
    123 /*----------------------------------------------------------------------------*/
    124 /** Get error status and call callback out.
    125  *
    126  * @param[in] instance Batch structure to use.
    127  */
    128 void usb_transfer_batch_call_out(usb_transfer_batch_t *instance)
    129 {
    130         assert(instance);
    131         assert(instance->callback_out);
    132 
    133         usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " completed: %s.\n",
    134             instance, USB_TRANSFER_BATCH_ARGS(*instance),
    135             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         }
    144 
    145         instance->callback_out(instance->fun,
    146             instance->error, instance->arg);
    147 }
    148 /*----------------------------------------------------------------------------*/
    14998/** Correctly dispose all used data structures.
    15099 *
    151100 * @param[in] instance Batch structure to use.
    152101 */
    153 void usb_transfer_batch_dispose(usb_transfer_batch_t *instance)
     102void usb_transfer_batch_destroy(const usb_transfer_batch_t *instance)
    154103{
    155104        if (!instance)
     
    166115        free(instance);
    167116}
     117/*----------------------------------------------------------------------------*/
     118/** Prepare data and call the right callback.
     119 *
     120 * @param[in] instance Batch structure to use.
     121 * @param[in] data Data to copy to the output buffer.
     122 * @param[in] size Size of @p data.
     123 */
     124void usb_transfer_batch_finish(
     125    const usb_transfer_batch_t *instance, const void *data, size_t size)
     126{
     127        assert(instance);
     128        usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " finishing.\n",
     129            instance, USB_TRANSFER_BATCH_ARGS(*instance));
     130
     131        /* NOTE: Only one of these pointers should be set. */
     132        if (instance->callback_out) {
     133                /* Check for commands that reset toggle bit */
     134                if (instance->ep->transfer_type == USB_TRANSFER_CONTROL
     135                    && instance->error == EOK) {
     136                        const usb_target_t target =
     137                            {{ instance->ep->address, instance->ep->endpoint }};
     138                        reset_ep_if_need(fun_to_hcd(instance->fun), target,
     139                            instance->setup_buffer);
     140                }
     141                instance->callback_out(instance->fun,
     142                    instance->error, instance->arg);
     143        }
     144
     145        if (instance->callback_in) {
     146                /* We care about the data and there are some to copy */
     147                if (data) {
     148                        const size_t min_size = size < instance->buffer_size
     149                            ? size : instance->buffer_size;
     150                        memcpy(instance->buffer, data, min_size);
     151                }
     152                instance->callback_in(instance->fun, instance->error,
     153                    instance->transfered_size, instance->arg);
     154        }
     155}
    168156/**
    169157 * @}
Note: See TracChangeset for help on using the changeset viewer.