📄 hpi.lst
字号:
854 3 break;
855 3
856 3 }//end search
857 2 if(sector>=DeviceInfo.BPB_RootEntCnt)
858 2 return FALSE;
859 2 }
860 1 else
861 1 {
C51 COMPILER V7.00 HPI 01/15/2008 09:38:31 PAGE 15
862 2 NowCluster=DirStartCluster;
863 2 do
864 2 {
865 3 NowSector=FirstSectorofCluster(NowCluster);
866 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
867 3 {
868 4 if(!SdReadSector(NowSector+sector,1,DBUF))
869 4 return FALSE;
870 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
871 4 {
872 5 if(DBUF[i]==0x00)
873 5 return FALSE;
874 5 j=0;
875 5 while(DBUF[i+j]==*(pBuffer+j))
876 5 {
877 6 j=j+1;
878 6 if(j>10)
879 6 break;
880 6 }
881 5 if(j>10)
882 5 {
883 6 DBUF[i]=0xE5;
884 6 ThisFile.StartCluster=LSwapINT16(DBUF[i+26],DBUF[i+27]);
885 6 for(k=(i-32);k>=0;k=k-32)
886 6 {
887 7 if(DBUF[k+11]==0x0F)
888 7 DBUF[k]=0xE5;
889 7 else
890 7 break;
891 7 }
892 6 DelayMs(15);
893 6 if(!SdWriteSector(NowSector+sector,1,DBUF))
894 6 return FALSE;
895 6 //////////////////// 清除FAT中的纪录////////////////////////
896 6 DelayMs(10);
897 6 if(!DeleteClusterLink(ThisFile.StartCluster))
898 6 return FALSE;
899 6 bStop=1;
900 6 break;
901 6 }
902 5 }
903 4 if(bStop==1)break;
904 4 }
905 3 if(bStop==1)break;
906 3 NowCluster=GetNextClusterNum(NowCluster);
907 3 }while(NowCluster<=0xffef);
908 2
909 2 if(NowCluster>0xffef)
910 2 return FALSE;
911 2 }
912 1 return TRUE;
913 1 }
914
915 unsigned char GetCapacity(void)
916 {
917 1 unsigned int sectorNum,i;
918 1 unsigned long FreeSize,Freesectorcnt;
919 1
920 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
921 1 return FALSE;
922 1
923 1 ////////////////////////////////////////////////////////////////////////
C51 COMPILER V7.00 HPI 01/15/2008 09:38:31 PAGE 16
924 1 sectorNum=DeviceInfo.FatStartSector;
925 1 Freesectorcnt=0;
926 1 while(sectorNum<DeviceInfo.BPB_FATSz16+DeviceInfo.FatStartSector)
927 1 {
928 2
929 2 if(SdReadSector(sectorNum,1,DBUF))
930 2 {
931 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+2)
932 3 {
933 4 if((DBUF[i]==0x00)&&(DBUF[i+1]==0x00))
934 4 {
935 5 Freesectorcnt++;
936 5 }
937 4 }
938 3 }
939 2 else
940 2 return FALSE;
941 2 sectorNum++;
942 2 }
943 1
944 1 ////////////////////////////////////////////////////////////////////////
945 1 FreeSize=DeviceInfo.BPB_BytesPerSec*DeviceInfo.BPB_SecPerClus;
946 1 FreeSize=Freesectorcnt*FreeSize;
947 1
948 1 UARTBUF[0]=(unsigned char)((FreeSize>>24)&0xff);
949 1 UARTBUF[1]=(unsigned char)((FreeSize>>16)&0xff);
950 1 UARTBUF[2]=(unsigned char)((FreeSize>>8)&0xff);
951 1 UARTBUF[3]=(unsigned char)(FreeSize&0xff);
952 1 Response.len=4;
953 1 return TRUE;
954 1 }
955
956 unsigned char CreateDir(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
957 {
958 1 unsigned int sector,i,j,DirCount;
959 1 unsigned int cnum,ClusterPointer;
960 1 unsigned char xdata bstop,InByte,bwrite;
961 1
962 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
963 1 return FALSE;
964 1 if((len%32)!=0)
965 1 return FALSE;
966 1 if((len+32)>DeviceInfo.BPB_BytesPerSec)
967 1 return FALSE;
968 1
969 1 ThisFile.bFileOpen=0;
970 1 ThisFile.FatSectorPointer=0;
971 1
972 1 cnum=GetFreeCusterNum();
973 1 if(cnum<0x02)
974 1 return FALSE;
975 1
976 1 pBuffer[11]=0x10;
977 1 pBuffer[26]=(unsigned char)(cnum);
978 1 pBuffer[27]=(unsigned char)(cnum>>8);
979 1 pBuffer[28]=0;pBuffer[29]=0;pBuffer[30]=0;pBuffer[31]=0;
980 1 bstop=0;
981 1
982 1 if(DirStartCluster==0)
983 1 {
984 2 /////// Search a free space in the root dir space and build the item ///
985 2 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
C51 COMPILER V7.00 HPI 01/15/2008 09:38:31 PAGE 17
986 2 {
987 3 if(!SdReadSector(DeviceInfo.RootStartSector+sector,1,DBUF))
988 3 return FALSE;
989 3 DirCount=0;bwrite=0;
990 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
991 3 {
992 4 if(len==0)
993 4 {
994 5 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
995 5 {
996 6 for(j=0;j<32;j++)
997 6 DBUF[i+j]=*(pBuffer+j);
998 6 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
999 6 return FALSE;
1000 6 bstop=1;
1001 6 break;
1002 6 }
1003 5 }
1004 4 else
1005 4 {
1006 5 if(DirCount==0)
1007 5 InByte=i;
1008 5 if(DBUF[i]==0xE5)
1009 5 DirCount++;
1010 5 else if(DBUF[i]==0x00)
1011 5 {
1012 6 DirCount++;
1013 6 DBUF[i]=0xE5;
1014 6 bwrite=1;
1015 6 }
1016 5 else
1017 5 DirCount=0;
1018 5
1019 5 if((DirCount*32)>=(len+32))
1020 5 {
1021 6 for(j=0;j<len;j++)
1022 6 DBUF[InByte+j]=*(pName+j);
1023 6
1024 6 for(j=0;j<32;j++)
1025 6 DBUF[InByte+len+j]=*(pBuffer+j);
1026 6
1027 6 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
1028 6 return FALSE;
1029 6 bstop=1;
1030 6 break;
1031 6 }
1032 5 }
1033 4 }
1034 3 if(bstop==1)break;
1035 3
1036 3 if((len!=0)&&(bwrite==1))
1037 3 {
1038 4 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
1039 4 return FALSE;
1040 4 }
1041 3 }
1042 2
1043 2 if(sector>=DeviceInfo.BPB_RootEntCnt)
1044 2 return FALSE;
1045 2 }
1046 1 ////////////////////////////////////////////////////////////
1047 1 else
C51 COMPILER V7.00 HPI 01/15/2008 09:38:31 PAGE 18
1048 1 {
1049 2 NowCluster=DirStartCluster;
1050 2 do
1051 2 {
1052 3 NowSector=FirstSectorofCluster(NowCluster);
1053 3 ClusterPointer=NowCluster;
1054 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
1055 3 {
1056 4 if(!SdReadSector(NowSector+sector,1,DBUF))
1057 4 return FALSE;
1058 4 DirCount=0;bwrite=0;
1059 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
1060 4 {
1061 5 if(len==0)
1062 5 {
1063 6 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
1064 6 {
1065 7 for(j=0;j<32;j++)
1066 7
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -