📄 hpi.lst
字号:
638 {
639 1 unsigned int len,sector,i,cnum,tlen;
640 1 unsigned char bSuccess,bStop;
641 1
642 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
643 1 return FALSE;
644 1 if(!ThisFile.bFileOpen)
645 1 return FALSE;
646 1 ThisFile.bFileOpen=0;
647 1 bSuccess=1;
648 1 bStop=0;
649 1 tlen=0;
650 1
651 1 while(writeLength>0)
652 1 {
653 2 if(ThisFile.SectorofCluster>=DeviceInfo.BPB_SecPerClus)
654 2 {
655 3 ThisFile.SectorofCluster=0;
656 3 ThisFile.ClusterPointer=CreateClusterLink(ThisFile.ClusterPointer);
657 3 if(ThisFile.ClusterPointer==0x00)
658 3 return FALSE;
659 3 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer);
660 3 }
661 2
662 2 if(writeLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
663 2 len=DeviceInfo.BPB_BytesPerSec;
664 2 else
665 2 len=writeLength+ThisFile.OffsetofSector;
666 2
667 2 //////////////////////////////////////////////////////
668 2 if(ThisFile.OffsetofSector>0)
669 2 {
670 3 if(SdReadSector(ThisFile.SectorPointer,1,DBUF))
671 3 {
672 4
673 4 len=len-ThisFile.OffsetofSector;
674 4 for(i=0;i<len;i++)
675 4
C51 COMPILER V7.00 HPI 01/15/2008 09:38:31 PAGE 12
676 4 DBUF[ThisFile.OffsetofSector+i]=*(pBuffer+i);
677 4 if(!SdWriteSector(ThisFile.SectorPointer,1,DBUF))
678 4 return FALSE;
679 4 ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
680 4 }
681 3 else
682 3 return FALSE;
683 3 }
684 2 else
685 2 {
686 3 if(!SdWriteSector(ThisFile.SectorPointer,1,pBuffer+tlen))
687 3 return FALSE;
688 3 ThisFile.OffsetofSector=len;
689 3 }
690 2 /////////////////////////////////////////////////////
691 2 writeLength-=len;
692 2 tlen+=len;
693 2 /////////////更新文件指针 //////////////////////////////
694 2 if(ThisFile.OffsetofSector>=DeviceInfo.BPB_BytesPerSec)
695 2 {
696 3 ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
697 3 ThisFile.SectorofCluster++;
698 3
699 3 ThisFile.SectorPointer++;;
700 3 }
701 2
702 2
703 2 }//end while
704 1 ThisFile.pointer+=tlen;
705 1 DelayMs(200);
706 1 ///////////更新文件目录信息/////////////////////////////
707 1 if(bSuccess==1)
708 1 {
709 2 if(DirStartCluster==0)
710 2 {
711 3 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
712 3 {
713 4 //////////////////////////////////////////////////
714 4 if(!SdReadSector(DeviceInfo.RootStartSector+sector,1,DBUF))
715 4 return FALSE;
716 4 ///////////////////////////////////////////////////
717 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
718 4 {
719 5 cnum=LSwapINT16(DBUF[i+26],DBUF[i+27]);
720 5 if((cnum==ThisFile.StartCluster)&&(DBUF[i]!=0xe5))
721 5 {
722 6 if(ThisFile.pointer>ThisFile.LengthInByte)
723 6 ThisFile.LengthInByte=ThisFile.pointer;
724 6 DBUF[i+28]=(unsigned char)(ThisFile.LengthInByte&0xff);
725 6 DBUF[i+29]=(unsigned char)((ThisFile.LengthInByte>>8)&0xff);
726 6 DBUF[i+30]=(unsigned char)((ThisFile.LengthInByte>>16)&0xff);
727 6 DBUF[i+31]=(unsigned char)((ThisFile.LengthInByte>>24)&0xff);
728 6 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
729 6 return FALSE;
730 6 bStop=1;
731 6 break;
732 6 }
733 5 }
734 4 if(bStop==1)
735 4 break;
736 4 }
737 3 }
C51 COMPILER V7.00 HPI 01/15/2008 09:38:31 PAGE 13
738 2 //////////////////////////////////////////////////////////////////////////////
739 2 else
740 2 {
741 3 NowCluster=DirStartCluster;
742 3 do
743 3 {
744 4 NowSector=FirstSectorofCluster(NowCluster);
745 4 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
746 4 {
747 5 if(!SdReadSector(NowSector+sector,1,DBUF))
748 5 return FALSE;
749 5 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
750 5 {
751 6 cnum=LSwapINT16(DBUF[i+26],DBUF[i+27]);
752 6 if((cnum==ThisFile.StartCluster)&&(DBUF[i]!=0xe5))
753 6 {
754 7 if(ThisFile.pointer>ThisFile.LengthInByte)
755 7 ThisFile.LengthInByte=ThisFile.pointer;
756 7 DBUF[i+28]=(unsigned char)(ThisFile.LengthInByte&0xff);
757 7 DBUF[i+29]=(unsigned char)((ThisFile.LengthInByte>>8)&0xff);
758 7 DBUF[i+30]=(unsigned char)((ThisFile.LengthInByte>>16)&0xff);
759 7 DBUF[i+31]=(unsigned char)((ThisFile.LengthInByte>>24)&0xff);
760 7 if(!SdWriteSector(NowSector+sector,1,DBUF))
761 7 return FALSE;
762 7 bStop=1;
763 7 break;
764 7 }
765 6 }
766 5 if(bStop==1)break;
767 5 }
768 4 if(bStop==1)break;
769 4 NowCluster=GetNextClusterNum(NowCluster);
770 4 }while(NowCluster<=0xffef);
771 3
772 3 if(NowCluster>0xffef)
773 3 return FALSE;
774 3 }
775 2 }
776 1
777 1 ThisFile.bFileOpen=1;
778 1 //////////////////////////////////////////////
779 1 return TRUE;
780 1 }
781
782 unsigned char RemoveFile(unsigned char *pBuffer)
783 {
784 1 unsigned int sector,i;
785 1 unsigned char bStop,j;
786 1 int k;
787 1
788 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
789 1 return FALSE;
790 1 if(DirStartCluster==0)
791 1 {
792 2 ////////////// 清除目录/////////////////////////////////////
793 2 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
794 2 {
795 3 //////////////////////////////////////////////////
796 3 if(!SdReadSector(DeviceInfo.RootStartSector+sector,1,DBUF))
797 3 return FALSE;
798 3 ///////////////////////////////////////////////////
799 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
C51 COMPILER V7.00 HPI 01/15/2008 09:38:31 PAGE 14
800 3 {
801 4 if(DBUF[i]==0x00)
802 4 return FALSE;
803 4 ///////////////////////////////////////////
804 4 j=0;
805 4 while(DBUF[i+j]==*(pBuffer+j))
806 4 {
807 5 j=j+1;
808 5 if(j>10) break;
809 5 }
810 4
811 4 if(j>10)
812 4 {
813 5 DBUF[i]=0xE5;
814 5 ThisFile.StartCluster=LSwapINT16(DBUF[i+26],DBUF[i+27]);
815 5
816 5 for(k=(i-32);k>=0;k=k-32)
817 5 {
818 6 if(DBUF[k+11]==0x0F)
819 6 DBUF[k]=0xE5;
820 6 else
821 6 break;
822 6 }
823 5 DelayMs(15);
824 5 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
825 5 return FALSE;
826 5 /*
827 5 k=sector-1;
828 5 if(k>=0)
829 5 {
830 5 if(!SdReadSector(DeviceInfo.RootStartSector+k,1,DBUF))
831 5 return FALSE;
832 5 for(k=DeviceInfo.BPB_BytesPerSec;k>=0;k=k-32)
833 5 {
834 5 if(DBUF[k+11]==0x0F)
835 5 DBUF[k]=0xE5;
836 5 else
837 5 break;
838 5 }
839 5 // DelayMs(15);
840 5 if(!SdWriteSector(DeviceInfo.RootStartSector+sector-1,1,DBUF))
841 5 return FALSE;
842 5 }
843 5 */
844 5 //////////////////// 清除FAT中的纪录////////////////////////
845 5 DelayMs(10);
846 5 if(!DeleteClusterLink(ThisFile.StartCluster))
847 5 return FALSE;
848 5 bStop=1;
849 5 break;
850 5 }
851 4
852 4 }//end for
853 3 if(bStop==1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -