Changeset 6843a9c in mainline for uspace/lib/usbhost/src/usb_transfer_batch.c
- Timestamp:
- 2012-06-29T13:02:14Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 722912e
- Parents:
- ba72f2b (diff), 0bbd13e (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
rba72f2b r6843a9c 33 33 */ 34 34 #include <errno.h> 35 #include < str_error.h>35 #include <macros.h> 36 36 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 fun DDF function (passed to callback function). 51 * @param arg Argument to pass to the callback function. 52 * @param private_data driver specific per batch data. 53 * @param private_data_dtor Function to properly destroy private_data. 54 * @return Pointer to valid usb_transfer_batch_t structure, NULL on failure. 55 */ 56 usb_transfer_batch_t * usb_transfer_batch_create( 43 57 endpoint_t *ep, 44 58 char *buffer, … … 53 67 ) 54 68 { 69 if (func_in == NULL && func_out == NULL) 70 return NULL; 71 if (func_in != NULL && func_out != NULL) 72 return NULL; 73 55 74 usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t)); 56 75 if (instance) { … … 78 97 } 79 98 /*----------------------------------------------------------------------------*/ 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 99 /** Correctly dispose all used data structures. 150 100 * 151 101 * @param[in] instance Batch structure to use. 152 102 */ 153 void usb_transfer_batch_d ispose(usb_transfer_batch_t *instance)103 void usb_transfer_batch_destroy(const usb_transfer_batch_t *instance) 154 104 { 155 105 if (!instance) … … 166 116 free(instance); 167 117 } 118 /*----------------------------------------------------------------------------*/ 119 /** Prepare data and call the right callback. 120 * 121 * @param[in] instance Batch structure to use. 122 * @param[in] data Data to copy to the output buffer. 123 * @param[in] size Size of @p data. 124 * @param[in] error Error value to use. 125 */ 126 void usb_transfer_batch_finish_error(const usb_transfer_batch_t *instance, 127 const void *data, size_t size, int error) 128 { 129 assert(instance); 130 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " finishing.\n", 131 instance, USB_TRANSFER_BATCH_ARGS(*instance)); 132 133 /* NOTE: Only one of these pointers should be set. */ 134 if (instance->callback_out) { 135 /* Check for commands that reset toggle bit */ 136 if (instance->ep->transfer_type == USB_TRANSFER_CONTROL 137 && error == EOK) { 138 const usb_target_t target = 139 {{ instance->ep->address, instance->ep->endpoint }}; 140 reset_ep_if_need(fun_to_hcd(instance->fun), target, 141 instance->setup_buffer); 142 } 143 instance->callback_out(instance->fun, error, instance->arg); 144 } 145 146 if (instance->callback_in) { 147 /* We care about the data and there are some to copy */ 148 const size_t safe_size = min(size, instance->buffer_size); 149 if (data) { 150 memcpy(instance->buffer, data, safe_size); 151 } 152 instance->callback_in(instance->fun, error, 153 safe_size, instance->arg); 154 } 155 } 168 156 /** 169 157 * @}
Note:
See TracChangeset
for help on using the changeset viewer.