📄 fat.lst
字号:
399 4 return(1);
400 4 }*/
401 4 else
402 4 {
403 5 if( --FileData.wCurFDBNo >= (U16)FileData.RootDirNum)
404 5 FileData.wCurFDBNo = (U16)FileData.RootDirNum - 1;
C51 COMPILER V8.08 FAT 07/28/2007 11:42:16 PAGE 8
405 5 if((FileData.wCurFDBNo & 0x0F) == 0x0F)
406 5 flag = 0;
407 5 }
408 4 }
409 3 else
410 3 {
411 4 if( --FileData.wCurFDBNo >= (U16)FileData.RootDirNum)
412 4 FileData.wCurFDBNo = (U16)FileData.RootDirNum - 1;
413 4 if((FileData.wCurFDBNo & 0x0F) == 0x0F)
414 4 flag = 0;
415 4 }
416 3 }
417 2 //CFatData.fRet = FATERR_NO_FILE;
418 2 return KO;
419 2 }
420 1 }
421 /************************************************
422 函 数 名: ReadRootCluster()
423 功 能:读FAT32根目录簇链表
424 说 明:
425 调 用:
426 全局变量:
427 入口参数:无
428 出口参数:无
429 返 回 值:
430 ************************************************/
431 void ReadRootCluster(void)
432 {
433 1 bit flag = 0;
434 1 U8 index = 0;
435 1 U32 p;
436 1 //U32 p1;
437 1
438 1 FileData.RootDirNum = 1;
439 1 rootclusters[index].cluster = CFatData.dwRootStartCluNo;
440 1 rootclusters[index].number = 1;
441 1
442 1 /*FATTab.dwCurCluNo*/varAl.TmpLong = CFatData.dwRootStartCluNo;
443 1
444 1 while(1)
445 1 {
446 2 if(!flag)
447 2 {
448 3 /*FileData.Temp*/p = (/*FATTab.dwCurCluNo*/varAl.TmpLong << FATTab.bShiftBits)/ (U32)CFatData.wBytes
-PerSec;
449 3 /*FileData.Temp*/p += CFatData.dwFatTabStartlba;
450 3 DMA_load_sector(/*FileData.Temp*/p, 0x05);
451 3 flag = 1;
452 3 }
453 2 p = CharToLong((U8 xdata *)(0xE000 + ((U16)(/*FATTab.dwCurCluNo*/varAl.TmpLong << FATTab.bShiftBits) & (U
-16)0x01FF))) & CFatData.dwMask;
454 2 if(p == CFatData.dwMask)
455 2 break;
456 2 if(p == /*FATTab.dwCurCluNo*/varAl.TmpLong + 1)
457 2 {
458 3 rootclusters[index].number++;
459 3 FileData.RootDirNum++;
460 3 }
461 2 else
462 2 {
463 3 index++;
464 3 if(index >= MAX_FILE_FRAGMENT_NUMBER)
C51 COMPILER V8.08 FAT 07/28/2007 11:42:16 PAGE 9
465 3 break;
466 3 rootclusters[index].cluster = p;
467 3 rootclusters[index].number = 1;
468 3 FileData.RootDirNum++;
469 3 }
470 2
471 2 if((p & (~(((U32)CFatData.wBytesPerSec >> FATTab.bShiftBits) - 1)))
472 2 != (/*FATTab.dwCurCluNo*/varAl.TmpLong & (~(((U32)CFatData.wBytesPerSec >> FATTab.bShiftBits) - 1)))
-)
473 2 flag = 0;
474 2 /*FATTab.dwCurCluNo*/varAl.TmpLong = p;
475 2 }
476 1 }
477 /************************************************
478 函 数 名: ReadFileFAT()
479 功 能:读文件簇链表
480 说 明:
481 调 用:
482 全局变量:
483 入口参数:无
484 出口参数:无
485 返 回 值:
486 ************************************************/
487 void ReadFileFAT(void)
488 {
489 1 bit flag = 0;
490 1 U8 index = 0;
491 1 U32 p;
492 1 // U32 p1;
493 1
494 1 fclusters[index].cluster = FileData.dwFileStartCluNo;
495 1 fclusters[index].number = 1;
496 1
497 1 /*FATTab.dwCurCluNo*/varAl.TmpLong = FileData.dwFileStartCluNo;
498 1
499 1 while(1)
500 1 {
501 2 if(!flag)
502 2 {
503 3 /*FileData.Temp*/p = (/*FATTab.dwCurCluNo*/varAl.TmpLong << FATTab.bShiftBits)/ (U32)CFatData.wBytes
-PerSec;
504 3 /*FileData.Temp*/p += CFatData.dwFatTabStartlba;
505 3 DMA_load_sector(/*FileData.Temp*/p, 0x05);
506 3 flag = 1;
507 3 }
508 2 p = CharToLong((U8 xdata *)(0xE000 + ((U16)(/*FATTab.dwCurCluNo*/varAl.TmpLong << FATTab.bShiftBits) & (U
-16)0x01FF))) & CFatData.dwMask;
509 2 if(p == CFatData.dwMask)
510 2 break;
511 2 if(p == /*FATTab.dwCurCluNo*/varAl.TmpLong + 1)
512 2 fclusters[index].number++;
513 2 else
514 2 {
515 3 index++;
516 3 if(index >= MAX_FILE_FRAGMENT_NUMBER)
517 3 break;
518 3 fclusters[index].cluster = p;
519 3 fclusters[index].number = 1;
520 3 }
521 2
522 2 if((p & (~(((U32)CFatData.wBytesPerSec >> FATTab.bShiftBits) - 1)))
523 2 != (/*FATTab.dwCurCluNo*/varAl.TmpLong & (~(((U32)CFatData.wBytesPerSec >> FATTab.bShiftBits) - 1)))
C51 COMPILER V8.08 FAT 07/28/2007 11:42:16 PAGE 10
-)
524 2 flag = 0;
525 2 /*FATTab.dwCurCluNo*/varAl.TmpLong = p;
526 2 }
527 1 }
528 /************************************************
529 函 数 名: ReadSector()
530 功 能:
531 说 明:
532 调 用:
533 全局变量:
534 入口参数:无
535 出口参数:无
536 返 回 值:
537 ************************************************/
538 void ReadSector(U32 logic_position,U8 DMA_CS)
539 {
540 1 U8 index;
541 1 U32 p;
542 1 /*if(CFatData.fFAT32)
543 1 {
544 1 //FAT32
545 1 #if TX_DEBUG
546 1 //SendChar(0xC2);
547 1 #endif
548 1
549 1 }
550 1 else*/
551 1 {
552 2 //FAT16
553 2 /*FileData.Temp*/p = logic_position % CFatData.bSectorsPerClu;
554 2 logic_position /= CFatData.bSectorsPerClu;
555 2
556 2 for(index = 0; index < MAX_FILE_FRAGMENT_NUMBER; index++)
557 2 {
558 3 if(logic_position < fclusters[index].number)
559 3 {
560 4 logic_position = fclusters[index].cluster + logic_position;
561 4 break;
562 4 }
563 3 else
564 3 {
565 4 logic_position -= fclusters[index].number;
566 4 }
567 3 }
568 2
569 2 logic_position = CFatData.dwClu2Startlba + (logic_position - 2)* (U32)CFatData.bSectorsPerClu + /*FileDat
-a.Temp*/p;
570 2 if(!DMA_load_sector(logic_position, DMA_CS))
571 2 DMA_load_sector(logic_position, DMA_CS);
572 2 }
573 1 }
574 /************************************************
575 函 数 名: CreateFile()
576 功 能:
577 说 明:
578 调 用:
579 全局变量:
580 入口参数:无
581 出口参数:无
582 返 回 值:
583 ************************************************/
C51 COMPILER V8.08 FAT 07/28/2007 11:42:16 PAGE 11
584 #if TX_DEBUG
585 void CreateFile(void)
586 {
587 1 bit flag = 0;
588 1 U8 index;
589 1 U32 p;
590 1 U32 position;
591 1
592 1 //在根目录中搜索是否已存在该文件夹
593 1 if(CFatData.fFAT32)
594 1 {
595 2 //FAT32
596 2 FileData.dwCurCluNo = 0;
597 2 FileData.wCurFDBNo = 0;
598 2 for(;FileData.dwCurCluNo < FileData.RootDirNum;)
599 2 {
600 3 p = FileData.dwCurCluNo;
601 3 for(index = 0; index < MAX_FILE_FRAGMENT_NUMBER; index++)
602 3 {
603 4 if(p < rootclusters[index].number)
604 4 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -