Changeset 549ff23 in mainline
- Timestamp:
- 2011-10-29T15:35:52Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 17412546
- Parents:
- 4dfc905
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ohci/ohci_batch.c
r4dfc905 r549ff23 59 59 free(ohci_batch->tds); 60 60 } 61 usb_transfer_batch_d ispose(ohci_batch->usb_batch);61 usb_transfer_batch_destroy(ohci_batch->usb_batch); 62 62 free32(ohci_batch->device_buffer); 63 63 free(ohci_batch); -
uspace/drv/bus/usb/ohci/root_hub.c
r4dfc905 r549ff23 235 235 usb_transfer_batch_finish_error(request, NULL, 0, EINVAL); 236 236 } 237 usb_transfer_batch_d ispose(request);237 usb_transfer_batch_destroy(request); 238 238 } 239 239 /*----------------------------------------------------------------------------*/ … … 254 254 interrupt_request(instance->unfinished_interrupt_transfer, 255 255 mask, instance->interrupt_mask_size); 256 usb_transfer_batch_d ispose(256 usb_transfer_batch_destroy( 257 257 instance->unfinished_interrupt_transfer); 258 258 instance->unfinished_interrupt_transfer = NULL; -
uspace/drv/bus/usb/uhci/uhci_batch.c
r4dfc905 r549ff23 48 48 { 49 49 if (uhci_batch) { 50 usb_transfer_batch_d ispose(uhci_batch->usb_batch);50 usb_transfer_batch_destroy(uhci_batch->usb_batch); 51 51 free32(uhci_batch->device_buffer); 52 52 free(uhci_batch); -
uspace/lib/usbhost/include/usb/host/hcd.h
r4dfc905 r549ff23 97 97 * @return pointer cast to hcd_t*. 98 98 */ 99 static inline hcd_t * fun_to_hcd( ddf_fun_t *fun)99 static inline hcd_t * fun_to_hcd(const ddf_fun_t *fun) 100 100 { 101 101 assert(fun); -
uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h
r4dfc905 r549ff23 43 43 #define USB_SETUP_PACKET_SIZE 8 44 44 45 typedef struct usb_transfer_batch usb_transfer_batch_t;46 45 /** Structure stores additional data needed for communication with EP */ 47 struct usb_transfer_batch {46 typedef struct usb_transfer_batch { 48 47 /** Endpoint used for communication */ 49 48 endpoint_t *ep; … … 77 76 /** Callback to properly remove driver data during destruction */ 78 77 void (*private_data_dtor)(void *p_data); 79 } ;78 } usb_transfer_batch_t; 80 79 81 80 /** Printf formatting string for dumping usb_transfer_batch_t. */ … … 93 92 94 93 95 usb_transfer_batch_t * usb_transfer_batch_ get(94 usb_transfer_batch_t * usb_transfer_batch_create( 96 95 endpoint_t *ep, 97 96 char *buffer, … … 105 104 void (*private_data_dtor)(void *p_data) 106 105 ); 106 void usb_transfer_batch_destroy(const usb_transfer_batch_t *instance); 107 107 108 void usb_transfer_batch_finish( usb_transfer_batch_t *instance,108 void usb_transfer_batch_finish(const usb_transfer_batch_t *instance, 109 109 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 }125 110 /*----------------------------------------------------------------------------*/ 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. 139 112 * 140 113 * @param[in] instance Batch structure to use. … … 151 124 } 152 125 /*----------------------------------------------------------------------------*/ 153 /** Helper function, determines batch direction absed on the present callbacks154 * @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. 155 128 * @return USB_DIRECTION_IN, or USB_DIRECTION_OUT. 156 129 */ -
uspace/lib/usbhost/src/iface.c
r4dfc905 r549ff23 76 76 /* No private data and no private data dtor */ 77 77 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, 79 79 in, out, arg, fun, NULL, NULL); 80 80 if (!batch) { … … 84 84 const int ret = hcd->schedule(hcd, batch); 85 85 if (ret != EOK) 86 usb_transfer_batch_d ispose(batch);86 usb_transfer_batch_destroy(batch); 87 87 88 88 return ret; -
uspace/lib/usbhost/src/usb_transfer_batch.c
r4dfc905 r549ff23 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.