📄 bulk_only.lst
字号:
C51 COMPILER V7.07 BULK_ONLY 11/20/2006 17:50:24 PAGE 1
C51 COMPILER V7.07, COMPILATION OF MODULE BULK_ONLY
OBJECT MODULE PLACED IN bulk_only.OBJ
COMPILER INVOKED BY: D:\Program Files\keil\C51\BIN\C51.EXE bulk_only.c LARGE BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*
2 * All rights reserved.
3 *
4 * 文件名称:bulk_only.c
5 * 文件标识:bulk_only
6 * 摘 要:批量传输函数定义
7 *
8 * 当前版本:
9 * 作 者:
10 * 完成日期:
11 *
12 *
13 */
14
15 //this file to process the request about bulk_only
16 #include <string.h>
17
18 #include "bulk_only.h"
19 #include "fat16.h"
20 #include "usbdisk.h"
21 #include "uart.h"
22 #include "flash.h"
23 #include "atmelusbci.h"
24
25 //extern unsigned char EpBuf[];
26 unsigned char *BulkPoint = 0;
27 unsigned char *BulkStartPoint = 0;
28 long unsigned int dDataResiduce = 0;//USB传输过程中,未传完的剩余数据
29 unsigned char bulk_state = 0; //当前传送状态
30 unsigned char *pCurrentBuf; //数据传送指针
31 long int nBufCount = 0; //传送数据当前位置
32
33
34 //unsigned char MSC_dCBWSignature[] = {0x55, 0x53, 0x42, 0x43};
35 //unsigned char MSC_dCSWSignature[] = {0x55, 0x53, 0x42, 0x53};
36
37 //以下是SCSI命令的命令字与其代码的对应表
38 #define Format_Unit 0x04
39 #define Inquiry 0x12
40 #define Mode_Select 0x55
41 #define Mode_Sense 0x1A
42 #define Medium_Removal 0x1E
43 #define Read10 0x28
44 #define Read12 0xA8
45 #define Read_Capacity 0x25
46 #define Read_Format_Capacities 0x23
47 #define Request_Sense 0x03
48 #define Rezero 0x01
49 #define Seek10 0x2B
50 #define Send_Diag 0x1D
51 #define Start_Stop_Unit 0x1B
52 #define Test_Unit_Ready 0x00
53 #define Verify 0x2F
54 #define Write10 0x2A
55 #define Write12 0xAA
C51 COMPILER V7.07 BULK_ONLY 11/20/2006 17:50:24 PAGE 2
56 #define Write_And_Verify 0x2E
57 /****************************************/
58
59
60
61 #define SCSI_MSPGCD_TPP 0x1c
62 #define SCSI_MSPGCD_RETALL 0x3f
63
64 //unsigned char Bulk_Out_Buf[64]; //64字节的端点缓存
65 unsigned char Page_Buf[512]; //512字节的页缓存
66 unsigned int Fat_Buf[544] _at_ 0x320;//1024字节的FAT表缓存
67
68 short int Transfer_Length; //要传送的扁区长度
69 long int Logical_Block_Address; //逻辑地址
70 long int nCurrentPage, nBeginPage; //当前扇区和超始扇区
71 long int nCurrentBlock; //当前Block
72
73 //SCSI-Inquiry命令的返回数据
74 code unsigned char B_InquiryData[] = {
75 0x00, //Direct Access Device
76 0x80, //RMB
77 0x00, //ISO/ECMA/ANSI
78 0x01, //Response Data Format
79 0x1f, //Additional Length
80 0x00, //Reserved
81 0x00, //Reserved
82 0x00, //Reserved
83 'C', 'Q', 'I', 'T', ' ', 'W', 'W', 'L', //Vendor Information
84 'M', 'P', '3', ' ', 'P', 'l', 'a', 'y', 'e', 'r', ' ', 'V', '1', '.', '0', '0',//Product Identifica
-tion
85 0, 0, 0, 0}; //Product Revision Level n.nn
86
87
88 //code unsigned char CapactiyLstHd[]={0x00,0x00,0x00,0x10};
89 //code unsigned char bBlockLength[]={0x00,0x02,0x00}; //512 Byte
90 //code unsigned char nLastLBAddr[]={0x00,0x01,0xf3,0xff}; //Last Logical Block Address for 64MB
91
92 //SCSI-Read_Format_capacities命令的返回数据
93 code unsigned char B_Read_Format_capacities[] = {0x00, 0x00, 0x00, 0x10, //capacity list header
94 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, //capacity descriptor
95 // Number of Blocks =1024,unformatted media,blocklength = 512Bytes
96 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00 //Formattable Capacity Descriptors
97 };
98 //SCSI-Read_Capacity命令的返回数据
99 code unsigned char B_Read_Capacity[] = {
100 0x00, 0x00, 0xff, 0xe0, //Last Logical Block Address for 64MB
101 0x00, 0x00, 0x02, 0x00 //block length in bytes
102 };
103
104 //SCSI-Mode_Sense命令的返回数据
105 code unsigned char B_Mode_Sense_ALL[] = {0x0b, 0x00,//Mode Data Length
106 0x00, 0x08, 0x00, 0x00,
107 0x7d, 0, 0, 0, 0x02, 0x00
108 };
109
110 //SCSI-Mode_Sense命令的返回数据
111 code unsigned char B_Mode_Sense_TPP[] = {0xf0, 0x00,//Mode Data Length
112 05, 00, 00, 00, 00, 0x0b, 00, 00, 00, 00, 0x24, 00, 00, 00, 00, 00
113 };
114 //SCSI-Mode_Sense命令的返回数据
115 code unsigned char B_Mode_Sense_ZERO[] = {0x00, 0x06,//Mode Data Length
116 0x00, //Medium Type Code
C51 COMPILER V7.07 BULK_ONLY 11/20/2006 17:50:24 PAGE 3
117 0,//write enabled
118 0, 0, 0, 0//reserved
119 };
120
121
122
123 typedef struct _STRUCT_CBW
124 {
125 unsigned char dCBWSignature[4];
126 unsigned char dCBWTag[4]; //dCBWTag of CBW
127 long unsigned int dCBWDataTransferLength;//dCBWDataTransferLength of CBW
128 unsigned char bmCBWFlags;
129 unsigned char bCBWLUN;
130 unsigned char bCBWCBLength;
131 unsigned char CBWCB[12];//for UFI Command all have 12bit
132 } struct_CBW ;
133
134 struct_CBW bulk_CBW;
135 //CSW数据内容,默认都为Good Status
136 unsigned char bulk_CSW[13] = {0x55, 0x53, 0x42, 0x53, // bytes 4 dCSWSignature
137 0x00, 0x00, 0x00, 0x00, //bytes 4 dCSWTag
138 0, 0, 0, 0, //bytes 4 dDataResiduce
139 0x00}; //bCSWStatus 00=good state.
140
141
142 //解析CBW块的数据内容
143 void InterpretCBW()
144 {
145 1 int i;
146 1 // printu("InterpretCBW");
147 1
148 1 //保存dCSWTag
149 1 bulk_CSW[4] = *(BulkStartPoint + 4);
150 1 bulk_CSW[5] = *(BulkStartPoint + 5);
151 1 bulk_CSW[6] = *(BulkStartPoint + 6);
152 1 bulk_CSW[7] = *(BulkStartPoint + 7);
153 1
154 1 //读取CBWCB
155 1 for (i=0; i<12; i++)
156 1 {
157 2 bulk_CBW.CBWCB[i] = *(BulkStartPoint + i + 15);
158 2 }
159 1
160 1 switch (bulk_CBW.CBWCB[0])
161 1 {//根据各个不同的命令字,处理相应的命令
162 2 // case 0x04 : UFI_Reserved(); break;
163 2 case Inquiry : UFI_Inquiry(); break;
164 2 // case 0x55 : UFI_Reserved(); break;
165 2 case Mode_Sense : UFI_Mode_Sense(); break;
166 2 case Read10 : UFI_Read10(); break;
167 2 // case 0xA8 : UFI_Reserved(); break;
168 2 case Read_Capacity : UFI_Read_Capacity(); break;
169 2 case Read_Format_Capacities : UFI_Read_Format_Capacities(); break;
170 2 // case 0x03 : UFI_Reserved(); break;
171 2 // case 0x01 : UFI_Reserved(); break;
172 2 // case 0x2B : UFI_Reserved(); break;
173 2 // case 0x1D : UFI_Reserved(); break;
174 2 // case 0x1B : UFI_Reserved(); break;
175 2 case Test_Unit_Ready : UFI_Test_Unit_Ready(); break;
176 2 case Verify : UFI_Verify(); break;
177 2 case Write10 : UFI_Write10(); break;
178 2 // case 0xAA : UFI_Reserved(); break;
C51 COMPILER V7.07 BULK_ONLY 11/20/2006 17:50:24 PAGE 4
179 2 // case 0x2E : UFI_Reserved(); break;
180 2 case Medium_Removal : UFI_Medium_Removal(); break;
181 2 default : UFI_Reserved(); break;
182 2 }
183 1
184 1 }
185
186
187 void UFI_Inquiry()
188 {
189 1 if (bulk_CBW.CBWCB[4] == 0)
190 1 return;
191 1
192 1 bulk_state = BULK_DATA_END;//置传输状态为Bulk_Data_End,当这个阶段完成后,程序会接着传送CSW,符合USB协议要求
193 1 WriteEpBulk(1, sizeof (B_InquiryData), B_InquiryData);//向Bulk-In端点写入数据
194 1
195 1 }
196
197
198 void UFI_Read_Format_Capacities()
199 {
200 1 if (bulk_CBW.CBWCB[7] == 0 && bulk_CBW.CBWCB[8] == 0)
201 1 return;
202 1
203 1 bulk_state = BULK_DATA_END;//置传输状态为Bulk_Data_End
204 1 WriteEpBulk(1, sizeof (B_Read_Format_capacities), B_Read_Format_capacities);//向Bulk-In端点写入数据
205 1
206 1 }
207
208
209 void UFI_Read_Capacity()
210 {
211 1
212 1 bulk_state = BULK_DATA_END;//置传输状态为Bulk_Data_End
213 1 WriteEpBulk(1, sizeof (B_Read_Capacity), B_Read_Capacity);//向Bulk-In端点写入数据
214 1
215 1 }
216
217 void UFI_Mode_Sense()
218 {
219 1 dDataResiduce = bulk_CBW.dCBWDataTransferLength;
220 1 bulk_state = BULK_DATA_END;//置传输状态为Bulk_Data_End
221 1
222 1 if (bulk_CBW.CBWCB[2] == SCSI_MSPGCD_TPP)
223 1 { //Page Code=Timer and Potect Page
224 2 WriteEpBulk(1, sizeof (B_Mode_Sense_TPP), B_Mode_Sense_TPP);
225 2 }
226 1 else if(bulk_CBW.CBWCB[2] == SCSI_MSPGCD_RETALL)
227 1 { //Page Code=All
228 2 WriteEpBulk(1, sizeof (B_Mode_Sense_ALL), B_Mode_Sense_ALL);
229 2 }
230 1 else
231 1 { //Page Code=Zero
232 2 WriteEpBulk(1, sizeof (B_Mode_Sense_ZERO), B_Mode_Sense_ZERO);
233 2 }
234 1 }
235
236 void UFI_Read10()
237 {
238 1 int i;
239 1 // printu("UFI_Read10__1\n");
240 1
C51 COMPILER V7.07 BULK_ONLY 11/20/2006 17:50:24 PAGE 5
241 1 for (i=0; i<4; i++)
242 1 {
243 2 Logical_Block_Address = (Logical_Block_Address << 8) + bulk_CBW.CBWCB[2 + i]; //要传的数据的起始簇
244 2 }
245 1
246 1 Transfer_Length = bulk_CBW.CBWCB[7] * 256 + bulk_CBW.CBWCB[8]; //要传的扇区数
247 1
248 1 nCurrentPage = Logical_Block_Address % 0x20; //由逻辑地址块取真实扇区
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -