📄 upsd_usb.lst
字号:
C51 COMPILER V7.00 Beta 6 UPSD_USB 02/19/2003 15:59:28 PAGE 1
C51 COMPILER V7.00 Beta 6, 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
stmt level source
1 /////////////////////////////////////////////////////////////////////////////
2 // upsd_usb.c
3 //
4 // USB driver module for uPSD3000 chip.
5 //
6 // Author: Jon Moore
7 //
8 // Revision History:
9 //
10 // 07/22/02 (JAM) Initial coding.
11 // 01/21/03 (JAM) V1.0.7 - Fixed '0 length packet' bug.
12
13 /*---------------------------------------------------------------------------
14 Copyright (c) 2002 ST Microelectronics
15 This example demo code is provided as is and has no warranty,
16 implied or otherwise. You are free to use/modify any of the provided
17 code at your own risk in your applications with the expressed limitation
18 of liability (see below) so long as your product using the code contains
19 at least one uPSD products (device).
20
21 LIMITATION OF LIABILITY: NEITHER STMicroelectronics NOR ITS VENDORS OR
22 AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
23 INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
24 CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
25 OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
26 --------------------------------------------------------------------------*/
27
28 #include "general.h"
29 #include "upsd3200.h"
30 #include "upsd_xreg.h"
31 #include "upsd_usb.h"
32
33 //-- Variables ---------------------------------------------------------------
34
35 #define HID_DEVICE 1
36
37 // Constant Variables for USB configuration
38 extern const uchar code cUSCL_value;
39
40 // Constant Variables for USB Descriptors
41 extern const device_descriptor code deviceDesc;
42 extern const configuration_descriptor code configDesc;
43 extern const uchar code string0Desc[];
44 extern const uchar code string1Desc[];
45 extern const uchar code string2Desc[];
46 extern const uchar * const code stringDescTable[];
47
48 #if HID_DEVICE
49 extern const uchar code hidClassDesc[];
50 extern const uchar code hidClassDescSize;
51 extern const uchar code reportDesc[];
52 extern const uchar code reportDescSize;
53 #endif
54
55 volatile uchar idata usbState;
C51 COMPILER V7.00 Beta 6 UPSD_USB 02/19/2003 15:59:28 PAGE 2
56
57 volatile uchar idata SuspendCounter;
58
59 setup_buffer setupPacket;
60
61 static uchar* pTransmitBufferEP0;
62 static int bytesToTransmitEP0;
63 static BOOL shortTransfer;
64
65 extern void OnDeviceConfigured();
66
67 /////////////////// UsbInitialize()
68 //
69 // USB driver module initialization routine.
70
71 void UsbInitialize()
72 {
73 1 pTransmitBufferEP0 = NULL;
74 1 bytesToTransmitEP0 = 0;
75 1
76 1 // Set USB clock prescaler
77 1 USCL = cUSCL_value;
78 1
79 1 // Reset EP0 and arm it for receiving only
80 1 UCON0 = uTX0E | uRX0E | 8;
81 1 UCON0 = uRX0E | 8;
82 1
83 1 // Enable ep1
84 1 UCON2 = uEP1E | uEP2E;
85 1 UCON1 = uTX1E | 8;
86 1 UDT1 = 0xBA;
87 1 UDT1 = 0xBE;
88 1 UCON1 = uTX1E | 2;
89 1
90 1 // Enable all USB interrupts except uMCUR (MCU reset on USB reset)
91 1 UIEN = ~uMCUR;
92 1
93 1 // Enable USB with default address 0
94 1 UADR = uUSBEN + 0;
95 1
96 1 // Enable USB interrupts
97 1 UISTA = 0;
98 1 IEA |= bEUSB;
99 1 }
100
101 /////////////////// OnClearFeature()
102 //
103 // Handler for CLEAR_FEATURE control requests.
104
105 static void OnClearFeature()
106 {
107 1 // No features currently implemented, so stall EP0
108 1 // UCON0 |= uSTALL0; problems, so try 0 length packet instead
109 1 UCON0 = uTSEQ0 | uRX0E | uTX0E;
110 1 }
111
112 /////////////////// OnSetAddress()
113 //
114 // Handler for SET_ADDRESS SETUP packets.
115
116 static void OnSetAddress()
117 {
C51 COMPILER V7.00 Beta 6 UPSD_USB 02/19/2003 15:59:28 PAGE 3
118 1 // Send back 0 length DATA1 packet
119 1 UCON0 = uTSEQ0 | uRX0E | uTX0E;
120 1 }
121
122 /////////////////// OnSetConfiguration()
123 //
124 // Handler for SET_CONFIGURATION SETUP requests.
125
126 static void OnSetConfiguration()
127 {
128 1 if (setupPacket.wValue.lo > 0)
129 1 {
130 2 usbState = US_CONFIGURED;
131 2 OnDeviceConfigured();
132 2 }
133 1 else
134 1 {
135 2 usbState = US_ADDRESSED;
136 2 }
137 1
138 1 // Send back 0 length DATA1 packet
139 1 UCON0 = uTSEQ0 | uRX0E | uTX0E;
140 1 }
141
142 /////////////////// TransmitBufferEP0()
143 //
144 // Transmits next segment of descriptor buffer (pTransmitBufferEP0).
145
146 static BOOL TransmitBufferEP0()
147 {
148 1 int i;
149 1 int nBytes;
150 1
151 1 // If there is data going out...
152 1 if (pTransmitBufferEP0)
153 1 {
154 2 // If data has already been sent...
155 2 if (!bytesToTransmitEP0)
156 2 {
157 3 // Transmit 0 length packet
158 3 UCON0 = ((UCON0 ^ uTSEQ0) & uTSEQ0) | uRX0E | uTX0E;
159 3 pTransmitBufferEP0 = NULL;
160 3 }
161 2 else
162 2 {
163 3 // Transmit next chunk of data
164 3 nBytes = bytesToTransmitEP0;
165 3 if (nBytes > 8)
166 3 nBytes = 8;
167 3
168 3 UCON0 = ((UCON0 ^ uTSEQ0) & uTSEQ0) | uRX0E | uTX0E | nBytes;
169 3 for (i = 0; i < nBytes; i++)
170 3 {
171 4 UDT0 = *pTransmitBufferEP0++;
172 4 }
173 3
174 3 if ((bytesToTransmitEP0 -= nBytes) == 0)
175 3 {
176 4 // For short transfers, we need a 0 length terminator
177 4 if (!shortTransfer || (nBytes < 8))
178 4 {
179 5 pTransmitBufferEP0 = NULL;
C51 COMPILER V7.00 Beta 6 UPSD_USB 02/19/2003 15:59:28 PAGE 4
180 5 }
181 4 }
182 3 }
183 2 return TRUE;
184 2 }
185 1
186 1 // No descriptor data going out
187 1 UCON0 = uTSEQ0 | uRX0E;
188 1 return FALSE;
189 1 }
190
191 /////////////////// TransmitDataEP0()
192 //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -