Ignore:
Timestamp:
2011-03-21T14:23:15Z (13 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
55e388a1
Parents:
c32688d (diff), 48fe0c9 (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:

merge with development

File:
1 moved

Legend:

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

    rc32688d r361e61b  
    2727 */
    2828
    29 /** @addtogroup drvusbuhci
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3636#include <errno.h>
    3737#include <usb/debug.h>
    38 
    39 #include "device_keeper.h"
    40 
    41 /*----------------------------------------------------------------------------*/
    42 /** Initializes device keeper structure.
     38#include <usb/host/device_keeper.h>
     39
     40/*----------------------------------------------------------------------------*/
     41/** Initialize device keeper structure.
    4342 *
    4443 * @param[in] instance Memory place to initialize.
     44 *
     45 * Set all values to false/0.
    4546 */
    4647void device_keeper_init(device_keeper_t *instance)
     
    5455                instance->devices[i].occupied = false;
    5556                instance->devices[i].handle = 0;
    56                 instance->devices[i].toggle_status = 0;
    57         }
    58 }
    59 /*----------------------------------------------------------------------------*/
    60 /** Attempts to obtain address 0, blocks.
     57                instance->devices[i].toggle_status[0] = 0;
     58                instance->devices[i].toggle_status[1] = 0;
     59        }
     60}
     61/*----------------------------------------------------------------------------*/
     62/** Attempt to obtain address 0, blocks.
    6163 *
    6264 * @param[in] instance Device keeper structure to use.
     
    7678}
    7779/*----------------------------------------------------------------------------*/
    78 /** Attempts to obtain address 0, blocks.
     80/** Attempt to obtain address 0, blocks.
    7981 *
    8082 * @param[in] instance Device keeper structure to use.
     
    9092}
    9193/*----------------------------------------------------------------------------*/
    92 /** Checks setup data for signs of toggle reset.
     94/** Check setup packet data for signs of toggle reset.
    9395 *
    9496 * @param[in] instance Device keeper structure to use.
    9597 * @param[in] target Device to receive setup packet.
    9698 * @param[in] data Setup packet data.
     99 *
     100 * Really ugly one.
    97101 */
    98102void device_keeper_reset_if_need(
     
    105109            || !instance->devices[target.address].occupied) {
    106110                fibril_mutex_unlock(&instance->guard);
     111                usb_log_error("Invalid data when checking for toggle reset.\n");
    107112                return;
    108113        }
     
    114119                if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) {
    115120                        /* endpoint number is < 16, thus first byte is enough */
    116                         instance->devices[target.address].toggle_status &=
     121                        instance->devices[target.address].toggle_status[0] &=
     122                            ~(1 << data[4]);
     123                        instance->devices[target.address].toggle_status[1] &=
    117124                            ~(1 << data[4]);
    118125                }
     
    123130                /* target must be device */
    124131                if ((data[0] & 0xf) == 0) {
    125                         instance->devices[target.address].toggle_status = 0;
     132                        instance->devices[target.address].toggle_status[0] = 0;
     133                        instance->devices[target.address].toggle_status[1] = 0;
    126134                }
    127135        break;
     
    130138}
    131139/*----------------------------------------------------------------------------*/
    132 /** Gets current value of endpoint toggle.
     140/** Get current value of endpoint toggle.
    133141 *
    134142 * @param[in] instance Device keeper structure to use.
     
    136144 * @return Error code
    137145 */
    138 int device_keeper_get_toggle(device_keeper_t *instance, usb_target_t target)
    139 {
    140         assert(instance);
     146int device_keeper_get_toggle(
     147    device_keeper_t *instance, usb_target_t target, usb_direction_t direction)
     148{
     149        assert(instance);
     150        /* only control pipes are bi-directional and those do not need toggle */
     151        if (direction == USB_DIRECTION_BOTH)
     152                return ENOENT;
    141153        int ret;
    142154        fibril_mutex_lock(&instance->guard);
     
    144156            || target.address >= USB_ADDRESS_COUNT || target.address < 0
    145157            || !instance->devices[target.address].occupied) {
     158                usb_log_error("Invalid data when asking for toggle value.\n");
    146159                ret = EINVAL;
    147160        } else {
    148                 ret =
    149                     (instance->devices[target.address].toggle_status
     161                ret = (instance->devices[target.address].toggle_status[direction]
    150162                        >> target.endpoint) & 1;
    151163        }
     
    154166}
    155167/*----------------------------------------------------------------------------*/
    156 /** Sets current value of endpoint toggle.
     168/** Set current value of endpoint toggle.
    157169 *
    158170 * @param[in] instance Device keeper structure to use.
    159171 * @param[in] target Device and endpoint used.
    160  * @param[in] toggle Current toggle value.
     172 * @param[in] toggle Toggle value.
    161173 * @return Error code.
    162174 */
    163 int device_keeper_set_toggle(
    164     device_keeper_t *instance, usb_target_t target, bool toggle)
    165 {
    166         assert(instance);
     175int device_keeper_set_toggle(device_keeper_t *instance,
     176    usb_target_t target, usb_direction_t direction, bool toggle)
     177{
     178        assert(instance);
     179        /* only control pipes are bi-directional and those do not need toggle */
     180        if (direction == USB_DIRECTION_BOTH)
     181                return ENOENT;
    167182        int ret;
    168183        fibril_mutex_lock(&instance->guard);
     
    170185            || target.address >= USB_ADDRESS_COUNT || target.address < 0
    171186            || !instance->devices[target.address].occupied) {
     187                usb_log_error("Invalid data when setting toggle value.\n");
    172188                ret = EINVAL;
    173189        } else {
    174190                if (toggle) {
    175                         instance->devices[target.address].toggle_status |= (1 << target.endpoint);
     191                        instance->devices[target.address].toggle_status[direction]
     192                            |= (1 << target.endpoint);
    176193                } else {
    177                         instance->devices[target.address].toggle_status &= ~(1 << target.endpoint);
     194                        instance->devices[target.address].toggle_status[direction]
     195                            &= ~(1 << target.endpoint);
    178196                }
    179197                ret = EOK;
     
    183201}
    184202/*----------------------------------------------------------------------------*/
    185 /** Gets a free USB address
     203/** Get a free USB address
    186204 *
    187205 * @param[in] instance Device keeper structure to use.
     
    210228        instance->devices[new_address].occupied = true;
    211229        instance->devices[new_address].speed = speed;
    212         instance->devices[new_address].toggle_status = 0;
     230        instance->devices[new_address].toggle_status[0] = 0;
     231        instance->devices[new_address].toggle_status[1] = 0;
    213232        instance->last_address = new_address;
    214233        fibril_mutex_unlock(&instance->guard);
     
    216235}
    217236/*----------------------------------------------------------------------------*/
    218 /** Binds USB address to devman handle.
     237/** Bind USB address to devman handle.
    219238 *
    220239 * @param[in] instance Device keeper structure to use.
     
    234253}
    235254/*----------------------------------------------------------------------------*/
    236 /** Releases used USB address.
     255/** Release used USB address.
    237256 *
    238257 * @param[in] instance Device keeper structure to use.
     
    251270}
    252271/*----------------------------------------------------------------------------*/
    253 /** Finds USB address associated with the device
     272/** Find USB address associated with the device
    254273 *
    255274 * @param[in] instance Device keeper structure to use.
     
    274293}
    275294/*----------------------------------------------------------------------------*/
    276 /** Gets speed associated with the address
     295/** Get speed associated with the address
    277296 *
    278297 * @param[in] instance Device keeper structure to use.
Note: See TracChangeset for help on using the changeset viewer.