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

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

fix for #132 2.0

  • Property mode set to 100644
File size: 9.9 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/** @addtogroup drvusbhub
29 * @{
30 */
31
32#ifndef HUB_PORT_STATUS_H
33#define HUB_PORT_STATUS_H
34
35#include <bool.h>
36#include <sys/types.h>
37#include <usb/request.h>
38#include "usbhub_private.h"
39
40/**
41 * structure holding port status and changes flags.
42 * should not be accessed directly, use supplied getter/setter methods.
43 *
44 * For more information refer to table 11-15 in
45 * "Universal Serial Bus Specification Revision 1.1"
46 *
47 */
48typedef uint32_t usb_port_status_t;
49
50/**
51 * set values in request to be it a port status request
52 * @param request
53 * @param port
54 */
55static inline void usb_hub_set_port_status_request(
56usb_device_request_setup_packet_t * request, uint16_t port
57){
58 request->index = port;
59 request->request_type = USB_HUB_REQ_TYPE_GET_PORT_STATUS;
60 request->request = USB_HUB_REQUEST_GET_STATUS;
61 request->value = 0;
62 request->length = 4;
63}
64
65
66/**
67 * create request for usb hub port status
68 * @param port
69 * @return
70 */
71static inline usb_device_request_setup_packet_t *
72usb_hub_create_port_status_request(uint16_t port){
73 usb_device_request_setup_packet_t * result =
74 usb_new(usb_device_request_setup_packet_t);
75 usb_hub_set_port_status_request(result,port);
76 return result;
77}
78
79
80/**
81 * set the device request to be a port feature enable request
82 * @param request
83 * @param port
84 * @param feature_selector
85 */
86static inline void usb_hub_set_enable_port_feature_request(
87usb_device_request_setup_packet_t * request, uint16_t port,
88 uint16_t feature_selector
89){
90 request->index = port;
91 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
92 request->request = USB_HUB_REQUEST_SET_FEATURE;
93 request->value = feature_selector;
94 request->length = 0;
95}
96
97
98/**
99 * set the device request to be a port enable request
100 * @param request
101 * @param port
102 */
103static inline void usb_hub_set_enable_port_request(
104usb_device_request_setup_packet_t * request, uint16_t port
105){
106 request->index = port;
107 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
108 request->request = USB_HUB_REQUEST_SET_FEATURE;
109 request->value = USB_HUB_FEATURE_C_PORT_ENABLE;
110 request->length = 0;
111}
112
113/**
114 * enable specified port
115 * @param port
116 * @return
117 */
118static inline usb_device_request_setup_packet_t *
119usb_hub_create_enable_port_request(uint16_t port){
120 usb_device_request_setup_packet_t * result =
121 usb_new(usb_device_request_setup_packet_t);
122 usb_hub_set_enable_port_request(result,port);
123 return result;
124}
125
126/**
127 * set the device request to be a port disable request
128 * @param request
129 * @param port
130 */
131static inline void usb_hub_set_disable_port_request(
132usb_device_request_setup_packet_t * request, uint16_t port
133){
134 request->index = port;
135 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
136 request->request = USB_HUB_REQUEST_SET_FEATURE;
137 request->value = USB_HUB_FEATURE_C_PORT_SUSPEND;
138 request->length = 0;
139}
140
141/**
142 * disable specified port
143 * @param port
144 * @return
145 */
146static inline usb_device_request_setup_packet_t *
147usb_hub_create_disable_port_request(uint16_t port){
148 usb_device_request_setup_packet_t * result =
149 usb_new(usb_device_request_setup_packet_t);
150 usb_hub_set_disable_port_request(result,port);
151 return result;
152}
153
154/**
155 * set the device request to be a port disable request
156 * @param request
157 * @param port
158 */
159static inline void usb_hub_set_reset_port_request(
160usb_device_request_setup_packet_t * request, uint16_t port
161){
162 request->index = port;
163 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
164 request->request = USB_HUB_REQUEST_SET_FEATURE;
165 request->value = USB_HUB_FEATURE_PORT_RESET;
166 request->length = 0;
167}
168
169/**
170 * disable specified port
171 * @param port
172 * @return
173 */
174static inline usb_device_request_setup_packet_t *
175usb_hub_create_reset_port_request(uint16_t port){
176 usb_device_request_setup_packet_t * result =
177 usb_new(usb_device_request_setup_packet_t);
178 usb_hub_set_reset_port_request(result,port);
179 return result;
180}
181
182/**
183 * set the device request to be a port disable request
184 * @param request
185 * @param port
186 */
187static inline void usb_hub_set_power_port_request(
188usb_device_request_setup_packet_t * request, uint16_t port
189){
190 request->index = port;
191 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
192 request->request = USB_HUB_REQUEST_SET_FEATURE;
193 request->value = USB_HUB_FEATURE_PORT_POWER;
194 request->length = 0;
195}
196
197/**
198 * set the device request to be a port disable request
199 * @param request
200 * @param port
201 */
202static inline void usb_hub_unset_power_port_request(
203usb_device_request_setup_packet_t * request, uint16_t port
204){
205 request->index = port;
206 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
207 request->request = USB_HUB_REQUEST_CLEAR_FEATURE;
208 request->value = USB_HUB_FEATURE_PORT_POWER;
209 request->length = 0;
210}
211
212
213/** get i`th bit of port status */
214static inline bool usb_port_get_bit(usb_port_status_t * status, int idx)
215{
216 return (((*status)>>(idx))%2);
217}
218
219/** set i`th bit of port status */
220static inline void usb_port_set_bit(
221 usb_port_status_t * status, int idx, bool value)
222{
223 (*status) = value?
224 ((*status)|(1<<(idx))):
225 ((*status)&(~(1<<(idx))));
226}
227
228//device connnected on port
229static inline bool usb_port_dev_connected(usb_port_status_t * status){
230 return usb_port_get_bit(status,0);
231}
232
233static inline void usb_port_set_dev_connected(usb_port_status_t * status,bool connected){
234 usb_port_set_bit(status,0,connected);
235}
236
237//port enabled
238static inline bool usb_port_enabled(usb_port_status_t * status){
239 return usb_port_get_bit(status,1);
240}
241
242static inline void usb_port_set_enabled(usb_port_status_t * status,bool enabled){
243 usb_port_set_bit(status,1,enabled);
244}
245
246//port suspended
247static inline bool usb_port_suspended(usb_port_status_t * status){
248 return usb_port_get_bit(status,2);
249}
250
251static inline void usb_port_set_suspended(usb_port_status_t * status,bool suspended){
252 usb_port_set_bit(status,2,suspended);
253}
254
255//over currect
256static inline bool usb_port_over_current(usb_port_status_t * status){
257 return usb_port_get_bit(status,3);
258}
259
260static inline void usb_port_set_over_current(usb_port_status_t * status,bool value){
261 usb_port_set_bit(status,3,value);
262}
263
264//port reset
265static inline bool usb_port_reset(usb_port_status_t * status){
266 return usb_port_get_bit(status,4);
267}
268
269static inline void usb_port_set_reset(usb_port_status_t * status,bool value){
270 usb_port_set_bit(status,4,value);
271}
272
273//powered
274static inline bool usb_port_powered(usb_port_status_t * status){
275 return usb_port_get_bit(status,8);
276}
277
278static inline void usb_port_set_powered(usb_port_status_t * status,bool powered){
279 usb_port_set_bit(status,8,powered);
280}
281
282//low speed device attached
283static inline bool usb_port_low_speed(usb_port_status_t * status){
284 return usb_port_get_bit(status,9);
285}
286
287static inline void usb_port_set_low_speed(usb_port_status_t * status,bool low_speed){
288 usb_port_set_bit(status,9,low_speed);
289}
290
291//low speed device attached
292static inline bool usb_port_high_speed(usb_port_status_t * status){
293 return usb_port_get_bit(status,10);
294}
295
296static inline void usb_port_set_high_speed(usb_port_status_t * status,bool high_speed){
297 usb_port_set_bit(status,10,high_speed);
298}
299
300static inline usb_speed_t usb_port_speed(usb_port_status_t * status){
301 if(usb_port_low_speed(status))
302 return USB_SPEED_LOW;
303 if(usb_port_high_speed(status))
304 return USB_SPEED_HIGH;
305 return USB_SPEED_FULL;
306}
307
308
309//connect change
310static inline bool usb_port_connect_change(usb_port_status_t * status){
311 return usb_port_get_bit(status,16);
312}
313
314static inline void usb_port_set_connect_change(usb_port_status_t * status,bool change){
315 usb_port_set_bit(status,16,change);
316}
317
318//port enable change
319static inline bool usb_port_enabled_change(usb_port_status_t * status){
320 return usb_port_get_bit(status,17);
321}
322
323static inline void usb_port_set_enabled_change(usb_port_status_t * status,bool change){
324 usb_port_set_bit(status,17,change);
325}
326
327//suspend change
328static inline bool usb_port_suspend_change(usb_port_status_t * status){
329 return usb_port_get_bit(status,18);
330}
331
332static inline void usb_port_set_suspend_change(usb_port_status_t * status,bool change){
333 usb_port_set_bit(status,18,change);
334}
335
336//over current change
337static inline bool usb_port_overcurrent_change(usb_port_status_t * status){
338 return usb_port_get_bit(status,19);
339}
340
341static inline void usb_port_set_overcurrent_change(usb_port_status_t * status,bool change){
342 usb_port_set_bit(status,19,change);
343}
344
345//reset change
346static inline bool usb_port_reset_completed(usb_port_status_t * status){
347 return usb_port_get_bit(status,20);
348}
349
350static inline void usb_port_set_reset_completed(usb_port_status_t * status,bool completed){
351 usb_port_set_bit(status,20,completed);
352}
353
354
355
356#endif /* HUB_PORT_STATUS_H */
357
358/**
359 * @}
360 */
Note: See TracBrowser for help on using the repository browser.