dev_sts.c
7.08 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*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/02/17 20:49:01 $
***
*** Comments:
*** This file contains the USB device API.
***
**************************************************************************
*END*********************************************************************/
#ifdef __USB_OS_MQX__
#include "mqx.h"
#include "bsp.h"
#else
#include "devapi.h"
#include "usb.h"
#include "vusb11.h"
#endif
#include "usbprv.h"
#include "usbdprv.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();
#ifdef __USB_OS_MQX__
((USB_CALLBACK_FUNCTIONS_STRUCT_PTR)usb_dev_ptr->CALLBACK_STRUCT_PTR)->\
DEV_UNSTALL_ENDPOINT(handle, endpoint_number);
#else
_usb_dci_vusb11_unstall_endpoint(handle, endpoint_number);
#endif
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) {
#ifdef __USB_OS_MQX__
*status =
((USB_CALLBACK_FUNCTIONS_STRUCT_PTR)usb_dev_ptr->\
CALLBACK_STRUCT_PTR)->DEV_GET_ENDPOINT_STATUS(handle,
component & USB_STATUS_ENDPOINT_NUMBER_MASK);
#else
*status = _usb_dci_vusb11_get_endpoint_status(handle,
component & USB_STATUS_ENDPOINT_NUMBER_MASK);
#endif
} 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) {
#ifdef __USB_OS_MQX__
((USB_CALLBACK_FUNCTIONS_STRUCT_PTR)usb_dev_ptr->\
CALLBACK_STRUCT_PTR)->DEV_SET_ENDPOINT_STATUS(handle,
component & USB_STATUS_ENDPOINT_NUMBER_MASK, setting);
#else
_usb_dci_vusb11_set_endpoint_status(handle,
component & USB_STATUS_ENDPOINT_NUMBER_MASK,
setting);
#endif
} 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 */
/* EOF */