Changeset d9b2c73 in mainline
- Timestamp:
- 2012-12-20T13:22:34Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d09791e6
- Parents:
- 8f68913f
- Location:
- uspace/lib/usbhost
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/hcd.h
r8f68913f rd9b2c73 97 97 } 98 98 99 int hcd_send_batch( 100 hcd_t *hcd, ddf_fun_t *fun, usb_target_t target, usb_direction_t direction, 101 void *data, size_t size, uint64_t setup_data, 102 usbhc_iface_transfer_in_callback_t in, 103 usbhc_iface_transfer_out_callback_t out, void *arg, const char* name); 99 104 100 105 int hcd_add_device(hcd_t *instance, ddf_dev_t *parent, -
uspace/lib/usbhost/src/hcd.c
r8f68913f rd9b2c73 184 184 } 185 185 186 /** Prepare generic usb_transfer_batch and schedule it. 187 * @param hcd Host controller driver. 188 * @param fun DDF fun 189 * @param target address and endpoint number. 190 * @param setup_data Data to use in setup stage (Control communication type) 191 * @param in Callback for device to host communication. 192 * @param out Callback for host to device communication. 193 * @param arg Callback parameter. 194 * @param name Communication identifier (for nicer output). 195 * @return Error code. 196 */ 197 int hcd_send_batch( 198 hcd_t *hcd, ddf_fun_t *fun, usb_target_t target, usb_direction_t direction, 199 void *data, size_t size, uint64_t setup_data, 200 usbhc_iface_transfer_in_callback_t in, 201 usbhc_iface_transfer_out_callback_t out, void *arg, const char* name) 202 { 203 assert(hcd); 204 205 endpoint_t *ep = usb_endpoint_manager_find_ep(&hcd->ep_manager, 206 target.address, target.endpoint, direction); 207 if (ep == NULL) { 208 usb_log_error("Endpoint(%d:%d) not registered for %s.\n", 209 target.address, target.endpoint, name); 210 return ENOENT; 211 } 212 213 usb_log_debug2("%s %d:%d %zu(%zu).\n", 214 name, target.address, target.endpoint, size, ep->max_packet_size); 215 216 const size_t bw = bandwidth_count_usb11( 217 ep->speed, ep->transfer_type, size, ep->max_packet_size); 218 /* Check if we have enough bandwidth reserved */ 219 if (ep->bandwidth < bw) { 220 usb_log_error("Endpoint(%d:%d) %s needs %zu bw " 221 "but only %zu is reserved.\n", 222 ep->address, ep->endpoint, name, bw, ep->bandwidth); 223 return ENOSPC; 224 } 225 if (!hcd->schedule) { 226 usb_log_error("HCD does not implement scheduler.\n"); 227 return ENOTSUP; 228 } 229 230 /* No private data and no private data dtor */ 231 usb_transfer_batch_t *batch = 232 usb_transfer_batch_create(ep, data, size, setup_data, 233 in, out, arg, fun, NULL, NULL); 234 if (!batch) { 235 return ENOMEM; 236 } 237 238 const int ret = hcd->schedule(hcd, batch); 239 if (ret != EOK) 240 usb_transfer_batch_destroy(batch); 241 242 return ret; 243 } 244 245 186 246 /** Announce root hub to the DDF 187 247 * -
uspace/lib/usbhost/src/iface.c
r8f68913f rd9b2c73 41 41 #include <usb/host/hcd.h> 42 42 43 /** Prepare generic usb_transfer_batch and schedule it.44 * @param fun DDF fun45 * @param target address and endpoint number.46 * @param setup_data Data to use in setup stage (Control communication type)47 * @param in Callback for device to host communication.48 * @param out Callback for host to device communication.49 * @param arg Callback parameter.50 * @param name Communication identifier (for nicer output).51 * @return Error code.52 */53 static inline int send_batch(54 ddf_fun_t *fun, usb_target_t target, usb_direction_t direction,55 void *data, size_t size, uint64_t setup_data,56 usbhc_iface_transfer_in_callback_t in,57 usbhc_iface_transfer_out_callback_t out, void *arg, const char* name)58 {59 assert(fun);60 hcd_t *hcd = fun_to_hcd(fun);61 assert(hcd);62 63 endpoint_t *ep = usb_endpoint_manager_find_ep(&hcd->ep_manager,64 target.address, target.endpoint, direction);65 if (ep == NULL) {66 usb_log_error("Endpoint(%d:%d) not registered for %s.\n",67 target.address, target.endpoint, name);68 return ENOENT;69 }70 71 usb_log_debug2("%s %d:%d %zu(%zu).\n",72 name, target.address, target.endpoint, size, ep->max_packet_size);73 74 const size_t bw = bandwidth_count_usb11(75 ep->speed, ep->transfer_type, size, ep->max_packet_size);76 /* Check if we have enough bandwidth reserved */77 if (ep->bandwidth < bw) {78 usb_log_error("Endpoint(%d:%d) %s needs %zu bw "79 "but only %zu is reserved.\n",80 ep->address, ep->endpoint, name, bw, ep->bandwidth);81 return ENOSPC;82 }83 if (!hcd->schedule) {84 usb_log_error("HCD does not implement scheduler.\n");85 return ENOTSUP;86 }87 88 /* No private data and no private data dtor */89 usb_transfer_batch_t *batch =90 usb_transfer_batch_create(ep, data, size, setup_data,91 in, out, arg, fun, NULL, NULL);92 if (!batch) {93 return ENOMEM;94 }95 96 const int ret = hcd->schedule(hcd, batch);97 if (ret != EOK)98 usb_transfer_batch_destroy(batch);99 100 return ret;101 }102 103 43 /** Calls ep_add_hook upon endpoint registration. 104 44 * @param ep Endpoint to be registered. … … 291 231 void *arg) 292 232 { 293 return send_batch(fun, target, USB_DIRECTION_IN, data, size,294 setup_data, callback, NULL, arg, "READ");233 return hcd_send_batch(fun_to_hcd(fun), fun, target, USB_DIRECTION_IN, 234 data, size, setup_data, callback, NULL, arg, "READ"); 295 235 } 296 236 … … 309 249 usbhc_iface_transfer_out_callback_t callback, void *arg) 310 250 { 311 return send_batch(fun, target, USB_DIRECTION_OUT, (uint8_t*)data, size,312 setup_data, NULL, callback, arg, "WRITE");251 return hcd_send_batch(fun_to_hcd(fun), fun, target, USB_DIRECTION_OUT, 252 (uint8_t*)data, size, setup_data, NULL, callback, arg, "WRITE"); 313 253 } 314 254
Note:
See TracChangeset
for help on using the changeset viewer.