📄 ufi.lst
字号:
144 1 //------------------------------------------------------------------
145 1 BlockCommand.CbwBlock.CBWCommand.Ufi_ReadCapacity.OperationCode=UFI_CMD_READCAPACITY;
146 1 DelayMs(45);
147 1 if(!BulkOut((BYTE *)&BlockCommand.CbwBlock,sizeof(BlockCommand.CbwBlock),0))
148 1 return FALSE;
149 1 DelayMs(45);
150 1 if(!BulkIn((BYTE *)bBUF,8))
151 1 return FALSE;
152 1 DelayMs(45);
153 1 if(!BulkIn((BYTE *)&BlockCommand.CswBlock,13))
154 1 return FALSE;
155 1 return TRUE;
156 1 }
157 //**********************************************************************
158 //读取U盘中的数据
159 //**********************************************************************
160 BYTE Read(DWORD dlba,BYTE blen,BYTE *pbBuffer)
161 { BYTE i;
162 1 ////////////////////////////////////////////////////////////////////////
163 1 BlockCommand.CbwBlock.dCBW_Signature=CBW_SIGNATURE;
164 1 BlockCommand.CbwBlock.dCBW_Tag=0x60a624de;
165 1 BlockCommand.CbwBlock.dCBW_DataXferLen=DWordSwap(blen*512);
166 1 BlockCommand.CbwBlock.bCBW_Flag=0x80;
167 1 BlockCommand.CbwBlock.bCBW_LUN=0;
168 1 BlockCommand.CbwBlock.bCBW_CDBLen=sizeof(READ);
169 1 //-----------------------------------------------------------------
170 1 //包含在CBWCB中的READ命令
171 1 //------------------------------------------------------------------
172 1 BlockCommand.CbwBlock.CBWCommand.Ufi_Read.OperationCode=UFI_CMD_READ;
173 1 BlockCommand.CbwBlock.CBWCommand.Ufi_Read.Reserved1=0;
174 1 BlockCommand.CbwBlock.CBWCommand.Ufi_Read.LBA=dlba;
175 1 BlockCommand.CbwBlock.CBWCommand.Ufi_Read.ReadLength=blen;
176 1 DelayMs(100);
177 1 if(!BulkOut((BYTE *)&BlockCommand.CbwBlock,sizeof(BlockCommand.CbwBlock),0))
178 1 return FALSE;
179 1 i=100;
C51 COMPILER V8.08 UFI 04/25/2009 23:03:20 PAGE 4
180 1 while(i--)
181 1 {
182 2 DelayMs(1);
183 2 if(BulkIn(pbBuffer,blen*512))
184 2 break;
185 2 }
186 1 if(i==0)
187 1 return FALSE;
188 1 DelayMs(2);
189 1 if(!BulkIn((BYTE *)&BlockCommand.CswBlock,13))
190 1 return FALSE;
191 1 return TRUE;
192 1 }
193 //**********************************************************************
194 //写数据到U盘
195 //**********************************************************************
196 BYTE Write(DWORD dlba,BYTE blen,BYTE *pbBuffer,BYTE bWaitTime)
197 {
198 1 BYTE i;
199 1 ////////////////////////////////////////////////////////////////////////
200 1 BlockCommand.CbwBlock.dCBW_Signature=CBW_SIGNATURE;
201 1 BlockCommand.CbwBlock.dCBW_Tag=0xb4d977c1;
202 1 BlockCommand.CbwBlock.dCBW_DataXferLen=DWordSwap(blen*512);
203 1 BlockCommand.CbwBlock.bCBW_Flag=0x0;
204 1 BlockCommand.CbwBlock.bCBW_LUN=0;
205 1 BlockCommand.CbwBlock.bCBW_CDBLen=sizeof(WRITE);
206 1 //-----------------------------------------------------------------
207 1 //包含在CBWCB中的WRITE命令
208 1 //------------------------------------------------------------------
209 1 BlockCommand.CbwBlock.CBWCommand.Ufi_Write.OperationCode=UFI_CMD_WRITE;
210 1 BlockCommand.CbwBlock.CBWCommand.Ufi_Write.Reserved1=0;
211 1 BlockCommand.CbwBlock.CBWCommand.Ufi_Write.LBA=dlba;
212 1 BlockCommand.CbwBlock.CBWCommand.Ufi_Write.WriteLength=blen;
213 1 BlockCommand.CbwBlock.CBWCommand.Ufi_Write.Reserved2=0;
214 1 if(!BulkOut((BYTE *)&BlockCommand.CbwBlock,sizeof(BlockCommand.CbwBlock),0))
215 1 return FALSE;
216 1 DelayMs(bWaitTime);
217 1 DelayMs(200);
218 1 if(!BulkOut(pbBuffer,512*blen,dlba))
219 1 return FALSE;
220 1 i=10;
221 1 while(i--)
222 1 {
223 2 if(BulkIn((BYTE *)&BlockCommand.CswBlock,13))
224 2 break;
225 2 }
226 1 if(i==0)
227 1 return FALSE;
228 1 return TRUE;
229 1 }
230 BYTE PollDisk(void)
231 {
232 1 //也许需要延长一定的时间,在每个测试参数后面
233 1 // BYTE Cache[512];
234 1 // BYTE i;
235 1 DelayMs(100);
236 1 printf("hehe1");
237 1 if(!Inquiry())
238 1 { printf("hehe1");
239 2
240 2 return FALSE;
241 2 }
C51 COMPILER V8.08 UFI 04/25/2009 23:03:20 PAGE 5
242 1 if(!TestUnit())
243 1 { printf("hehe2");
244 2 return FALSE; }
245 1 if(!RequestSense())
246 1 { printf("hehe3");
247 2 return FALSE;}
248 1 if(!TestUnit())
249 1 { printf("hehe4");
250 2 return FALSE;}
251 1 if(!ReadCapacity())
252 1 { printf("hehe5");
253 2 return FALSE; }
254 1 if(!RequestSense())
255 1 { printf("hehe6");
256 2 return FALSE; }
257 1 if(!TestUnit())
258 1 { printf("hehe7");
259 2 return FALSE; }
260 1 if(!ReadCapacity())
261 1 { printf("hehe8");
262 2 return FALSE; }
263 1 if(!TestUnit())
264 1 { printf("hehe9");
265 2 return FALSE; }
266 1 if(!RequestSense())
267 1 { printf("hehe10");
268 2 return FALSE; }
269 1 printf("hehe11");
270 1 return TRUE;
271 1 }
272 //************************************************************************
273 //author:dragon
274 //web:8dragon.com
275 //2004.2.5完成于桃龙源
276 //*************************************************************************
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1245 ----
CONSTANT SIZE = 68 ----
XDATA SIZE = ---- 34
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = 31 ----
BIT SIZE = ---- ----
EDATA SIZE = ---- ----
HDATA SIZE = ---- ----
XDATA CONST SIZE = ---- ----
FAR CONST SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -