Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FLASH_SYSTEM_FDT_CACHE_COUNT 8
- #define FLASH_SYSTEM_DATA_CACHE_COUNT 4
- #define FLASH_DATA_FAT_CACHE_COUNT 32
- #define FLASH_DATA_FDT_CACHE_COUNT 8
- #define FLASH_DATA_DATA_CACHE_COUNT 4
- #define FLASH_USER_FAT_CACHE_COUNT 32
- #define FLASH_USER_FDT_CACHE_COUNT 8
- #define FLASH_USER_DATA_CACHE_COUNT 4
- uint8 FlashFatCacheBuf[FLASH_SYSTEM_FAT_CACHE_COUNT][512];
- uint8 FlashFdtCacheBuf[FLASH_SYSTEM_FDT_CACHE_COUNT][512];
- uint8 FlashDataCacheBuf[FLASH_SYSTEM_DATA_CACHE_COUNT][512];
- FS_CACHE_DATA FLASH_FatCacheData[FLASH_SYSTEM_FAT_CACHE_COUNT];
- FS_CACHE_DATA FLASH_FdtCacheData[FLASH_SYSTEM_FDT_CACHE_COUNT];
- FS_CACHE_DATA FLASH_DataCacheData[FLASH_SYSTEM_DATA_CACHE_COUNT];
- FS_CACHE FlashFatCache = {FLASH_FatCacheData, 0, FLASH_SYSTEM_FAT_CACHE_COUNT};
- FS_CACHE FlashFdtCache = {FLASH_FdtCacheData, 0, FLASH_SYSTEM_FDT_CACHE_COUNT};
- FS_CACHE FlashDataCache = {FLASH_DataCacheData, 0, FLASH_SYSTEM_DATA_CACHE_COUNT};
- uint8 FlashDataFatCacheBuf[FLASH_DATA_FAT_CACHE_COUNT][512];
- uint8 FlashDataFdtCacheBuf[FLASH_DATA_FDT_CACHE_COUNT][512];
- uint8 FlashDataDataCacheBuf[FLASH_DATA_DATA_CACHE_COUNT][512];
- FS_CACHE_DATA FLASH_DataFatCacheData[FLASH_DATA_FAT_CACHE_COUNT];
- FS_CACHE_DATA FLASH_DataFdtCacheData[FLASH_DATA_FDT_CACHE_COUNT];
- FS_CACHE_DATA FLASH_DataDataCacheData[FLASH_DATA_DATA_CACHE_COUNT];
- FS_CACHE FlashDataFatCache = {FLASH_DataFatCacheData, 0, FLASH_DATA_FAT_CACHE_COUNT};
- FS_CACHE FlashDataFdtCache = {FLASH_DataFdtCacheData, 0, FLASH_DATA_FDT_CACHE_COUNT};
- FS_CACHE FlashDataDataCache = {FLASH_DataDataCacheData, 0, FLASH_DATA_DATA_CACHE_COUNT};
- uint8 FlashUFatCacheBuf[FLASH_USER_FAT_CACHE_COUNT][512];
- uint8 FlashUFdtCacheBuf[FLASH_USER_FDT_CACHE_COUNT][512];
- uint8 FlashUDataCacheBuf[FLASH_USER_DATA_CACHE_COUNT][512];
- FS_CACHE_DATA FLASH_UFatCacheData[FLASH_USER_FAT_CACHE_COUNT];
- FS_CACHE_DATA FLASH_UFdtCacheData[FLASH_USER_FDT_CACHE_COUNT];
- FS_CACHE_DATA FLASH_UDataCacheData[FLASH_USER_DATA_CACHE_COUNT];
- FS_CACHE FlashUFatCache = {FLASH_UFatCacheData, 0, FLASH_USER_FAT_CACHE_COUNT};
- FS_CACHE FlashUFdtCache = {FLASH_UFdtCacheData, 0, FLASH_USER_FDT_CACHE_COUNT};
- FS_CACHE FlashUDataCache = {FLASH_UDataCacheData, 0, FLASH_USER_DATA_CACHE_COUNT};
- #ifdef SETUP
- // 080324,huangsl,FOR SETUP¹¤³Ì,±ê¼ÇÊÇ·ñÐèÒªµÍ¸ñ FLASH.0:²»ÐèÒªµÍ¸ñ,1:ÐèÒªµÍ¸ñ.
- uint16 FtlLowFormat;
- #endif
- int FS_FlashGetStatus(void);
- int FS_FlashSysReadSec(uint32 LBA, uint32 SecCount, void *buf);
- int FS_FlashSysWriteSec(uint32 LBA, uint32 SecCount, void *buf);
- int FS_FlashUserReadSec(uint32 LBA, uint32 SecCount, void *buf);
- int FS_FlashUserWriteSec(uint32 LBA, uint32 SecCount, void *buf);
- int FS_FlashDataReadSec(uint32 LBA, uint32 SecCount, void *buf);
- int FS_FlashDataWriteSec(uint32 LBA, uint32 SecCount, void *buf);
- int FS_FlashSysIoCtl(uint32 cmd, uint32 arg, void *buf);
- int FS_FlashUserIoCtl(uint32 cmd, uint32 arg, void *buf);
- int FS_FlashDataIoCtl(uint32 cmd, uint32 arg, void *buf);
- int FS_FlashSysMediumInit(void);
- int FS_FlashUserMediumInit(void);
- int FS_FlashDataMediumInit(void);
- void FlashSysCacheInit(void);
- void FlashUserCacheInit(void);
- void FlashDataCacheInit(void);
- const FS_DEVICE_TYPE FS_FlashSysDevice =
- {
- "C:\\",
- "SysDisk",
- FS_FlashGetStatus,
- FS_FlashSysReadSec,
- FS_FlashSysWriteSec,
- FS_FlashSysIoCtl,
- FS_FlashSysMediumInit,
- &FlashFatCache,
- &FlashFdtCache,
- &FlashDataCache
- };
- const FS_DEVICE_TYPE FS_FlashUserDevice =
- {
- "D:\\",
- "Flash",
- FS_FlashGetStatus,
- FS_FlashUserReadSec,
- FS_FlashUserWriteSec,
- FS_FlashUserIoCtl,
- FS_FlashUserMediumInit,
- &FlashUFatCache,
- &FlashUFdtCache,
- &FlashUDataCache
- };
- const FS_DEVICE_TYPE FS_FlashDataDevice =
- {
- "Z:\\",
- "Data",
- FS_FlashGetStatus,
- FS_FlashDataReadSec,
- FS_FlashDataWriteSec,
- FS_FlashDataIoCtl,
- FS_FlashDataMediumInit,
- &FlashDataFatCache,
- &FlashDataFdtCache,
- &FlashDataDataCache
- };
- int FS_FlashGetStatus(void)
- {
- return(0);
- }
- uint8 InFLashOperate = FALSE;
- #if 1
- int FlashDiskRead(unsigned char LUN, unsigned int Index, unsigned int nSec, void *buf)
- {
- int sts;
- RockSemObtain(&gHwI2CSem); // zyf rtcºÍflash CS 2/3»á³åÍ»£¬ÐèÒª±£»¤
- InFLashOperate = TRUE;
- sts = FtlRead(LUN, Index,nSec, buf);
- InFLashOperate = FALSE;
- RockSemRelease(&gHwI2CSem);
- return sts;
- }
- int FS_FlashSysReadSec(uint32 LBA, uint32 SecCount, void *buf)
- {
- return((int)FlashDiskRead(DISK_NAND_CODE, LBA,SecCount, buf));
- }
- int FS_FlashUserReadSec(uint32 LBA, uint32 SecCount, void *buf)
- {
- return((int)FlashDiskRead(DISK_NAND_USER, LBA,SecCount, buf));
- }
- int FS_FlashDataReadSec(uint32 LBA, uint32 SecCount, void *buf)
- {
- return((int)FlashDiskRead(DISK_NAND_DATA, LBA,SecCount, buf));
- }
- int FlashDiskWrite(unsigned char LUN, unsigned int Index, unsigned int nSec, void *buf)
- {
- int sts;
- RockSemObtain(&gHwI2CSem);// zyf rtcºÍflash CS 2/3»á³åÍ»£¬ÐèÒª±£»¤
- InFLashOperate = TRUE;
- sts = FtlWrite(LUN, Index,nSec, buf);
- InFLashOperate = FALSE;
- RockSemRelease(&gHwI2CSem);
- return sts;
- }
- int FS_FlashSysWriteSec(uint32 LBA, uint32 SecCount, void *buf)
- {
- return((int)FlashDiskWrite(DISK_NAND_CODE, LBA,SecCount, buf));
- }
- int FS_FlashUserWriteSec(uint32 LBA, uint32 SecCount, void *buf)
- {
- return((int)FlashDiskWrite(DISK_NAND_USER, LBA,SecCount, buf));
- }
- int FS_FlashDataWriteSec(uint32 LBA, uint32 SecCount, void *buf)
- {
- return((int)FlashDiskWrite(DISK_NAND_DATA, LBA,SecCount, buf));
- }
- #else
- int FS_FlashSysReadSec(uint32 LBA, uint32 SecCount, void *buf)
- {
- return((int)FtlRead(DISK_NAND_CODE, LBA,SecCount, buf));
- }
- int FS_FlashUserReadSec(uint32 LBA, uint32 SecCount, void *buf)
- {
- return((int)FtlRead(DISK_NAND_USER, LBA,SecCount, buf));
- }
- int FS_FlashDataReadSec(uint32 LBA, uint32 SecCount, void *buf)
- {
- return((int)FtlRead(DISK_NAND_DATA, LBA,SecCount, buf));
- }
- int FS_FlashSysWriteSec(uint32 LBA, uint32 SecCount, void *buf)
- {
- return((int)FtlWrite(DISK_NAND_CODE, LBA,SecCount, buf));
- }
- int FS_FlashUserWriteSec(uint32 LBA, uint32 SecCount, void *buf)
- {
- return((int)FtlWrite(DISK_NAND_USER, LBA,SecCount, buf));
- }
- int FS_FlashDataWriteSec(uint32 LBA, uint32 SecCount, void *buf)
- {
- return((int)FtlWrite(DISK_NAND_DATA, LBA,SecCount, buf));
- }
- #endif
- int FS_FlashSysIoCtl(uint32 cmd, uint32 arg, void *buf)
- {
- uint32 *rbuf;
- rbuf = (uint32 *)buf;
- switch (cmd)
- {
- case IO_CTL_GET_CAPACITY:
- *rbuf = FtlGetCapacity(DISK_NAND_CODE);
- break;
- case IO_CTL_GET_MEDIUM_START_SEC:
- *rbuf = 0;
- break;
- case IO_CTL_CACHE_WRITE_BACK:
- //FlashCacheCloseAll();
- break;
- case IO_CTL_FLUSH_CACHE:
- FlashSysCacheInit();
- break;
- default:
- break;
- }
- return(0);
- }
- int FS_FlashUserIoCtl(uint32 cmd, uint32 arg, void *buf)
- {
- uint32 *rbuf;
- rbuf = (uint32 *)buf;
- switch (cmd)
- {
- case IO_CTL_GET_CAPACITY:
- *rbuf = FtlGetCapacity(DISK_NAND_USER);
- break;
- case IO_CTL_GET_MEDIUM_START_SEC:
- *rbuf = 0; /* Óû§Å̵ĿªÊ¼ÎªSYSTEMÅ̵ĴóС */
- break;
- case IO_CTL_CACHE_WRITE_BACK:
- //FlashCacheCloseAll();
- break;
- case IO_CTL_FLUSH_CACHE:
- FlashUserCacheInit();
- break;
- default:
- break;
- }
- return(0);
- }
- int FS_FlashDataIoCtl(uint32 cmd, uint32 arg, void *buf)
- {
- uint32 *rbuf;
- rbuf = (uint32 *)buf;
- switch (cmd)
- {
- case IO_CTL_GET_CAPACITY:
- *rbuf = FtlGetCapacity(DISK_NAND_DATA);
- break;
- case IO_CTL_GET_MEDIUM_START_SEC:
- *rbuf = 0; /* Óû§Å̵ĿªÊ¼ÎªSYSTEMÅ̵ĴóС */
- break;
- case IO_CTL_CACHE_WRITE_BACK:
- //FlashCacheCloseAll();
- break;
- case IO_CTL_FLUSH_CACHE:
- FlashDataCacheInit();
- break;
- default:
- break;
- }
- return(0);
- }
- void FlashSysCacheInit(void)
- {
- uint32 i;
- FS_CACHE_DATA *pCache;
- pCache = FlashFatCache.pCacheData;
- for (i = 0; i < FLASH_SYSTEM_FAT_CACHE_COUNT; i++)
- {
- pCache->flag = 0;
- pCache->pBuffer = &FlashFatCacheBuf[i][0];
- pCache->SectorNo = 0xFFFFFFFF;
- pCache++;
- }
- pCache = FlashFdtCache.pCacheData;
- for (i = 0; i < FLASH_SYSTEM_FDT_CACHE_COUNT; i++)
- {
- pCache->flag = 0;
- pCache->pBuffer = &FlashFdtCacheBuf[i][0];
- pCache->SectorNo = 0xFFFFFFFF;
- pCache++;
- }
- pCache = FlashDataCache.pCacheData;
- for (i = 0; i < FLASH_SYSTEM_DATA_CACHE_COUNT; i++)
- {
- pCache->flag = 0;
- pCache->pBuffer = &FlashDataCacheBuf[i][0];
- pCache->SectorNo = 0xFFFFFFFF;
- pCache++;
- }
- }
- int FS_FlashSysMediumInit(void)
- {
- int err = 0;
- FlashSysCacheInit();
- // err=(FTLInit()>1) ? -1 : 0;
- return (err);
- }
- void FlashUserCacheInit(void)
- {
- uint32 i;
- FS_CACHE_DATA *pCache;
- pCache = FlashUFatCache.pCacheData;
- for (i = 0; i < FLASH_USER_FAT_CACHE_COUNT; i++)
- {
- pCache->flag = 0;
- pCache->pBuffer = &FlashUFatCacheBuf[i][0];
- pCache->SectorNo = 0xFFFFFFFF;
- pCache++;
- }
- pCache = FlashUFdtCache.pCacheData;
- for (i = 0; i < FLASH_USER_FDT_CACHE_COUNT; i++)
- {
- pCache->flag = 0;
- pCache->pBuffer = &FlashUFdtCacheBuf[i][0];
- pCache->SectorNo = 0xFFFFFFFF;
- pCache++;
- }
- pCache = FlashUDataCache.pCacheData;
- for (i = 0; i < FLASH_USER_DATA_CACHE_COUNT; i++)
- {
- pCache->flag = 0;
- pCache->pBuffer = &FlashUDataCacheBuf[i][0];
- pCache->SectorNo = 0xFFFFFFFF;
- pCache++;
- }
- }
- int FS_FlashUserMediumInit(void)
- {
- FlashUserCacheInit();
- return(0);
- }
- void FlashDataCacheInit(void)
- {
- uint32 i;
- FS_CACHE_DATA *pCache;
- pCache = FlashDataFatCache.pCacheData;
- for (i = 0; i < FLASH_DATA_FAT_CACHE_COUNT; i++)
- {
- pCache->flag = 0;
- pCache->pBuffer = &FlashDataFatCacheBuf[i][0];
- pCache->SectorNo = 0xFFFFFFFF;
- pCache++;
- }
- pCache = FlashDataFdtCache.pCacheData;
- for (i = 0; i < FLASH_DATA_FDT_CACHE_COUNT; i++)
- {
- pCache->flag = 0;
- pCache->pBuffer = &FlashDataFdtCacheBuf[i][0];
- pCache->SectorNo = 0xFFFFFFFF;
- pCache++;
- }
- pCache = FlashDataDataCache.pCacheData;
- for (i = 0; i < FLASH_DATA_DATA_CACHE_COUNT; i++)
- {
- pCache->flag = 0;
- pCache->pBuffer = &FlashDataDataCacheBuf[i][0];
- pCache->SectorNo = 0xFFFFFFFF;
- pCache++;
- }
- }
- int FS_FlashDataMediumInit(void)
- {
- FlashDataCacheInit();
- return(0);
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement