📄 fat32.lst
字号:
C51 COMPILER V7.00 FAT32 10/27/2006 00:20:29 PAGE 1
C51 COMPILER V7.00, COMPILATION OF MODULE FAT32
OBJECT MODULE PLACED IN Fat32.OBJ
COMPILER INVOKED BY: e:\Keil\C51\BIN\C51.EXE Fat32.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include "common.h"
2 #include "Fat.h"
3 #include "Fat32.h"
4 #include "DEVICE.H"
5 #include "HAL.H"
6 ////////////////////////////////////////
7 extern SYS_INFO_BLOCK xdata DeviceInfo;
8 extern FILE_INFO xdata ThisFile;
9 extern unsigned char xdata DBUF[];//BUFFER_LENGTH];
10 extern unsigned char xdata FATBUF[512];
11 ////////////////////////////////////////
12
13 unsigned long FirstSectorofCluster32(unsigned long clusterNum)
14 {
15 1 unsigned long temp;
16 1 temp=clusterNum-2;
17 1 temp=temp*DeviceInfo.BPB_SecPerClus;
18 1 temp=temp+DeviceInfo.FirstDataSector;
19 1 return temp;
20 1 }
21
22 unsigned long ThisFatSecNum32(unsigned long clusterNum)
23 {
24 1 unsigned long temp;
25 1 temp=clusterNum/(DeviceInfo.BPB_BytesPerSec/4);
26 1 temp=temp+DeviceInfo.FatStartSector;
27 1 return temp;
28 1 }
29
30 unsigned long ThisFatEntOffset32(unsigned long clusterNum)
31 {
32 1 return (clusterNum%(DeviceInfo.BPB_BytesPerSec/4))*4;
33 1 }
34
35 unsigned long GetNextClusterNum32(unsigned long clusterNum)
36 {
37 1 unsigned long FatSecNum,FatEntOffset;
38 1
39 1 FatSecNum=ThisFatSecNum32(clusterNum);
40 1 FatEntOffset=ThisFatEntOffset32(clusterNum);
41 1 if(ThisFile.FatSectorPointer!=FatSecNum)
42 1 {
43 2
44 2 if(!SdReadSector(FatSecNum,1,FATBUF))
45 2 return 0xFFFFFFFF;
46 2 ThisFile.FatSectorPointer=FatSecNum;
47 2 }
48 1
49 1 ///////////////////////////////////////////////////
50 1 clusterNum=LSwapINT32(FATBUF[FatEntOffset],FATBUF[FatEntOffset+1],FATBUF[FatEntOffset+2],FATBUF[FatEntOff
-set+3]);
51 1 return clusterNum;
52 1 }
53
54 unsigned char GoToPointer32(unsigned long pointer)
C51 COMPILER V7.00 FAT32 10/27/2006 00:20:29 PAGE 2
55 {
56 1
57 1 unsigned int clusterSize;
58 1
59 1 clusterSize=DeviceInfo.BPB_SecPerClus*DeviceInfo.BPB_BytesPerSec;
60 1 ThisFile.ClusterPointer=ThisFile.StartCluster;
61 1 while(pointer>clusterSize)
62 1 {
63 2 pointer-=clusterSize;
64 2 ThisFile.ClusterPointer=GetNextClusterNum32(ThisFile.ClusterPointer);
65 2 if(ThisFile.ClusterPointer==0xffffffff)
66 2 {
67 3 return FALSE;
68 3 }
69 2 }
70 1 ThisFile.SectorofCluster=pointer/DeviceInfo.BPB_BytesPerSec;
71 1 ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.ClusterPointer)+ThisFile.SectorofCluster;
72 1 ThisFile.OffsetofSector=pointer%DeviceInfo.BPB_BytesPerSec;
73 1 ThisFile.FatSectorPointer=0;
74 1 return TRUE;
75 1
76 1 }
77
78 unsigned char DeleteClusterLink32(unsigned long clusterNum)
79 {
80 1 unsigned long FatSecNum,FatEntOffset;
81 1 unsigned char i;
82 1 while((clusterNum>1)&&(clusterNum<DeviceInfo.TotCluster))
83 1 {
84 2 FatSecNum=ThisFatSecNum32(clusterNum);
85 2 FatEntOffset=ThisFatEntOffset32(clusterNum);
86 2 if(SdReadSector(FatSecNum,1,DBUF))
87 2 {
88 3 if(clusterNum<DeviceInfo.LastFreeCluster) DeviceInfo.LastFreeCluster=clusterNum;
89 3 clusterNum=LSwapINT32(DBUF[FatEntOffset],DBUF[FatEntOffset+1],DBUF[FatEntOffset+2],DBUF[FatEntOffset+3]
-);
90 3 }
91 2 else
92 2 return FALSE;
93 2 DBUF[FatEntOffset]=0x00;DBUF[FatEntOffset+1]=0x00;DBUF[FatEntOffset+2]=0x00;DBUF[FatEntOffset+3]=0x00;
94 2 for(i=0;i<DeviceInfo.BPB_NumFATs;i++)
95 2 {
96 3 DelayMs(5);
97 3 if(!SdWriteSector(FatSecNum+i*DeviceInfo.BPB_FATSz32,1,DBUF))
98 3 return FALSE;
99 3 }
100 2 }
101 1 return TRUE;
102 1 }
103
104 unsigned long GetFreeCusterNum32(void)
105 {
106 1 unsigned long xdata clusterNum,i;
107 1 unsigned long xdata sectorNum;
108 1 unsigned char xdata j;
109 1 sectorNum=ThisFatSecNum32(DeviceInfo.LastFreeCluster);
110 1 clusterNum=(sectorNum-DeviceInfo.FatStartSector)*(DeviceInfo.BPB_BytesPerSec/4);
111 1
112 1 while(sectorNum<DeviceInfo.BPB_FATSz32+DeviceInfo.FatStartSector)
113 1 {
114 2 if(!SdReadSector(sectorNum,1,DBUF))
115 2 return 0x0;
C51 COMPILER V7.00 FAT32 10/27/2006 00:20:29 PAGE 3
116 2 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+4)
117 2 {
118 3 if((DBUF[i]==0)&&(DBUF[i+1]==0)&&(DBUF[i+2]==0)&&(DBUF[i+3]==0))
119 3 {
120 4 DBUF[i]=0xff;DBUF[i+1]=0xff;DBUF[i+2]=0xff;DBUF[i+3]=0xff;
121 4 for(j=0;j<DeviceInfo.BPB_NumFATs;j++)
122 4 {
123 5 DelayMs(5);
124 5 if(!SdWriteSector(sectorNum+j*DeviceInfo.BPB_FATSz32,1,DBUF))
125 5 return FALSE;
126 5 }
127 4 clusterNum=clusterNum+i/4;
128 4 if((clusterNum-2)<DeviceInfo.TotCluster)
129 4 {
130 5 if(clusterNum>DeviceInfo.LastFreeCluster) DeviceInfo.LastFreeCluster=clusterNum;
131 5 return clusterNum;
132 5 }
133 4 else return FALSE;
134 4 }
135 3 }
136 2 clusterNum+=DeviceInfo.BPB_BytesPerSec/4;
137 2 sectorNum++;
138 2 DelayMs(1);
139 2 }
140 1 return 0x0;
141 1 }
142
143 unsigned long CreateClusterLink32(unsigned long currentCluster)
144 {
145 1 unsigned long xdata newCluster;
146 1 unsigned long xdata FatSecNum,FatEntOffset;
147 1 unsigned char xdata i;
148 1
149 1 newCluster=GetFreeCusterNum32();
150 1
151 1 FatSecNum=ThisFatSecNum32(currentCluster);
152 1 FatEntOffset=ThisFatEntOffset32(currentCluster);
153 1 if(SdReadSector(FatSecNum,1,DBUF))
154 1 {
155 2 DBUF[FatEntOffset]=newCluster;
156 2 DBUF[FatEntOffset+1]=newCluster>>8;
157 2 DBUF[FatEntOffset+2]=newCluster>>16;
158 2 DBUF[FatEntOffset+3]=newCluster>>24;
159 2 for(i=0;i<DeviceInfo.BPB_NumFATs;i++)
160 2 {
161 3 DelayMs(5);
162 3 if(!SdWriteSector(FatSecNum+i*DeviceInfo.BPB_FATSz32,1,DBUF))
163 3 return FALSE;
164 3 }
165 2 }
166 1 else
167 1 return 0x00;
168 1
169 1 return newCluster;
170 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2311 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- 26
PDATA SIZE = ---- ----
C51 COMPILER V7.00 FAT32 10/27/2006 00:20:29 PAGE 4
DATA SIZE = ---- 55
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -