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