📄 bulkloop.lst
字号:
C51 COMPILER V6.10 BULKLOOP 07/06/2005 19:50:46 PAGE 1
C51 COMPILER V6.10, COMPILATION OF MODULE BULKLOOP
OBJECT MODULE PLACED IN .\bulkloop.OBJ
COMPILER INVOKED BY: e:\pp\Keil\C51\BIN\C51.EXE .\bulkloop.c DEBUG OBJECTEXTEND
stmt level source
1 #pragma NOIV // Do not generate interrupt vectors
2 //-----------------------------------------------------------------------------
3 // File: bulkloop.c
4 // Contents: Hooks required to implement USB peripheral function.
5 //
6 // Copyright (c) 2000 Cypress Semiconductor All rights reserved
7 //-----------------------------------------------------------------------------
8 #include "fx2.h"
9 #include "fx2regs.h"
10 #include "fx2sdly.h" // SYNCDELAY macro
11
12 extern BOOL GotSUD; // Received setup data flag
13 extern BOOL Sleep;
14 extern BOOL Rwuen;
15 extern BOOL Selfpwr;
16
17 BYTE Configuration; // Current configuration
18 BYTE AlternateSetting; // Alternate settings
19
20 #define VR_NAKALL_ON 0xD0
21 #define VR_NAKALL_OFF 0xD1
22
23 //-----------------------------------------------------------------------------
24 // Task Dispatcher hooks
25 // The following hooks are called by the task dispatcher.
26 //-----------------------------------------------------------------------------
27
28 void TD_Init(void) // Called once at startup
29 {
30 1 // set the CPU clock to 48MHz
31 1 CPUCS = ((CPUCS & ~bmCLKSPD) | bmCLKSPD1) ;
32 1
33 1 //ML: set PORTA.0 as OUTPUT
34 1 OEA = OEA|1;
35 1 PORTACFG = PORTACFG&0xfe;
36 1 //MLEND
37 1
38 1 // set the slave FIFO interface to 48MHz
39 1 IFCONFIG |= 0x40;
40 1
41 1 // Registers which require a synchronization delay, see section 15.14
42 1 // FIFORESET FIFOPINPOLAR
43 1 // INPKTEND OUTPKTEND
44 1 // EPxBCH:L REVCTL
45 1 // GPIFTCB3 GPIFTCB2
46 1 // GPIFTCB1 GPIFTCB0
47 1 // EPxFIFOPFH:L EPxAUTOINLENH:L
48 1 // EPxFIFOCFG EPxGPIFFLGSEL
49 1 // PINFLAGSxx EPxFIFOIRQ
50 1 // EPxFIFOIE GPIFIRQ
51 1 // GPIFIE GPIFADRH:L
52 1 // UDMACRCH:L EPxGPIFTRIG
53 1 // GPIFTRIG
54 1
55 1 // Note: The pre-REVE EPxGPIFTCH/L register are affected, as well...
C51 COMPILER V6.10 BULKLOOP 07/06/2005 19:50:46 PAGE 2
56 1 // ...these have been replaced by GPIFTC[B3:B0] registers
57 1
58 1 // default: all endpoints have their VALID bit set
59 1 // default: TYPE1 = 1 and TYPE0 = 0 --> BULK
60 1 // default: EP2 and EP4 DIR bits are 0 (OUT direction)
61 1 // default: EP6 and EP8 DIR bits are 1 (IN direction)
62 1 // default: EP2, EP4, EP6, and EP8 are double buffered
63 1
64 1 // we are just using the default values, yes this is not necessary...
65 1 EP1OUTCFG = 0xA0;
66 1 EP1INCFG = 0xA0;
67 1 SYNCDELAY; // see TRM section 15.14
68 1 EP2CFG = 0xA2;
69 1 SYNCDELAY;
70 1 EP4CFG = 0xA0;
71 1 SYNCDELAY;
72 1 EP6CFG = 0xE2;
73 1 SYNCDELAY;
74 1 EP8CFG = 0xE0;
75 1
76 1 // out endpoints do not come up armed
77 1
78 1 // since the defaults are double buffered we must write dummy byte counts twice
79 1 SYNCDELAY;
80 1 EP2BCL = 0x80; // arm EP2OUT by writing byte count w/skip.
81 1 SYNCDELAY;
82 1 EP2BCL = 0x80;
83 1 SYNCDELAY;
84 1 EP4BCL = 0x80; // arm EP4OUT by writing byte count w/skip.
85 1 SYNCDELAY;
86 1 EP4BCL = 0x80;
87 1
88 1 // enable dual autopointer feature
89 1 AUTOPTRSETUP |= 0x01;
90 1
91 1 Rwuen = TRUE; // Enable remote-wakeup
92 1 }
93
94
95 void TD_Poll(void) // Called repeatedly while the device is idle
96 {
97 1 WORD i;
98 1 WORD count;
99 1
100 1 if(!(EP2468STAT & bmEP2EMPTY))
101 1 { // check EP2 EMPTY(busy) bit in EP2468STAT (SFR), core set's this bit when FIFO is empty
102 2 IOA=IOA&0xfe;
103 2 EZUSB_Delay(1000);
104 2 IOA=IOA|1;
105 2 EZUSB_Delay(1000);
106 2
107 2 if(!(EP2468STAT & bmEP6FULL))
108 2 { // check EP6 FULL(busy) bit in EP2468STAT (SFR), core set's this bit when FIFO is full
109 3 APTR1H = MSB( &EP2FIFOBUF );
110 3 APTR1L = LSB( &EP2FIFOBUF );
111 3
112 3 AUTOPTRH2 = MSB( &EP6FIFOBUF );
113 3 AUTOPTRL2 = LSB( &EP6FIFOBUF );
114 3
115 3 count = (EP2BCH << 8) + EP2BCL;
116 3
117 3 // loop EP2OUT buffer data to EP6IN
C51 COMPILER V6.10 BULKLOOP 07/06/2005 19:50:46 PAGE 3
118 3 for( i = 0x0000; i < count; i++ )
119 3 {
120 4 // setup to transfer EP2OUT buffer to EP6IN buffer using AUTOPOINTER(s)
121 4 EXTAUTODAT2 = EXTAUTODAT1;
122 4 }
123 3 EP6BCH = EP2BCH;
124 3 SYNCDELAY;
125 3 EP6BCL = EP2BCL; // arm EP6IN
126 3 SYNCDELAY;
127 3 EP2BCL = 0x80; // re(arm) EP2OUT
128 3 }
129 2 }
130 1
131 1 if(!(EP2468STAT & bmEP4EMPTY))
132 1 { // check EP4 EMPTY(busy) bit in EP2468STAT (SFR), core set's this bit when FIFO is empty
133 2 if(!(EP2468STAT & bmEP8FULL))
134 2 { // check EP8 FULL(busy) bit in EP2468STAT (SFR), core set's this bit when FIFO is full
135 3 APTR1H = MSB( &EP4FIFOBUF );
136 3 APTR1L = LSB( &EP4FIFOBUF );
137 3
138 3 AUTOPTRH2 = MSB( &EP8FIFOBUF );
139 3 AUTOPTRL2 = LSB( &EP8FIFOBUF );
140 3
141 3 count = (EP4BCH << 8) + EP4BCL;
142 3
143 3 // loop EP4OUT buffer data to EP8IN
144 3 for( i = 0x0000; i < count; i++ )
145 3 {
146 4 // setup to transfer EP4OUT buffer to EP8IN buffer using AUTOPOINTER(s)
147 4 EXTAUTODAT2 = EXTAUTODAT1;
148 4 }
149 3 EP8BCH = EP4BCH;
150 3 SYNCDELAY;
151 3 EP8BCL = EP4BCL; // arm EP8IN
152 3 SYNCDELAY;
153 3 EP4BCL = 0x80; // re(arm) EP4OUT
154 3 }
155 2 }
156 1 }
157
158 BOOL TD_Suspend(void) // Called before the device goes into suspend mode
159 {
160 1 return(TRUE);
161 1 }
162
163 BOOL TD_Resume(void) // Called after the device resumes
164 {
165 1 return(TRUE);
166 1 }
167
168 //-----------------------------------------------------------------------------
169 // Device Request hooks
170 // The following hooks are called by the end point 0 device request parser.
171 //-----------------------------------------------------------------------------
172
173 BOOL DR_GetDescriptor(void)
174 {
175 1 return(TRUE);
176 1 }
177
178 BOOL DR_SetConfiguration(void) // Called when a Set Configuration command is received
179 {
C51 COMPILER V6.10 BULKLOOP 07/06/2005 19:50:46 PAGE 4
180 1 Configuration = SETUPDAT[2];
181 1 return(TRUE); // Handled by user code
182 1 }
183
184 BOOL DR_GetConfiguration(void) // Called when a Get Configuration command is received
185 {
186 1 EP0BUF[0] = Configuration;
187 1 EP0BCH = 0;
188 1 EP0BCL = 1;
189 1 return(TRUE); // Handled by user code
190 1 }
191
192 BOOL DR_SetInterface(void) // Called when a Set Interface command is received
193 {
194 1 AlternateSetting = SETUPDAT[2];
195 1 return(TRUE); // Handled by user code
196 1 }
197
198 BOOL DR_GetInterface(void) // Called when a Set Interface command is received
199 {
200 1 EP0BUF[0] = AlternateSetting;
201 1 EP0BCH = 0;
202 1 EP0BCL = 1;
203 1 return(TRUE); // Handled by user code
204 1 }
205
206 BOOL DR_GetStatus(void)
207 {
208 1 return(TRUE);
209 1 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -