Changeset 6e3c005 in mainline


Ignore:
Timestamp:
2011-12-14T15:29:41Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a0487a2
Parents:
22ecbde
Message:

libusbdev: Doxygen and minor cleanup/renaming.

Location:
uspace
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhcirh/port.c

    r22ecbde r6e3c005  
    313313
    314314        /* Driver stopped, free used address */
    315         ret = usb_hc_unregister_device(&port->hc_connection,
    316             port->attached_device.address);
     315        ret = usb_hub_unregister_device(&port->hc_connection,
     316            &port->attached_device);
    317317        if (ret != EOK) {
    318318                usb_log_error("%s: Failed to unregister address of removed "
  • uspace/drv/bus/usb/usbhub/port.c

    r22ecbde r6e3c005  
    288288        port->attached_device.fun = NULL;
    289289
    290         ret = usb_hc_unregister_device(&hub->usb_device->hc_conn,
    291             port->attached_device.address);
     290        ret = usb_hub_unregister_device(&hub->usb_device->hc_conn,
     291            &port->attached_device);
    292292        if (ret != EOK) {
    293293                usb_log_warning("Failed to unregister address of the "
  • uspace/lib/usbdev/include/usb/dev/hub.h

    r22ecbde r6e3c005  
    4040#include <ddf/driver.h>
    4141#include <sys/types.h>
     42#include <errno.h>
    4243#include <usb/hc.h>
    4344
     
    5960} usb_hub_attached_device_t;
    6061
    61 usb_address_t usb_hc_request_address(usb_hc_connection_t *, usb_address_t,
    62     bool, usb_speed_t);
    63 int usb_hc_register_device(usb_hc_connection_t *,
     62int usb_hub_register_device(usb_hc_connection_t *,
    6463    const usb_hub_attached_device_t *);
    65 int usb_hc_unregister_device(usb_hc_connection_t *, usb_address_t);
     64
     65static inline int usb_hub_unregister_device(usb_hc_connection_t *conn,
     66    const usb_hub_attached_device_t *attached_device)
     67{
     68        assert(conn);
     69        if (attached_device == NULL)
     70                return EBADMEM;
     71        return usb_hc_release_address(conn, attached_device->address);
     72}
    6673
    6774#endif
  • uspace/lib/usbdev/include/usb/dev/poll.h

    r22ecbde r6e3c005  
    3939#include <time.h>
    4040
     41/** Parameters and callbacks for automated polling. */
    4142typedef struct {
    4243        /** Level of debugging messages from auto polling.
  • uspace/lib/usbdev/include/usb/dev/usb_device_connection.h

    r22ecbde r6e3c005  
    5252} usb_device_connection_t;
    5353
     54/** Initialize device connection. Set address and hc connection.
     55 * @param instance Structure to initialize.
     56 * @param hc_connection. Host controller connection to use.
     57 * @param address USB address.
     58 * @return Error code.
     59 */
    5460static inline int usb_device_connection_initialize(
    55     usb_device_connection_t *connection, usb_hc_connection_t *hc_connection,
     61    usb_device_connection_t *instance, usb_hc_connection_t *hc_connection,
    5662    usb_address_t address)
    5763{
    58         assert(connection);
     64        assert(instance);
    5965        if (hc_connection == NULL)
    6066                return EBADMEM;
     
    6268                return EINVAL;
    6369
    64         connection->hc_connection = hc_connection;
    65         connection->address = address;
     70        instance->hc_connection = hc_connection;
     71        instance->address = address;
    6672        return EOK;
    6773}
    6874/*----------------------------------------------------------------------------*/
    69 static inline int usb_device_register_endpoint(usb_device_connection_t *conn,
    70     usb_endpoint_t ep, usb_transfer_type_t type, usb_direction_t direction,
     75/** Register endpoint on the device.
     76 * @param instance device connection structure to use.
     77 * @param ep USB endpoint number.
     78 * @param type Communication type of the endpoint.
     79 * @param direction Communication direction.
     80 * @param packet_size Maximum packet size for the endpoint.
     81 * @param interval Preferrred interval between communication.
     82 * @return Error code.
     83 */
     84static inline int usb_device_register_endpoint(
     85    usb_device_connection_t *instance, usb_endpoint_t ep,
     86    usb_transfer_type_t type, usb_direction_t direction,
    7187    size_t packet_size, unsigned interval)
    7288{
    73         assert(conn);
    74         return usb_hc_register_endpoint(conn->hc_connection,
    75             conn->address, ep, type, direction, packet_size, interval);
     89        assert(instance);
     90        return usb_hc_register_endpoint(instance->hc_connection,
     91            instance->address, ep, type, direction, packet_size, interval);
    7692}
    7793/*----------------------------------------------------------------------------*/
    78 static inline int usb_device_unregister_endpoint(usb_device_connection_t *conn,
    79     usb_endpoint_t ep, usb_direction_t direction)
     94/** Unregister endpoint on the device.
     95 * @param instance device connection structure
     96 * @param ep Endpoint number.
     97 * @param dir Communication direction.
     98 * @return Error code.
     99 */
     100static inline int usb_device_unregister_endpoint(
     101    usb_device_connection_t *instance, usb_endpoint_t ep, usb_direction_t dir)
    80102{
    81         assert(conn);
    82         return usb_hc_unregister_endpoint(conn->hc_connection,
    83             conn->address, ep, direction);
     103        assert(instance);
     104        return usb_hc_unregister_endpoint(instance->hc_connection,
     105            instance->address, ep, dir);
    84106}
    85107/*----------------------------------------------------------------------------*/
    86 static inline int usb_device_control_read(usb_device_connection_t *conn,
     108/** Get data from the device.
     109 * @param[in] instance device connection structure to use.
     110 * @param[in] ep target endpoint's number.
     111 * @param[in] setup Setup stage data (control transfers).
     112 * @param[in] data data buffer.
     113 * @param[in] size size of the data buffer.
     114 * @param[out] rsize bytes actually copied to the buffer.
     115 * @return Error code.
     116 */
     117static inline int usb_device_control_read(usb_device_connection_t *instance,
    87118    usb_endpoint_t ep, uint64_t setup, void *data, size_t size, size_t *rsize)
    88119{
    89         assert(conn);
    90         return usb_hc_read(conn->hc_connection,
    91             conn->address, ep, setup, data, size, rsize);
     120        assert(instance);
     121        return usb_hc_read(instance->hc_connection,
     122            instance->address, ep, setup, data, size, rsize);
    92123}
    93124/*----------------------------------------------------------------------------*/
    94 static inline int usb_device_control_write(usb_device_connection_t *conn,
     125/** Send data to the device.
     126 * @param instance device connection structure to use.
     127 * @param ep target endpoint's number.
     128 * @param setup Setup stage data (control transfers).
     129 * @param data data buffer.
     130 * @param size size of the data buffer.
     131 * @return Error code.
     132 */
     133static inline int usb_device_control_write(usb_device_connection_t *instance,
    95134    usb_endpoint_t ep, uint64_t setup, const void *data, size_t size)
    96135{
    97         assert(conn);
    98         return usb_hc_write(conn->hc_connection,
    99             conn->address, ep, setup, data, size);
     136        assert(instance);
     137        return usb_hc_write(instance->hc_connection,
     138            instance->address, ep, setup, data, size);
    100139}
    101140/*----------------------------------------------------------------------------*/
    102141/** Wrapper for read calls with no setup stage.
    103  * @param[in] connection hc connection to use.
     142 * @param[in] instance device connection structure.
    104143 * @param[in] address USB device address.
    105144 * @param[in] endpoint USB device endpoint.
     
    109148 * @return Error code.
    110149 */
    111 static inline int usb_device_read(usb_device_connection_t *conn,
     150static inline int usb_device_read(usb_device_connection_t *instance,
    112151    usb_endpoint_t ep, void *data, size_t size, size_t *real_size)
    113152{
    114         return usb_device_control_read(conn, ep, 0, data, size, real_size);
     153        return usb_device_control_read(instance, ep, 0, data, size, real_size);
    115154}
    116155/*----------------------------------------------------------------------------*/
    117156/** Wrapper for write calls with no setup stage.
    118  * @param connection hc connection to use.
     157 * @param instance device connection structure.
    119158 * @param address USB device address.
    120159 * @param endpoint USB device endpoint.
     
    123162 * @return Error code.
    124163 */
    125 static inline int usb_device_write(usb_device_connection_t *conn,
     164static inline int usb_device_write(usb_device_connection_t *instance,
    126165    usb_endpoint_t ep, const void *data, size_t size)
    127166{
    128         return usb_device_control_write(conn, ep, 0, data, size);
     167        return usb_device_control_write(instance, ep, 0, data, size);
    129168}
    130169#endif
  • uspace/lib/usbdev/src/altiface.c

    r22ecbde r6e3c005  
    167167}
    168168
    169 void usb_alternate_interfaces_deinit(usb_alternate_interfaces_t *alternate)
     169/** Clean initialized structure.
     170 * @param instance structure do deinitialize.
     171 */
     172void usb_alternate_interfaces_deinit(usb_alternate_interfaces_t *instance)
    170173{
    171         if (!alternate)
     174        if (!instance)
    172175                return;
    173         free(alternate->alternatives);
     176        free(instance->alternatives);
     177        instance->alternatives = NULL;
    174178}
    175179/**
  • uspace/lib/usbdev/src/devdrv.c

    r22ecbde r6e3c005  
    516516        }
    517517
     518        /* Open hc connection for pipe registration. */
    518519        rc = usb_hc_connection_open(&usb_dev->hc_conn);
    519520        if (rc != EOK) {
     
    575576}
    576577
     578/** Allocate driver specific data.
     579 * @param usb_dev usb_device structure.
     580 * @param size requested data size.
     581 * @return Pointer to the newly allocated space, NULL on failure.
     582 */
    577583void * usb_device_data_alloc(usb_device_t *usb_dev, size_t size)
    578584{
  • uspace/lib/usbdev/src/devpoll.c

    r22ecbde r6e3c005  
    4646/** Data needed for polling. */
    4747typedef struct {
     48        /** Parameters for automated polling. */
    4849        usb_device_auto_polling_t auto_polling;
    4950
     51        /** USB device to poll. */
    5052        usb_device_t *dev;
     53        /** Device pipe to use for polling. */
    5154        size_t pipe_index;
     55        /** Size of the recieved data. */
    5256        size_t request_size;
     57        /** Data buffer. */
    5358        uint8_t *buffer;
     59        /** Argument to pass to callbacks. */
    5460        void *custom_arg;
    5561} polling_data_t;
  • uspace/lib/usbdev/src/hub.c

    r22ecbde r6e3c005  
    3838#include <usb/dev/recognise.h>
    3939#include <usb/debug.h>
    40 #include <usbhc_iface.h>
    4140#include <errno.h>
    4241#include <assert.h>
     
    4544#include <async.h>
    4645
    47 /** How much time to wait between attempts to register endpoint 0:0.
     46/** How much time to wait between attempts to get the default address.
    4847 * The value is based on typical value for port reset + some overhead.
    4948 */
    50 #define ENDPOINT_0_0_REGISTER_ATTEMPT_DELAY_USEC (1000 * (10 + 2))
    51 
    52 /** Check that HC connection is alright.
    53  *
    54  * @param conn Connection to be checked.
    55  */
    56 #define CHECK_CONNECTION(conn) \
    57         do { \
    58                 assert((conn)); \
    59                 if (!usb_hc_connection_is_opened((conn))) { \
    60                         usb_log_error("Connection not open.\n"); \
    61                         return ENOTCONN; \
    62                 } \
    63         } while (false)
    64 
     49#define DEFAULT_ADDRESS_ATTEMPT_DELAY_USEC (1000 * (10 + 2))
    6550
    6651/** Inform host controller about new device.
     
    7055 * @return Error code.
    7156 */
    72 int usb_hc_register_device(usb_hc_connection_t *connection,
     57int usb_hub_register_device(usb_hc_connection_t *connection,
    7358    const usb_hub_attached_device_t *attached_device)
    7459{
    75 //      CHECK_CONNECTION(connection);
     60        assert(connection);
    7661        if (attached_device == NULL || attached_device->fun == NULL)
    77                 return EINVAL;
    78 
    79         async_exch_t *exch = async_exchange_begin(connection->hc_sess);
    80         if (!exch)
    81                 return ENOMEM;
    82         const int ret = usbhc_bind_address(exch,
     62                return EBADMEM;
     63        return usb_hc_bind_address(connection,
    8364            attached_device->address, attached_device->fun->handle);
    84         async_exchange_end(exch);
    85 
    86         return ret;
    87 }
    88 
    89 /** Inform host controller about device removal.
    90  *
    91  * @param connection Opened connection to host controller.
    92  * @param address Address of the device that is being removed.
    93  * @return Error code.
    94  */
    95 int usb_hc_unregister_device(usb_hc_connection_t *connection,
    96     usb_address_t address)
    97 {
    98 //      CHECK_CONNECTION(connection);
    99 
    100         async_exch_t *exch = async_exchange_begin(connection->hc_sess);
    101         if (!exch)
    102                 return ENOMEM;
    103         const int ret = usbhc_release_address(exch, address);
    104         async_exchange_end(exch);
    105 
    106         return ret;
    10765}
    10866
     
    144102                    "Failed to unregister the old pipe on address change.\n");
    145103        }
    146         /* Address changed. We can release the default, thus
    147          * allowing other to access the default address. */
    148         usb_hc_unregister_device(pipe->wire->hc_connection,
    149             pipe->wire->address);
     104        /* Address changed. We can release the old one, thus
     105         * allowing other to us it. */
     106        usb_hc_release_address(pipe->wire->hc_connection, pipe->wire->address);
    150107
    151108        /* The address is already changed so set it in the wire */
     
    256213                if (rc == ENOENT) {
    257214                        /* Do not overheat the CPU ;-). */
    258                         async_usleep(ENDPOINT_0_0_REGISTER_ATTEMPT_DELAY_USEC);
     215                        async_usleep(DEFAULT_ADDRESS_ATTEMPT_DELAY_USEC);
    259216                }
    260217        } while (rc == ENOENT);
     
    328285
    329286        /* Inform the host controller about the handle. */
    330         rc = usb_hc_register_device(hc_conn, &new_device);
     287        rc = usb_hub_register_device(hc_conn, &new_device);
    331288        if (rc != EOK) {
    332289                /* We know nothing about that data. */
     
    353310         */
    354311leave_release_default_address:
    355         if (usb_hc_unregister_device(hc_conn, USB_ADDRESS_DEFAULT) != EOK)
    356                 usb_log_warning("%s: Failed to unregister defaut device.\n",
     312        if (usb_hc_release_address(hc_conn, USB_ADDRESS_DEFAULT) != EOK)
     313                usb_log_warning("%s: Failed to release defaut address.\n",
    357314                    __FUNCTION__);
    358315
     
    363320                    __FUNCTION__);
    364321
    365         if (usb_hc_unregister_device(hc_conn, dev_addr) != EOK)
    366                 usb_log_warning("%s: Failed to unregister device.\n",
    367                     __FUNCTION__);
     322        if (usb_hc_release_address(hc_conn, dev_addr) != EOK)
     323                usb_log_warning("%s: Failed to release address: %d.\n",
     324                    __FUNCTION__, dev_addr);
    368325
    369326close_connection:
  • uspace/lib/usbdev/src/recognise.c

    r22ecbde r6e3c005  
    324324        }
    325325
    326 
    327326        /** Index to append after device name for uniqueness. */
    328327        static atomic_t device_name_index = {0};
Note: See TracChangeset for help on using the changeset viewer.