source: mainline/uspace/drv/vhc/hub/hub.h@ 6427cf67

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6427cf67 was 95622c4, checked in by Vojtech Horky <vojtechhorky@…>, 15 years ago

Add standalone virtual hub

Similar to virtual USB keyboard (vuk'), vuh' is a virtual USB hub.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2010 Vojtech Horky
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 drvusbvhc
30 * @{
31 */
32/** @file
33 * @brief Representation of an USB hub.
34 */
35#ifndef VHC_HUB_HUB_H_
36#define VHC_HUB_HUB_H_
37
38#include <fibril_synch.h>
39
40#ifndef HUB_PORT_COUNT
41#define HUB_PORT_COUNT 2
42#endif
43#define BITS2BYTES(bits) (bits ? ((((bits)-1)>>3)+1) : 0)
44
45/** Hub port internal state.
46 * Some states (e.g. port over current) are not covered as they are not
47 * simulated at all.
48 */
49typedef enum {
50 HUB_PORT_STATE_UNKNOWN,
51 HUB_PORT_STATE_NOT_CONFIGURED,
52 HUB_PORT_STATE_POWERED_OFF,
53 HUB_PORT_STATE_DISCONNECTED,
54 HUB_PORT_STATE_DISABLED,
55 HUB_PORT_STATE_RESETTING,
56 HUB_PORT_STATE_ENABLED,
57 HUB_PORT_STATE_SUSPENDED,
58 HUB_PORT_STATE_RESUMING,
59 /* HUB_PORT_STATE_, */
60} hub_port_state_t;
61
62char hub_port_state_to_char(hub_port_state_t);
63
64/** Hub status change mask bits. */
65typedef enum {
66 HUB_STATUS_C_PORT_CONNECTION = (1 << 0),
67 HUB_STATUS_C_PORT_ENABLE = (1 << 1),
68 HUB_STATUS_C_PORT_SUSPEND = (1 << 2),
69 HUB_STATUS_C_PORT_OVER_CURRENT = (1 << 3),
70 HUB_STATUS_C_PORT_RESET = (1 << 4),
71 /* HUB_STATUS_C_ = (1 << ), */
72} hub_status_change_t;
73
74/** Hub port information. */
75typedef struct {
76 /** Custom pointer to connected device. */
77 void *connected_device;
78 /** Port index (one based). */
79 size_t index;
80 /** Port state. */
81 hub_port_state_t state;
82 /** Status change bitmap. */
83 uint16_t status_change;
84} hub_port_t;
85
86/** Hub device type. */
87typedef struct {
88 /** Hub ports. */
89 hub_port_t ports[HUB_PORT_COUNT];
90 /** Custom hub data. */
91 void *custom_data;
92 /** Access guard to the whole hub. */
93 fibril_mutex_t guard;
94} hub_t;
95
96void hub_init(hub_t *);
97size_t hub_connect_device(hub_t *, void *);
98int hub_disconnect_device(hub_t *, void *);
99size_t hub_find_device(hub_t *, void *);
100void hub_acquire(hub_t *);
101void hub_release(hub_t *);
102void hub_set_port_state(hub_t *, size_t, hub_port_state_t);
103void hub_set_port_state_all(hub_t *, hub_port_state_t);
104hub_port_state_t hub_get_port_state(hub_t *, size_t);
105void hub_clear_port_status_change(hub_t *, size_t, hub_status_change_t);
106uint16_t hub_get_port_status_change(hub_t *, size_t);
107uint32_t hub_get_port_status(hub_t *, size_t);
108uint8_t hub_get_status_change_bitmap(hub_t *);
109
110
111#endif
112/**
113 * @}
114 */
Note: See TracBrowser for help on using the repository browser.