Ignore:
Timestamp:
2011-03-21T20:22:50Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c56c5b5b
Parents:
4fb6d9ee (diff), 31b568e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Development branch changes (including OHCI)

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/host/device_keeper.c

    r4fb6d9ee re099f26  
    2727 */
    2828
    29 /** @addtogroup drvusbuhcihc
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * @brief UHCI driver
     33 * Device keeper structure and functions (implementation).
    3434 */
    3535#include <assert.h>
    3636#include <errno.h>
    3737#include <usb/debug.h>
    38 
    39 #include "device_keeper.h"
     38#include <usb/host/device_keeper.h>
    4039
    4140/*----------------------------------------------------------------------------*/
     
    4645 * Set all values to false/0.
    4746 */
    48 void device_keeper_init(device_keeper_t *instance)
     47void usb_device_keeper_init(usb_device_keeper_t *instance)
    4948{
    5049        assert(instance);
     
    5655                instance->devices[i].occupied = false;
    5756                instance->devices[i].handle = 0;
    58                 instance->devices[i].toggle_status = 0;
     57                instance->devices[i].toggle_status[0] = 0;
     58                instance->devices[i].toggle_status[1] = 0;
    5959        }
    6060}
     
    6565 * @param[in] speed Speed of the device requesting default address.
    6666 */
    67 void device_keeper_reserve_default(device_keeper_t *instance, usb_speed_t speed)
     67void usb_device_keeper_reserve_default_address(usb_device_keeper_t *instance,
     68    usb_speed_t speed)
    6869{
    6970        assert(instance);
     
    8384 * @param[in] speed Speed of the device requesting default address.
    8485 */
    85 void device_keeper_release_default(device_keeper_t *instance)
     86void usb_device_keeper_release_default_address(usb_device_keeper_t *instance)
    8687{
    8788        assert(instance);
     
    100101 * Really ugly one.
    101102 */
    102 void device_keeper_reset_if_need(
    103     device_keeper_t *instance, usb_target_t target, const unsigned char *data)
     103void usb_device_keeper_reset_if_need(usb_device_keeper_t *instance,
     104    usb_target_t target, const uint8_t *data)
    104105{
    105106        assert(instance);
     
    119120                if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) {
    120121                        /* endpoint number is < 16, thus first byte is enough */
    121                         instance->devices[target.address].toggle_status &=
     122                        instance->devices[target.address].toggle_status[0] &=
     123                            ~(1 << data[4]);
     124                        instance->devices[target.address].toggle_status[1] &=
    122125                            ~(1 << data[4]);
    123126                }
     
    128131                /* target must be device */
    129132                if ((data[0] & 0xf) == 0) {
    130                         instance->devices[target.address].toggle_status = 0;
     133                        instance->devices[target.address].toggle_status[0] = 0;
     134                        instance->devices[target.address].toggle_status[1] = 0;
    131135                }
    132136        break;
     
    141145 * @return Error code
    142146 */
    143 int device_keeper_get_toggle(device_keeper_t *instance, usb_target_t target)
    144 {
    145         assert(instance);
     147int usb_device_keeper_get_toggle(usb_device_keeper_t *instance,
     148    usb_target_t target, usb_direction_t direction)
     149{
     150        assert(instance);
     151        /* only control pipes are bi-directional and those do not need toggle */
     152        if (direction == USB_DIRECTION_BOTH)
     153                return ENOENT;
    146154        int ret;
    147155        fibril_mutex_lock(&instance->guard);
     
    152160                ret = EINVAL;
    153161        } else {
    154                 ret = (instance->devices[target.address].toggle_status
     162                ret = (instance->devices[target.address].toggle_status[direction]
    155163                        >> target.endpoint) & 1;
    156164        }
     
    166174 * @return Error code.
    167175 */
    168 int device_keeper_set_toggle(
    169     device_keeper_t *instance, usb_target_t target, bool toggle)
    170 {
    171         assert(instance);
     176int usb_device_keeper_set_toggle(usb_device_keeper_t *instance,
     177    usb_target_t target, usb_direction_t direction, bool toggle)
     178{
     179        assert(instance);
     180        /* only control pipes are bi-directional and those do not need toggle */
     181        if (direction == USB_DIRECTION_BOTH)
     182                return ENOENT;
    172183        int ret;
    173184        fibril_mutex_lock(&instance->guard);
     
    179190        } else {
    180191                if (toggle) {
    181                         instance->devices[target.address].toggle_status |=
    182                             (1 << target.endpoint);
     192                        instance->devices[target.address].toggle_status[direction]
     193                            |= (1 << target.endpoint);
    183194                } else {
    184                         instance->devices[target.address].toggle_status &=
    185                             ~(1 << target.endpoint);
     195                        instance->devices[target.address].toggle_status[direction]
     196                            &= ~(1 << target.endpoint);
    186197                }
    187198                ret = EOK;
     
    197208 * @return Free address, or error code.
    198209 */
    199 usb_address_t device_keeper_request(
    200     device_keeper_t *instance, usb_speed_t speed)
     210usb_address_t device_keeper_get_free_address(usb_device_keeper_t *instance,
     211    usb_speed_t speed)
    201212{
    202213        assert(instance);
     
    218229        instance->devices[new_address].occupied = true;
    219230        instance->devices[new_address].speed = speed;
    220         instance->devices[new_address].toggle_status = 0;
     231        instance->devices[new_address].toggle_status[0] = 0;
     232        instance->devices[new_address].toggle_status[1] = 0;
    221233        instance->last_address = new_address;
    222234        fibril_mutex_unlock(&instance->guard);
     
    230242 * @param[in] handle Devman handle of the device.
    231243 */
    232 void device_keeper_bind(
    233     device_keeper_t *instance, usb_address_t address, devman_handle_t handle)
     244void usb_device_keeper_bind(usb_device_keeper_t *instance,
     245    usb_address_t address, devman_handle_t handle)
    234246{
    235247        assert(instance);
     
    247259 * @param[in] address Device address
    248260 */
    249 void device_keeper_release(device_keeper_t *instance, usb_address_t address)
     261void usb_device_keeper_release(usb_device_keeper_t *instance,
     262    usb_address_t address)
    250263{
    251264        assert(instance);
     
    265278 * @return USB Address, or error code.
    266279 */
    267 usb_address_t device_keeper_find(
    268     device_keeper_t *instance, devman_handle_t handle)
     280usb_address_t usb_device_keeper_find(usb_device_keeper_t *instance,
     281    devman_handle_t handle)
    269282{
    270283        assert(instance);
     
    288301 * @return USB speed.
    289302 */
    290 usb_speed_t device_keeper_speed(
    291     device_keeper_t *instance, usb_address_t address)
     303usb_speed_t usb_device_keeper_get_speed(usb_device_keeper_t *instance,
     304    usb_address_t address)
    292305{
    293306        assert(instance);
     
    296309        return instance->devices[address].speed;
    297310}
     311
    298312/**
    299313 * @}
Note: See TracChangeset for help on using the changeset viewer.