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


Ignore:
Timestamp:
2018-01-08T17:17:38Z (6 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/usb2_bus.c

    reb928c4 r1102eca  
    3131 */
    3232/** @file
    33  * HC Endpoint management.
     33 *
     34 * A bus_t implementation for USB 2 and lower. Implements USB 2 enumeration and
     35 * configurable bandwidth counting.
    3436 */
    3537
     
    5052#include "usb2_bus.h"
    5153
    52 /** Ops receive generic bus_t pointer. */
     54/**
     55 * Ops receive generic bus_t pointer.
     56 */
    5357static inline usb2_bus_t *bus_to_usb2_bus(bus_t *bus_base)
    5458{
     
    5761}
    5862
    59 /** Unregister and destroy all endpoints using given address.
    60  * @param bus usb_bus structure, non-null.
    61  * @param address USB address.
    62  * @param endpoint USB endpoint number.
    63  * @param direction Communication direction.
    64  * @return Error code.
    65  */
    66 static int release_address(usb2_bus_t *bus, usb_address_t address)
    67 {
    68         if (!usb_address_is_valid(address))
    69                 return EINVAL;
    70 
    71         const int ret = bus->address_occupied[address] ? EOK : ENOENT;
    72         bus->address_occupied[address] = false;
    73         return ret;
    74 }
    75 
    76 /** Request USB address.
     63/**
     64 * Request a new address. A free address is found and marked as occupied.
     65 *
     66 * There's no need to synchronize this method, because it is called only with
     67 * default address reserved.
     68 *
    7769 * @param bus usb_device_manager
    7870 * @param addr Pointer to requested address value, place to store new address
    79  * @return Error code.
    80  * @note Default address is only available in strict mode.
    8171 */
    8272static int request_address(usb2_bus_t *bus, usb_address_t *addr)
     
    9989}
    10090
     91/**
     92 * Mark address as free.
     93 */
     94static void release_address(usb2_bus_t *bus, usb_address_t address)
     95{
     96        bus->address_occupied[address] = false;
     97}
     98
    10199static const usb_target_t usb2_default_target = {{
    102100        .address = USB_ADDRESS_DEFAULT,
     
    104102}};
    105103
     104/**
     105 * Transition the device to the addressed state.
     106 *
     107 * Reserve address, configure the control EP, issue a SET_ADDRESS command.
     108 * Configure the device with the new address, mark the device as online.
     109 */
    106110static int address_device(device_t *dev)
    107111{
     
    184188}
    185189
    186 /** Enumerate a new USB device
     190/**
     191 * Enumerate a USB device. Move it to the addressed state, then explore it
     192 * to create a DDF function node with proper characteristics.
    187193 */
    188194static int usb2_bus_device_enumerate(device_t *dev)
     
    223229}
    224230
    225 static endpoint_t *usb2_bus_create_ep(device_t *dev, const usb_endpoint_descriptors_t *desc)
    226 {
    227         endpoint_t *ep = malloc(sizeof(endpoint_t));
    228         if (!ep)
    229                 return NULL;
    230 
    231         endpoint_init(ep, dev, desc);
    232         return ep;
    233 }
    234 
    235 /** Register an endpoint to the bus. Reserves bandwidth.
    236  * @param bus usb_bus structure, non-null.
    237  * @param endpoint USB endpoint number.
     231/**
     232 * Register an endpoint to the bus. Reserves bandwidth.
    238233 */
    239234static int usb2_bus_register_ep(endpoint_t *ep)
     
    252247}
    253248
    254 /** Release bandwidth reserved by the given endpoint.
     249/**
     250 * Release bandwidth reserved by the given endpoint.
    255251 */
    256252static int usb2_bus_unregister_ep(endpoint_t *ep)
     
    266262const bus_ops_t usb2_bus_ops = {
    267263        .device_enumerate = usb2_bus_device_enumerate,
    268         .endpoint_create = usb2_bus_create_ep,
    269264        .endpoint_register = usb2_bus_register_ep,
    270265        .endpoint_unregister = usb2_bus_unregister_ep,
     
    275270 * @param bus usb_bus structure, non-null.
    276271 * @param available_bandwidth Size of the bandwidth pool.
    277  * @param bw_count function to use to calculate endpoint bw requirements.
    278  * @return Error code.
    279272 */
    280273void usb2_bus_init(usb2_bus_t *bus, size_t available_bandwidth)
     
    287280        bus->free_bw = available_bandwidth;
    288281}
     282
    289283/**
    290284 * @}
Note: See TracChangeset for help on using the changeset viewer.