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