Changeset 327f147 in mainline for uspace/lib/usbhost/src/hcd.c
- Timestamp:
- 2017-10-23T19:03:37Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b724494
- Parents:
- e160bfe8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/hcd.c
re160bfe8 r327f147 80 80 * @return Error code. 81 81 */ 82 int hcd_send_batch(hcd_t *hcd, usb_target_t target, usb_direction_t direction, 83 void *data, size_t size, uint64_t setup_data, 84 usbhc_iface_transfer_in_callback_t in, usbhc_iface_transfer_out_callback_t out, 85 void *arg, const char *name) 82 int hcd_send_batch(hcd_t *hcd, device_t *device, usb_target_t target, 83 usb_direction_t direction, char *data, size_t size, uint64_t setup_data, 84 usb_transfer_batch_callback_t on_complete, void *arg, const char *name) 86 85 { 87 86 assert(hcd); 87 assert(device->address == target.address); 88 88 89 endpoint_t *ep = bus_find_endpoint(hcd->bus, target, direction);89 endpoint_t *ep = bus_find_endpoint(hcd->bus, device, target, direction); 90 90 if (ep == NULL) { 91 91 usb_log_error("Endpoint(%d:%d) not registered for %s.\n", 92 target.address, target.endpoint, name);92 device->address, target.endpoint, name); 93 93 return ENOENT; 94 94 } … … 120 120 batch->setup.packed = setup_data; 121 121 batch->dir = direction; 122 batch->on_complete = on_complete; 123 batch->on_complete_data = arg; 122 124 123 125 /* Check for commands that reset toggle bit */ … … 125 127 batch->toggle_reset_mode 126 128 = usb_request_get_toggle_reset_mode(&batch->setup.packet); 127 128 usb_transfer_batch_set_old_handlers(batch, in, out, arg);129 129 130 130 const int ret = hcd->ops.schedule(hcd, batch); … … 144 144 fibril_condvar_t done_cv; 145 145 unsigned done; 146 int ret; 147 size_t size; 146 147 size_t transfered_size; 148 int error; 148 149 } sync_data_t; 149 150 150 static void transfer_in_cb(int ret, size_t size, void* data)151 static int sync_transfer_complete(usb_transfer_batch_t *batch) 151 152 { 152 sync_data_t *d = data;153 sync_data_t *d = batch->on_complete_data; 153 154 assert(d); 154 d-> ret = ret;155 d-> size = size;155 d->transfered_size = batch->transfered_size; 156 d->error = batch->error; 156 157 fibril_mutex_lock(&d->done_mtx); 157 158 d->done = 1; 158 159 fibril_condvar_broadcast(&d->done_cv); 159 160 fibril_mutex_unlock(&d->done_mtx); 161 return EOK; 160 162 } 161 163 162 static void transfer_out_cb(int ret, void* data) 163 { 164 sync_data_t *d = data; 165 assert(data); 166 d->ret = ret; 167 fibril_mutex_lock(&d->done_mtx); 168 d->done = 1; 169 fibril_condvar_broadcast(&d->done_cv); 170 fibril_mutex_unlock(&d->done_mtx); 171 } 172 173 /** this is really ugly version of sync usb communication */ 174 ssize_t hcd_send_batch_sync( 175 hcd_t *hcd, usb_target_t target, usb_direction_t dir, 176 void *data, size_t size, uint64_t setup_data, const char* name) 164 ssize_t hcd_send_batch_sync(hcd_t *hcd, device_t *device, usb_target_t target, 165 usb_direction_t direction, char *data, size_t size, uint64_t setup_data, 166 const char *name) 177 167 { 178 168 assert(hcd); 179 sync_data_t sd = { .done = 0 , .ret = EBUSY, .size = size};169 sync_data_t sd = { .done = 0 }; 180 170 fibril_mutex_initialize(&sd.done_mtx); 181 171 fibril_condvar_initialize(&sd.done_cv); 182 172 183 const int ret = hcd_send_batch(hcd, target, dir, data, size, setup_data,184 d ir == USB_DIRECTION_IN ? transfer_in_cb : NULL,185 dir == USB_DIRECTION_OUT ? transfer_out_cb : NULL, &sd, name);173 const int ret = hcd_send_batch(hcd, device, target, direction, 174 data, size, setup_data, 175 sync_transfer_complete, &sd, name); 186 176 if (ret != EOK) 187 177 return ret; … … 192 182 fibril_mutex_unlock(&sd.done_mtx); 193 183 194 if (sd.ret== EOK)195 return sd.size;196 return sd.ret;184 return (sd.error == EOK) 185 ? (ssize_t) sd.transfered_size 186 : (ssize_t) sd.error; 197 187 } 198 188
Note:
See TracChangeset
for help on using the changeset viewer.