Changeset 32fb6bce in mainline for uspace/lib/usbhost/src/endpoint.c
- Timestamp:
- 2017-12-18T22:50:21Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7f70d1c
- Parents:
- 1ea0bbf
- git-author:
- Ondřej Hlavatý <aearsis@…> (2017-12-18 22:04:50)
- git-committer:
- Ondřej Hlavatý <aearsis@…> (2017-12-18 22:50:21)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/endpoint.c
r1ea0bbf r32fb6bce 39 39 #include <mem.h> 40 40 #include <stdlib.h> 41 #include <str_error.h> 42 #include <usb/debug.h> 43 #include <usb/host/hcd.h> 41 44 42 45 #include "usb_transfer_batch.h" … … 187 190 } 188 191 192 /** Prepare generic usb_transfer_batch and schedule it. 193 * @param ep Endpoint for which the batch shall be created. 194 * @param target address and endpoint number. 195 * @param setup_data Data to use in setup stage (Control communication type) 196 * @param in Callback for device to host communication. 197 * @param out Callback for host to device communication. 198 * @param arg Callback parameter. 199 * @param name Communication identifier (for nicer output). 200 * @return Error code. 201 */ 202 int endpoint_send_batch(endpoint_t *ep, usb_target_t target, 203 usb_direction_t direction, char *data, size_t size, uint64_t setup_data, 204 usbhc_iface_transfer_callback_t on_complete, void *arg, const char *name) 205 { 206 usb_log_debug2("%s %d:%d %zu(%zu).\n", 207 name, target.address, target.endpoint, size, ep->max_packet_size); 208 209 bus_t *bus = endpoint_get_bus(ep); 210 const bus_ops_t *ops = BUS_OPS_LOOKUP(bus->ops, batch_schedule); 211 if (!ops) { 212 usb_log_error("HCD does not implement scheduler.\n"); 213 return ENOTSUP; 214 } 215 216 const size_t bw = endpoint_count_bw(ep, size); 217 /* Check if we have enough bandwidth reserved */ 218 if (ep->bandwidth < bw) { 219 usb_log_error("Endpoint(%d:%d) %s needs %zu bw " 220 "but only %zu is reserved.\n", 221 ep->device->address, ep->endpoint, name, bw, ep->bandwidth); 222 return ENOSPC; 223 } 224 225 usb_transfer_batch_t *batch = usb_transfer_batch_create(ep); 226 if (!batch) { 227 usb_log_error("Failed to create transfer batch.\n"); 228 return ENOMEM; 229 } 230 231 batch->target = target; 232 batch->buffer = data; 233 batch->buffer_size = size; 234 batch->setup.packed = setup_data; 235 batch->dir = direction; 236 batch->on_complete = on_complete; 237 batch->on_complete_data = arg; 238 239 /* Check for commands that reset toggle bit */ 240 if (ep->transfer_type == USB_TRANSFER_CONTROL) 241 batch->toggle_reset_mode 242 = hcd_get_request_toggle_reset_mode(&batch->setup.packet); 243 244 const int ret = ops->batch_schedule(batch); 245 if (ret != EOK) { 246 usb_log_warning("Batch %p failed to schedule: %s", batch, str_error(ret)); 247 usb_transfer_batch_destroy(batch); 248 } 249 250 return ret; 251 } 252 189 253 /** 190 254 * @}
Note:
See TracChangeset
for help on using the changeset viewer.