Changeset 1102eca in mainline for uspace/lib/usbhost/src/bus.c


Ignore:
Timestamp:
2018-01-08T17:17:38Z (8 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bdd8842c
Parents:
eb928c4
Message:

usbhost: documentation & cleanup

File:
1 edited

Legend:

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

    reb928c4 r1102eca  
    3232/** @file
    3333 *
     34 * The Bus is a structure that serves as an interface of the HC driver
     35 * implementation for the usbhost library. Every HC driver that uses libusbhost
     36 * must use a bus_t (or its child), fill it with bus_ops and present it to the
     37 * library. The library then handles the DDF interface and translates it to the
     38 * bus callbacks.
    3439 */
    3540
     
    4449
    4550/**
    46  * Initializes the bus structure.
     51 * Initializes the base bus structure.
    4752 */
    4853void bus_init(bus_t *bus, size_t device_size)
     
    5762}
    5863
     64/**
     65 * Initialize the device_t structure belonging to a bus.
     66 */
    5967int bus_device_init(device_t *dev, bus_t *bus)
    6068{
     
    7280}
    7381
     82/**
     83 * Create a name of the ddf function node.
     84 */
    7485int bus_device_set_default_name(device_t *dev)
    7586{
     
    8495}
    8596
     97/**
     98 * Invoke the device_enumerate bus operation.
     99 */
    86100int bus_device_enumerate(device_t *dev)
    87101{
     
    95109}
    96110
     111/**
     112 * Invoke the device_remove bus operation.
     113 */
    97114int bus_device_remove(device_t *dev)
    98115{
     
    106123}
    107124
     125/**
     126 * Invoke the device_online bus operation.
     127 */
    108128int bus_device_online(device_t *dev)
    109129{
     
    117137}
    118138
     139/**
     140 * Invoke the device_offline bus operation.
     141 */
    119142int bus_device_offline(device_t *dev)
    120143{
     
    128151}
    129152
     153/**
     154 * Create and register new endpoint to the bus.
     155 *
     156 * @param[in] device The device of which the endpoint shall be created
     157 * @param[in] desc Endpoint descriptors as reported by the device
     158 * @param[out] out_ep The resulting new endpoint reference, if any. Can be NULL.
     159 */
    130160int bus_endpoint_add(device_t *device, const usb_endpoint_descriptors_t *desc, endpoint_t **out_ep)
    131161{
     
    135165        bus_t *bus = device->bus;
    136166
     167        const bus_ops_t *register_ops = BUS_OPS_LOOKUP(bus->ops, endpoint_register);
     168        if (!register_ops)
     169                return ENOTSUP;
     170
    137171        const bus_ops_t *create_ops = BUS_OPS_LOOKUP(bus->ops, endpoint_create);
    138         const bus_ops_t *register_ops = BUS_OPS_LOOKUP(bus->ops, endpoint_register);
    139         if (!create_ops || !register_ops)
    140                 return ENOTSUP;
    141 
    142         endpoint_t *ep = create_ops->endpoint_create(device, desc);
    143         if (!ep)
    144                 return ENOMEM;
     172        endpoint_t *ep;
     173        if (create_ops) {
     174                ep = create_ops->endpoint_create(device, desc);
     175                if (!ep)
     176                        return ENOMEM;
     177        } else {
     178                ep = calloc(1, sizeof(endpoint_t));
     179                if (!ep)
     180                        return ENOMEM;
     181                endpoint_init(ep, device, desc);
     182        }
    145183
    146184        /* Bus reference */
     
    186224}
    187225
    188 /** Searches for an endpoint. Returns a reference.
     226/**
     227 * Search for an endpoint. Returns a reference.
    189228 */
    190229endpoint_t *bus_find_endpoint(device_t *device, usb_endpoint_t endpoint)
     
    204243}
    205244
     245/**
     246 * Remove an endpoint from the device. Consumes a reference.
     247 */
    206248int bus_endpoint_remove(endpoint_t *ep)
    207249{
     
    233275        endpoint_del_ref(ep);
    234276
     277        /* Given reference */
     278        endpoint_del_ref(ep);
     279
    235280        return EOK;
    236281}
    237282
     283/**
     284 * Reserve the default address on the bus. Also, report the speed of the device
     285 * that is listening on the default address.
     286 *
     287 * The speed is then used for devices enumerated while the address is reserved.
     288 */
    238289int bus_reserve_default_address(bus_t *bus, usb_speed_t speed)
    239290{
     
    251302}
    252303
     304/**
     305 * Release the default address.
     306 */
    253307void bus_release_default_address(bus_t *bus)
    254308{
     
    257311}
    258312
    259 /** Prepare generic usb_transfer_batch and schedule it.
     313/**
     314 * Initiate a transfer on the bus. Finds the target endpoint, creates
     315 * a transfer batch and schedules it.
     316 *
    260317 * @param device Device for which to send the batch
    261  * @param target address and endpoint number.
    262  * @param setup_data Data to use in setup stage (Control communication type)
    263  * @param in Callback for device to host communication.
    264  * @param out Callback for host to device communication.
     318 * @param target The target of the transfer.
     319 * @param direction A direction of the transfer.
     320 * @param data A pointer to the data buffer.
     321 * @param size Size of the data buffer.
     322 * @param setup_data Data to use in the setup stage (Control communication type)
     323 * @param on_complete Callback which is called after the batch is complete
    265324 * @param arg Callback parameter.
    266325 * @param name Communication identifier (for nicer output).
     
    301360} sync_data_t;
    302361
     362/**
     363 * Callback for finishing the transfer. Wake the issuing thread.
     364 */
    303365static int sync_transfer_complete(void *arg, int error, size_t transfered_size)
    304366{
     
    314376}
    315377
     378/**
     379 * Issue a transfer on the bus, wait for result.
     380 *
     381 * @param device Device for which to send the batch
     382 * @param target The target of the transfer.
     383 * @param direction A direction of the transfer.
     384 * @param data A pointer to the data buffer.
     385 * @param size Size of the data buffer.
     386 * @param setup_data Data to use in the setup stage (Control communication type)
     387 * @param name Communication identifier (for nicer output).
     388 */
    316389ssize_t bus_device_send_batch_sync(device_t *device, usb_target_t target,
    317390    usb_direction_t direction, char *data, size_t size, uint64_t setup_data,
     
    330403        fibril_mutex_lock(&sd.done_mtx);
    331404        while (!sd.done) {
    332                 fibril_condvar_wait_timeout(&sd.done_cv, &sd.done_mtx, 3000000);
    333                 if (!sd.done)
    334                         usb_log_debug2("Still waiting...");
     405                fibril_condvar_wait(&sd.done_cv, &sd.done_mtx);
    335406        }
    336407        fibril_mutex_unlock(&sd.done_mtx);
Note: See TracChangeset for help on using the changeset viewer.