Ignore:
Timestamp:
2011-03-22T10:07:53Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f8e4cb6
Parents:
18b3cfd (diff), b01995b (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:

Merged changes from development

File:
1 moved

Legend:

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

    r18b3cfd r62f4212  
    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 |= (1 << target.endpoint);
     192                        instance->devices[target.address].toggle_status[direction]
     193                            |= (1 << target.endpoint);
    182194                } else {
    183                         instance->devices[target.address].toggle_status &= ~(1 << target.endpoint);
     195                        instance->devices[target.address].toggle_status[direction]
     196                            &= ~(1 << target.endpoint);
    184197                }
    185198                ret = EOK;
     
    195208 * @return Free address, or error code.
    196209 */
    197 usb_address_t device_keeper_request(
    198     device_keeper_t *instance, usb_speed_t speed)
    199 {
    200         assert(instance);
    201         fibril_mutex_lock(&instance->guard);
    202 
    203         usb_address_t new_address = instance->last_address + 1;
    204         while (instance->devices[new_address].occupied) {
     210usb_address_t device_keeper_get_free_address(usb_device_keeper_t *instance,
     211    usb_speed_t speed)
     212{
     213        assert(instance);
     214        fibril_mutex_lock(&instance->guard);
     215
     216        usb_address_t new_address = instance->last_address;
     217        do {
     218                ++new_address;
     219                if (new_address > USB11_ADDRESS_MAX)
     220                        new_address = 1;
    205221                if (new_address == instance->last_address) {
    206222                        fibril_mutex_unlock(&instance->guard);
    207223                        return ENOSPC;
    208224                }
    209                 if (new_address == USB11_ADDRESS_MAX)
    210                         new_address = 1;
    211                 ++new_address;
    212         }
     225        } while (instance->devices[new_address].occupied);
    213226
    214227        assert(new_address != USB_ADDRESS_DEFAULT);
     
    216229        instance->devices[new_address].occupied = true;
    217230        instance->devices[new_address].speed = speed;
    218         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;
    219233        instance->last_address = new_address;
    220234        fibril_mutex_unlock(&instance->guard);
     
    228242 * @param[in] handle Devman handle of the device.
    229243 */
    230 void device_keeper_bind(
    231     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)
    232246{
    233247        assert(instance);
     
    245259 * @param[in] address Device address
    246260 */
    247 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)
    248263{
    249264        assert(instance);
     
    263278 * @return USB Address, or error code.
    264279 */
    265 usb_address_t device_keeper_find(
    266     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)
    267282{
    268283        assert(instance);
     
    286301 * @return USB speed.
    287302 */
    288 usb_speed_t device_keeper_speed(
    289     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)
    290305{
    291306        assert(instance);
     
    294309        return instance->devices[address].speed;
    295310}
     311
    296312/**
    297313 * @}
Note: See TracChangeset for help on using the changeset viewer.