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