📄 upsd_usb.lst
字号:
C51 COMPILER V7.06 UPSD_USB 10/15/2004 20:55:31 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE UPSD_USB
OBJECT MODULE PLACED IN upsd_usb.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE upsd_usb.c LARGE BROWSE DEBUG OBJECTEXTEND SRC(.\upsd_usb.SRC)
stmt level source
1 /* `=========================================================================`
2
3 ***************************************
4 **** * * ****
5 Title: UPSD_USB
6 File name: upsd_usb.c
7 Project name: USB Demo
8 *** ****
9 ****************** * ******************
10 **** ****
11 Author: Petr PFEIFER
12 MPG Prague, Czech Republic
13 **** * * ****
14 ***************************************
15
16 $Version: 0.107a Build: April 30, 2004
17
18 $Version: 0.107 Build: 2004-04-29,17:55:46
19
20
21
22
23 Description:
24 ============
25
26 USB driver module for uPSD3200 chip.
27 Improved version of USB demo v7
28 Version 0.105 - GetStatus added
29
30
31 Notes:
32 ======
33 - do not change EPx service routines
34 and the order of commands ...
35
36
37 ..........................
38 . .
39 . ****************** .
40 . **PPPPPPPPPPPPPPPP .
41 . *PPPP*******PP**** .
42 . **PPP********PP*** .
43 . ***PPP******PP**** .
44 . *****PPP****PP**** .
45 . *****PPP****PP**** .
46 . PPPPPPPP****PP**** (R) .
47 . .
48 ..........................
49
50
51 =-=-=-=-=-=
52 =-=-=-=-=-=-=-=-=-=-=-=-=
53 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
54
55 Copyright 2004 ST Microelectronics
C51 COMPILER V7.06 UPSD_USB 10/15/2004 20:55:31 PAGE 2
56
57 This code/file is provided as is and has no warranty,
58 implied or otherwise. You are free to use/modify any of the provided
59 code at your own risk in your applications with the expressed limitation
60 of liability (see below) so long as your product using the code
61 contains at least one uPSD products (device).
62
63 LIMITATION OF LIABILITY:
64 ========================
65 NEITHER STMicroelectronics NOR ITS VENDORS OR AGENTS
66 SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
67 INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
68 CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
69 OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
70
71 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
72 =-=-=-=-=-=-=-=-=-=-=-=-=
73 =-=-=-=-=-=
74
75 For current information on uPSD products,
76 please consult our pages on the World Wide Web:
77
78 www.st.com/psm
79
80 - - - - - - - - - - - -
81
82 STMicroelectronics GROUP OF COMPANIES
83 Australia - Brazil - China - Czech Republic - Finland - France - Germany
84 Hong Kong - India - Italy - Japan - Malaysia - Malta - Morocco - Singapore
85 Spain - Sweden - Switzerland - United Kingdom - U.S.A.
86
87 http://www.st.com
88
89
90 `========================================================================` */
91
92 #pragma NOAREGS
93
94 #include "upsd3200.h"
95 #include "upsd_usb.h"
96
97 //-- Variables ---------------------------------------------------------------
98
99 #define HID_DEVICE 1
100
101 // Constant Variables for USB configuration
102 extern const uchar code cUSCL_value;
103
104 // Constant Variables for USB Descriptors
105 extern const device_descriptor code deviceDesc;
106 extern const configuration_descriptor code configDesc;
107 extern const uchar code string0Desc[];
108 extern const uchar code string1Desc[];
109 extern const uchar code string2Desc[];
110 extern const uchar * const code stringDescTable[];
111
112 #if HID_DEVICE
113 extern const uchar code hidClassDesc[];
114 extern const uchar code hidClassDescSize;
115 extern const uchar code reportDesc[];
116 extern const uchar code reportDescSize;
117 extern const uchar code PhysicalReportDesc;
C51 COMPILER V7.06 UPSD_USB 10/15/2004 20:55:31 PAGE 3
118 extern const uchar code PhysicalReportDescSize;
119 #endif
120
121 volatile uchar idata usbState;
122 volatile uchar idata ep1State; //added April 30, 2004
123
124
125 volatile uchar idata SuspendCounter;
126
127 setup_buffer setupPacket;
128
129 static uchar* pTransmitBufferEP0;
130 static int bytesToTransmitEP0;
131 static BOOL shortTransfer;
132
133 extern void OnDeviceConfigured();
134
135
136
137
138
139
140
141 void OnUSBReset()
142 /******************************************************************************
143 Function : void OnUSBReset()
144 Parameters : none
145 Description: USB driver module initialization routine, in USR ISR only !!!.
146 ******************************************************************************/
147 {
148 1 pTransmitBufferEP0 = NULL;
149 1 bytesToTransmitEP0 = 0;
150 1
151 1 UADR = 0; // Disable USB hardware
152 1 UCON0 = uRX0E; // Enable EP0 for receiving only
153 1 UCON1 = 0; // Disable Endpoint 1
154 1 UCON2 = uEP1E; // Enable EP1
155 1 UADR = uUSBEN + 0; // Enable USB with default address 0
156 1 UIEN = ~(uMCUR+uEOPF+uRESUMIE);
157 1 // Enable all USB interrupts except uMCUR (MCU reset on USB reset) and EOP, ...
158 1 USTA = 0;
159 1 UISTA = 0; // Clear USB interrupts
160 1 IEA |= bEUSB;
161 1 }
162
163
164
165
166
167
168 void UsbInitialize()
169 /******************************************************************************
170 Function : void UsbInitialize()
171 Parameters : none
172 Description: USB driver module initialization routine after MCU startup.
173 ******************************************************************************/
174 {
175 1 USCL = cUSCL_value; // Set USB clock prescaler
176 1 UIEN = 0; // Disable all USB interrupts
177 1 UADR = 0; // Disable USB hardware
178 1 OnUSBReset();
179 1 }
C51 COMPILER V7.06 UPSD_USB 10/15/2004 20:55:31 PAGE 4
180
181
182
183
184
185
186
187
188 extern data char usr_cnt;
189
190
191
192 void STALL_EP0()
193 /******************************************************************************
194 Function : void STALL_EP0()
195 Parameters : none
196 Description: Stalls EP0.
197 This endpoint is halted or a control pipe request is not supported.
198 Endpoint can be unstalled by the next SETUP packet.
199 STALL is returned by a function in response to an IN token
200 or after the data phase of an OUT transaction.
201 It indicates that a function is unable to transmit or receive data,
202 or that a control pipe request is not supported.
203 ******************************************************************************/
204 {
205 1 #pragma asm
206 1 anl UCON0,#uTSEQ0+uRX0E+uSTALL0+uTX0E ;mask
207 1 orl UCON0,#uSTALL0 ;clear TSEQ bit, STALL EP0
208 1 #pragma endasm
209 1 }
210
211
212
213
214
215
216 static BOOL TransmitBufferEP0()
217 /******************************************************************************
218 Function : static BOOL TransmitBufferEP0()
219 Parameters : none
220 Description: Transmits next segment of descriptor buffer (pTransmitBufferEP0).
221 This routine prepates 0..8 bytes of data from TransmitBufferEP0
222 at endpoint0. If no data is available in buffer, the endpoint is disabled.
223 According to USB standard, zero length packet is trasmitted at then end.
224 ******************************************************************************/
225 {
226 1 data int i;
227 1 data int nBytes;
228 1
229 1 if (pTransmitBufferEP0) // If there is data going out...
230 1 {
231 2 #pragma asm // send zero length packet
232 2 xrl UCON0,#uTSEQ0 ;toggle TSEQ bit
233 2 anl UCON0,#uTSEQ0+uRX0E ;mask
234 2 #pragma endasm
235 2 if (!bytesToTransmitEP0) // If data has already been sent...
236 2 {
237 3 #pragma asm // send zero length packet
238 3 orl UCON0,#uTX0E ;enable transmit
239 3 #pragma endasm
240 3 pTransmitBufferEP0 = NULL; // If data has already been sent...
241 3 }
C51 COMPILER V7.06 UPSD_USB 10/15/2004 20:55:31 PAGE 5
242 2 else
243 2 {
244 3 nBytes = bytesToTransmitEP0; // Transmit next chunk of data
245 3 if (nBytes > 8)
246 3 {
247 4 nBytes = 8;
248 4 }
249 3 UCON0 |= nBytes; // set FIFO size
250 3
251 3 for (i = 0; i < nBytes; i++) // Load data into FIFO
252 3 {
253 4 UDT0 = *pTransmitBufferEP0++;
254 4 }
255 3
256 3 if ((bytesToTransmitEP0 -= nBytes) == 0)
257 3 {
258 4 // For short transfers, we need to send a zero length terminator
259 4 if (!shortTransfer || (nBytes < 8))
260 4 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -