📄 bulk_only.lst
字号:
179 1
180 1
181 1 bulk_CSW[4] = Bulk_Out_Buf[4];
182 1 bulk_CSW[5] = Bulk_Out_Buf[5];
183 1 bulk_CSW[6] = Bulk_Out_Buf[6];
184 1 bulk_CSW[7] = Bulk_Out_Buf[7];
185 1
186 1 // for(i=0;i<4;i++) bulk_CBW.dCBWDataTransferLength = (bulk_CBW.dCBWDataTransferLength<<8) +*(EpBuf+11-i);
187 1 // bulk_CBW.bmCBWFlags = *(EpBuf+12);
188 1 // bulk_CBW.bCBWLUN = *(EpBuf+13)&0x0f;
189 1 // bulk_CBW.bCBWCBLength = *(EpBuf+14)&0x1f;
190 1
191 1 for (i=0; i<12; i++)
192 1 bulk_CBW.CBWCB [i] = Bulk_Out_Buf[i+15];
193 1 // printu("\n\nSCSI:");
194 1 // for(j=0;j<12;j++) {printuf("%x ",bulk_CBW.CBWCB[j]);}
195 1
196 1 switch (bulk_CBW.CBWCB[0])
197 1 {
198 2 // case 0x04 : UFI_Reserved(); break;
199 2 case Inquiry : UFI_Inquiry(); break;
200 2 // case 0x55 : UFI_Reserved();break;
201 2 case Mode_Sense : UFI_Mode_Sense(); break;
202 2 case Read10 : UFI_Read10(); break;
203 2 // case 0xA8 : UFI_Reserved();break;
204 2 case Read_Capacity : UFI_Read_Capacity(); break;
205 2 case Read_Format_Capacities : UFI_Read_Format_Capacities(); break;
206 2 // case 0x03 : UFI_Reserved();break;
207 2 // case 0x01 : UFI_Reserved();break;
208 2 // case 0x2B : UFI_Reserved();break;
209 2 // case 0x1D : UFI_Reserved();break;
210 2 // case 0x1B : UFI_Reserved();break;
211 2 case Test_Unit_Ready : UFI_Test_Unit_Ready(); break;
212 2 case Verify : UFI_Verify(); break;
213 2 case Write10 : UFI_Write10(); break;
214 2 // case 0xAA : UFI_Reserved(); break;
215 2 // case 0x2E : UFI_Reserved(); break;
216 2 case Medium_Removal : UFI_Medium_Removal(); break;
217 2 default : UFI_Reserved(); break;
218 2 }
219 1
220 1 }
221
222 void UFI_Inquiry()
223 {
224 1 if (bulk_CBW.CBWCB[4] == 0)
225 1 return;
226 1 bulk_state = BULK_DATA_END;
227 1 WriteEpBulk(1, sizeof (B_InquiryData), B_InquiryData);
228 1
229 1 }
230
231
232 void UFI_Read_Format_Capacities()
233 {
234 1 if (bulk_CBW.CBWCB[7] == 0 && bulk_CBW.CBWCB[8] == 0)
235 1 return;
236 1 bulk_state = BULK_DATA_END;
237 1 WriteEpBulk(1, sizeof (B_Read_Format_capacities), B_Read_Format_capacities);
238 1
239 1 }
240
C51 COMPILER V7.50 BULK_ONLY 03/16/2006 09:11:14 PAGE 5
241
242 void UFI_Read_Capacity()
243 {
244 1
245 1 bulk_state = BULK_DATA_END;
246 1 WriteEpBulk(1, sizeof (B_Read_Capacity), B_Read_Capacity);
247 1
248 1 }
249
250 void UFI_Read10()
251 {
252 1 int i;
253 1 // printu("UFI_Read10__1\n");
254 1
255 1 for (i=0; i<4; i++)
256 1 {
257 2 Logical_Block_Address = (Logical_Block_Address << 8) + bulk_CBW.CBWCB[2 + i];//要传的数据的起始簇
258 2 }
259 1 Transfer_Length = bulk_CBW.CBWCB[7] * 256 + bulk_CBW.CBWCB[8]; //要传的扇区数
260 1
261 1 nCurrentPage = Logical_Block_Address % 0x20; //由逻辑地址块取真实扇区
262 1 nCurrentBlock = Logical_Block_Address = Logical_Block_Address / 0x20 + Root_Cluster; //由逻辑地址块取簇
263 1
264 1
265 1 nBufCount = 0; //传送数据当前位置
266 1
267 1 ReadPage(Logical_Block_Address, nCurrentPage, Page_Buf);
268 1
269 1 Transfer_Length--;
270 1 nCurrentPage++; //指向下一扇区
271 1
272 1 bulk_state = BULK_DATA_TRANS;
273 1 pCurrentBuf = Page_Buf;
274 1
275 1 WriteEpBulk(1, 64, pCurrentBuf);//传第一个64字节
276 1
277 1 }
278
279 void TransDataGoOn()
280 {
281 1 // int i;
282 1 if (nBufCount < 0x1c0)
283 1 { //如果一个扇区未传完
284 2 nBufCount += 0x40;
285 2 WriteEpBulk(1, 64, pCurrentBuf + nBufCount);
286 2 }
287 1
288 1 else if (Transfer_Length > 0)
289 1 { //如果总扇区未传完,
290 2
291 2 if (nCurrentPage == 0x20)
292 2 {
293 3 nCurrentBlock++;
294 3 nCurrentPage = 0;
295 3 }
296 2
297 2 ReadPage(nCurrentBlock, nCurrentPage, Page_Buf); //读新的一个扇区
298 2 nCurrentPage++; //指向下一扇区
299 2 Transfer_Length--;
300 2
301 2
302 2 nBufCount = 0; //重新计另一扁区
C51 COMPILER V7.50 BULK_ONLY 03/16/2006 09:11:14 PAGE 6
303 2 pCurrentBuf = Page_Buf;
304 2 bulk_state = BULK_DATA_TRANS;
305 2 WriteEpBulk(1, 64, pCurrentBuf); //写第一次
306 2 }
307 1
308 1 else
309 1 {
310 2 bulk_state = BULK_DATA_END;
311 2
312 2 nBufCount =0; //重新计另一扁区
313 2 TransmitCSW();
314 2 }
315 1 }
316
317 void UFI_Write10()
318 {
319 1 int i;
320 1 for (i=0; i<4; i++)
321 1 {
322 2 Logical_Block_Address = (Logical_Block_Address << 8) + bulk_CBW.CBWCB[2 + i]; //要传的数据的起始簇
323 2 }
324 1 Transfer_Length = bulk_CBW.CBWCB[7] * 256 + bulk_CBW.CBWCB[8]; //要传的扇区数
325 1
326 1 nBeginPage = nCurrentPage = Logical_Block_Address % 0x20; //由逻辑地址块取真实扇区
327 1 nCurrentBlock = Logical_Block_Address = Logical_Block_Address / 0x20 + Root_Cluster; //由逻辑地址块取簇
328 1
329 1
330 1 bulk_state = BULK_DATA_RECIEVE;
331 1 // Erase_Cluster(3);//Erase The Buf
332 1 if ((nCurrentBlock < 6) || nBeginPage) Erase_Cluster(2040);//Erase The Buf
333 1 else Erase_Cluster(nCurrentBlock);//Erase The Block to be write
334 1 }
335
336
337 void Trans_Data2PC()
338 {
339 1 int i;
340 1 // printuf("E:%x\n",nBufCount/0x40);
341 1 memcpy(Page_Buf + nBufCount, Bulk_Out_Buf, 64);//将Bulk_Out端点中的64bytes的数据移入528的Page_buf中共8次
342 1 dDataResiduce -= 0x40;
343 1 nBufCount += 0x40;
344 1
345 1
346 1
347 1 // if((Transfer_Length==1) &&(dDataResiduce==0x40)) WriteEpBulk(1, sizeof(bulk_CSW), bulk_CSW);
348 1
349 1 if (((nBufCount%0x200 == 0) && nBufCount >= 0x200) \
350 1 || (nBufCount == 0x00))
351 1 {
352 2
353 2 if ((nCurrentBlock<6) || nBeginPage)
354 2 {
355 3 WritePage(2040, nCurrentPage, Page_Buf);
356 3 }
357 2 else
358 2 {
359 3 WritePage(nCurrentBlock, nCurrentPage, Page_Buf);//Write to Flash Directlly
360 3 }
361 2
362 2
363 2 nCurrentPage++; //指向下一扇区
364 2 Transfer_Length--; //已传输扇区减1
C51 COMPILER V7.50 BULK_ONLY 03/16/2006 09:11:14 PAGE 7
365 2 nBufCount = 0; //准备下一个扇区接
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -