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