📄 bulk_only.lst
字号:
251 1 nCurrentPage = Logical_Block_Address % 0x20; //由逻辑地址块取真实扇区
252 1 nCurrentBlock = Logical_Block_Address = Logical_Block_Address / 0x20 + Root_Cluster; //由逻辑地址块取簇
253 1
254 1
255 1 nBufCount=0; //传送数据当前位置
256 1
257 1 ReadPage(Logical_Block_Address, nCurrentPage, Page_Buf);//读出当前簇的512个字节数据
258 1
259 1 Transfer_Length--; //传输扇区数减1
260 1 nCurrentPage++; //指向下一扇区
261 1
262 1 bulk_state = BULK_DATA_TRANS; //置传输状态为传数状态
263 1 pCurrentBuf = Page_Buf; //将当前数据缓存指针传给送数指数
264 1
265 1 WriteEpBulk(1, 64, pCurrentBuf);//传送第一个64字节
266 1 }
267
268 void TransDataGoOn()
269 {
270 1 // int i;
271 1 if (nBufCount < 0x1c0)
272 1 { //如果一个扇区数据未传完
273 2 nBufCount += 0x40; //指向下一个64字节
274 2 WriteEpBulk(1, 64, pCurrentBuf + nBufCount);//将当前64个字节传输出去
275 2 }
276 1 else if(Transfer_Length > 0)
277 1 { //如果总扇区未传完,
278 2
279 2 if(nCurrentPage == 0x20)
280 2 { //扇区数满32时,指向下一个Block
281 3 nCurrentBlock++;
282 3 nCurrentPage = 0; //扇区数重新指向0
283 3 }
284 2
285 2 ReadPage(nCurrentBlock, nCurrentPage, Page_Buf); //读新的一个扇区
286 2 nCurrentPage++; //指向下一扇区
287 2 Transfer_Length--;
288 2
289 2 nBufCount =0; //重新计另一扁区
290 2 pCurrentBuf = Page_Buf;
291 2 bulk_state = BULK_DATA_TRANS;
292 2 WriteEpBulk(1, 64, pCurrentBuf); //写第一次
293 2 }
294 1
295 1 else
296 1 {
297 2 bulk_state = BULK_DATA_END; //数据传输结束,置传输状态
298 2
299 2 nBufCount = 0; //指针复位
300 2 TransmitCSW();
301 2 }
302 1 }
C51 COMPILER V7.20 BULK_ONLY 03/21/2007 13:33:19 PAGE 6
303
304 void UFI_Write10()
305 {
306 1 int i;
307 1
308 1 for (i=0; i<4; i++)
309 1 {
310 2 Logical_Block_Address = (Logical_Block_Address << 8) + bulk_CBW.CBWCB[2 + i]; //要传的数据的起始簇
311 2 }
312 1
313 1 Transfer_Length = bulk_CBW.CBWCB[7] * 256 + bulk_CBW.CBWCB[8]; //要传的扇区数
314 1
315 1 nBeginPage = nCurrentPage = Logical_Block_Address % 0x20; //由逻辑地址块取真实扇区
316 1 nCurrentBlock = Logical_Block_Address = Logical_Block_Address/0x20 + Root_Cluster; //由逻辑地址块取簇
317 1
318 1
319 1 bulk_state = BULK_DATA_RECIEVE;//置状态为数据接收状态
320 1 //如果目标Block小于6,或是起始扇区不为零,则擦除1000Block作为缓存Erase The Buf
321 1 if ((nCurrentBlock<6)||nBeginPage)
322 1 {
323 2 Erase_Cluster(1000);//Erase The Buf
324 2 }
325 1 else
326 1 {
327 2 Erase_Cluster(nCurrentBlock);//否则直接擦除目标Blcok,准备存入数据Erase The Block to be write
328 2 }
329 1 }
330
331
332 void Trans_Data2PC()
333 {
334 1 int i;
335 1 // printuf("E:%x\n",nBufCount/0x40);
336 1 // memcpy(Page_Buf+nBufCount,Bulk_Out_Buf,64);//将Bulk_Out端点中的64bytes的数据移入512的Page_buf中共8次
337 1 // dDataResiduce -=0x40;
338 1 // nBufCount+=0x40;
339 1 nBufCount = 512;
340 1 BulkPoint = Page_Buf;//Bulk指针退回到开始
341 1 // if((Transfer_Length==1) &&(dDataResiduce==0x40)) WriteEpBulk(1, sizeof(bulk_CSW), bulk_CSW);
342 1
343 1 //如果满512字节时,
344 1 if (((nBufCount % 0x200 == 0) && nBufCount >= 0x200) || (nBufCount == 0x00))
345 1 {
346 2 //如果写前6个Block或是超始Page不为0时,则需要缓存,先将数据写入第1000Block中
347 2 if ((nCurrentBlock < 6) || nBeginPage)
348 2 {
349 3 WritePage(1000, nCurrentPage, Page_Buf);
350 3 }
351 2 else
352 2 {
353 3 WritePage(nCurrentBlock, nCurrentPage, Page_Buf);//否则,直接写入目标Block
354 3 }
355 2
356 2
357 2 nCurrentPage++; //指向下一扇区
358 2 Transfer_Length--; //已传输扇区减1
359 2 nBufCount = 0; //准备下一个扇区接收
360 2
361 2 }
362 1
363 1 // if(((Transfer_Length%0x20)==0) && (Transfer_Length>=0x20)&&(nCurrentPage == 0x20)){
364 1 if ((Transfer_Length > 0) && (nCurrentPage == 0x20))
C51 COMPILER V7.20 BULK_ONLY 03/21/2007 13:33:19 PAGE 7
365 1 {
366 2 nBufCount = 0;
367 2 // Write2Flash(nCurrentBlock,nBeginPage,nCurrentPage-1,Flash_One_Page);
368 2 if ((nCurrentBlock < 6) || nBeginPage)
369 2 {//如果采用了缓存,则需要保留部分数据
370 3 for (i=0; i<nBeginPage; i++)
371 3 {
372 4 ReadPage(nCurrentBlock, i, Page_Buf);//将起始Block以前的数据移入缓存中
373 4 WritePage(1000, i, Page_Buf);
374 4 }
375 3
376 3 Erase_Cluster(nCurrentBlock);//擦除目标Block
377 3 for (i=0; i<32; i++)
378 3 {//将缓存中的数据存入目标Block中
379 4 ReadPage(1000, i, Page_Buf);
380 4 WritePage(nCurrentBlock, i, Page_Buf);
381 4 }
382 3 }
383 2
384 2 nCurrentBlock++;//指向下一个Block
385 2 nCurrentPage = 0;
386 2 nBeginPage = 0;
387 2
388 2 // Erase_Cluster(1000);
389 2 //根据下一个Block的位置,决定是否缓存,并擦除目标位置
390 2 if ((nCurrentBlock < 6) || nBeginPage)
391 2 {
392 3 Erase_Cluster(1000);//Write One 32k Buf,Erase The Buf for next transaction
393 3 }
394 2 else
395 2 {
396 3 Erase_Cluster(nCurrentBlock);//Erase The Block to be write
397 3 }
398 2
399 2 // Uart_Printf("%x\n",Transfer_Length);
400 2 }
401 1 if (Transfer_Length == 0)
402 1 {//数据传送完毕后,将当前缓存中的所有内容写入Flash
403 2 nBufCount = 0;
404 2 // Write2Flash(nCurrentBlock,nBeginPage,nCurrentPage-1,Flash_One_Page);
405 2 if ((nCurrentBlock < 6) || nBeginPage)
406 2 {
407 3 for (i=0; i<nBeginPage; i++)
408 3 {
409 4 ReadPage(nCurrentBlock, i, Page_Buf);
410 4 WritePage(1000, i, Page_Buf);
411 4 }
412 3 for (i=nCurrentPage; i<32; i++)
413 3 {
414 4 ReadPage(nCurrentBlock, i, Page_Buf);
415 4 WritePage(1000, i, Page_Buf);
416 4 }
417 3
418 3 Erase_Cluster(nCurrentBlock);
419 3
420 3 for (i=0; i<32; i++)
421 3 {
422 4 ReadPage(1000, i, Page_Buf);
423 4 WritePage(nCurrentBlock, i, Page_Buf);
424 4 }
425 3 }
426 2
C51 COMPILER V7.20 BULK_ONLY 03/21/2007 13:33:19 PAGE 8
427 2 TransmitCSW();//向主机发送CSW
428 2 }
429 1 }
430
431
432
433 void UFI_Medium_Removal()
434 {
435 1 TransmitCSW(); //直接返回CSW
436 1 }
437
438 void UFI_Test_Unit_Ready()
439 {
440 1 TransmitCSW(); //Flash Disk are always ready!
441 1 }
442
443
444 void TransmitCSW()
445 {
446 1 unsigned char i;
447 1 // WriteEpBulk(1, sizeof(bulk_CSW), bulk_CSW); //向端点发送CSW
448 1 // bulk_state = BULK_CSW_END; //置传输状态。
449 1
450 1 UEPNUM = 1;//指向相应端点
451 1 UEPSTAX |= DIR;//设置方向为写Set for status of a Control In transaction
452 1 for (i=0; i<13; i++)
453 1 {
454 2 UEPDATX = bulk_CSW[i];//将数据写入端点
455 2 }
456 1 UEPSTAX |= TXRDY;//发送数据Sending the data,this action will switch between bank0 and bank1
457 1
458 1 bulk_state = BULK_CSW_END; //置传输状态。
459 1 }
460
461
462
463 void TransRequestGoOn()
464 {
465 1 if (dDataResiduce > 0x40)
466 1 {//如果要传送的数据大于64,则置传输状态为请求数据传送状态
467 2 dDataResiduce -= 0x40;
468 2 bulk_state = BULK_REQEST_TRANS;
469 2 nBufCount += 0x40;
470 2 WriteEpBulk(1, 64, pCurrentBuf + nBufCount);
471 2 }
472 1 else
473 1 {//如果小于64,则置数据传输完毕状态
474 2 bulk_state = BULK_DATA_END;
475 2 nBufCount += 0x40;
476 2 WriteEpBulk(1, dDataResiduce, pCurrentBuf + nBufCount);
477 2 nBufCount = 0; //prepare for nexe into
478 2 }
479 1 }
480
481
482
483 void UFI_Verify()
484 {
485 1 TransmitCSW();//直接返回CSW
486 1 }
487
488
C51 COMPILER V7.20 BULK_ONLY 03/21/2007 13:33:19 PAGE 9
489 void UFI_Reserved()
490 {
491 1 printuf("\nUFI Function 0x%x doesn't Defined!", bulk_CBW.CBWCB[0]);
492 1 TransmitCSW();
493 1
494 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2591 ----
CONSTANT SIZE = 138 ----
XDATA SIZE = 588 6
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -