📄 bulkloop.lst
字号:
C51 COMPILER V7.06 BULKLOOP 03/01/2009 11:36:39 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE BULKLOOP
OBJECT MODULE PLACED IN bulkloop.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE bulkloop.c BROWSE 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 #define ad5933_addr 0x0d
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 // set the CPU clock to 48MHz,设置CPUCS第四三位为10.
32 1 CPUCS = ((CPUCS & ~bmCLKSPD) | bmCLKSPD1) ;
33 1
34 1 // set the slave FIFO interface to 48MHz,set ifconfig.
35 1 IFCONFIG |= 0x40;
36 1
37 1 // Registers which require a synchronization delay, see section 15.14
38 1 // FIFORESET FIFOPINPOLAR
39 1 // INPKTEND OUTPKTEND
40 1 // EPxBCH:L REVCTL
41 1 // GPIFTCB3 GPIFTCB2
42 1 // GPIFTCB1 GPIFTCB0
43 1 // EPxFIFOPFH:L EPxAUTOINLENH:L
44 1 // EPxFIFOCFG EPxGPIFFLGSEL
45 1 // PINFLAGSxx EPxFIFOIRQ
46 1 // EPxFIFOIE GPIFIRQ
47 1 // GPIFIE GPIFADRH:L
48 1 // UDMACRCH:L EPxGPIFTRIG
49 1 // GPIFTRIG
50 1
51 1 // Note: The pre-REVE EPxGPIFTCH/L register are affected, as well...
52 1 // ...these have been replaced by GPIFTC[B3:B0] registers
53 1
54 1 // default: all endpoints have their VALID bit set
55 1 // default: TYPE1 = 1 and TYPE0 = 0 --> BULK
C51 COMPILER V7.06 BULKLOOP 03/01/2009 11:36:39 PAGE 2
56 1 // default: EP2 and EP4 DIR bits are 0 (OUT direction)
57 1 // default: EP6 and EP8 DIR bits are 1 (IN direction)
58 1 // default: EP2, EP4, EP6, and EP8 are double buffered
59 1
60 1 // we are just using the default values, yes this is not necessary...
61 1 EP1OUTCFG = 0xA0; //激活端点1OUT,类型为BULK
62 1 EP1INCFG = 0xA0; //激活端点1IN,类型为BULK
63 1 SYNCDELAY; // see TRM section 15.14
64 1 EP2CFG = 0xA2; //EP2CFG=10100010,激活端点2OUT,类型BULK,端点缓冲区512字节,缓冲区数量2倍
-
65 1 SYNCDELAY;
66 1 EP4CFG = 0xA0; //EP4CFG=10100000,激活端点4OUT,类型BULK,端点缓冲区512字节
67 1 SYNCDELAY;
68 1 EP6CFG = 0xE2; //EP6CFG=11100010,激活端点6IN,类型BULK,端点缓冲区512字节,缓冲区数量2倍
69 1 SYNCDELAY;
70 1 EP8CFG = 0xE0; //EP8CFG=11100000,激活端点8IN,类型BULK,端点缓冲区512字节
71 1
72 1 // out endpoints do not come up armed
73 1
74 1 // since the defaults are double buffered we must write dummy byte counts twice
75 1 SYNCDELAY;
76 1 EP2BCL = 0x80; // arm EP2OUT by writing byte count w/skip.刚刚接收的OUT包不会立即传给FIFO
-输出
77 1 SYNCDELAY;
78 1 EP2BCL = 0x80;
79 1 SYNCDELAY;
80 1 EP4BCL = 0x80; // arm EP4OUT by writing byte count w/skip.
81 1 SYNCDELAY;
82 1 EP4BCL = 0x80;
83 1
84 1 // enable dual autopointer feature使两个自动指针有效
85 1 AUTOPTRSETUP |= 0x01;
86 1
87 1 Rwuen = TRUE; // Enable remote-wakeup
88 1 EZUSB_InitI2C();
89 1
90 1
91 1 }
92
93
94 void TD_Poll(void) // Called repeatedly while the device is idle
95 {
96 1 WORD i;
97 1 WORD count;
98 1 BYTE xdata buttons;
99 1 //增加部分//
100 1 BYTE xdata reg1[]={0xb0,0x82};
101 1 BYTE xdata reg2[]={0x82,0x88};
102 1 EZUSB_WriteI2C(ad5933_addr,0x02,®2);
103 1 EZUSB_WaitForEEPROMWrite(ad5933_addr);
104 1 EZUSB_WriteI2C(ad5933_addr,0x02,®1);
105 1 EZUSB_WaitForEEPROMWrite(ad5933_addr);
106 1 EZUSB_ReadI2C(ad5933_addr,0x01,&buttons);
107 1
108 1 if(!(EP2468STAT & bmEP2EMPTY))
109 1 { // check EP2 EMPTY(busy) bit in EP2468STAT (SFR), core set's this bit when FIFO is empty
110 2 if(!(EP2468STAT & bmEP6FULL))
111 2 { // check EP6 FULL(busy) bit in EP2468STAT (SFR), core set's this bit when FIFO is full
112 3 // APTR1H = MSB( &EP2FIFOBUF );
113 3 // APTR1L = LSB( &EP2FIFOBUF );
114 3
115 3 APTR1H = MSB( &buttons );
C51 COMPILER V7.06 BULKLOOP 03/01/2009 11:36:39 PAGE 3
116 3 APTR1L = LSB( &buttons );
117 3
118 3 AUTOPTRH2 = MSB( &EP6FIFOBUF );
119 3 AUTOPTRL2 = LSB( &EP6FIFOBUF );
120 3
121 3 count = (EP2BCH << 8) + EP2BCL;
122 3
123 3 // loop EP2OUT buffer data to EP6IN
124 3 for( i = 0x0000; i < count; i++ )
125 3 {
126 4 // setup to transfer EP2OUT buffer to EP6IN buffer using AUTOPOINTER(s)
127 4 EXTAUTODAT2 = EXTAUTODAT1;
128 4 }
129 3 EP6BCH = EP2BCH;
130 3 SYNCDELAY;
131 3 EP6BCL = EP2BCL; // arm EP6IN
132 3 SYNCDELAY;
133 3 EP2BCL = 0x80; // re(arm) EP2OUT
134 3 }
135 2 }
136 1
137 1 if(!(EP2468STAT & bmEP4EMPTY))
138 1 { // check EP4 EMPTY(busy) bit in EP2468STAT (SFR), core set's this bit when FIFO is empty
139 2 if(!(EP2468STAT & bmEP8FULL))
140 2 { // check EP8 FULL(busy) bit in EP2468STAT (SFR), core set's this bit when FIFO is full
141 3 APTR1H = MSB( &EP4FIFOBUF );
142 3 APTR1L = LSB( &EP4FIFOBUF );
143 3
144 3 AUTOPTRH2 = MSB( &EP8FIFOBUF );
145 3 AUTOPTRL2 = LSB( &EP8FIFOBUF );
146 3
147 3 count = (EP4BCH << 8) + EP4BCL;
148 3
149 3 // loop EP4OUT buffer data to EP8IN
150 3 for( i = 0x0000; i < count; i++ )
151 3 {
152 4 // setup to transfer EP4OUT buffer to EP8IN buffer using AUTOPOINTER(s)
153 4 EXTAUTODAT2 = EXTAUTODAT1;
154 4 }
155 3 EP8BCH = EP4BCH;
156 3 SYNCDELAY;
157 3 EP8BCL = EP4BCL; // arm EP8IN
158 3 SYNCDELAY;
159 3 EP4BCL = 0x80; // re(arm) EP4OUT
160 3 }
161 2 }
162 1 }
163
164 BOOL TD_Suspend(void) // Called before the device goes into suspend mode
165 {
166 1 return(TRUE);
167 1 }
168
169 BOOL TD_Resume(void) // Called after the device resumes
170 {
171 1 return(TRUE);
172 1 }
173
174 //-----------------------------------------------------------------------------
175 // Device Request hooks
176 // The following hooks are called by the end point 0 device request parser.
177 //-----------------------------------------------------------------------------
C51 COMPILER V7.06 BULKLOOP 03/01/2009 11:36:39 PAGE 4
178
179 BOOL DR_GetDescriptor(void)
180 {
181 1 return(TRUE);
182 1 }
183
184 BOOL DR_SetConfiguration(void) // Called when a Set Configuration command is received
185 {
186 1 Configuration = SETUPDAT[2];
187 1 return(TRUE); // Handled by user code
188 1 }
189
190 BOOL DR_GetConfiguration(void) // Called when a Get Configuration command is received
191 {
192 1 EP0BUF[0] = Configuration;
193 1 EP0BCH = 0;
194 1 EP0BCL = 1;
195 1 return(TRUE); // Handled by user code
196 1 }
197
198 BOOL DR_SetInterface(void) // Called when a Set Interface command is received
199 {
200 1 AlternateSetting = SETUPDAT[2];
201 1 return(TRUE); // Handled by user code
202 1 }
203
204 BOOL DR_GetInterface(void) // Called when a Set Interface command is received
205 {
206 1 EP0BUF[0] = AlternateSetting;
207 1 EP0BCH = 0;
208 1 EP0BCL = 1;
209 1 return(TRUE); // Handled by user code
210 1 }
211
212 BOOL DR_GetStatus(void)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -