📄 device.lst
字号:
C51 COMPILER V8.02 DEVICE 04/29/2007 12:48:54 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE DEVICE
OBJECT MODULE PLACED IN DEVICE.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE DEVICE.C BROWSE DEBUG OBJECTEXTEND
line level source
1 #include "common.h"
2 #include "DEVICE.H"
3 #include "HAL.H"
4 #include "HPI.H"
5 #include "HPI32.H"
6
7 //////////////////////////////////
8 extern unsigned char xdata DBUF[BUFFER_LENGTH];
9 extern SYS_INFO_BLOCK xdata DeviceInfo;
10 extern FILE_INFO xdata ThisFile;
11 extern unsigned int xdata DirStartCluster;
12 extern unsigned long xdata DirStartCluster32;
13
14 unsigned char xdata DBUF[BUFFER_LENGTH];
15
16 ///////////////////////////////////////////////////////////////////////////
17 unsigned char InitFileSystem(void)
18 {
19 1 unsigned int ReservedSectorsNum;
20 1
21 1 ////////////////////////////////////////////////////
22 1 DeviceInfo.BPB_BytesPerSec=512; //暂假设为512
23 1
24 1
25 1 ////////////////////////////////////////////////////
26 1 if(!SdReadSector(0x0,1,DBUF))
27 1 return FALSE;
28 1 if(DBUF[510] != 0x55 || DBUF[511] != 0xaa) return FALSE;
29 1
30 1 //////////////////////////////////
31 1 if(DBUF[0]==0xeb||DBUF[0]==0xe9)
32 1 {
33 2 DeviceInfo.StartSector=0;
34 2 }
35 1 else
36 1 {
37 2 if(DBUF[446] != 0x80 && DBUF[446] != 0) return FALSE;
38 2 DeviceInfo.StartSector=LSwapINT32(DBUF[454],DBUF[455],DBUF[456],DBUF[457]);
39 2 }
40 1 ///////////////////////////////////////////////////////
41 1 if(!SdReadSector(DeviceInfo.StartSector,1,DBUF))
42 1 return FALSE;
43 1
44 1 if(DBUF[510] != 0x55 || DBUF[511] != 0xaa) return FALSE;
45 1
46 1 DeviceInfo.BPB_BytesPerSec=LSwapINT16(DBUF[11],DBUF[12]);
47 1 DeviceInfo.BPB_SecPerClus=DBUF[13];
48 1 ReservedSectorsNum=LSwapINT16(DBUF[14],DBUF[15]);
49 1 DeviceInfo.BPB_NumFATs=DBUF[16];
50 1
51 1 if(DBUF[82]=='F'&&DBUF[83]=='A'&&DBUF[84]=='T'&&DBUF[85]=='3'&&DBUF[86]=='2')
52 1 {
53 2 DeviceInfo.BPB_RootEntCnt=LSwapINT16(DBUF[17],DBUF[18]);
54 2 DeviceInfo.BPB_RootEntCnt=(DeviceInfo.BPB_RootEntCnt)*32/DeviceInfo.BPB_BytesPerSec;
55 2 DeviceInfo.BPB_TotSec32=LSwapINT32(DBUF[32],DBUF[33],DBUF[34],DBUF[35]);
C51 COMPILER V8.02 DEVICE 04/29/2007 12:48:54 PAGE 2
56 2 DeviceInfo.BPB_FATSz32=LSwapINT32(DBUF[36],DBUF[37],DBUF[38],DBUF[39]);
57 2 DeviceInfo.RootStartCluster=LSwapINT32(DBUF[44],DBUF[45],DBUF[46],DBUF[47]);
58 2 DeviceInfo.FatStartSector=DeviceInfo.StartSector+ReservedSectorsNum;
59 2 DeviceInfo.FirstDataSector=DeviceInfo.FatStartSector+DeviceInfo.BPB_NumFATs*DeviceInfo.BPB_FATSz32;
60 2 //DeviceInfo.TotCluster=(DeviceInfo.BPB_TotSec32-DeviceInfo.FirstDataSector+1)/DeviceInfo.BPB_SecPerClus
-+1;
61 2 DeviceInfo.TotCluster=(DeviceInfo.BPB_TotSec32-ReservedSectorsNum-DeviceInfo.BPB_NumFATs*DeviceInfo.BPB_
-FATSz32-DeviceInfo.BPB_RootEntCnt)/DeviceInfo.BPB_SecPerClus;
62 2 DirStartCluster32=DeviceInfo.RootStartCluster;
63 2 DeviceInfo.FAT=1; //FAT16=0,FAT32=1;
64 2
65 2 }
66 1 else
67 1 {
68 2 DeviceInfo.BPB_RootEntCnt=LSwapINT16(DBUF[17],DBUF[18]);
69 2 DeviceInfo.BPB_RootEntCnt=(DeviceInfo.BPB_RootEntCnt)*32/DeviceInfo.BPB_BytesPerSec;
70 2 DeviceInfo.BPB_TotSec16=LSwapINT16(DBUF[19],DBUF[20]);
71 2 if(DeviceInfo.BPB_TotSec16==0)
72 2 DeviceInfo.BPB_TotSec16=LSwapINT32(DBUF[32],DBUF[33],DBUF[34],DBUF[35]);
73 2 DeviceInfo.BPB_FATSz16=LSwapINT16(DBUF[22],DBUF[23]);
74 2 DeviceInfo.FatStartSector=DeviceInfo.StartSector+ReservedSectorsNum;
75 2 DeviceInfo.RootStartSector=DeviceInfo.StartSector+DeviceInfo.BPB_NumFATs*DeviceInfo.BPB_FATSz16+Reserved
-SectorsNum;
76 2 DeviceInfo.FirstDataSector=DeviceInfo.FatStartSector+DeviceInfo.BPB_NumFATs*DeviceInfo.BPB_FATSz16+Devic
-eInfo.BPB_RootEntCnt;
77 2 DeviceInfo.TotCluster=(DeviceInfo.BPB_TotSec16-DeviceInfo.BPB_RootEntCnt-DeviceInfo.BPB_NumFATs*DeviceIn
-fo.BPB_FATSz16-1)/DeviceInfo.BPB_SecPerClus;
78 2 if(DeviceInfo.TotCluster<4085) return FALSE; //FAT12 不被支持
79 2 DeviceInfo.FAT=0;
80 2 }
81 1 ///////////////////////////////////////////////////////
82 1 ThisFile.bFileOpen=0;
83 1 ///////////////////////////////////////////////////////
84 1 return TRUE;
85 1 }
86
87 unsigned char SdReadSector(unsigned long sector,unsigned char len,unsigned char *pBuffer)
88 {
89 1 while(len--)
90 1 {
91 2 if(SdReadBlock(pBuffer,sector<<9)==0)
92 2 return 0;
93 2 pBuffer+=512;
94 2 }
95 1 return 1;
96 1 }
97
98 unsigned char SdWriteSector(unsigned long sector,unsigned char len,unsigned char *pBuffer)
99 {
100 1 while(len--)
101 1 {
102 2 if(SdWriteBlock(pBuffer,sector<<9)==0) return 0;
103 2 pBuffer+=512;
104 2 }
105 1 return 1;
106 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1439 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 8192 ----
C51 COMPILER V8.02 DEVICE 04/29/2007 12:48:54 PAGE 3
PDATA SIZE = ---- ----
DATA SIZE = ---- 18
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 + -