📄 libdrive.lst
字号:
C51 COMPILER V8.01 LIBDRIVE 04/17/2008 09:46:00 PAGE 1
C51 COMPILER V8.01, COMPILATION OF MODULE LIBDRIVE
OBJECT MODULE PLACED IN .\Debug\libdrive.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE file\libdrive.c LARGE OPTIMIZE(9,SIZE) NOINTPROMOTE INCDIR(.\common;.\e2pro
-m;.\file;.\fmtx;.\ir;.\keyboard;.\lcm;.\led;.\main;.\matrixkey;.\mp3ctrl;.\sd;.\usbhost;.\include;.\lib) DEBUG OBJECTEXT
-END PRINT(.\Debug\libdrive.lst) OBJECT(.\Debug\libdrive.obj)
line level source
1 /****************************************************************
2 * Viaon Technology (Suzhou) Co.,Ltd
3 *
4 * Copyright 2007, Viaon Technology (Suzhou) Co.,Ltd,Suzhou,China
5 * All rights reserved.
6 *
7 *
8 * Filename: libdrive.c
9 *
10 * Programmer: Greg
11 *
12 * Created: 1/2/2008
13 *
14 * Description: public functions
15 *
16 *
17 * Change History (most recent first): 2008.1.2
18 ****************************************************************/
19 //#include "string.h"
20
21 #include "utiltypedef.h"
22 #include "va4010reg.h"
23 #include "common.h"
24 #include "halsdif.h"
25 #include "halusbhif.h"
26 #include "libfat.h"
27 #include "libfile.h"
28 #include "libdrive.h"
29 #include "timer.h"
30
31 //#define MAX_PARTITION_NUM 4
32 #define MAX_PARTITION_NUM 1
33 //#pragma alignvar(4)
34 extern BYTE DBUF[512]; // 512B data buffer
35 CACHE CacheBuffer[FS_MAX_DRIVE];
36 DRIVE Drive[FS_MAX_DRIVE];
37 //BYTE DriveCounter, CurrDrive;
38
39 /*
40 *******************************************************************************
41 * LOCAL FUNCTIONS
42 *******************************************************************************
43 */
44 // Init drive buffer and assign cache
45 static void DriveInit()
46 {
47 1 DRIVE *drv;
48 1 CACHE *cache;
49 1 BYTE i;
50 1
51 1 memclr(Drive, sizeof(DRIVE) * FS_MAX_DRIVE);
52 1 memclr(CacheBuffer, sizeof(CACHE) * FS_MAX_DRIVE);
53 1
C51 COMPILER V8.01 LIBDRIVE 04/17/2008 09:46:00 PAGE 2
54 1 //why we should add 0x20000000
55 1 //set up the cache in the Cached Memory Space under MIPS Architecture.
56 1 // cache = (CACHE *)((DWORD)(&CacheBuffer[0]) + 0x20000000);//??????????gregxu
57 1 cache = &CacheBuffer[0];//??????????gregxu
58 1 drv = Drive;
59 1
60 1 for(i = 0; i < FS_MAX_DRIVE; i ++){ // initialize the cache buffer point
61 2 drv->FatCacheBuffer = cache->FatCache;
62 2 drv->DirStackBuffer = cache->Stack;
63 2 drv->DirCacheBuffer = cache->DirCache;
64 2 drv->FatCachePoint = 0xffffffff;
65 2 drv->FatCacheOffset = 0xff;
66 2 drv->DirCachePoint = 0xffffffff;
67 2 drv->DirCacheOffset = 0xff;
68 2 drv ++;
69 2 cache ++;
70 2 }
71 1
72 1 return;
73 1 }
74
75
76 // Should we change the name of param.2 from sector to cluster??????
77 // No No No the cluster>>8, the sector offset in the File Allocation Table.
78 //param. 2 is the sector offset in the File Allocation Table.
79 //该函数负责: 若FatCache中内容有改动则将其写会FAT1和FAT2.
80 // 将FAT中的指定定扇区读到FatCache中.
81 //If sector is big than 512B, such as 2048, offset will be used to figure out which 512B should be cached.
82 static BYTE FatCaching(DRIVE *drv, UDWORD sector, BYTE offset)
83 {
84 1 #if 1
85 1 UDWORD block;
86 1 //Ignor the lower two bits???????
87 1 // 4 sectors will be readed each time.
88 1 //block = sector & 0xfffffffc;
89 1 //block = (sector>>FAT_CACHE_SIZEEXP)<<FAT_CACHE_SIZEEXP;
90 1 block = sector;
91 1 //If the FAT entry is not in the FatCache
92 1 if((drv->FatCachePoint != block)||(drv->FatCacheOffset != offset)){
93 2 drv->FatCachePoint = block;
94 2 drv->FatCacheOffset = offset;
95 2 //read FAT_CACHE_SIZE sectors from FAT;
96 2 //if(DriveRead512(drv, drv->FatCacheBuffer, block + drv->FatStart, offset) != FS_SUCCEED)
97 2 if(DriveRead(drv->FatCacheBuffer, block + drv->FatStart, offset) != FS_SUCCEED)
98 2 return DRIVE_ACCESS_FAIL;
99 2
100 2 //drv->Flag.FatCacheChanged = 0;
101 2 #if 0
UartOutText("sector: ");UartOutValue(sector, 8);
UartOutText("offset: ");UartOutValue(offset, 2);
//UartOutText("block: ");UartOutValue(block, 8);
//UartOutText("drv->FatStart: ");UartOutValue(drv->FatStart, 8);
UartOutText("Update FAT Cache \r\n");
#endif
108 2 }
109 1 #else
UDWORD block;
//Ignor the lower two bits???????
// 4 sectors will be readed each time.
//block = sector & 0xfffffffc;
block = (sector>>FAT_CACHE_SIZEEXP)<<FAT_CACHE_SIZEEXP;
//If the FAT entry is not in the FatCache
C51 COMPILER V8.01 LIBDRIVE 04/17/2008 09:46:00 PAGE 3
if(drv->FatCachePoint != block){
drv->FatCachePoint = block;
//read FAT_CACHE_SIZE sectors from FAT;
if(DriveRead(drv, drv->FatCacheBuffer, block + drv->FatStart) != FS_SUCCEED)
return DRIVE_ACCESS_FAIL;
//drv->Flag.FatCacheChanged = 0;
#if 0
UartOutText("sector: ");UartOutValue(sector, 8);
//UartOutText("block: ");UartOutValue(block, 8);
//UartOutText("drv->FatStart: ");UartOutValue(drv->FatStart, 8);
UartOutText("Update FAT Cache \r\n");
#endif
}
#endif
131 1 return FS_SUCCEED;
132 1 }
133
134 UDWORD ReadFatxx(UDWORD cluster)
135 {
136 1 DRIVE *drv = &Drive[0];
137 1 #if 0
DWORD content, tmp;
BYTE *addr;
if(drv->Flag.Fat32 != 1){
//在FAT16时,每个FAT ENTRY是16bits,一个512B的SECTOR可容纳256个FAT ENTRY
//从cluster num.到对应FAT表的sector偏移的计算方法:cluster >> 8
//将cluster号对应的FAT ENTRY从FAT中读到FatCacheBuffer中
if(FatCaching(drv, cluster >> 8) != FS_SUCCEED) //// 256 fat entry per sector
return 0xffffffff;
// cluster&((1<<(FAT_CACHE_SIZEEXP + 8)) - 1) //the fat entry offset of cluster in fat cache buffer, in
-fat entry unit(2byte)
addr = drv->FatCacheBuffer + ((cluster&((1<<(FAT_CACHE_SIZEEXP + 8)) - 1)) << 1 ); //<< 1, fat entry
-unit -> byte unit
//取出cluster号对应的FAT Entry的content.
content = (UDWORD)LoadAlien16(addr);
//content >= 0xfff8表示文件最后一个簇
if(content >= 0xfff8) content = 0xffffffff;
return content;//返回Fat Entry的值
}else{
//在FAT32时,每个FAT ENTRY是32bits,一个512B的SECTOR可容纳128个FAT ENTRY
//从cluster num.到对应FAT表的sector偏移的计算方法:cluster >> 7
//将cluster号对应的FAT ENTRY从FAT中读到FatCacheBuffer中
if(FatCaching(drv, cluster >> 7) != FS_SUCCEED)
return 0xffffffff;
tmp = ((cluster&((1<<(FAT_CACHE_SIZEEXP + 7)) - 1)) );
addr = drv->FatCacheBuffer + ((cluster&((1<<(FAT_CACHE_SIZEEXP + 7)) - 1)) << 2); //<< 1, fat32 entry
- unit -> byte unit
//content = (UDWORD)LoadAlien32(addr);
LoadAlien32(addr, &content);
//UartOutText("FatCacheBuffer offset: "); UartOutValue(tmp, 8);
//UartOutText("Fat Entry content: "); UartOutValue(content, 8);
if(content >= 0x0ffffff8) content = 0xffffffff;
return content;
}
#elif 0
UDWORD content, tmp;
BYTE *addr;
//WORD wFatEntPerSector;
BYTE bFatEntPerSectorExp;
BYTE offset512;
C51 COMPILER V8.01 LIBDRIVE 04/17/2008 09:46:00 PAGE 4
if(drv->Flag.Fat32 != 1){
//在FAT16时,每个FAT ENTRY是16bits,一个512B的SECTOR可容纳256个FAT ENTRY
//从cluster num.到对应FAT表的sector偏移的计算方法:cluster >> 8
//将cluster号对应的FAT ENTRY从FAT中读到FatCacheBuffer中
bFatEntPerSectorExp = drv->bBytesPerSectorExp - FAT16ENTRY_SIZEEXP;//exp of FAT ENTRY size
offset512 = (cluster>>FAT16ENTRY_512B_EXP) & drv->bMaxOffset; //exp of 256
if(FatCaching(drv, cluster>>bFatEntPerSectorExp, (BYTE )offset512) != FS_SUCCEED) //// 256 fat entry p
-er 512b
return 0xffffffff;
// cluster&((1<<(FAT_CACHE_SIZEEXP + 8)) - 1) //the fat entry offset of cluster in fat cache buffer, in
-fat entry unit(2byte)
addr = drv->FatCacheBuffer +
((cluster&((1<<(FAT_CACHE_SIZEEXP + FAT16ENTRY_512B_EXP)) - 1)) << FAT16ENTRY_SIZEEXP ); //<<
-1, fat entry unit -> byte unit
//取出cluster号对应的FAT Entry的content.
content = (UDWORD)LoadAlien16(addr);
//content >= 0xfff8表示文件最后一个簇
if(content >= 0xfff8) content = 0xffffffff;
return content;//返回Fat Entry的值
}else{
//在FAT32时,每个FAT ENTRY是32bits,一个512B的SECTOR可容纳128个FAT ENTRY
//从cluster num.到对应FAT表的sector偏移的计算方法:cluster >> 7
//将cluster号对应的FAT ENTRY从FAT中读到FatCacheBuffer中
bFatEntPerSectorExp = drv->bBytesPerSectorExp - FAT32ENTRY_SIZEEXP; //exp of FAT32 ENTRY size
offset512 = (cluster>>FAT32ENTRY_512B_EXP) & drv->bMaxOffset; //offset of 512B block in physical sector
if(FatCaching(drv, cluster>>bFatEntPerSectorExp, (BYTE)offset512) != FS_SUCCEED)
return 0xffffffff;
//tmp = ((cluster&((1<<(FAT_CACHE_SIZEEXP + FAT32ENTRY_512B_EXP)) - 1)) );
addr = drv->FatCacheBuffer +
((cluster&((1<<(FAT_CACHE_SIZEEXP + FAT32ENTRY_512B_EXP)) - 1)) << FAT32ENTRY_SIZEEXP); //<< 2
-, fat32 entry unit -> byte unit
LoadAlien32(addr, &content);//content = (UDWORD)LoadAlien32(addr);
//UartOutText("FatCacheBuffer offset: "); UartOutValue(tmp, 8);
//UartOutText("Fat Entry content: "); UartOutValue(content, 8);
if(content >= 0x0ffffff8) content = 0xffffffff;
return content;
}
#else
211 1 UDWORD content;
212 1 BYTE * data addr;
213 1 //WORD wFatEntPerSector;
214 1 BYTE data bFatEntPerSectorExp;
215 1 BYTE data offset512;
216 1
217 1 BYTE data bFatEntrySizeExp;
218 1 BYTE data bFatEntry512BExp; //The exp of the number of fat entry in a 512byte virtual sector
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -