Ignore:
Timestamp:
2011-03-11T15:42:43Z (14 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0bd4810c
Parents:
60a228f (diff), a8def7d (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 hidd

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/utils/device_keeper.c

    r60a228f r9d9ffdd  
    3535#include <assert.h>
    3636#include <errno.h>
     37#include <usb/debug.h>
    3738
    3839#include "device_keeper.h"
    3940
    4041/*----------------------------------------------------------------------------*/
     42/** Initializes device keeper structure.
     43 *
     44 * @param[in] instance Memory place to initialize.
     45 */
    4146void device_keeper_init(device_keeper_t *instance)
    4247{
     
    4954                instance->devices[i].occupied = false;
    5055                instance->devices[i].handle = 0;
    51         }
    52 }
    53 /*----------------------------------------------------------------------------*/
    54 void device_keeper_reserve_default(
    55     device_keeper_t *instance, usb_speed_t speed)
     56                instance->devices[i].toggle_status = 0;
     57        }
     58}
     59/*----------------------------------------------------------------------------*/
     60/** Attempts to obtain address 0, blocks.
     61 *
     62 * @param[in] instance Device keeper structure to use.
     63 * @param[in] speed Speed of the device requesting default address.
     64 */
     65void device_keeper_reserve_default(device_keeper_t *instance, usb_speed_t speed)
    5666{
    5767        assert(instance);
     
    6676}
    6777/*----------------------------------------------------------------------------*/
     78/** Attempts to obtain address 0, blocks.
     79 *
     80 * @param[in] instance Device keeper structure to use.
     81 * @param[in] speed Speed of the device requesting default address.
     82 */
    6883void device_keeper_release_default(device_keeper_t *instance)
    6984{
     
    7590}
    7691/*----------------------------------------------------------------------------*/
     92/** Checks setup data for signs of toggle reset.
     93 *
     94 * @param[in] instance Device keeper structure to use.
     95 * @param[in] target Device to receive setup packet.
     96 * @param[in] data Setup packet data.
     97 */
     98void device_keeper_reset_if_need(
     99    device_keeper_t *instance, usb_target_t target, const unsigned char *data)
     100{
     101        assert(instance);
     102        fibril_mutex_lock(&instance->guard);
     103        if (target.endpoint > 15 || target.endpoint < 0
     104            || target.address >= USB_ADDRESS_COUNT || target.address < 0
     105            || !instance->devices[target.address].occupied) {
     106                fibril_mutex_unlock(&instance->guard);
     107                return;
     108        }
     109
     110        switch (data[1])
     111        {
     112        case 0x01: /*clear feature*/
     113                /* recipient is endpoint, value is zero (ENDPOINT_STALL) */
     114                if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) {
     115                        /* endpoint number is < 16, thus first byte is enough */
     116                        instance->devices[target.address].toggle_status &=
     117                            ~(1 << data[4]);
     118                }
     119        break;
     120
     121        case 0x9: /* set configuration */
     122        case 0x11: /* set interface */
     123                /* target must be device */
     124                if ((data[0] & 0xf) == 0) {
     125                        instance->devices[target.address].toggle_status = 0;
     126                }
     127        break;
     128        }
     129        fibril_mutex_unlock(&instance->guard);
     130}
     131/*----------------------------------------------------------------------------*/
     132/** Gets current value of endpoint toggle.
     133 *
     134 * @param[in] instance Device keeper structure to use.
     135 * @param[in] target Device and endpoint used.
     136 * @return Error code
     137 */
     138int device_keeper_get_toggle(device_keeper_t *instance, usb_target_t target)
     139{
     140        assert(instance);
     141        int ret;
     142        fibril_mutex_lock(&instance->guard);
     143        if (target.endpoint > 15 || target.endpoint < 0
     144            || target.address >= USB_ADDRESS_COUNT || target.address < 0
     145            || !instance->devices[target.address].occupied) {
     146                ret = EINVAL;
     147        } else {
     148                ret =
     149                    (instance->devices[target.address].toggle_status
     150                        >> target.endpoint) & 1;
     151        }
     152        fibril_mutex_unlock(&instance->guard);
     153        return ret;
     154}
     155/*----------------------------------------------------------------------------*/
     156/** Sets current value of endpoint toggle.
     157 *
     158 * @param[in] instance Device keeper structure to use.
     159 * @param[in] target Device and endpoint used.
     160 * @param[in] toggle Current toggle value.
     161 * @return Error code.
     162 */
     163int device_keeper_set_toggle(
     164    device_keeper_t *instance, usb_target_t target, bool toggle)
     165{
     166        assert(instance);
     167        int ret;
     168        fibril_mutex_lock(&instance->guard);
     169        if (target.endpoint > 15 || target.endpoint < 0
     170            || target.address >= USB_ADDRESS_COUNT || target.address < 0
     171            || !instance->devices[target.address].occupied) {
     172                ret = EINVAL;
     173        } else {
     174                if (toggle) {
     175                        instance->devices[target.address].toggle_status |= (1 << target.endpoint);
     176                } else {
     177                        instance->devices[target.address].toggle_status &= ~(1 << target.endpoint);
     178                }
     179                ret = EOK;
     180        }
     181        fibril_mutex_unlock(&instance->guard);
     182        return ret;
     183}
     184/*----------------------------------------------------------------------------*/
     185/** Gets a free USB address
     186 *
     187 * @param[in] instance Device keeper structure to use.
     188 * @param[in] speed Speed of the device requiring address.
     189 * @return Free address, or error code.
     190 */
    77191usb_address_t device_keeper_request(
    78192    device_keeper_t *instance, usb_speed_t speed)
     
    96210        instance->devices[new_address].occupied = true;
    97211        instance->devices[new_address].speed = speed;
     212        instance->devices[new_address].toggle_status = 0;
    98213        instance->last_address = new_address;
    99214        fibril_mutex_unlock(&instance->guard);
     
    101216}
    102217/*----------------------------------------------------------------------------*/
     218/** Binds USB address to devman handle.
     219 *
     220 * @param[in] instance Device keeper structure to use.
     221 * @param[in] address Device address
     222 * @param[in] handle Devman handle of the device.
     223 */
    103224void device_keeper_bind(
    104225    device_keeper_t *instance, usb_address_t address, devman_handle_t handle)
     
    113234}
    114235/*----------------------------------------------------------------------------*/
     236/** Releases used USB address.
     237 *
     238 * @param[in] instance Device keeper structure to use.
     239 * @param[in] address Device address
     240 */
    115241void device_keeper_release(device_keeper_t *instance, usb_address_t address)
    116242{
     
    125251}
    126252/*----------------------------------------------------------------------------*/
     253/** Finds USB address associated with the device
     254 *
     255 * @param[in] instance Device keeper structure to use.
     256 * @param[in] handle Devman handle of the device seeking its address.
     257 * @return USB Address, or error code.
     258 */
    127259usb_address_t device_keeper_find(
    128260    device_keeper_t *instance, devman_handle_t handle)
     
    142274}
    143275/*----------------------------------------------------------------------------*/
     276/** Gets speed associated with the address
     277 *
     278 * @param[in] instance Device keeper structure to use.
     279 * @param[in] address Address of the device.
     280 * @return USB speed.
     281 */
    144282usb_speed_t device_keeper_speed(
    145283    device_keeper_t *instance, usb_address_t address)
Note: See TracChangeset for help on using the changeset viewer.