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