📄 usb.lst
字号:
164
165 9,
166 4,
167 0, //the index of the interface descriptor Number of Interface
168 0, //Value used to select alternative setting
169 2, //EndPoint Number Used in this Descriptor
170 8, //Class Code (Assigned by USB Org)
171 6, //interface subclass1=RBC,2=SFF,3=QIC,4=UFI,5=SFF,6=SCSI
172 0x50, //bulk 0nly Transport
173 0, //Index of String Descriptor Describing this interface
174
175 //Bulk-in Endpoint
176 0x07, //length of this desc.
177 0x05, //ENDPOINT descriptor TYPE
178 0x81, //address (IN) Endpoint 4 84
179 0x02, //attributes (BULK)
C51 COMPILER V7.50 USB 03/08/2005 10:46:21 PAGE 4
180 0x40, 0x00, //max packet size (64)
181 0x0, //Does not apply to Bulk endpoints
182
183 //Bulk-out Endpoint
184 0x07, //length of this desc.
185 0x05, //ENDPOINT descriptor TYPE
186 0x02, //address (OUT) Endpoint 5 05
187 0x02, //attributes (BULK)
188 0x40, 0x00, //max packet size (64)
189 0x0 //Does not apply to Bulk endpoints
190 };
191
192 void Get_Descriptor(unsigned char DesType,unsigned char nLength) //得到描述符
193 {
194 if(DesType==0x01) //取设备描述符
195 WriteEp(0,18,Device_Descriptor);
196
197 if((DesType==0x02)&&(nLength==0x09)) //取端口描述符
198 WriteEp(0,9,Configuration_Descriptor_All);
199
200 if((DesType==0x02)&&(nLength==0xff)) //取端点描述符
201 {
202 WriteEp(0,32,Configuration_Descriptor_All);
203 WriteEp(0,2,&Device_Descriptor[4]);
204 }
205
206 if((DesType==0x02)&&(nLength==0x20))
207 WriteEp(0,32,Configuration_Descriptor_All); //取配置描述符
208 }
209
210 void Set_Configuration(unsigned char wValue) //设置配置
211 {
212 if(wValue == 0)
213 {
214 UEPNUM=0x00; UEPCONX=0x80;
215 UEPNUM=0x01; UEPCONX=0x86;
216 UEPNUM=0x02; UEPCONX=0x82;
217 USBCON&=(~CONFG);
218 WriteEp(0,0,0); //状态传送阶段之前完成指定操作
219 }
220 else if(wValue == 1)
221 {
222 UEPNUM=0x00; UEPCONX=0x80;
223 UEPNUM=0x01; UEPCONX=0x86;
224 UEPNUM=0x02; UEPCONX=0x82;
225 USBCON|=CONFG;
226 WriteEp(0,0,0); //状态传送阶段之前完成指定操作
227 }
228 }
229
230 void Ep0() //---端点0处理主函数
231 {
232 unsigned char data DT[32]={0,};
233 unsigned char data i;
234 i = ReadEp(0,DT);
235 if (((DT[0] & 0x60)==0) && i)
236 {
237 switch (DT[1])
238 {
239 case set_address :Set_Address(DT[2]); break; //设置地址
240 case get_descriptor :Get_Descriptor(DT[3],DT[6]); break; //取描述符
241 case set_configuration :Set_Configuration(DT[2]); break; //设置配置
C51 COMPILER V7.50 USB 03/08/2005 10:46:21 PAGE 5
242 default :; break;
243 }
244 }
245 else if(DT[0]==0xa1) //非标准USB请求
246 {
247 WriteEp(0,0,0);
248 }
249 }
250
251 //-----------------------------------------------------------------------------/
252 // 以下为利用Bulk_Only传输协议的函数部分 //
253 //-----------------------------------------------------------------------------/
254 unsigned char data bulk_CSW[]={0x55,0x53,0x42,0x53, // bytes 4 dCSWSignature
255 0x00,0x00,0x00,0x00, //bytes 4 dCSWTag
256 0x00,0x00,0x00,0x00, //bytes 4 dDataResiduce
257 0x00}; //bCSWStatus 00=good state.
258
259 typedef struct _STRUCT_CBW
260 {
261 unsigned char CBWCB[12]; //for UFI Command all have 12bit
262
263 } struct_CBW;
264
265 struct_CBW data bulk_CBW;
266
267 void WriteEpBulk(unsigned char EpNum,unsigned char nLength,unsigned char *Data)
268 {
269 unsigned char data i;
270 UEPNUM=EpNum; //---设置端点号
271 UEPSTAX|=DIR; //...设置为In模式
272 for(i=0;i<nLength;i++) UEPDATX=Data[i]; //---填缓冲区
273 UEPSTAX|=TXRDY; //---发送数据
274 }
275
276 void TransmitCSW() //向Host返回CSW
277 {
278 WriteEpBulk(1, sizeof(bulk_CSW), bulk_CSW);
279 while(!(UEPSTAX&TXCMP)) ;
280 UEPSTAX&=(~(TXCMP)); //清除TXCMP
281 UEPINT = 0;
282 }
283
284 void main_txdone() //数据发送完毕给出回复
285 {
286 UEPSTAX&=(~(TXCMP)); //清除TXCMP
287 TransmitCSW();
288 }
289
290 //////////////////////////////////有关输出端点的调用//////////////////////////////////////////////
291 #define Inquiry 0x12
292 #define Mode_Sense 0x1A
293 #define Read10 0x28
294 #define Read_Capacity 0x25
295 #define Read_Format_Capacities 0x23
296 #define Test_Unit_Ready 0x00
297 #define Verify 0x2F
298 #define Write10 0x2A
299 #define Medium_Removal 0x1E
300
301 #define SCSI_MSPGCD_TPP 0x1C
302 #define SCSI_MSPGCD_RETALL 0x3F
303
C51 COMPILER V7.50 USB 03/08/2005 10:46:21 PAGE 6
304 //SCSI-Inquiry命令的返回数据
305 code unsigned char B_InquiryData[] = {
306 0x00, //Direct Access Device
307 0x80, //RMB
308 0x00, //ISO/ECMA/ANSI
309 0x01, //Response Data Format
310 0x1f, //Additional Length
311 0x00, //Reserved
312 0x00, //Reserved
313 0x00, //Reserved
314 'U', 'P', '-', 'T', 'E', 'C', 'H', ' ', //Vendor Information
315 'M', 'P', '3', ' ', 'P', 'l', 'a', 'y', 'e', 'r', ' ', 'V', '3', '.', '0', '0',//Product Identifica
-tion
316 0, 0, 0, 0}; //Product Revision Level n.nn
317
318 //SCSI-Read_Format_capacities命令的返回数据
319 code unsigned char B_Read_Format_capacities[] = {0x00, 0x00, 0x00, 0x10, //capacity list header
320 0x00, 0x00, 0x07, 0xf5, 0x01, 0x00, 0x02, 0x00, //capacity descriptor
321 //Number of Blocks =2037,unformatted media,blocklength = 512Bytes
322 0x00, 0x00, 0x07, 0xfd, 0x00, 0x00, 0x02, 0x00 //Formattable Capacity Descriptors
323 };
324 //SCSI-Read_Capacity命令的返回数据
325 code unsigned char B_Read_Capacity[] = {
326 0x00, 0x00, 0xfe, 0xa0, //Last Logical Block Address for 32MB
327 0x00, 0x00, 0x02, 0x00 //block length in bytes
328 };
329 //SCSI-Mode_Sense命令的返回数据
330 code unsigned char B_Mode_Sense_ALL[] = {0x0b, 0x00, //Mode Data Length
331 0x00, 0x08, 0x00, 0x00,
332 0x7d, 0, 0, 0, 0x02, 0x00
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -