?? usb.lst
字號:
C51 COMPILER V7.06 USB 03/02/2006 23:51:19 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE USB
OBJECT MODULE PLACED IN USB.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE USB.C BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /******************************************************************
2 本程序只供學習使用,未經作者許可,不得用于其它任何用途
3 我的郵箱:computer-lov@tom.com
4 歡迎訪問我的blog: http://computer00.21ic.org
5
6 USB.C file
7
8 Created by Computer-lov
9 Date: 2004.9.21
10
11 Edit date:2006.3.2
12
13 Version V1.1
14 Copyright(C) Computer-lov 2004-2014
15 All rigths reserved
16
17 *******************************************************************/
18
19 #include<AT89x52.H>
20 #include "USB.H"
21 #include "PDIUSBD12.H"
22 #include "MASS_STORAGE.H"
23 //#include<serial.h>
24 #include "ide.h"
25
26 #define USB_COMMAND_ADD 1
27 #define USB_DATA_ADD 0
28
29 #define USB_DATA P0
30 #define USB_A0 P3_5
31 #define USB_WR P3_6
32 #define USB_RD P3_7
33 #define USB_INT P3_2
34
35
36 #define ENDPOINT_NUMBER 2
37 #define MAX_CONTROL_DATA_SIZE 16
38 #define MAX_LUN 0
39 #define MAX_BULK_DATA_SIZE 64
40
41 CONTROL_DATA_BUFF idata Control_Data;
42
43 unsigned char idata buffer[64];
44
45 CBW idata cbw;
46 CSW idata csw;
47
48
49 /*union
50 {
51 unsigned char Register;
52 struct
53 {
54 unsigned char Command :1;
55 unsigned char Data :1;
C51 COMPILER V7.06 USB 03/02/2006 23:51:19 PAGE 2
56 }Status;
57 }SCSI;*/
58
59
60 unsigned char bdata SCSI_Register;
61 sbit SCSI_Command = SCSI_Register^0;
62 sbit SCSI_Data = SCSI_Register^1;
63
64
65 unsigned char *pData;
66
67 unsigned char code DISK_INF[36]
68 = //磁盤信息
69 {
70 0x00,
71 0x00,
72 0x02,
73 0x02,
74 0x1F,
75 0x00,0x00,0x00,
76 0x49,0x44,0x45,0xA1,0xFA,0x55,0x53,0x42,
77 0xD7,0xD4,0xBC,0xBA,0xD7,0xF6,0xB5,0xC4,0xD2,0xC6,0xB6,0xAF,0xD3,0xB2,0xC5,0xCC,
78 0x31,0x2E,0x30,0x31
79 };
80
81 unsigned char DISK_CAPACITY[8]= //磁盤容量
82 {
83 0x00,0x01,0xff,0x00,
84 0x00,0x00,0x02,0x00
85 };
86
87 code unsigned char SENSE[0x12]= //模式探測返回數據
88 {
89 0x70, 0x00, 0x05, 0x00, 0x00, 0x00,
90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00
91 };
92
93
94 unsigned int SWAP(unsigned int temp) //高低字節交換
95 {
96 1 unsigned char i;
97 1 i=((unsigned char *)&temp)[0];
98 1 ((unsigned char *)&temp)[0]=((unsigned char *)&temp)[1];
99 1 ((unsigned char *)&temp)[1]=i;
100 1 return temp;
101 1 }
102
103 unsigned char LSB(unsigned int temp) //取一個整數的低字節
104 {
105 1 return (unsigned char)temp;
106 1 }
107
108 unsigned char MSB(unsigned int temp) //取一個整數的高字節
109 {
110 1 return (unsigned char)(temp>>8);
111 1 }
112
113 code unsigned char LANGUAGE_ID[4]={0x04,0x03,0x09,0x04}; //字符串描述符所用的語言種類
114
115 code unsigned char device_serial_number[18]= //設備序列號
116 {0x12,0x03,0x32,0x00,0x30,0x00,0x37,0x00,0x31,0x00,0x30,0x00,0x39,0x00,0x38,0x00,0x32,0x00};
117
C51 COMPILER V7.06 USB 03/02/2006 23:51:19 PAGE 3
118 code DEVICE_DESCRIPTOR_STRUCT device_descriptor= //設備描述符
119 {
120 sizeof(DEVICE_DESCRIPTOR_STRUCT), //設備描述符的字節數大小
121 DEVICE_DESCRIPTOR, //設備描述符類型編號
122 0x1001, //USB版本號
123 0x00, //USB分配的設備類代碼
124 0x00, //USB分配的子類代碼
125 0x00, //USB分配的設備協議代碼
126 0x10, //端點0的最大包大小
127 0x7104, //廠商編號
128 0xf0ff, //產品編號
129 0x0100, //設備出廠編號
130 0x00, //設備廠商字符串的索引
131 0x00, //描述產品字符串的索引
132 0x02, //描述設備序列號字符串的索引
133 0x01 //可能的配置數量
134 };
135
136 typedef struct _CON_INT_ENDP_DESCRIPTOR_STRUCT
137 {
138 CONFIGURATION_DESCRIPTOR_STRUCT configuration_descriptor;
139 INTERFACE_DESCRIPTOR_STRUCT interface_descritor;
140 ENDPOINT_DESCRIPTOR_STRUCT endpoint_descriptor[ENDPOINT_NUMBER];
141 }CON_INT_ENDP_DESCRIPTOR_STRUCT;
142
143 code CON_INT_ENDP_DESCRIPTOR_STRUCT con_int_endp_descriptor=
144 {
145 //configuration_descriptor //配置描述符
146 {
147 sizeof(CONFIGURATION_DESCRIPTOR_STRUCT), //配置描述符的字節數大小
148 CONFIGURATION_DESCRIPTOR, //配置描述符類型編號
149 (sizeof(CONFIGURATION_DESCRIPTOR_STRUCT)+sizeof(INTERFACE_DESCRIPTOR_STRUCT)+sizeof(ENDPOINT_DESCRIPTOR_S
-TRUCT)*ENDPOINT_NUMBER)*256+
150 (sizeof(CONFIGURATION_DESCRIPTOR_STRUCT)+sizeof(INTERFACE_DESCRIPTOR_STRUCT)+sizeof(ENDPOINT_DESCRIPTOR_S
-TRUCT)*ENDPOINT_NUMBER)/256,
151 0x01, //只包含一個接口
152 0x01, //該配置的編號
153 0x00, //iConfiguration字段
154 0x80, //采用總線供電,不支持遠程喚醒
155 0xC8 //從總線獲取最大電流400mA
156 },
157 //interface_descritor //接口描述符
158 {
159 sizeof(INTERFACE_DESCRIPTOR_STRUCT), //接口描述符的字節數大小
160 INTERFACE_DESCRIPTOR, //接口描述符類型編號
161 0x00, //接口編號為0
162 0x00, //該接口描述符的編號
163 ENDPOINT_NUMBER, //非0端點數量為2,只使用端點主端點輸入和
-輸出
164 0x08, //USB大容量存儲設備
165 0x06, //使用的子類,為簡化塊命令
166 0x50, //使用的協議,這里使用單批量傳輸協議
167 0x00 //接口描述符字符串索引
168 },
169
170 //endpoint_descriptor[]
171 {
172 { //主端點輸入描述
173 sizeof(ENDPOINT_DESCRIPTOR_STRUCT), //端點描述符的字節數大小
174 ENDPOINT_DESCRIPTOR, //端點描述符類型編號
175 MAIN_POINT_IN, //端點號,主輸入端點
176 ENDPOINT_TYPE_BULK, //使用的傳輸類型,批量傳輸
C51 COMPILER V7.06 USB 03/02/2006 23:51:19 PAGE 4
177 0x4000, //該端點支持的最大包尺寸,64字節
178 0x00 //中斷掃描時間,對批量傳輸無效
179 },
180
181 { //主端點輸出描述
182 sizeof(ENDPOINT_DESCRIPTOR_STRUCT), //端點描述符的字節數大小
183 ENDPOINT_DESCRIPTOR, //端點描述符類型編號
184 MAIN_POINT_OUT, //端點號,主輸出端點
185 ENDPOINT_TYPE_BULK, //使用的傳輸類型,批量傳輸
186 0x4000, //該端點支持的最大包尺寸,64字節
187 0x00 //中斷掃描時間,對批量傳輸無效
188 }
189 }
190 };
191
192 /*union //程序標志位
193 {
194 unsigned int Register;
195 struct
196 {
197 unsigned char bus_reset :1;
198 unsigned char suspend :1;
199 unsigned char remote_wakeup :1;
200 unsigned char int_isr :1;
201 unsigned char not_end :1;
202 unsigned char usb_idle :1;
203 unsigned char usb_busy :1;
204 unsigned char setup_packet_in :1;
205 unsigned char setup_packet_out :1;
206 unsigned char set_addr :1;
207 unsigned char usb_endp0_in :1;
208 unsigned char usb_endp2_in :1;
209 unsigned char usb_endp2_out :1;
210 }flags;
211 }usb_flags;
212 */
213
214 unsigned int bdata usb_flags_Register;
215 //unsigned bdata usb_flags_Register2;
216
217 sbit USB__bus_reset = usb_flags_Register^0;
218 sbit USB_suspend = usb_flags_Register^1;
219 sbit USB_remote_wakeup = usb_flags_Register^2;
220 sbit USB_int_isr = usb_flags_Register^3;
221 sbit USB_not_end = usb_flags_Register^4;
222 sbit USB_usb_idle = usb_flags_Register^5;
223 sbit USB_usb_busy = usb_flags_Register^6;
224 sbit USB_setup_packet_in = usb_flags_Register^7;
225 sbit USB_setup_packet_out = usb_flags_Register^8;
226 sbit USB_set_addr = usb_flags_Register^9;
227 sbit USB_usb_endp0_in = usb_flags_Register^10;
228 sbit USB_usb_endp2_in = usb_flags_Register^11;
229 sbit USB_usb_endp2_out = usb_flags_Register^12;
230
231 /*union //中斷寄存器
232 {
233 unsigned char Register[2];
234 struct
235 {
236 unsigned char control_out_port :1;
237 unsigned char control_in_port :1;
238 unsigned char port_out_1 :1;
C51 COMPILER V7.06 USB 03/02/2006 23:51:19 PAGE 5
239 unsigned char port_in_1 :1;
240 unsigned char main_out_port :1;
241 unsigned char main_in_port :1;
242 unsigned char bus_reset :1;
243 unsigned char suspend_change :1;
244 unsigned char DMA_EOT :1;
245 unsigned char not_use :7;
246 }Interrupt;
247 }Interrupt_Register;
248 */
249
250 unsigned char bdata Interrupt_Register[2];
251
252 sbit Interrupt_control_out_port = Interrupt_Register[0]^0;
253 sbit Interrupt_control_in_port = Interrupt_Register[0]^1;
254 sbit Interrupt_port_out_1 = Interrupt_Register[0]^2;
255 sbit Interrupt_port_in_1 = Interrupt_Register[0]^3;
256 sbit Interrupt_main_out_port = Interrupt_Register[0]^4;
257 sbit Interrupt_main_in_port = Interrupt_Register[0]^5;
258 sbit Interrupt_bus_reset = Interrupt_Register[0]^6;
259 sbit Interrupt_suspend_change = Interrupt_Register[0]^7;
260 sbit Interrupt_DMA_EOT = Interrupt_Register[1]^0;
261
262
263 /*union //端點最后處理狀態
264 {
265 unsigned char Register;
266 struct
267 {
268 unsigned char successful :1;
269 unsigned char error_code :4;
270 unsigned char setup_packet :1;
271 unsigned char data_1 :1;
272 unsigned char prestatus_not_read :1;
273 }Status;
274 }Last_Status;*/
275
276 unsigned char bdata Last_Status_Register;
277
278 sbit Last_Status_successful = Last_Status_Register^0;
279 sbit Last_Status_error_code0 = Last_Status_Register^1;
280 sbit Last_Status_error_code1 = Last_Status_Register^2;
281 sbit Last_Status_error_code2 = Last_Status_Register^3;
282 sbit Last_Status_error_code3 = Last_Status_Register^4;
283 sbit Last_Status_setup_packet = Last_Status_Register^5;
284 sbit Last_Status_data_1 = Last_Status_Register^6;
285 sbit Last_Status_prestatus_not_read = Last_Status_Register^7;
286
287 //***************** 延時x毫秒函數 ***********
288 void delay(unsigned int x)
289 {
290 1 unsigned int i;
291 1 unsigned int j;
292 1 for(i=0;i<x;i++)
293 1 for(j=0;j<230;j++);
294 1 }
295 //********************************************
296
297
298 void write_usb_command(unsigned char usb_command) //寫USB命令
299 {
300 1 USB_A0=USB_COMMAND_ADD;
C51 COMPILER V7.06 USB 03/02/2006 23:51:19 PAGE 6
301 1 USB_DATA=usb_command;
302 1 USB_WR=0;
303 1 USB_WR=1;
304 1 USB_DATA=0xFF;
305 1 }
306
307 void write_a_usb_data(unsigned char usb_data) //寫一字節USB數據
308 {
309 1 USB_A0=USB_DATA_ADD;
310 1 USB_DATA=usb_data;
311 1 USB_WR=0;
312 1 USB_WR=1;
313 1 USB_DATA=0XFF;
314 1 }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -