Changeset f1d6866 in mainline for uspace/lib/usbhost/src/usb_transfer_batch.c
- Timestamp:
- 2011-09-18T21:22:59Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- dcc44ca1
- Parents:
- 85ff862 (diff), 45a9cf4 (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 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/usb_transfer_batch.c
r85ff862 rf1d6866 37 37 #include <usb/usb.h> 38 38 #include <usb/debug.h> 39 #include <usb/host/batch.h> 39 #include <usb/host/usb_transfer_batch.h> 40 #include <usb/host/hcd.h> 40 41 41 void usb_transfer_batch_call_in(usb_transfer_batch_t *instance); 42 void usb_transfer_batch_call_out(usb_transfer_batch_t *instance); 43 44 void usb_transfer_batch_init( 45 usb_transfer_batch_t *instance, 42 usb_transfer_batch_t * usb_transfer_batch_get( 46 43 endpoint_t *ep, 47 44 char *buffer, 48 char *data_buffer,49 45 size_t buffer_size, 50 char *setup_buffer, 51 size_t setup_size, 46 uint64_t setup_buffer, 52 47 usbhc_iface_transfer_in_callback_t func_in, 53 48 usbhc_iface_transfer_out_callback_t func_out, … … 55 50 ddf_fun_t *fun, 56 51 void *private_data, 57 void (*private_data_dtor)(void * p_data)52 void (*private_data_dtor)(void *) 58 53 ) 59 54 { 60 assert(instance); 61 link_initialize(&instance->link); 62 instance->ep = ep; 63 instance->callback_in = func_in; 64 instance->callback_out = func_out; 65 instance->arg = arg; 66 instance->buffer = buffer; 67 instance->data_buffer = data_buffer; 68 instance->buffer_size = buffer_size; 69 instance->setup_buffer = setup_buffer; 70 instance->setup_size = setup_size; 71 instance->fun = fun; 72 instance->private_data = private_data; 73 instance->private_data_dtor = private_data_dtor; 74 instance->transfered_size = 0; 75 instance->next_step = NULL; 76 instance->error = EOK; 77 endpoint_use(instance->ep); 55 usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t)); 56 if (instance) { 57 instance->ep = ep; 58 instance->callback_in = func_in; 59 instance->callback_out = func_out; 60 instance->arg = arg; 61 instance->buffer = buffer; 62 instance->buffer_size = buffer_size; 63 instance->setup_size = 0; 64 instance->fun = fun; 65 instance->private_data = private_data; 66 instance->private_data_dtor = private_data_dtor; 67 instance->transfered_size = 0; 68 instance->error = EOK; 69 if (ep && ep->transfer_type == USB_TRANSFER_CONTROL) { 70 memcpy(instance->setup_buffer, &setup_buffer, 71 USB_SETUP_PACKET_SIZE); 72 instance->setup_size = USB_SETUP_PACKET_SIZE; 73 } 74 if (instance->ep) 75 endpoint_use(instance->ep); 76 } 77 return instance; 78 78 } 79 79 /*----------------------------------------------------------------------------*/ 80 /** Helper function, calls callback and correctly destroys batch structure.80 /** Mark batch as finished and run callback. 81 81 * 82 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. 83 85 */ 84 void usb_transfer_batch_call_in_and_dispose(usb_transfer_batch_t *instance) 85 { 86 assert(instance); 87 usb_transfer_batch_call_in(instance); 88 usb_transfer_batch_dispose(instance); 89 } 90 /*----------------------------------------------------------------------------*/ 91 /** Helper function calls callback and correctly destroys batch structure. 92 * 93 * @param[in] instance Batch structure to use. 94 */ 95 void usb_transfer_batch_call_out_and_dispose(usb_transfer_batch_t *instance) 96 { 97 assert(instance); 98 usb_transfer_batch_call_out(instance); 99 usb_transfer_batch_dispose(instance); 100 } 101 /*----------------------------------------------------------------------------*/ 102 /** Mark batch as finished and continue with next step. 103 * 104 * @param[in] instance Batch structure to use. 105 * 106 */ 107 void usb_transfer_batch_finish(usb_transfer_batch_t *instance) 86 void usb_transfer_batch_finish( 87 usb_transfer_batch_t *instance, const void *data, size_t size) 108 88 { 109 89 assert(instance); 110 90 assert(instance->ep); 111 assert(instance->next_step); 112 endpoint_release(instance->ep); 113 instance->next_step(instance); 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 114 103 } 115 104 /*----------------------------------------------------------------------------*/ … … 124 113 assert(instance); 125 114 assert(instance->callback_in); 126 assert(instance->ep);127 128 /* We are data in, we need data */129 memcpy(instance->buffer, instance->data_buffer, instance->buffer_size);130 115 131 116 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " completed (%zuB): %s.\n", … … 150 135 str_error(instance->error)); 151 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 152 145 instance->callback_out(instance->fun, 153 146 instance->error, instance->arg); … … 160 153 void usb_transfer_batch_dispose(usb_transfer_batch_t *instance) 161 154 { 162 assert(instance); 155 if (!instance) 156 return; 163 157 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " disposing.\n", 164 158 instance, USB_TRANSFER_BATCH_ARGS(*instance)); 159 if (instance->ep) { 160 endpoint_release(instance->ep); 161 } 165 162 if (instance->private_data) { 166 163 assert(instance->private_data_dtor);
Note:
See TracChangeset
for help on using the changeset viewer.