📄 periph.lst
字号:
C51 COMPILER V7.10 PERIPH 11/13/2005 15:55:34 PAGE 1
C51 COMPILER V7.10, COMPILATION OF MODULE PERIPH
OBJECT MODULE PLACED IN periph.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE periph.c BROWSE INCDIR(f:\Keil\C51\INC\Cypress\) DEBUG OBJECTEXTEND
line level source
1 #pragma NOIV // Do not generate interrupt vectors
2 //-----------------------------------------------------------------------------
3 // File: periph.c
4 // Contents: Hooks required to implement USB peripheral function.
5 //
6 // Copyright (c) 1997 AnchorChips, Inc. All rights reserved
7 //-----------------------------------------------------------------------------
8 #include "fx2.h"
9 #include "fx2regs.h"
10 #include "fx2sdly.h"
11 #include "io.h"
12 #include "gpif.h"
13 #include "ad.h"
14
15 extern BOOL GotSUD; // Received setup data flag
16 extern BOOL Sleep;
17 extern BOOL Rwuen;
18 extern BOOL Selfpwr;
19
20 BYTE data Configuration; // Current configuration
21 BYTE data AlternateSetting; // Alternate settings
22 BYTE data GpifHighAddr; //gpif high addr
23 BYTE data GpifReadWriteFlag; //gpif read write flag
24 BYTE data GpifFinishFlag;
25 BYTE data High_Full_Flag;
26 BYTE data PowerDown_Flag; //AD Power Down Mode
27
28 BYTE data Ad_complete_Flag;
29
30 #define bmEP1OUTBSY 0x02
31 #define bmEP1INBSY 0x04
32
33 //-----------------------------------------------------------------------------
34 // Task Dispatcher hooks
35 // The following hooks are called by the task dispatcher.
36 //-----------------------------------------------------------------------------
37
38 void TD_Init(void) // Called once at startup
39 {
40 1 BREAKPT &= ~bmBPEN; // to see BKPT LED go out TGE
41 1 Rwuen = TRUE; // Enable remote-wakeup
42 1 ////////////////////////////////////////////////////////////////////
43 1 //将GPIF初试化用在收到控制通道命令字来重新动态调用
44 1 GpifInit();
45 1
46 1 SYNCDELAY;
47 1 EP1OUTCFG = 0xA0; // always OUT, valid, bulk
48 1 EP1INCFG = 0xA0; // always IN, valid, bulk
49 1 // EP2 512 BULK OUT 4x
50 1 SYNCDELAY; // see TRM section 15.14
51 1 EP2CFG = 0xA0; //512PACKET; // BUF[1:0]=00 for 4x buffering
52 1
53 1 // EP4 and EP6 and EP8 are not used in this implementation...
54 1 SYNCDELAY; //
55 1 EP4CFG = 0x20; // clear valid bit
C51 COMPILER V7.10 PERIPH 11/13/2005 15:55:34 PAGE 2
56 1 SYNCDELAY; //
57 1 EP6CFG = 0xE0; //
58 1 SYNCDELAY; //
59 1 EP8CFG = 0x60; // clear valid bit
60 1 SYNCDELAY;
61 1 EP1OUTBC = 0x80;
62 1
63 1 SYNCDELAY; //
64 1 FIFORESET = 0x80; // activate NAK-ALL to avoid race conditions
65 1 SYNCDELAY; //
66 1 FIFORESET = 0x02; // reset, FIFO 2
67 1 SYNCDELAY; //
68 1 FIFORESET = 0x04; // reset, FIFO 4
69 1 SYNCDELAY; //
70 1 FIFORESET = 0x06; // reset, FIFO 6
71 1 SYNCDELAY; //
72 1 FIFORESET = 0x08; // reset, FIFO 8
73 1 SYNCDELAY; //
74 1 FIFORESET = 0x00; // deactivate NAK-ALL
75 1 SYNCDELAY;
76 1
77 1 // 8-bit bus (WORDWIDE=1)...
78 1 EP2FIFOCFG = 0x00;//AUTO OUT 8-BIT BUS
79 1 SYNCDELAY;
80 1 EP6FIFOCFG = 0x09;//AUTO IN 8-BIT BUS
81 1 SYNCDELAY;
82 1
83 1 EP2BCL = 0x80;
84 1 SYNCDELAY;
85 1 EP2BCL = 0x80;
86 1 SYNCDELAY;
87 1 EP2BCL = 0x80;
88 1 SYNCDELAY;
89 1 EP2BCL = 0x80;
90 1 SYNCDELAY;
91 1
92 1 // setup INT4 as internal source for GPIF interrupts
93 1 // using INT4CLR (SFR), automatically enabled
94 1 SYNCDELAY;
95 1 INTSETUP |= 0x03; // Enable INT4 FIFO/GPIF Autovectoring
96 1 SYNCDELAY; // used here as "delay"
97 1 EXIF &= ~0x40; // just in case one was pending...
98 1 SYNCDELAY; // used here as "delay"
99 1 GPIFIRQ = 0x01;
100 1 SYNCDELAY; //
101 1 GPIFIE = 0x01; // Enable GPIFDONE interrupt
102 1 SYNCDELAY; //
103 1 EIE |= 0x04; // Enable INT4 ISR, EIE.2(EIEX4=1)
104 1
105 1 GpifReadWriteFlag = 0; //write
106 1 GpifFinishFlag = 0;
107 1 High_Full_Flag = 0;
108 1 PowerDown_Flag = 0; //AD Power Down Mode
109 1 }
110
111
112
113 void TD_Poll(void) // Called repeatedly while the device is idle
114 {
115 1
116 1 WORD data MyNumber;
117 1 BYTE data My_EP6GPIFBCHX;
C51 COMPILER V7.10 PERIPH 11/13/2005 15:55:34 PAGE 3
118 1 BYTE data My_EP6GPIFBCLX; //高16位
119 1 BYTE data My_EP6GPIFBCH;
120 1 BYTE data My_EP6GPIFBCL; //低16位
121 1 WORD data My_EP6GPIFNOX;
122 1 WORD data My_EP6GPIFNO;
123 1 BYTE data My_OUT1_Temp1;
124 1 BYTE data My_OUT1_Temp2;
125 1 BYTE data My_OUT1_Channel;//
126 1 WORD data My_Channel_Word;//通道控制字
127 1 //-----------------------------------------------------------------------------------------------
128 1 //handle OUT1 Control Word
129 1 //-----------------------------------------------------------------------------------------------
130 1 if(!(EP01STAT & bmEP1OUTBSY))
131 1 {
132 2 // handle OUTs to EP1OUT
133 2 MyNumber = EP1OUTBC;
134 2 My_OUT1_Temp1 = EP1OUTBUF[0];
135 2 switch(My_OUT1_Temp1)
136 2 {
137 3 case SetAdDen: //设置采样深度0x01
138 3
139 3 My_EP6GPIFBCHX = EP1OUTBUF[1];
140 3 My_EP6GPIFBCLX = EP1OUTBUF[2];
141 3 My_EP6GPIFBCH = EP1OUTBUF[3];
142 3 My_EP6GPIFBCL = EP1OUTBUF[4];
143 3 My_EP6GPIFNOX = (My_EP6GPIFBCHX <<8 ) + My_EP6GPIFBCLX;
144 3 My_EP6GPIFNO = (My_EP6GPIFBCH <<8 ) + My_EP6GPIFBCL;
145 3 break;
146 3 case StartAd://应该增加启动失败的功能0x02
147 3 My_OUT1_Temp2 = EP1OUTBUF[1];
148 3 if(My_OUT1_Temp2 == OUT1_START_AD)
149 3 {
150 4 // Peripheral_SingleWordWrite(0);//start ad
151 4 Peripheral_SingleWordWrite(My_Channel_Word);//start ad
152 4 GpifReadWriteFlag = 0;
153 4 }
154 3 break;
155 3 case EndAd: //Stop AD 0x03
156 3 My_OUT1_Temp2 = EP1OUTBUF[1];
157 3 if(My_OUT1_Temp2 == OUT1_END_AD)
158 3 {
159 4 WORD *pTemp_gpif;
160 4 Peripheral_SingleWordRead(pTemp_gpif);
161 4 SetEP6GPIFPFSTOP();
162 4 }
163 3 break;
164 3 case SelectADCh: //Select AD Channel 0x04 装载波形
165 3 My_OUT1_Channel = EP1OUTBUF[1];
166 3
167 3 My_Channel_Word = ((WORD)(My_OUT1_Channel<<8))+0x00;
168 3 if(My_OUT1_Channel == 0x00)
169 3 {
170 4 GPIF_LOAD_SINGLE(); //默认状态装载波形
171 4 }
172 3 if(My_OUT1_Channel == 0x01)
173 3 {
174 4 GPIF_LOAD_DOUBLE();//双通道
175 4 }
176 3 if(My_OUT1_Channel == 0x02)
177 3 {
178 4 GPIF_LOAD_TRI();
179 4 }
C51 COMPILER V7.10 PERIPH 11/13/2005 15:55:34 PAGE 4
180 3 if(My_OUT1_Channel == 0x03)
181 3 {
182 4 GPIF_LOAD_QUAD();
183 4 }
184 3 if((0x04<=My_OUT1_Channel)&&(My_OUT1_Channel < 0x08))
185 3 {
186 4 ;
187 4 }
188 3 if(My_OUT1_Channel >= 0x08)
189 3 {
190 4 PowerDown_Flag = 1;
191 4 GPIF_LOAD_PWDW();
192 4 }
193 3 break;
194 3 default:
195 3 break;
196 3 }
197 2 SYNCDELAY;
198 2 EP1OUTBC = 0x80;
199 2 }
200 1 //-----------------------------------------------------------------------------------------------
201 1 //Handle EP6 FIFO Read
202 1 //-----------------------------------------------------------------------------------------------
203 1 if(GpifFinishFlag == 1)
204 1 {
205 2 GpifFinishFlag = 0; //每次中断完成就切换读和写
206 2
207 2 if(GpifReadWriteFlag == 0)
208 2 {
209 3 SYNCDELAY; //
210 3 EP6GPIFTCHX = My_EP6GPIFNOX >> 8; // setup transaction count
211 3 SYNCDELAY; //
212 3 EP6GPIFTCLX = ( BYTE )My_EP6GPIFNOX;
213 3 Peripheral_SetEP6GPIFTC(My_EP6GPIFNO); //read 512 byte data from gipf 底16位
214 3 Peripheral_FIFORead(2);
215 3 // i++;
216 3 // if(i > My_EP6GPIFNO1) //如果采样深度没有达到跳出
217 3 GpifReadWriteFlag = 1; //read
218 3 }
219 2 }
220 1 }
221
222 BOOL TD_Suspend(void) // Called before the device goes into suspend mode
223 {
224 1 return(TRUE);
225 1 }
226
227 BOOL TD_Resume(void) // Called after the device resumes
228 {
229 1 return(TRUE);
230 1 }
231
232 //-----------------------------------------------------------------------------
233 // Device Request hooks
234 // The following hooks are called by the end point 0 device request parser.
235 //-----------------------------------------------------------------------------
236
237 BOOL DR_GetDescriptor(void)
238 {
239 1 return(TRUE);
240 1 }
241
C51 COMPILER V7.10 PERIPH 11/13/2005 15:55:34 PAGE 5
242 BOOL DR_SetConfiguration(void) // Called when a Set Configuration command is received
243 {
244 1 Configuration = SETUPDAT[2];
245 1 if(High_Full_Flag == 1)
246 1 {
247 2 SYNCDELAY; //
248 2 EP2AUTOINLENH = 0x02; //ep2 auto commit length 512
249 2 SYNCDELAY;
250 2 EP2AUTOINLENL = 0x00;
251 2 SYNCDELAY;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -