dev_sts.c
6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*HEADER******************************************************************
**************************************************************************
***
*** Copyright (c) 2001-2002 ARC International.
*** All rights reserved
***
*** This software embodies materials and concepts which are
*** confidential to ARC International and is made
*** available solely pursuant to the terms of a written license
*** agreement with ARC International
***
*** $Workfile:devapi.c$
*** $Revision: 1.1 $
*** $Date: 2003/04/08 06:19:42 $
***
*** Comments:
*** This file contains the USB device API.
***
**************************************************************************
*END*********************************************************************/
#include "os_bb.h"
#include "osint.h"
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : _usb_device_unstall_endpoint
* Returned Value : USB_OK or error code
* Comments :
* Clears an endpoint after a stall
*
*END*--------------------------------------------------------------------*/
void _usb_device_unstall_endpoint
(
/* [IN] Handle to the USB device */
_usb_device_handle handle,
/* [IN] Endpoint to clear */
uint_8 endpoint_number,
/* [IN] the direction */
uint_8 direction
)
{ /* Body */
USB_DEV_STATE_STRUCT_PTR usb_dev_ptr;
usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle;
USB_lock();
_usb_dci_vusb11_unstall_endpoint(handle, endpoint_number);
usb_dev_ptr->XDSEND[endpoint_number].STATUS = USB_STATUS_IDLE;
usb_dev_ptr->XDRECV[endpoint_number].STATUS = USB_STATUS_IDLE;
USB_unlock();
} /* EndBody */
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : _usb_device_get_status
* Returned Value : USB_OK or error code
* Comments :
* Provides API to access the USB internal state.
*
*END*--------------------------------------------------------------------*/
uint_8 _usb_device_get_status
(
/* [IN] Handle to the USB device */
_usb_device_handle handle,
/* [IN] What to get the status of */
uint_8 component,
/* [OUT] The requested status */
uint_16_ptr status
)
{ /* Body */
USB_DEV_STATE_STRUCT_PTR usb_dev_ptr;
usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle;
USB_lock();
switch (component) {
case USB_STATUS_DEVICE_STATE:
*status = usb_dev_ptr->USB_STATE;
break;
case USB_STATUS_DEVICE:
*status = usb_dev_ptr->USB_DEVICE_STATE;
break;
case USB_STATUS_INTERFACE:
break;
case USB_STATUS_ADDRESS:
*status = usb_dev_ptr->USB->ADDRESS;
break;
case USB_STATUS_CURRENT_CONFIG:
*status = usb_dev_ptr->USB_CURR_CONFIG;
break;
case USB_STATUS_SOF_COUNT:
*status = usb_dev_ptr->USB_SOF_COUNT;
break;
default:
if (component & USB_STATUS_ENDPOINT) {
*status = _usb_dci_vusb11_get_endpoint_status(handle,
component & USB_STATUS_ENDPOINT_NUMBER_MASK);
} else {
USB_unlock();
return USBERR_BAD_STATUS;
} /* Endif */
break;
} /* Endswitch */
USB_unlock();
return USB_OK;
} /* EndBody */
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : _usb_device_set_status
* Returned Value : USB_OK or error code
* Comments :
* Provides API to set internal state
*
*END*--------------------------------------------------------------------*/
uint_8 _usb_device_set_status
(
/* [IN] Handle to the usb device */
_usb_device_handle handle,
/* [IN] What to set the status of */
uint_8 component,
/* [IN] What to set the status to */
uint_16 setting
)
{ /* Body */
USB_DEV_STATE_STRUCT_PTR usb_dev_ptr;
usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle;
USB_lock();
switch (component) {
case USB_STATUS_DEVICE_STATE:
usb_dev_ptr->USB_STATE = setting;
break;
case USB_STATUS_DEVICE:
usb_dev_ptr->USB_DEVICE_STATE = setting;
break;
case USB_STATUS_INTERFACE:
break;
case USB_STATUS_ADDRESS:
usb_dev_ptr->USB->ADDRESS = setting;
break;
case USB_STATUS_CURRENT_CONFIG:
usb_dev_ptr->USB_CURR_CONFIG = setting;
break;
case USB_STATUS_SOF_COUNT:
usb_dev_ptr->USB_SOF_COUNT = setting;
break;
default:
if (component & USB_STATUS_ENDPOINT) {
_usb_dci_vusb11_set_endpoint_status(handle,
component & USB_STATUS_ENDPOINT_NUMBER_MASK,
setting);
} else {
USB_unlock();
return USBERR_BAD_STATUS;
} /* Endif */
break;
} /* Endswitch */
USB_unlock();
return USB_OK;
} /* EndBody */
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : _usb_device_stall_endpoint
* Returned Value : None
* Comments :
* Stalls the specified endpoint
*
*END*--------------------------------------------------------------------*/
void _usb_device_stall_endpoint
(
/* [IN] Handle to the USB device */
_usb_device_handle handle,
/* [IN] The endpoint to stall */
uint_8 endpoint_num,
/* [IN] the direction */
uint_8 direction
)
{ /* Body */
USB_DEV_STATE_STRUCT_PTR usb_dev_ptr;
usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle;
usb_dev_ptr->XDSEND[endpoint_num].STATUS = USB_STATUS_STALLED;
usb_dev_ptr->XDRECV[endpoint_num].STATUS = USB_STATUS_STALLED;
_usb_device_set_status(handle, USB_STATUS_ENDPOINT | endpoint_num, 1);
return;
} /* EndBody */