source: mainline/uspace/drv/usbhub/port_status.h@ b5ec347

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b5ec347 was b5ec347, checked in by Matus Dekanek <smekideki@…>, 15 years ago

various convenience definitions
removing of usb_hcd_hub_info_t from public declarations
usb-side implementation of adding a new device (assign addressand enable port)

  • Property mode set to 100644
File size: 6.7 KB
Line 
1/*
2 * Copyright (c) 2010 Matus Dekanek
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#ifndef PORT_STATUS_H
30#define PORT_STATUS_H
31
32#include <bool.h>
33#include <sys/types.h>
34#include <usb/devreq.h>
35#include "usbhub_private.h"
36
37/**
38 * structure holding port status and changes flags.
39 * should not be accessed directly, use supplied getter/setter methods.
40 *
41 * For more information refer to table 11-15 in
42 * "Universal Serial Bus Specification Revision 1.1"
43 *
44 */
45typedef uint8_t usb_port_status_t[4];
46
47/**
48 * set values in request to be it a port status request
49 * @param request
50 * @param port
51 */
52static inline void usb_hub_set_port_status_request(
53usb_device_request_setup_packet_t * request, uint16_t port
54){
55 request->index = port;
56 request->request_type = USB_HUB_REQ_TYPE_GET_PORT_STATUS;
57 request->request = USB_HUB_REQUEST_GET_STATE;
58 request->value = 0;
59 request->length = 4;
60}
61
62
63/**
64 * create request for usb hub port status
65 * @param port
66 * @return
67 */
68static inline usb_device_request_setup_packet_t *
69usb_hub_create_port_status_request(uint16_t port){
70 usb_device_request_setup_packet_t * result =
71 usb_new(usb_device_request_setup_packet_t);
72 usb_hub_set_port_status_request(result,port);
73 return result;
74}
75
76
77/**
78 * set the device request to be a port enable request
79 * @param request
80 * @param port
81 */
82static inline void usb_hub_set_enable_port_request(
83usb_device_request_setup_packet_t * request, uint16_t port
84){
85 request->index = port;
86 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
87 request->request = USB_HUB_REQUEST_SET_FEATURE;
88 request->value = USB_HUB_FEATURE_C_PORT_ENABLE;
89 request->length = 0;
90}
91
92/**
93 * enable specified port
94 * @param port
95 * @return
96 */
97static inline usb_device_request_setup_packet_t *
98usb_hub_create_enable_port_request(uint16_t port){
99 usb_device_request_setup_packet_t * result =
100 usb_new(usb_device_request_setup_packet_t);
101 usb_hub_set_enable_port_request(result,port);
102 return result;
103}
104
105
106/** get i`th bit of port status */
107static inline bool usb_port_get_bit(usb_port_status_t * status, int idx)
108{
109 return (((*status)[idx/8])>>(idx%8))%2;
110}
111
112/** set i`th bit of port status */
113static inline void usb_port_set_bit(
114 usb_port_status_t * status, int idx, bool value)
115{
116 (*status)[idx/8] = value?
117 ((*status)[idx/8]|(1<<(idx%8))):
118 ((*status)[idx/8]&(~(1<<(idx%8))));
119}
120
121//device connnected on port
122static inline bool usb_port_dev_connected(usb_port_status_t * status){
123 return usb_port_get_bit(status,0);
124}
125
126static inline void usb_port_set_dev_connected(usb_port_status_t * status,bool connected){
127 usb_port_set_bit(status,0,connected);
128}
129
130//port enabled
131static inline bool usb_port_enabled(usb_port_status_t * status){
132 return usb_port_get_bit(status,1);
133}
134
135static inline void usb_port_set_enabled(usb_port_status_t * status,bool enabled){
136 usb_port_set_bit(status,1,enabled);
137}
138
139//port suspended
140static inline bool usb_port_suspended(usb_port_status_t * status){
141 return usb_port_get_bit(status,2);
142}
143
144static inline void usb_port_set_suspended(usb_port_status_t * status,bool suspended){
145 usb_port_set_bit(status,2,suspended);
146}
147
148//over currect
149static inline bool usb_port_over_current(usb_port_status_t * status){
150 return usb_port_get_bit(status,3);
151}
152
153static inline void usb_port_set_over_current(usb_port_status_t * status,bool value){
154 usb_port_set_bit(status,3,value);
155}
156
157//port reset
158static inline bool usb_port_reset(usb_port_status_t * status){
159 return usb_port_get_bit(status,4);
160}
161
162static inline void usb_port_set_reset(usb_port_status_t * status,bool value){
163 usb_port_set_bit(status,4,value);
164}
165
166//powered
167static inline bool usb_port_powered(usb_port_status_t * status){
168 return usb_port_get_bit(status,8);
169}
170
171static inline void usb_port_set_powered(usb_port_status_t * status,bool powered){
172 usb_port_set_bit(status,8,powered);
173}
174
175//low speed device attached
176static inline bool usb_port_low_speed(usb_port_status_t * status){
177 return usb_port_get_bit(status,9);
178}
179
180static inline void usb_port_set_low_speed(usb_port_status_t * status,bool low_speed){
181 usb_port_set_bit(status,9,low_speed);
182}
183
184
185//connect change
186static inline bool usb_port_connect_change(usb_port_status_t * status){
187 return usb_port_get_bit(status,16);
188}
189
190static inline void usb_port_set_connect_change(usb_port_status_t * status,bool change){
191 usb_port_set_bit(status,16,change);
192}
193
194//port enable change
195static inline bool usb_port_enabled_change(usb_port_status_t * status){
196 return usb_port_get_bit(status,17);
197}
198
199static inline void usb_port_set_enabled_change(usb_port_status_t * status,bool change){
200 usb_port_set_bit(status,17,change);
201}
202
203//suspend change
204static inline bool usb_port_suspend_change(usb_port_status_t * status){
205 return usb_port_get_bit(status,18);
206}
207
208static inline void usb_port_set_suspend_change(usb_port_status_t * status,bool change){
209 usb_port_set_bit(status,18,change);
210}
211
212//over current change
213static inline bool usb_port_overcurrent_change(usb_port_status_t * status){
214 return usb_port_get_bit(status,19);
215}
216
217static inline void usb_port_set_overcurrent_change(usb_port_status_t * status,bool change){
218 usb_port_set_bit(status,19,change);
219}
220
221//reset change
222static inline bool usb_port_reset_completed(usb_port_status_t * status){
223 return usb_port_get_bit(status,20);
224}
225
226static inline void usb_port_set_reset_completed(usb_port_status_t * status,bool completed){
227 usb_port_set_bit(status,20,completed);
228}
229
230
231
232#endif /* PORT_STATUS_H */
233
Note: See TracBrowser for help on using the repository browser.