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