📄 fat.lst
字号:
C51 COMPILER V7.00 FAT 10/27/2006 00:20:27 PAGE 1
C51 COMPILER V7.00, COMPILATION OF MODULE FAT
OBJECT MODULE PLACED IN Fat.OBJ
COMPILER INVOKED BY: e:\Keil\C51\BIN\C51.EXE Fat.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 unsigned char xdata FATBUF[512];
11 ////////////////////////////////////////
12
13 unsigned long FirstSectorofCluster(unsigned int 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 int ThisFatSecNum(unsigned int clusterNum)
23 {
24 1
25 1 unsigned int temp;
26 1 temp=clusterNum/(DeviceInfo.BPB_BytesPerSec/2);
27 1 temp=temp+DeviceInfo.FatStartSector;
28 1 return temp;
29 1
30 1 }
31
32 unsigned int ThisFatEntOffset(unsigned int clusterNum)
33 {
34 1 return (clusterNum%(DeviceInfo.BPB_BytesPerSec/2))*2;
35 1 }
36
37 unsigned int GetNextClusterNum(unsigned int clusterNum)
38 {
39 1 unsigned int FatSecNum,FatEntOffset;
40 1
41 1 FatSecNum=ThisFatSecNum(clusterNum);
42 1 FatEntOffset=ThisFatEntOffset(clusterNum);
43 1 if(ThisFile.FatSectorPointer!=FatSecNum)
44 1 {
45 2
46 2 if(!SdReadSector(FatSecNum,1,FATBUF))
47 2 return 0xFFFF;
48 2 ThisFile.FatSectorPointer=FatSecNum;
49 2 }
50 1
51 1 ///////////////////////////////////////////////////
52 1 clusterNum=FATBUF[FatEntOffset+1];
53 1 clusterNum=clusterNum<<8;
54 1 clusterNum+=FATBUF[FatEntOffset];
55 1 return clusterNum;
C51 COMPILER V7.00 FAT 10/27/2006 00:20:27 PAGE 2
56 1 }
57
58 unsigned char GoToPointer(unsigned long pointer)
59 {
60 1
61 1 unsigned int clusterSize;
62 1
63 1 clusterSize=DeviceInfo.BPB_SecPerClus*DeviceInfo.BPB_BytesPerSec;
64 1 ThisFile.ClusterPointer=ThisFile.StartCluster;
65 1 while(pointer>clusterSize)
66 1 {
67 2 pointer-=clusterSize;
68 2 ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
69 2 if(ThisFile.ClusterPointer==0xffff)
70 2 {
71 3 return FALSE;
72 3 }
73 2 }
74 1 ThisFile.SectorofCluster=pointer/DeviceInfo.BPB_BytesPerSec;
75 1 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer)+ThisFile.SectorofCluster;
76 1 ThisFile.OffsetofSector=pointer%DeviceInfo.BPB_BytesPerSec;
77 1 ThisFile.FatSectorPointer=0;
78 1 return TRUE;
79 1
80 1 }
81
82 unsigned char DeleteClusterLink(unsigned int clusterNum)
83 {
84 1 unsigned int FatSecNum,FatEntOffset;
85 1 unsigned char i;
86 1 while((clusterNum>1)&&(clusterNum<0xfff0))
87 1 {
88 2 FatSecNum=ThisFatSecNum(clusterNum);
89 2 FatEntOffset=ThisFatEntOffset(clusterNum);
90 2 if(SdReadSector(FatSecNum,1,DBUF))
91 2 {
92 3 if(clusterNum<DeviceInfo.LastFreeCluster) DeviceInfo.LastFreeCluster=clusterNum;
93 3 clusterNum=DBUF[FatEntOffset+1];
94 3 clusterNum=clusterNum<<8;
95 3 clusterNum+=DBUF[FatEntOffset];
96 3 }
97 2 else
98 2 return FALSE;
99 2 DBUF[FatEntOffset]=0x00;
100 2 DBUF[FatEntOffset+1]=0x00;
101 2 for(i=0;i<DeviceInfo.BPB_NumFATs;i++)
102 2 {
103 3 DelayMs(5);
104 3 if(!SdWriteSector(FatSecNum+i*DeviceInfo.BPB_FATSz16,1,DBUF))
105 3 return FALSE;
106 3 }
107 2 }
108 1 return TRUE;
109 1 }
110
111 unsigned int GetFreeCusterNum(void)
112 {
113 1 unsigned int clusterNum,i;
114 1 unsigned long sectorNum;
115 1 unsigned char j;
116 1 clusterNum=0;
117 1 // sectorNum=DeviceInfo.FatStartSector;
C51 COMPILER V7.00 FAT 10/27/2006 00:20:27 PAGE 3
118 1
119 1 sectorNum=ThisFatSecNum(DeviceInfo.LastFreeCluster);
120 1 clusterNum=(sectorNum-DeviceInfo.FatStartSector)*(DeviceInfo.BPB_BytesPerSec/2);
121 1
122 1 while(sectorNum<DeviceInfo.BPB_FATSz16+DeviceInfo.FatStartSector)
123 1 {
124 2
125 2 if(!SdReadSector(sectorNum,1,DBUF))
126 2 return 0x0;
127 2 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+2)
128 2 {
129 3 if((DBUF[i]==0)&&(DBUF[i+1]==0))
130 3 {
131 4 DBUF[i]=0xff;
132 4 DBUF[i+1]=0xff;
133 4 for(j=0;j<DeviceInfo.BPB_NumFATs;j++)
134 4 {
135 5 DelayMs(5);
136 5 if(!SdWriteSector(sectorNum+j*DeviceInfo.BPB_FATSz16,1,DBUF))
137 5 return FALSE;
138 5 }
139 4 clusterNum=clusterNum+i/2;
140 4 if((clusterNum-2)<DeviceInfo.TotCluster)
141 4 {
142 5 if(clusterNum>DeviceInfo.LastFreeCluster) DeviceInfo.LastFreeCluster=clusterNum;
143 5 return clusterNum;
144 5 }
145 4 else return FALSE;
146 4 }
147 3
148 3 }
149 2 clusterNum+=DeviceInfo.BPB_BytesPerSec/2;
150 2 sectorNum++;
151 2 DelayMs(1);
152 2 }
153 1
154 1 return 0x0;
155 1 }
156
157 unsigned int CreateClusterLink(unsigned int currentCluster)
158 {
159 1 unsigned int newCluster;
160 1 unsigned int FatSecNum,FatEntOffset;
161 1 unsigned char i;
162 1
163 1 newCluster=GetFreeCusterNum();
164 1
165 1 if(newCluster==0)
166 1 return 0x00;
167 1
168 1 FatSecNum=ThisFatSecNum(currentCluster);
169 1 FatEntOffset=ThisFatEntOffset(currentCluster);
170 1 if(SdReadSector(FatSecNum,1,DBUF))
171 1 {
172 2 DBUF[FatEntOffset]=newCluster;
173 2 DBUF[FatEntOffset+1]=newCluster>>8;
174 2 for(i=0;i<DeviceInfo.BPB_NumFATs;i++)
175 2 {
176 3 DelayMs(5);
177 3 if(!SdWriteSector(FatSecNum+i*DeviceInfo.BPB_FATSz16,1,DBUF))
178 3 return FALSE;
179 3 }
C51 COMPILER V7.00 FAT 10/27/2006 00:20:27 PAGE 4
180 2 }
181 1 else
182 1 return 0x00;
183 1
184 1 return newCluster;
185 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1494 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 512 ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 41
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 + -