Changeset d9b2c73 in mainline for uspace/lib/usbhost/src/iface.c


Ignore:
Timestamp:
2012-12-20T13:22:34Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d09791e6
Parents:
8f68913f
Message:

libusbhost: Add hcd parameter to batch scheduling and move implementaiotn to hcd.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/iface.c

    r8f68913f rd9b2c73  
    4141#include <usb/host/hcd.h>
    4242
    43 /** Prepare generic usb_transfer_batch and schedule it.
    44  * @param fun DDF fun
    45  * @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 
    10343/** Calls ep_add_hook upon endpoint registration.
    10444 * @param ep Endpoint to be registered.
     
    291231    void *arg)
    292232{
    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");
    295235}
    296236
     
    309249    usbhc_iface_transfer_out_callback_t callback, void *arg)
    310250{
    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");
    313253}
    314254
Note: See TracChangeset for help on using the changeset viewer.