📄 ufi.lst
字号:
C51 COMPILER V8.08 UFI 04/25/2009 23:03:20 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE UFI
OBJECT MODULE PLACED IN UFI.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE UFI.C LARGE OMF2 BROWSE DEBUG
line level source
1 //************************************************************************
2 //author:dragon
3 //web:8dragon.com
4 //2004.2.5完成于桃龙源
5 //*************************************************************************
6 #include <c8051F020.h>
7 #include "host_811.h"
8 #include "ufi.h"
9 #include <stdio.h>
10 BLOCK idata BlockCommand;
11 extern idata USBDEV uDev;
12 extern BYTE bBUF[256];
13 //*********************************************************************
14 //*底层的批量传输函数
15 //*********************************************************************
16 BYTE BulkOut(BYTE *pbBuffer,UINT len,UINT lba)
17 {
18 1 WORD j;
19 1
20 1 ////////////////////////////////////////////////////////////////////////
21 1 lba = lba;
22 1 while(len>0)
23 1 {
24 2 if (len >64)
25 2 j = 64;
26 2 else
27 2 j= len;
28 2 if(!usbXfer(0x01,uDev.bEpOut,PID_OUT,64,j,pbBuffer))
29 2 return FALSE;
30 2 len-=j;
31 2 pbBuffer=pbBuffer+j;
32 2 }
33 1
34 1 return TRUE;
35 1 }
36 BYTE BulkIn(BYTE *pbBuffer,UINT len)
37 {
38 1 BYTE i;
39 1 ////////////////////////////////////////////////////////////////////////
40 1 if(len)
41 1 {
42 2 i=2;
43 2 while(!usbXfer(0x01,uDev.bEpin,PID_IN,64,len,pbBuffer))
44 2 {
45 3 i--;
46 3 }
47 2 if(i<=0)
48 2 return FALSE;
49 2 }
50 1 return TRUE;
51 1 }
52 //**********************************************************************
53 //获取U盘的硬件信息
54 //**********************************************************************
55 BYTE Inquiry(void)
C51 COMPILER V8.08 UFI 04/25/2009 23:03:20 PAGE 2
56 {
57 1 BlockCommand.CbwBlock.dCBW_Signature=CBW_SIGNATURE;
58 1 BlockCommand.CbwBlock.dCBW_Tag=0x60a624de;
59 1 BlockCommand.CbwBlock.dCBW_DataXferLen=0x24000000;
60 1 BlockCommand.CbwBlock.bCBW_Flag=0x80;
61 1 BlockCommand.CbwBlock.bCBW_LUN=0;
62 1 BlockCommand.CbwBlock.bCBW_CDBLen=sizeof(INQUIRY);
63 1 //-----------------------------------------------------------------
64 1 //包含在CBWCB中的Inquiry命令
65 1 //------------------------------------------------------------------
66 1 BlockCommand.CbwBlock.CBWCommand.Ufi_Inquiry.OperationCode=UFI_CMD_INQUIRY;
67 1 BlockCommand.CbwBlock.CBWCommand.Ufi_Inquiry.Reserved0=0;
68 1 BlockCommand.CbwBlock.CBWCommand.Ufi_Inquiry.PageCode=0;
69 1 BlockCommand.CbwBlock.CBWCommand.Ufi_Inquiry.AllocationLen=0x24;
70 1 DelayMs(20);
71 1 if(!BulkOut((BYTE *)&BlockCommand.CbwBlock,sizeof(BlockCommand.CbwBlock),TRUE))
72 1 return FALSE;
73 1 DelayMs(20);
74 1 if(!BulkIn(bBUF,38))
75 1 return FALSE;
76 1 if(!BulkIn((BYTE *)&BlockCommand.CswBlock,13))
77 1 return FALSE;
78 1 return TRUE;
79 1 }
80 //**********************************************************************
81 //测试U盘是否可用www.8dragon.com
82 //**********************************************************************
83 BYTE TestUnit(void)
84 {
85 1 BlockCommand.CbwBlock.dCBW_Signature=CBW_SIGNATURE;
86 1 BlockCommand.CbwBlock.dCBW_Tag=0x60a624de;
87 1 BlockCommand.CbwBlock.dCBW_DataXferLen=0x00000000;
88 1 BlockCommand.CbwBlock.bCBW_Flag=0x00;
89 1 BlockCommand.CbwBlock.bCBW_LUN=0;
90 1 BlockCommand.CbwBlock.bCBW_CDBLen=sizeof(TEST_UNIT);
91 1 //-----------------------------------------------------------------
92 1 //包含在CBWCB中的TestUnit命令
93 1 //------------------------------------------------------------------
94 1 BlockCommand.CbwBlock.CBWCommand.Ufi_TestUnit.OperationCode=UFI_CMD_TESTUNITREADY;
95 1 DelayMs(70);
96 1 if(!BulkOut((BYTE *)&BlockCommand.CbwBlock,sizeof(BlockCommand.CbwBlock),TRUE))
97 1 return FALSE;
98 1 DelayMs(150);
99 1 if(!BulkIn((BYTE *)&BlockCommand.CswBlock,13))
100 1 return FALSE;
101 1 return TRUE;
102 1 }
103 //**********************************************************************
104 //让U盘传回必要数据
105 //**********************************************************************
106 BYTE RequestSense(void)
107 {
108 1 BlockCommand.CbwBlock.dCBW_Signature=CBW_SIGNATURE;
109 1 BlockCommand.CbwBlock.dCBW_Tag=0x60a624de;
110 1 BlockCommand.CbwBlock.dCBW_DataXferLen=0x0e000000;
111 1 BlockCommand.CbwBlock.bCBW_Flag=0x80;
112 1 BlockCommand.CbwBlock.bCBW_LUN=0;
113 1 BlockCommand.CbwBlock.bCBW_CDBLen=sizeof(REQUEST_SENSE);
114 1 //-----------------------------------------------------------------
115 1 //包含在CBWCB中的RSEQUESTSENS命令
116 1 //------------------------------------------------------------------
117 1 BlockCommand.CbwBlock.CBWCommand.Ufi_RequestSense.OperationCode=UFI_CMD_REQUESTSENSE;
C51 COMPILER V8.08 UFI 04/25/2009 23:03:20 PAGE 3
118 1 BlockCommand.CbwBlock.CBWCommand.Ufi_RequestSense.AllocationLen=0x0e;
119 1 DelayMs(45);
120 1 if(!BulkOut((BYTE *)&BlockCommand.CbwBlock,sizeof(BlockCommand.CbwBlock),0))
121 1 return FALSE;
122 1 DelayMs(45);
123 1 if(!BulkIn((BYTE *)bBUF,18))
124 1 return FALSE;
125 1 DelayMs(45);
126 1 if(!BulkIn((BYTE *)&BlockCommand.CswBlock,13))
127 1 return FALSE;
128 1 return TRUE;
129 1 }
130 //**********************************************************************
131 //读取已格U盘的容量
132 //**********************************************************************
133 BYTE ReadCapacity(void)
134 {
135 1 BlockCommand.CbwBlock.dCBW_Signature=CBW_SIGNATURE;
136 1 BlockCommand.CbwBlock.dCBW_Tag=0x60a624de;
137 1 BlockCommand.CbwBlock.dCBW_DataXferLen=0x08000000;
138 1 BlockCommand.CbwBlock.bCBW_Flag=0x80;
139 1 BlockCommand.CbwBlock.bCBW_LUN=0;
140 1 //BlockCommand.CbwBlock.CBW_CDBLen=sizeof(READ_CAPACITY);
141 1 BlockCommand.CbwBlock.bCBW_CDBLen=sizeof(READ_CAPACITY);
142 1 //-----------------------------------------------------------------
143 1 //包含在CBWCB中的READCAPACITY命令
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -