📄 upsd3400_upsd_usb.lst
字号:
C51 COMPILER V7.50 UPSD3400_UPSD_USB 09/13/2005 18:00:20 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE UPSD3400_UPSD_USB
OBJECT MODULE PLACED IN upsd3400_upsd_usb.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE upsd3400_upsd_usb.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*------------------------------------------------------------------------------
2 upsd3400_upsd_usb.c
3
4 Version:
5 September 13, 2005 Ver 1.1 - Updated disclaimer, renamed file.
6 March 22, 2005 - Version 1.0 - Initial Release.
7
8 Description: Basic USB Functions that include enumeration.
9
10 Copyright (c) 2005 STMicroelectronics Inc.
11
12 THIS INFORMATION (or THIS SOFTWARE or THIS DOCUMENT) IS FOR GUIDANCE ONLY. ST
13 MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS
14 SOFTWARE nor for any infringement of patents or other rights of third parties
15 which may result from its use. ST MICROELECTRONICS SHALL NOT BE HELD LIABLE FOR
16 ANY DIRECT, INDIRECT INCIDENTAL OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY
17 CLAIMS ARISING IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE,
18 OR USE OF THIS SOFTWARE. Specifications mentioned in this publication are
19 subject to change without notice. This publication supersedes and replaces all
20 information previously supplied. STMicroelectronics products are not authorized
21 for use as critical components in life support devices or systems without the
22 express written approval of STMicroelectronics.
23
24 ------------------------------------------------------------------------------*/
25
26 #pragma NOAREGS
27
28 #include "upsd3400.h"
29 #include "upsd3400_hardware.h"
30 #include "upsd3400_usb.h"
31 #include "upsd3400_upsd_usb.h"
32 #include "upsd3400_usb_app.h"
33
34 #define MASS_STORAGE 1
35
36 // Constant Variables for USB Descriptors
37 extern const device_descriptor code deviceDesc;
38 extern const configuration_descriptor code configDesc;
39 extern const uchar * const code stringDescTable[];
40
41 unsigned char data usbState, ep0state, ep1state;
42 static unsigned char confignum;
43 static unsigned char remotewakeupen;
44 static unsigned char DevIdleRate;
45
46 setup_buffer setupPacket;
47 static unsigned char* pTransmitBufferEP0;
48 static unsigned char bytesToTransmitEP0;
49
50 //data unsigned char xdata * TxBufferEP0;
51 //data unsigned char xdata * RxBufferEP0;
52
53 #define USB_FIFO ((unsigned char volatile xdata *) USB_BASE_ADDR)
54
55
C51 COMPILER V7.50 UPSD3400_UPSD_USB 09/13/2005 18:00:20 PAGE 2
56 /******************************************************************************
57
58 PRODUCT SPECIFIC AREA
59
60 ******************************************************************************
61
62
63
64 /******************************************************************************
65
66 PRODUCT INDEPENDENT AREA
67
68 ******************************************************************************/
69
70
71
72 void OnUsbReset()
73 /******************************************************************************
74 Function : void OnUsbReset()
75 Parameters : none
76 Description: USB driver module initialization routine.
77 ******************************************************************************/
78 {
79 1 UCTL &= ~USBEN;
80 1 UCTL |= USBEN; //USB enable
81 1
82 1 UIE0 = RSTIE | SUSPENDIE; //Enable RESET, SUSPEND, RESUME INT
83 1 UIE1 = IN0IE; //Enable EP0 IN INT
84 1 UIE2 = OUT0IE; //Enable EP0 OUT INT
85 1 UIE3 = 0;
86 1
87 1 UPAIR = 0;
88 1 //1+2+4+8;
89 1
90 1 USEL = OUTDIR | SELEP0; //Select EP0 OUT
91 1 UCON = ENABLE_FIFO | EPFIFO_BSY;
92 1
93 1 USEL = INDIR | SELEP0; //Select EP0 IN
94 1 UCON = ENABLE_FIFO;
95 1
96 1 confignum = 0;
97 1 usbState = US_DEFAULT;
98 1 ep0state = US_EPDEFAULT;
99 1 ep1state = US_EPDEFAULT;
100 1 }
101
102
103
104
105
106
107
108
109 void STALL_EP0()
110 /******************************************************************************
111 Function : void STALL_EP0()
112 Parameters : none
113 Description: Stalls EP0.
114 This endpoint is halted or a control pipe request is not supported.
115 Endpoint can be unstalled by Bus Reset.
116 ******************************************************************************/
117 {
C51 COMPILER V7.50 UPSD3400_UPSD_USB 09/13/2005 18:00:20 PAGE 3
118 1 USEL = INDIR | SELEP0;
119 1 UCON |= STALL | ENABLE_FIFO;
120 1 UCON &= ~TOGGLE; //clear toggle
121 1 USIZE = 0;
122 1 ep0state = US_EPSTALL;
123 1 }
124
125
126
127
128
129
130 void STALL_EP1()
131 /******************************************************************************
132 Function : void STALL_EP1()
133 Parameters : none
134 Description: Stalls EP1.
135 This endpoint is halted or a control pipe request is not supported.
136 Endpoint can be unstalled by Bus Reset.
137 ******************************************************************************/
138 {
139 1 USEL = INDIR | SELEP1;
140 1 UCON |= STALL;
141 1 UCON &= ~TOGGLE; //clear toggle
142 1 USIZE = 0;
143 1 ep1state = US_EPSTALL;
144 1 }
145
146
147
148
149
150 /*
151 void RemoteWakeup()
152 /******************************************************************************
153 Function : void RemoteWakeup()
154 Parameters : none
155 Description: USB device remote wakeup
156 ******************************************************************************/
157 /*
158 {
159 data int i;
160 if (remotewakeupen)
161 {
162 UCTL |= WAKEUP;
163
164 for (i=0;i<10000;i++) // delay cca 10ms();
165 {
166 i++;
167 i--;
168 }
169 UCTL &= ~WAKEUP;
170 usbState = US_DEFAULT;
171 }
172 }
173 */
174
175
176
177
178
179 void OnUsbSuspend()
C51 COMPILER V7.50 UPSD3400_UPSD_USB 09/13/2005 18:00:20 PAGE 4
180 /******************************************************************************
181 Function : void OnUsbSuspend()
182 Parameters : none
183 Description: service routine for USB Suspend event
184 ******************************************************************************/
185 {
186 1 usbState = US_SUSPENDED;
187 1 }
188
189
190
191
192
193
194 void OnUsbResume()
195 /******************************************************************************
196 Function : void OnUsbResume()
197 Parameters : none
198 Description: service routine for USB Host resume event
199 ******************************************************************************/
200 {
201 1 usbState = US_DEFAULT;
202 1 }
203
204
205
206
207
208
209
210 void TransmitZeroLengthEP0()
211 /******************************************************************************
212 Function : void TransmitZeroLengthEP0()
213 Parameters : none
214 Description: Transmits zero length data of EP0.
215 ******************************************************************************/
216 {
217 1 data unsigned int count;
218 1
219 1 USEL = INDIR | SELEP0;
220 1 UCON ^= TOGGLE;
221 1 count = 0;
222 1 while (UCON & EPFIFO_BSY) //check busy
223 1 {
224 2 count++;
225 2 if (count==0)
226 2 {
227 3 USIZE = 0;
228 3 return;
229 3 }
230 2 }
231 1 USIZE = 0;
232 1 }
233
234
235
236
237
238
239
240
241
C51 COMPILER V7.50 UPSD3400_UPSD_USB 09/13/2005 18:00:20 PAGE 5
242
243
244
245 void TransmitEP0()
246 /******************************************************************************
247 Function : void TransmitEP0()
248 Parameters : none
249 Description: Transmits next segment of descriptor buffer (pTransmitBufferEP0).
250 ******************************************************************************/
251 {
252 1 data unsigned char i;
253 1 data unsigned char nBytes;
254 1 data unsigned int count;
255 1 data unsigned ZLPacket;
256 1
257 1 if (bytesToTransmitEP0 == 0)
258 1 {
259 2 USEL = OUTDIR | SELEP0; //Select EP0 OUT
260 2 UCON |= ENABLE_FIFO;
261 2 UCON |= TOGGLE;
262 2 USIZE = 0;
263 2 return;
264 2 }
265 1 else
266 1 {
267 2 USEL = INDIR | SELEP0; //select EP0 IN
268 2 UCON |= ENABLE_FIFO;
269 2
270 2 count = 0;
271 2 while (UCON & EPFIFO_BSY) //check busy
272 2 {
273 3 count++;
274 3 if (count==0)
275 3 {
276 4 USIZE = 0;
277 4 return;
278 4 }
279 3 }
280 2
281 2 UCON ^= TOGGLE;
282 2
283 2 if (pTransmitBufferEP0 == NULL)
284 2 {
285 3 bytesToTransmitEP0 = 0;
286 3 ZLPacket = 0;
287 3 }
288 2 else
289 2 {
290 3 ZLPacket = (bytesToTransmitEP0 == EP0_PKT_SIZE)?1:0;
291 3 }
292 2
293 2 nBytes = bytesToTransmitEP0;
294 2 if (nBytes > EP0_PKT_SIZE)
295 2 {
296 3 nBytes = EP0_PKT_SIZE;
297 3 }
298 2
299 2 for(i=0; i<nBytes; i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -