📄 usb.lst
字号:
C51 COMPILER V6.23a USB 03/09/2005 20:46:02 PAGE 1
C51 COMPILER V6.23a, COMPILATION OF MODULE USB
OBJECT MODULE PLACED IN usb.OBJ
COMPILER INVOKED BY: G:\Program Files\keil\C51\BIN\C51.EXE usb.c
stmt level source
1 //usb.c
2 #include "head.c"
3 #include "ADUC812.H"
4 #include "stdio.h"
5 //#include "USB_protocol.c""
6
7
8 /////////////////////////////////////////////////////////////////////
9 union rec_data_cache//数据接收缓冲
10 {
11 struct setup_package//setup包专用区
12 {
13 unsigned char RequestType;
14 unsigned char Request;
15 unsigned char ValueL;
16 unsigned char ValueH;
17 unsigned char IndexL;
18 unsigned char IndexH;
19 unsigned char LengthL;
20 unsigned char LengthH;
21 //int b;
22 //int c;
23 //int d;
24 }setup;
25 unsigned char buffer[64];
26 struct cbw_package//CBW包专用区
27 {unsigned long dCBWSignature;//offset 0
28 unsigned long dCBWTag;//offset 4
29 unsigned long dCBWDataTransferLength;//offset 8
30 unsigned char bmCBWFlags;//offset 12
31 unsigned char bCBWLUN;
32 unsigned char bCBWCBLength;//offset 14
33 unsigned char CBWCB_Operation_Code;
34 unsigned char CBWCB_Logicol_unit_Number;//offset 16
35 unsigned long CBWCB_Logical_block_address;//offset 17
36 unsigned long CBWCB_length;//offset 21
37 unsigned char CBWCB10;
38 unsigned char CBWCB_control;
39 unsigned char CBWCB12;
40 unsigned char CBWCB13;
41 unsigned char CBWCB14;
42 unsigned char CBWCB15;//offset 30
43 }CBW;
44 }USB;
45 unsigned long dCBWTag;
46 //unsigned long dCSWDataResidue;
47 //unsigned char bCSWStatus;
48 /////////////////////////////////////////
49 bit bulk_Transfer_data; //bulk数据
50 bit bulk_Transfer_code; //bulk命令
51 bit bsetup ;//:1;//收到setup包标志位
52 bit bSuspend ;//:1;//挂起标志位
53 bit bBusreset ;//:1;//总线复位标志位
54 bit bEndpointRequest ;//:1;//对端点请求处理标志位
55 bit bInterfaceRequest ;//:1;//对接口请求处理标志位
C51 COMPILER V6.23a USB 03/09/2005 20:46:02 PAGE 2
56 bit bBusDataPID ;//:1;//设备端当前传送数据pid
57 bit bDataTransmittal ;//数据传送状态标识
58 bit bconfiguration ;//;配置标志位
59 bit ADbusy ;//AD忙碌
60 ////////////////////////////////////////////////////
61 //extern void StandardRuest(void);//标准请求处理
62 extern code unsigned char DDescriptor[18];
63 extern code unsigned char SDescriptor[46];
64 extern code unsigned char subitID[];
65 extern code unsigned char subit1[];
66 extern code unsigned char subit2[];
67 extern code unsigned char subit3[];
68 extern code unsigned char subit4[];
69 extern code unsigned char subit5[];
70 extern code unsigned char INQUIRYinformation[36];
71 //extern code unsigned char audio[5360];//={//0x14f0//
72 void UsbMassStorgeClassRequest(void);
73 extern void DAC(void);//DA转换
74 ///////////////////////////////////////////////////////
75 void T0_initializtion(void);//初始化定时器0
76 void ADC(void);//AD转换
77 //////////////////////////////////////////////////////
78 //公用函数
79 unsigned char read_d12(unsigned int rp)//d12读函数
80 {
81 1 unsigned char xdata *data p;
82 1 p=rp;
83 1 return(*p);
84 1 }
85
86 void write_d12(unsigned char wd,unsigned int wp)//d12写函数
87 {
88 1 unsigned char xdata *data p;
89 1 p=wp;
90 1 *p=wd;
91 1 return ;
92 1 }
93
94 void AcknonwledgeEndpoint (unsigned char point)//端点应答
95 {
96 1 write_d12(point,order);
97 1 write_d12(0xf1,order);
98 1 if(point==0)
99 1 write_d12(0xf2,order);
100 1 return;}
101
102 /*
103 void EndpointStop(unsigned char point)//停止握手
104 {
105 write_d12(point|0x40,order);
106 write_d12(0x01,digital);
107 return;}
108 */
109
110 /*void UnLinkUSB(void)//断开usb总线
111 {
112 write_d12(0xf3,order);
113 write_d12(0x0e,digital);
114 return;}
115 */
116 void ReLinkUSB()//重连usb ()(重连后时钟从4M->16M)12m
117 {
C51 COMPILER V6.23a USB 03/09/2005 20:46:02 PAGE 3
118 1 /*unsigned int a;
119 1
120 1 write_d12(0xF3,order);//0xF3
121 1 write_d12(0x0e,digital);//0x0e
122 1 write_d12(0x0b,digital);//0x0b
123 1 for(;a<=0x00ff;)
124 1 {a++;
125 1 }*/
126 1 write_d12(0xF3,order);//0xF3
127 1 //write_d12(0x0e,digital);//0x0e
128 1 write_d12(0x16,digital);//0x16
129 1 write_d12(0x03,digital);//0x03;分频系数16
130 1
131 1 return;
132 1 }
133
134 /*void GetAddress(void)//设置地址
135 {
136 write_d12(0xd0,order);
137 write_d12(USB.setup.ValueL|0x80,digital);
138 return;
139 }*/
140
141
142 /*void Rorder(void)//发送恢复命令
143 {
144 return;}
145 */
146
147 /*void stall(void)//stall握手
148 {
149 write_d12(0x40,order);
150 write_d12(0x01,digital);
151 write_d12(0x41,order);
152 write_d12(0x01,digital);
153 write_d12(0x42,order);
154 write_d12(0x01,digital);
155 write_d12(0x43,order);
156 write_d12(0x01,digital);
157 write_d12(0x44,order);
158 write_d12(0x01,digital);
159 write_d12(0x45,order);
160 write_d12(0x01,digital);
161 return;}
162 */
163 void SetEndpointEnable_No(unsigned char i)//普通/同步端点使能_禁止
164 {
165 1 write_d12(0xd8,order);
166 1 write_d12(i,digital);
167 1 return;}
168
169
170 /*void Endpointnew(unsigned char point)//端点刷新
171 {
172 write_d12(point|0x40,order);
173 write_d12(0x00,digital);
174 return;}
175 */
176
177 //USB;
178 unsigned char read_point(unsigned char point)//读端点
179 {
C51 COMPILER V6.23a USB 03/09/2005 20:46:02 PAGE 4
180 1 unsigned char buffer_long=0;
181 1 unsigned char j;
182 1 j=0;
183 1 write_d12(point,order);
184 1 buffer_long=read_d12(digital);
185 1 write_d12(point|0x80,order);
186 1 buffer_long=read_d12(digital);
187 1 if(buffer_long^2)
188 1 {bsetup=1;}
189 1 write_d12(0xf0,order);
190 1 buffer_long=read_d12(digital);
191 1 buffer_long=read_d12(digital);
192 1 if(buffer_long!=0)//
193 1 {while(j<buffer_long)
194 2 {
195 3 USB.buffer[j]=read_d12(digital);
196 3 j=j+1;
197 3 }
198 2 write_d12(0xf2,order);
199 2 }
200 1 else
201 1 {
202 2 AcknonwledgeEndpoint (0x00);
203 2 AcknonwledgeEndpoint (0x01);
204 2 }
205 1 return buffer_long;
206 1 }
207
208 void write_point(unsigned char point,buffer_long)//写端点
209 {
210 1 unsigned char nextsendL,j=0;
211 1 if(/*(point==0x02)||*/(point==0x03))
212 1 {
213 2 if(bDataTransmittal==1)
214 2 {j=USB.setup.RequestType;}
215 2 if(buffer_long>16)
216 2 {bDataTransmittal=1;
217 3 nextsendL=buffer_long-16;
218 3 buffer_long=16;
219 3 }
220 2 else
221 2 {bDataTransmittal=0;
222 3 }
223 2 }
224 1 write_d12(point,order);
225 1 write_d12(0xf0,order);
226 1 write_d12(0x00,digital);
227 1 write_d12(buffer_long,digital);
228 1 while(j<buffer_long)
229 1 {
230 2 write_d12(USB.buffer[j],digital);
231 2 j=j+1;
232 2 }
233 1 if(bDataTransmittal==1)
234 1 {USB.setup.RequestType=j;
235 2 USB.setup.Request=nextsendL;}
236 1 write_d12(0xfa,order);//写数完毕使能缓冲区
237 1 write_d12(point+1,order);///发数之前将指针切换到out区
238 1 return;
239 1 }
240
241
C51 COMPILER V6.23a USB 03/09/2005 20:46:02 PAGE 5
242 ///////////////////////////////////////
243 ////////////标准设备请求处理
244
245 /*void GetStatus(void)//获取状态
246 {
247 return;}
248 void ClearFeature(void)//清除特性选择符
249 {
250 return;}
251 void SetFeature(void)//设置特性选择符
252 {
253 return;}
254
255 void SetAddress(void)//分配地址
256 {
257 return;}
258 */
259 /*void GetDescriptor(void)//获取描述符(类型)
260 {
261 return;}*/
262
263
264
265 void StandardRuest(void)//标准请求处理
266 {
267 1 /*if(USB.setup.Request==0x00)
268 1 {GetStatus();}//获取状态
269 1 if(USB.setup.Request==0x01)
270 1 {ClearFeature();}//清除特性选择符
271 1 if(USB.setup.Request==0x03)
272 1 {SetFeature();} //设置特性选择符
273 1 */
274 1
275 1 if(USB.setup.Request==0x05)
276 1 {/*GetAddress;*/
277 2 write_d12(0xd0,order);
278 2 write_d12(USB.setup.ValueL|0x80,digital);
279 2 write_point(0x01,0);}//分配地址
280 1 else if(USB.setup.Request==0x06)
281 1 {/*GetDescriptor;*/
282 2 if(USB.setup.ValueH==0x01)//获取设备描述符
283 2 {
284 3 unsigned char i=0;
285 3 if(USB.setup.LengthL==0x40){USB.buffer[63]=0x10;}
286 3 else{USB.buffer[63]=USB.setup.LengthL;}
287 3 while (i<18)
288 3 {USB.buffer[i]=DDescriptor[i];i=i+1;}
289 3 write_point(0x01,USB.buffer[63]);
290 3 }
291 2 else if(USB.setup.ValueH==0x02)//获取配置描述符
292 2 {
293 3 unsigned char i=0;
294 3 if(USB.setup.LengthL==0xff){USB.buffer[63]=0x2e;}
295 3 else{USB.buffer[63]=USB.setup.LengthL;}
296 3 while (i<46)
297 3 {USB.buffer[i]=SDescriptor[i];i=i+1;}
298 3 write_point(0x01,USB.buffer[63]);
299 3 }
300 2 else if(USB.setup.ValueH==0x03);//获取字符串描述符
301 2 { unsigned char i=0;
302 3 if(USB.setup.ValueL==0x00){while(i<subitID[0]){USB.buffer[i]=subitID[i];i=i+1;}
303 4 write_point(0x01,subitID[0]);}
C51 COMPILER V6.23a USB 03/09/2005 20:46:02 PAGE 6
304 3 else if(USB.setup.ValueL==0x01){while(i<subit1[0]){USB.buffer[i]=subit1[i];i=i+1;}
305 4 write_point(0x01,subit1[0]);}
306 3 else if(USB.setup.ValueL==0x02){while(i<subit2[0]){USB.buffer[i]=subit2[i];i=i+1;}
307 4 write_point(0x01,subit2[0]);}
308 3 else if(USB.setup.ValueL==0x03){while(i<subit3[0]){USB.buffer[i]=subit3[i];i=i+1;}
309 4 write_point(0x01,subit3[0]);}
310 3 else if(USB.setup.ValueL==0x04){while(i<subit4[0]){USB.buffer[i]=subit4[i];i=i+1;}
311 4 write_point(0x01,subit4[0]);}
312 3 else if(USB.setup.ValueL==0x05){while(i<subit5[0]){USB.buffer[i]=subit5[i];i=i+1;}
313 4 write_point(0x01,subit5[0]);}
314 3
315 3 }
316 2 }//获取描述符(类型)
317 1 if(USB.setup.Request==0x07)
318 1 {/*SetDescriptor;*/}//;设置描述符类型
319 1 if(USB.setup.Request==0x08)
320 1 {USB.buffer[0]=bconfiguration;
321 2 write_point(0x01,1);
322 2 /*GetConfiguration;*/}//;读配置值
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -