source: mainline/uspace/lib/usb/include/usb/host/device_keeper.h@ d773285f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d773285f was d773285f, checked in by Jan Vesely <jano.vesely@…>, 15 years ago

Use per endpoint control transfer mutex

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libusb
30 * @{
31 */
32/** @file
33 * Device keeper structure and functions.
34 *
35 * Typical USB host controller needs to keep track of various settings for
36 * each device that is connected to it.
37 * State of toggle bit, device speed etc. etc.
38 * This structure shall simplify the management.
39 */
40#ifndef LIBUSB_HOST_DEVICE_KEEPER_H
41#define LIBUSB_HOST_DEVICE_KEEPER_H
42#include <devman.h>
43#include <fibril_synch.h>
44#include <usb/usb.h>
45
46/** Number of USB address for array dimensions. */
47#define USB_ADDRESS_COUNT (USB11_ADDRESS_MAX + 1)
48
49/** Information about attached USB device. */
50struct usb_device_info {
51 usb_speed_t speed;
52 bool occupied;
53 uint16_t control_used;
54 uint16_t toggle_status[2];
55 devman_handle_t handle;
56};
57
58/** Host controller device keeper.
59 * You shall not access members directly but only using functions below.
60 */
61typedef struct {
62 struct usb_device_info devices[USB_ADDRESS_COUNT];
63 fibril_mutex_t guard;
64 fibril_condvar_t change;
65 usb_address_t last_address;
66} usb_device_keeper_t;
67
68void usb_device_keeper_init(usb_device_keeper_t *instance);
69
70void usb_device_keeper_reserve_default_address(usb_device_keeper_t *instance,
71 usb_speed_t speed);
72
73void usb_device_keeper_release_default_address(usb_device_keeper_t *instance);
74
75void usb_device_keeper_reset_if_need(usb_device_keeper_t *instance,
76 usb_target_t target,
77 const uint8_t *setup_data);
78
79int usb_device_keeper_get_toggle(usb_device_keeper_t *instance,
80 usb_target_t target, usb_direction_t direction);
81
82int usb_device_keeper_set_toggle(usb_device_keeper_t *instance,
83 usb_target_t target, usb_direction_t direction, bool toggle);
84
85usb_address_t device_keeper_get_free_address(usb_device_keeper_t *instance,
86 usb_speed_t speed);
87
88void usb_device_keeper_bind(usb_device_keeper_t *instance,
89 usb_address_t address, devman_handle_t handle);
90
91void usb_device_keeper_release(usb_device_keeper_t *instance,
92 usb_address_t address);
93
94usb_address_t usb_device_keeper_find(usb_device_keeper_t *instance,
95 devman_handle_t handle);
96
97usb_speed_t usb_device_keeper_get_speed(usb_device_keeper_t *instance,
98 usb_address_t address);
99
100void usb_device_keeper_use_control(usb_device_keeper_t *instance,
101 usb_target_t target);
102
103void usb_device_keeper_release_control(usb_device_keeper_t *instance,
104 usb_target_t target);
105
106#endif
107/**
108 * @}
109 */
Note: See TracBrowser for help on using the repository browser.