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

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

fixed use of new usb pipe api
each hub has it`s own fibril

  • Property mode set to 100644
File size: 8.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 PORT_STATUS_H
33#define 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 enable request
82 * @param request
83 * @param port
84 */
85static inline void usb_hub_set_enable_port_request(
86usb_device_request_setup_packet_t * request, uint16_t port
87){
88 request->index = port;
89 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
90 request->request = USB_HUB_REQUEST_SET_FEATURE;
91 request->value = USB_HUB_FEATURE_C_PORT_ENABLE;
92 request->length = 0;
93}
94
95/**
96 * enable specified port
97 * @param port
98 * @return
99 */
100static inline usb_device_request_setup_packet_t *
101usb_hub_create_enable_port_request(uint16_t port){
102 usb_device_request_setup_packet_t * result =
103 usb_new(usb_device_request_setup_packet_t);
104 usb_hub_set_enable_port_request(result,port);
105 return result;
106}
107
108/**
109 * set the device request to be a port disable request
110 * @param request
111 * @param port
112 */
113static inline void usb_hub_set_disable_port_request(
114usb_device_request_setup_packet_t * request, uint16_t port
115){
116 request->index = port;
117 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
118 request->request = USB_HUB_REQUEST_SET_FEATURE;
119 request->value = USB_HUB_FEATURE_C_PORT_SUSPEND;
120 request->length = 0;
121}
122
123/**
124 * disable specified port
125 * @param port
126 * @return
127 */
128static inline usb_device_request_setup_packet_t *
129usb_hub_create_disable_port_request(uint16_t port){
130 usb_device_request_setup_packet_t * result =
131 usb_new(usb_device_request_setup_packet_t);
132 usb_hub_set_disable_port_request(result,port);
133 return result;
134}
135
136/**
137 * set the device request to be a port disable request
138 * @param request
139 * @param port
140 */
141static inline void usb_hub_set_reset_port_request(
142usb_device_request_setup_packet_t * request, uint16_t port
143){
144 request->index = port;
145 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
146 request->request = USB_HUB_REQUEST_SET_FEATURE;
147 request->value = USB_HUB_FEATURE_PORT_RESET;
148 request->length = 0;
149}
150
151/**
152 * disable specified port
153 * @param port
154 * @return
155 */
156static inline usb_device_request_setup_packet_t *
157usb_hub_create_reset_port_request(uint16_t port){
158 usb_device_request_setup_packet_t * result =
159 usb_new(usb_device_request_setup_packet_t);
160 usb_hub_set_reset_port_request(result,port);
161 return result;
162}
163
164/**
165 * set the device request to be a port disable request
166 * @param request
167 * @param port
168 */
169static inline void usb_hub_set_power_port_request(
170usb_device_request_setup_packet_t * request, uint16_t port
171){
172 request->index = port;
173 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
174 request->request = USB_HUB_REQUEST_SET_FEATURE;
175 request->value = USB_HUB_FEATURE_PORT_POWER;
176 request->length = 0;
177}
178
179/**
180 * set the device request to be a port disable request
181 * @param request
182 * @param port
183 */
184static inline void usb_hub_unset_power_port_request(
185usb_device_request_setup_packet_t * request, uint16_t port
186){
187 request->index = port;
188 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
189 request->request = USB_HUB_REQUEST_CLEAR_FEATURE;
190 request->value = USB_HUB_FEATURE_PORT_POWER;
191 request->length = 0;
192}
193
194/** get i`th bit of port status */
195static inline bool usb_port_get_bit(usb_port_status_t * status, int idx)
196{
197 return (((*status)>>(idx))%2);
198}
199
200/** set i`th bit of port status */
201static inline void usb_port_set_bit(
202 usb_port_status_t * status, int idx, bool value)
203{
204 (*status) = value?
205 ((*status)|(1<<(idx))):
206 ((*status)&(~(1<<(idx))));
207}
208
209//device connnected on port
210static inline bool usb_port_dev_connected(usb_port_status_t * status){
211 return usb_port_get_bit(status,0);
212}
213
214static inline void usb_port_set_dev_connected(usb_port_status_t * status,bool connected){
215 usb_port_set_bit(status,0,connected);
216}
217
218//port enabled
219static inline bool usb_port_enabled(usb_port_status_t * status){
220 return usb_port_get_bit(status,1);
221}
222
223static inline void usb_port_set_enabled(usb_port_status_t * status,bool enabled){
224 usb_port_set_bit(status,1,enabled);
225}
226
227//port suspended
228static inline bool usb_port_suspended(usb_port_status_t * status){
229 return usb_port_get_bit(status,2);
230}
231
232static inline void usb_port_set_suspended(usb_port_status_t * status,bool suspended){
233 usb_port_set_bit(status,2,suspended);
234}
235
236//over currect
237static inline bool usb_port_over_current(usb_port_status_t * status){
238 return usb_port_get_bit(status,3);
239}
240
241static inline void usb_port_set_over_current(usb_port_status_t * status,bool value){
242 usb_port_set_bit(status,3,value);
243}
244
245//port reset
246static inline bool usb_port_reset(usb_port_status_t * status){
247 return usb_port_get_bit(status,4);
248}
249
250static inline void usb_port_set_reset(usb_port_status_t * status,bool value){
251 usb_port_set_bit(status,4,value);
252}
253
254//powered
255static inline bool usb_port_powered(usb_port_status_t * status){
256 return usb_port_get_bit(status,8);
257}
258
259static inline void usb_port_set_powered(usb_port_status_t * status,bool powered){
260 usb_port_set_bit(status,8,powered);
261}
262
263//low speed device attached
264static inline bool usb_port_low_speed(usb_port_status_t * status){
265 return usb_port_get_bit(status,9);
266}
267
268static inline void usb_port_set_low_speed(usb_port_status_t * status,bool low_speed){
269 usb_port_set_bit(status,9,low_speed);
270}
271
272
273//connect change
274static inline bool usb_port_connect_change(usb_port_status_t * status){
275 return usb_port_get_bit(status,16);
276}
277
278static inline void usb_port_set_connect_change(usb_port_status_t * status,bool change){
279 usb_port_set_bit(status,16,change);
280}
281
282//port enable change
283static inline bool usb_port_enabled_change(usb_port_status_t * status){
284 return usb_port_get_bit(status,17);
285}
286
287static inline void usb_port_set_enabled_change(usb_port_status_t * status,bool change){
288 usb_port_set_bit(status,17,change);
289}
290
291//suspend change
292static inline bool usb_port_suspend_change(usb_port_status_t * status){
293 return usb_port_get_bit(status,18);
294}
295
296static inline void usb_port_set_suspend_change(usb_port_status_t * status,bool change){
297 usb_port_set_bit(status,18,change);
298}
299
300//over current change
301static inline bool usb_port_overcurrent_change(usb_port_status_t * status){
302 return usb_port_get_bit(status,19);
303}
304
305static inline void usb_port_set_overcurrent_change(usb_port_status_t * status,bool change){
306 usb_port_set_bit(status,19,change);
307}
308
309//reset change
310static inline bool usb_port_reset_completed(usb_port_status_t * status){
311 return usb_port_get_bit(status,20);
312}
313
314static inline void usb_port_set_reset_completed(usb_port_status_t * status,bool completed){
315 usb_port_set_bit(status,20,completed);
316}
317
318
319
320#endif /* PORT_STATUS_H */
321
322/**
323 * @}
324 */
Note: See TracBrowser for help on using the repository browser.