Changeset 6e3c005 in mainline for uspace/lib/usbdev/src/hub.c


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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:
Note: See TracChangeset for help on using the changeset viewer.