Changeset 549ff23 in mainline


Ignore:
Timestamp:
2011-10-29T15:35:52Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
17412546
Parents:
4dfc905
Message:

libusbhost: Cleanup usb_transfer_batch interface.

Remove redundant and unused call_in/call_out functions.
Rename functions: get ⇒ create, dispose ⇒ destroy.
Add/Fix doxygen comments.

Location:
uspace
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ohci/ohci_batch.c

    r4dfc905 r549ff23  
    5959                free(ohci_batch->tds);
    6060        }
    61         usb_transfer_batch_dispose(ohci_batch->usb_batch);
     61        usb_transfer_batch_destroy(ohci_batch->usb_batch);
    6262        free32(ohci_batch->device_buffer);
    6363        free(ohci_batch);
  • uspace/drv/bus/usb/ohci/root_hub.c

    r4dfc905 r549ff23  
    235235                usb_transfer_batch_finish_error(request, NULL, 0, EINVAL);
    236236        }
    237         usb_transfer_batch_dispose(request);
     237        usb_transfer_batch_destroy(request);
    238238}
    239239/*----------------------------------------------------------------------------*/
     
    254254                interrupt_request(instance->unfinished_interrupt_transfer,
    255255                    mask, instance->interrupt_mask_size);
    256                 usb_transfer_batch_dispose(
     256                usb_transfer_batch_destroy(
    257257                    instance->unfinished_interrupt_transfer);
    258258                instance->unfinished_interrupt_transfer = NULL;
  • uspace/drv/bus/usb/uhci/uhci_batch.c

    r4dfc905 r549ff23  
    4848{
    4949        if (uhci_batch) {
    50                 usb_transfer_batch_dispose(uhci_batch->usb_batch);
     50                usb_transfer_batch_destroy(uhci_batch->usb_batch);
    5151                free32(uhci_batch->device_buffer);
    5252                free(uhci_batch);
  • uspace/lib/usbhost/include/usb/host/hcd.h

    r4dfc905 r549ff23  
    9797 * @return pointer cast to hcd_t*.
    9898 */
    99 static inline hcd_t * fun_to_hcd(ddf_fun_t *fun)
     99static inline hcd_t * fun_to_hcd(const ddf_fun_t *fun)
    100100{
    101101        assert(fun);
  • uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h

    r4dfc905 r549ff23  
    4343#define USB_SETUP_PACKET_SIZE 8
    4444
    45 typedef struct usb_transfer_batch usb_transfer_batch_t;
    4645/** Structure stores additional data needed for communication with EP */
    47 struct usb_transfer_batch {
     46typedef struct usb_transfer_batch {
    4847        /** Endpoint used for communication */
    4948        endpoint_t *ep;
     
    7776        /** Callback to properly remove driver data during destruction */
    7877        void (*private_data_dtor)(void *p_data);
    79 };
     78} usb_transfer_batch_t;
    8079
    8180/** Printf formatting string for dumping usb_transfer_batch_t. */
     
    9392
    9493
    95 usb_transfer_batch_t * usb_transfer_batch_get(
     94usb_transfer_batch_t * usb_transfer_batch_create(
    9695    endpoint_t *ep,
    9796    char *buffer,
     
    105104    void (*private_data_dtor)(void *p_data)
    106105);
     106void usb_transfer_batch_destroy(const usb_transfer_batch_t *instance);
    107107
    108 void usb_transfer_batch_finish(usb_transfer_batch_t *instance,
     108void usb_transfer_batch_finish(const usb_transfer_batch_t *instance,
    109109    const void* data, size_t size);
    110 void usb_transfer_batch_call_in(usb_transfer_batch_t *instance);
    111 void usb_transfer_batch_call_out(usb_transfer_batch_t *instance);
    112 void usb_transfer_batch_dispose(usb_transfer_batch_t *instance);
    113 
    114 /** Helper function, calls callback and correctly destroys batch structure.
    115  *
    116  * @param[in] instance Batch structure to use.
    117  */
    118 static inline void usb_transfer_batch_call_in_and_dispose(
    119     usb_transfer_batch_t *instance)
    120 {
    121         assert(instance);
    122         usb_transfer_batch_call_in(instance);
    123         usb_transfer_batch_dispose(instance);
    124 }
    125110/*----------------------------------------------------------------------------*/
    126 /** Helper function calls callback and correctly destroys batch structure.
    127  *
    128  * @param[in] instance Batch structure to use.
    129  */
    130 static inline void usb_transfer_batch_call_out_and_dispose(
    131     usb_transfer_batch_t *instance)
    132 {
    133         assert(instance);
    134         usb_transfer_batch_call_out(instance);
    135         usb_transfer_batch_dispose(instance);
    136 }
    137 /*----------------------------------------------------------------------------*/
    138 /** Helper function, sets error value and finishes transfer.
     111/** Override error value and finishes transfer.
    139112 *
    140113 * @param[in] instance Batch structure to use.
     
    151124}
    152125/*----------------------------------------------------------------------------*/
    153 /** Helper function, determines batch direction absed on the present callbacks
    154  * @param[in] instance Batch structure to use.
     126/** Determine batch direction based on the callbacks present
     127 * @param[in] instance Batch structure to use, non-null.
    155128 * @return USB_DIRECTION_IN, or USB_DIRECTION_OUT.
    156129 */
  • uspace/lib/usbhost/src/iface.c

    r4dfc905 r549ff23  
    7676        /* No private data and no private data dtor */
    7777        usb_transfer_batch_t *batch =
    78             usb_transfer_batch_get(ep, data, size, setup_data,
     78            usb_transfer_batch_create(ep, data, size, setup_data,
    7979            in, out, arg, fun, NULL, NULL);
    8080        if (!batch) {
     
    8484        const int ret = hcd->schedule(hcd, batch);
    8585        if (ret != EOK)
    86                 usb_transfer_batch_dispose(batch);
     86                usb_transfer_batch_destroy(batch);
    8787
    8888        return ret;
  • uspace/lib/usbhost/src/usb_transfer_batch.c

    r4dfc905 r549ff23  
    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.