?? hpi32.lst
字號(hào):
450 1 }
451
452
453 unsigned char WriteFile32(unsigned long writeLength,unsigned char *pBuffer)
454 {
455 1 unsigned long cnum;
456 1 unsigned int len,sector,i,tlen;
457 1 unsigned char bSuccess,bStop;
458 1
459 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
460 1 return FALSE;
461 1 if(!ThisFile.bFileOpen)
462 1 return FALSE;
463 1 ThisFile.bFileOpen=0;
464 1 bSuccess=1;
465 1 bStop=0;
466 1 tlen=0;
467 1
468 1 while(writeLength>0)
469 1 {
470 2 if(ThisFile.SectorofCluster>=DeviceInfo.BPB_SecPerClus)
471 2 {
472 3 ThisFile.SectorofCluster=0;
473 3 ThisFile.ClusterPointer=CreateClusterLink32(ThisFile.ClusterPointer);
474 3 if(ThisFile.ClusterPointer==0x00)
475 3 return FALSE;
476 3 ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.ClusterPointer);
477 3 }
478 2
479 2 if(writeLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
480 2 len=DeviceInfo.BPB_BytesPerSec;
481 2 else
482 2 len=writeLength+ThisFile.OffsetofSector;
483 2
484 2 //////////////////////////////////////////////////////
485 2 if(ThisFile.OffsetofSector>0)
486 2 {
487 3 if(SdReadSector(ThisFile.SectorPointer,1,DBUF))
488 3 {
489 4
C51 COMPILER V7.00 HPI32 01/15/2008 09:38:32 PAGE 9
490 4 len=len-ThisFile.OffsetofSector;
491 4 for(i=0;i<len;i++)
492 4 DBUF[ThisFile.OffsetofSector+i]=*(pBuffer+i);
493 4 if(!SdWriteSector(ThisFile.SectorPointer,1,DBUF))
494 4 return FALSE;
495 4 ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
496 4 }
497 3 else
498 3 return FALSE;
499 3 }
500 2 else
501 2 {
502 3 if(!SdWriteSector(ThisFile.SectorPointer,1,pBuffer+tlen))
503 3 return FALSE;
504 3 ThisFile.OffsetofSector=len;
505 3 }
506 2 /////////////////////////////////////////////////////
507 2 writeLength-=len;
508 2 tlen+=len;
509 2 /////////////更新文件指針 //////////////////////////////
510 2 if(ThisFile.OffsetofSector>=DeviceInfo.BPB_BytesPerSec)
511 2 {
512 3 ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
513 3 ThisFile.SectorofCluster++;
514 3
515 3 ThisFile.SectorPointer++;
516 3 }
517 2
518 2
519 2 }//end while
520 1 ThisFile.pointer+=tlen;
521 1 ///////////更新文件目錄信息/////////////////////////////
522 1 if(bSuccess==1)
523 1 {
524 2 NowCluster32=DirStartCluster32;
525 2 do
526 2 {
527 3 NowSector=FirstSectorofCluster32(NowCluster32);
528 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
529 3 {
530 4 if(!SdReadSector(NowSector+sector,1,DBUF))
531 4 return FALSE;
532 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
533 4 {
534 5 cnum=LSwapINT32(DBUF[i+26],DBUF[i+27],DBUF[i+20],DBUF[i+21]);
535 5 if((cnum==ThisFile.StartCluster)&&(DBUF[i]!=0xe5))
536 5 {
537 6 if(ThisFile.pointer>ThisFile.LengthInByte)
538 6 ThisFile.LengthInByte=ThisFile.pointer;
539 6 DBUF[i+28]=(unsigned char)(ThisFile.LengthInByte&0xff);
540 6 DBUF[i+29]=(unsigned char)((ThisFile.LengthInByte>>8)&0xff);
541 6 DBUF[i+30]=(unsigned char)((ThisFile.LengthInByte>>16)&0xff);
542 6 DBUF[i+31]=(unsigned char)((ThisFile.LengthInByte>>24)&0xff);
543 6 if(!SdWriteSector(NowSector+sector,1,DBUF))
544 6 return FALSE;
545 6 bStop=1;
546 6 break;
547 6 }
548 5 }
549 4 if(bStop==1)break;
550 4 }
551 3 if(bStop==1)break;
C51 COMPILER V7.00 HPI32 01/15/2008 09:38:32 PAGE 10
552 3 NowCluster32=GetNextClusterNum32(NowCluster32);
553 3 }while(NowCluster32<=DeviceInfo.TotCluster);
554 2
555 2 if(NowCluster32>DeviceInfo.TotCluster)
556 2 return FALSE;
557 2 }
558 1
559 1 ThisFile.bFileOpen=1;
560 1 //////////////////////////////////////////////
561 1 return TRUE;
562 1 }
563
564
565 unsigned char RemoveFile32(unsigned char *pBuffer)
566 {
567 1 unsigned int sector,i;
568 1 unsigned char bStop,j;
569 1 int k;
570 1
571 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
572 1 return FALSE;
573 1 ////////////// 清除目錄/////////////////////////////////////
574 1 NowCluster32=DirStartCluster32;
575 1 do
576 1 {
577 2 NowSector=FirstSectorofCluster32(NowCluster32);
578 2 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
579 2 {
580 3 if(!SdReadSector(NowSector+sector,1,DBUF))
581 3 return FALSE;
582 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
583 3 {
584 4 if(DBUF[i]==0x00)
585 4 return FALSE;
586 4 j=0;
587 4 while(DBUF[i+j]==*(pBuffer+j))
588 4 {
589 5 j=j+1;
590 5 if(j>10)
591 5 break;
592 5 }
593 4 if(j>10)
594 4 {
595 5 DBUF[i]=0xE5;
596 5 ThisFile.StartCluster=LSwapINT32(DBUF[i+26],DBUF[i+27],DBUF[i+20],DBUF[i+21]);
597 5 for(k=(i-32);k>=0;k=k-32)
598 5 {
599 6 if(DBUF[k+11]==0x0F)
600 6 DBUF[k]=0xE5;
601 6 else
602 6 break;
603 6 }
604 5 DelayMs(15);
605 5 if(!SdWriteSector(NowSector+sector,1,DBUF))
606 5 return FALSE;
607 5 //////////////////// 清除FAT中的紀(jì)錄////////////////////////
608 5 DelayMs(10);
609 5 if(!DeleteClusterLink32(ThisFile.StartCluster))
610 5 return FALSE;
611 5 bStop=1;
612 5 break;
613 5 }
C51 COMPILER V7.00 HPI32 01/15/2008 09:38:32 PAGE 11
614 4 }
615 3 if(bStop==1)break;
616 3 }
617 2 if(bStop==1)break;
618 2 NowCluster32=GetNextClusterNum32(NowCluster32);
619 2 }while(NowCluster32<=DeviceInfo.TotCluster);
620 1
621 1 if(NowCluster32>DeviceInfo.TotCluster)
622 1 return FALSE;
623 1
624 1 return TRUE;
625 1 }
626
627
628 unsigned char GetCapacity32(void)
629 {
630 1 unsigned int sectorNum,i;
631 1 unsigned long FreeSize,Freesectorcnt;
632 1
633 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
634 1 return FALSE;
635 1
636 1 ////////////////////////////////////////////////////////////////////////
637 1 sectorNum=DeviceInfo.FatStartSector;
638 1 Freesectorcnt=0;
639 1 while(sectorNum<DeviceInfo.BPB_FATSz32+DeviceInfo.FatStartSector)
640 1 {
641 2
642 2 if(SdReadSector(sectorNum,1,DBUF))
643 2 {
644 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+4)
645 3 {
646 4 if((DBUF[i]||DBUF[i+1]||DBUF[i+2]||DBUF[i+3])==0x00)
647 4 {
648 5 Freesectorcnt++;
649 5 }
650 4 }
651 3 }
652 2 else
653 2 return FALSE;
654 2 sectorNum++;
655 2 }
656 1
657 1 ////////////////////////////////////////////////////////////////////////
658 1 FreeSize=DeviceInfo.BPB_BytesPerSec*DeviceInfo.BPB_SecPerClus;
659 1 FreeSize=Freesectorcnt*FreeSize;
660 1
661 1 UARTBUF[0]=(unsigned char)((FreeSize>>24)&0xff);
662 1 UARTBUF[1]=(unsigned char)((FreeSize>>16)&0xff);
663 1 UARTBUF[2]=(unsigned char)((FreeSize>>8)&0xff);
664 1 UARTBUF[3]=(unsigned char)(FreeSize&0xff);
665 1 Response.len=4;
666 1 return TRUE;
667 1 }
668
669
670 unsigned char CreateDir32(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
671 {
672 1 unsigned int sector,i,j,DirCount;
673 1 unsigned long cnum;
674 1 unsigned char xdata bstop,InByte,bwrite;
675 1 unsigned long ClusterPointer;
C51 COMPILER V7.00 HPI32 01/15/2008 09:38:32 PAGE 12
676 1
677 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -