Changeset 20a3465 in mainline for uspace/lib/usbhost/src/usb_transfer_batch.c
- Timestamp:
- 2011-10-30T19:50:54Z (13 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/usb_transfer_batch.c
r4c3ad56 r20a3465 37 37 #include <usb/usb.h> 38 38 #include <usb/debug.h> 39 39 40 #include <usb/host/usb_transfer_batch.h> 40 41 #include <usb/host/hcd.h> 41 42 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 */ 55 usb_transfer_batch_t * usb_transfer_batch_create( 43 56 endpoint_t *ep, 44 57 char *buffer, … … 53 66 ) 54 67 { 68 if (func_in == NULL && func_out == NULL) 69 return NULL; 70 if (func_in != NULL && func_out != NULL) 71 return NULL; 72 55 73 usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t)); 56 74 if (instance) { … … 78 96 } 79 97 /*----------------------------------------------------------------------------*/ 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_OUT93 && 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 appropriate109 * 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_CONTROL138 && 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 /*----------------------------------------------------------------------------*/149 98 /** Correctly dispose all used data structures. 150 99 * 151 100 * @param[in] instance Batch structure to use. 152 101 */ 153 void usb_transfer_batch_d ispose(usb_transfer_batch_t *instance)102 void usb_transfer_batch_destroy(const usb_transfer_batch_t *instance) 154 103 { 155 104 if (!instance) … … 166 115 free(instance); 167 116 } 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 */ 124 void 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 } 168 156 /** 169 157 * @}
Note:
See TracChangeset
for help on using the changeset viewer.