📄 fat.lst
字号:
C51 COMPILER V8.01 FAT 08/28/2007 14:58:56 PAGE 1
C51 COMPILER V8.01, COMPILATION OF MODULE FAT
OBJECT MODULE PLACED IN Fat.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Fat.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include "common.h"
2 #include "Fat.h"
3 #include "SL811.H"
4 #include "TPBULK.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 unsigned char xdata FATBUF[512];
11 ////////////////////////////////////////
12 unsigned long FirstSectorofCluster(unsigned int clusterNum)
13 {
14 1 unsigned long temp;
15 1 temp=clusterNum-2;
16 1 temp=temp*DeviceInfo.BPB_SecPerClus;
17 1 temp=temp+DeviceInfo.FirstDataSector;
18 1 return temp;
19 1 }
20
21 unsigned int ThisFatSecNum(unsigned int clusterNum)
22 {
23 1 unsigned int temp;
24 1 temp=clusterNum*2;
25 1 temp=temp/DeviceInfo.BPB_BytesPerSec;
26 1 temp=temp+DeviceInfo.FatStartSector;
27 1 return temp;
28 1 }
29
30 unsigned int ThisFatEntOffset(unsigned int clusterNum)
31 {
32 1 unsigned int temp1,temp2;
33 1 temp1=2*clusterNum;
34 1 temp2=temp1/DeviceInfo.BPB_BytesPerSec;
35 1 temp1=temp1-temp2*DeviceInfo.BPB_BytesPerSec;
36 1 return temp1;
37 1 }
38
39 unsigned int GetNextClusterNum(unsigned int clusterNum)
40 {
41 1 unsigned int xxgFatSecNum,xxgFatEntOffset;
42 1
43 1 xxgFatSecNum=ThisFatSecNum(clusterNum);
44 1 xxgFatEntOffset=ThisFatEntOffset(clusterNum);
45 1 //ThisFile.FatSectorPointer=xxgFatSecNum;
46 1 if(ThisFile.FatSectorPointer!=xxgFatSecNum)
47 1 {
48 2
49 2 if(!RBC_Read(xxgFatSecNum,1,FATBUF))
50 2 return 0xFFFF;
51 2 ThisFile.FatSectorPointer=xxgFatSecNum;
52 2 }
53 1
54 1 ///////////////////////////////////////////////////
55 1 clusterNum=FATBUF[xxgFatEntOffset+1];
C51 COMPILER V8.01 FAT 08/28/2007 14:58:56 PAGE 2
56 1 clusterNum=clusterNum<<8;
57 1 clusterNum+=FATBUF[xxgFatEntOffset];
58 1 return clusterNum;
59 1 }
60
61 unsigned char DeleteClusterLink(unsigned int clusterNum)
62 {
63 1 //unsigned int nextClusterNum;
64 1 unsigned int xxgFatSecNum,xxgFatEntOffset;
65 1 //nextClusterNum=GetNextClusterNum(clusterNum);
66 1 ////////////////////////////////////////////
67 1 //nextClusterNum=clusterNum;
68 1 while((clusterNum>1)&&(clusterNum<0xfff0))
69 1 {
70 2 xxgFatSecNum=ThisFatSecNum(clusterNum);
71 2 xxgFatEntOffset=ThisFatEntOffset(clusterNum);
72 2 if(RBC_Read(xxgFatSecNum,1,DBUF))
73 2 {
74 3 clusterNum=DBUF[xxgFatEntOffset+1];
75 3 clusterNum=clusterNum<<8;
76 3 clusterNum+=DBUF[xxgFatEntOffset];
77 3 //return clusterNum;
78 3 }
79 2 else
80 2 return FALSE;
81 2 DBUF[xxgFatEntOffset]=0x00;
82 2 DBUF[xxgFatEntOffset+1]=0x00;
83 2 //DelayMs(5);
84 2 if(!RBC_Write(xxgFatSecNum,1,DBUF))
85 2 return FALSE;
86 2 //DelayMs(5);
87 2 if(!RBC_Write(xxgFatSecNum+DeviceInfo.BPB_FATSz16,1,DBUF))
88 2 return FALSE;
89 2 ////////////////////////////////////////////
90 2 }
91 1 return TRUE;
92 1 }
93
94 unsigned int GetClusterNumFromSectorNum(unsigned long sectorNum)
95 {
96 1 unsigned long temp;
97 1 temp=sectorNum-DeviceInfo.FirstDataSector;
98 1 temp=temp/DeviceInfo.BPB_SecPerClus;
99 1 temp=temp+2;
100 1 return (unsigned int)temp;
101 1 }
102 /*
103 unsigned long GetSecNumFromPointer(void)
104 {
105 unsigned int clusterNum,clusterSize;
106 unsigned long temp,pointer;
107 pointer=ThisFile.FilePointer;
108 clusterSize=DeviceInfo.BPB_SecPerClus*DeviceInfo.BPB_BytesPerSec;
109 clusterNum=ThisFile.StartCluster;
110 while(pointer>clusterSize)
111 {
112 pointer-=clusterSize;
113 clusterNum=GetNextClusterNum(clusterNum);
114 }
115 temp=FirstSectorofCluster(clusterNum)+pointer/DeviceInfo.BPB_BytesPerSec;
116 return temp;
117 }
C51 COMPILER V8.01 FAT 08/28/2007 14:58:56 PAGE 3
118 */
119 unsigned char GoToPointer(unsigned long pointer)
120 {
121 1 //unsigned char temp;
122 1 unsigned int clusterSize;
123 1 //unsigned long temp;
124 1 //pointer=ThisFile.FilePointer;
125 1 clusterSize=DeviceInfo.BPB_SecPerClus*DeviceInfo.BPB_BytesPerSec;
126 1 ThisFile.ClusterPointer=ThisFile.StartCluster;
127 1 while(pointer>clusterSize)
128 1 {
129 2 pointer-=clusterSize;
130 2 ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
131 2 if(ThisFile.ClusterPointer==0xffff)
132 2 {
133 3 return FALSE;
134 3 }
135 2 }
136 1 ThisFile.SectorofCluster=pointer/DeviceInfo.BPB_BytesPerSec;
137 1 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer)+ThisFile.SectorofCluster;
138 1 ThisFile.OffsetofSector=pointer-ThisFile.SectorofCluster*DeviceInfo.BPB_BytesPerSec;
139 1 ThisFile.FatSectorPointer=0;
140 1 return TRUE;
141 1
142 1 }
143
144 unsigned int GetFreeCusterNum(void)
145 {
146 1 unsigned int clusterNum,i;
147 1 unsigned long sectorNum;
148 1 clusterNum=0;
149 1 sectorNum=DeviceInfo.FatStartSector;
150 1 while(sectorNum<DeviceInfo.BPB_FATSz16+DeviceInfo.FatStartSector)
151 1 {
152 2
153 2 if(!RBC_Read(sectorNum,1,DBUF))
154 2 return 0x0;
155 2 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+2)
156 2 {
157 3 //clusterNum++;
158 3
159 3 if((DBUF[i]==0)&&(DBUF[i+1]==0))
160 3 {
161 4 DBUF[i]=0xff;
162 4 DBUF[i+1]=0xff;
163 4 //DelayMs(10);
164 4 if(!RBC_Write(sectorNum,1,DBUF))
165 4 return 0x00;
166 4 //DelayMs(10);
167 4 if(!RBC_Write(sectorNum+DeviceInfo.BPB_FATSz16,1,DBUF))
168 4 return 0x00;
169 4
170 4 return clusterNum;
171 4 }
172 3 clusterNum++;
173 3 }
174 2
175 2 sectorNum=2*clusterNum/DeviceInfo.BPB_BytesPerSec+DeviceInfo.FatStartSector;
176 2 //clusterNum+=DeviceInfo.BPB_BytesPerSec;
177 2 //DelayMs(10);
178 2 }
179 1
C51 COMPILER V8.01 FAT 08/28/2007 14:58:56 PAGE 4
180 1 return 0x0;
181 1 }
182
183 unsigned int CreateClusterLink(unsigned int currentCluster)
184 {
185 1 unsigned int newCluster;
186 1 unsigned int xxgFatSecNum,xxgFatEntOffset;
187 1
188 1 newCluster=GetFreeCusterNum();
189 1
190 1 xxgFatSecNum=ThisFatSecNum(currentCluster);
191 1 xxgFatEntOffset=ThisFatEntOffset(currentCluster);
192 1 if(RBC_Read(xxgFatSecNum,1,DBUF))
193 1 {
194 2 //clusterNum=DBUF[xxgFatEntOffset+1];
195 2 //clusterNum=clusterNum<<8;
196 2 //clusterNum+=DBUF[xxgFatEntOffset];
197 2 //return clusterNum;
198 2 DBUF[xxgFatEntOffset]=newCluster;
199 2 DBUF[xxgFatEntOffset+1]=newCluster>>8;
200 2 //DelayMs(5);
201 2 if(!RBC_Write(xxgFatSecNum,1,DBUF))
202 2 return 0x00;
203 2 //DelayMs(10);
204 2 if(!RBC_Write(xxgFatSecNum+DeviceInfo.BPB_FATSz16,1,DBUF))
205 2 return 0x00;
206 2 }
207 1 else
208 1 return 0x00;
209 1
210 1 return newCluster;
211 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1375 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 512 ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 46
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 + -