📄 systffs.c
字号:
FLSocket vol /* pointer identifying drive */ ) { /* Physical base as a 4K page */ if (vol.serialNo == 0) { vol.window.baseAddress = TFFS_BASE_ADRS >> 12; flSetWindowSize (&vol, TFFS_WINDOW_SIZE >> 12); } else if(vol.serialNo == 1) { #if defined(FLASH_PARTITION2) && defined(INCLUDE_FLASH_NO2) vol.window.baseAddress = TFFS_BASE_ADRS1 >> 12; flSetWindowSize (&vol, TFFS_WINDOW_SIZE1 >> 12); #endif /* defined(FLASH_PARTITION2) && defined(INCLUDE_FLASH_NO2) by luhb */ #if defined(FLASH_PARTITION2) && !defined(INCLUDE_FLASH_NO2) vol.window.baseAddress = TFFS_BASE_ADRS1 >> 12; flSetWindowSize (&vol, TFFS_WINDOW_SIZE1 >> 12); #endif /* defined(FLASH_PARTITION2) && !defined(INCLUDE_FLASH_NO2) by luhb 2007-03-27 */ #if !defined(FLASH_PARTITION2) && defined(INCLUDE_FLASH_NO2) vol.window.baseAddress = TFFS_BASE_ADRS_NO2 >> 12; flSetWindowSize (&vol, TFFS2_WINDOW_SIZE >> 12); #ifdef TFFS_DEBUG printf("TFFS_DEBUG:\n void simmSetWindow():bsp/sysTffs.c vol.serialNo = %d,SIZE = %X\n", vol.serialNo, TFFS2_WINDOW_SIZE); #endif #endif /* !defined(FLASH_PARTITION2) && defined(INCLUDE_FLASH_NO2) by luhb 2007-03-23 */ } else if(vol.serialNo == 2) { #ifdef INCLUDE_FLASH_NO2 vol.window.baseAddress = TFFS_BASE_ADRS_NO2 >> 12; flSetWindowSize (&vol, TFFS2_WINDOW_SIZE >> 12); #endif /* INCLUDE_FLASH_NO2 by luhb 2007-03-23 */ #ifdef TFFS_DEBUG printf("TFFS_DEBUG:\n void simmSetWindow():bsp/sysTffs.c vol.serialNo = %d\n", vol.serialNo); #endif } #ifdef TFFS_DEBUG printf("TFFS_DEBUG:\n void simmSetWindow():bsp/sysTffs.c vol.serialNo = %d\n",vol.serialNo);#endif /* TFFS_DEBUG by luhb 2007-03-16 */ }/********************************************************************************* simmSetMappingContext - sets the window mapping register to a card address** This routine sets the window mapping register to a card address.* The window should be set to the value of 'vol.window.currentPage',* which is the card address divided by 4 KB. An address over 128MB,* (page over 32K) specifies an attribute-space address.** The page to map is guaranteed to be on a full window-size boundary.** RETURNS: N/A*/LOCAL void simmSetMappingContext ( FLSocket vol, /* pointer identifying drive */ unsigned page /* page to be mapped */ ) { }/********************************************************************************* simmGetAndClearCardChangeIndicator - return the hardware card-change indicator** This routine returns the hardware card-change indicator and clears it if set.** RETURNS: FALSE, or TRUE if the card has been changed*/LOCAL FLBoolean simmGetAndClearCardChangeIndicator ( FLSocket vol /* pointer identifying drive */ ) { return (FALSE); }/********************************************************************************* simmWriteProtected - return the write-protect state of the media** This routine returns the write-protect state of the media** RETURNS: FALSE, or TRUE if the card is write-protected*/LOCAL FLBoolean simmWriteProtected ( FLSocket vol /* pointer identifying drive */ ) { return (FALSE); }#endif /* INCLUDE_SOCKET_SIMM *//********************************************************************************* flFitInSocketWindow - check whether the flash array fits in the socket window** This routine checks whether the flash array fits in the socket window.** RETURNS: A chip size guaranteed to fit in the socket window.*/long int flFitInSocketWindow ( long int chipSize, /* size of single physical chip in bytes */ int interleaving, /* flash chip interleaving (1,2,4 etc) */ long int windowSize /* socket window size in bytes */ ) { if (chipSize*interleaving > windowSize) /* doesn't fit in socket window */ { int roundedSizeBits; /* fit chip in the socket window */ chipSize = windowSize / interleaving; /* round chip size at powers of 2 */ for (roundedSizeBits = 0; (0x1L << roundedSizeBits) <= chipSize; roundedSizeBits++) ; chipSize = (0x1L << (roundedSizeBits - 1)); } return (chipSize); }#if FALSE/********************************************************************************* sysTffsCpy - copy memory from one location to another** This routine copies <size> characters from the object pointed* to by <source> into the object pointed to by <destination>. If copying* takes place between objects that overlap, the behavior is undefined.** INCLUDE FILES: string.h** RETURNS: A pointer to <destination>.** NOMANUAL*/void * sysTffsCpy ( void * destination, /* destination of copy */ const void * source, /* source of copy */ size_t size /* size of memory to copy */ ) { bcopy ((char *) source, (char *) destination, (size_t) size); return (destination); }/********************************************************************************* sysTffsSet - set a block of memory** This routine stores <c> converted to an `unsigned char' in each of the* elements of the array of `unsigned char' beginning at <m>, with size <size>.** INCLUDE FILES: string.h** RETURNS: A pointer to <m>.** NOMANUAL*/void * sysTffsSet ( void * m, /* block of memory */ int c, /* character to store */ size_t size /* size of memory */ ) { bfill ((char *) m, (int) size, c); return (m); }#endif /* FALSE *//********************************************************************************* flDelayMsecs - wait for specified number of milliseconds** This routine waits for specified number of milliseconds.** RETURNS: N/A** NOMANUAL*/void flDelayMsecs ( unsigned milliseconds /* milliseconds to wait */ ) { UINT32 ix; UINT32 iy = 1; UINT32 iz = 2; /* it doesn't count time consumed in interrupt level */ for (ix = 0; ix < milliseconds; ix++) for (ix = 0; ix < sysTffsMsecLoopCount; ix++) { tickGet (); /* dummy */ iy = KILL_TIME_FUNC; /* consume time */ } }/********************************************************************************* flDelayLoop - consume the specified time** This routine consumes the specified time.** RETURNS: N/A*/void flDelayLoop ( int cycles ) { while (--cycles) ; }/********************************************************************************* sysTffsFormat - format the flash memory above an offset** This routine formats the flash memory. Because this function defines * the symbolic constant, HALF_FORMAT, the lower half of the specified flash * memory is left unformatted. If the lower half of the flash memory was* previously formated by TrueFFS, and you are trying to format the upper half,* you need to erase the lower half of the flash memory before you format the* upper half. To do this, you could use:* .CS* tffsRawio(0, 3, 0, 8) * .CE* The first argument in the tffsRawio() command shown above is the TrueFFS * drive number, 0. The second argument, 3, is the function number (also * known as TFFS_PHYSICAL_ERASE). The third argument, 0, specifies the unit * number of the first erase unit you want to erase. The fourth argument, 8,* specifies how many erase units you want to erase. ** RETURNS: OK, or ERROR if it fails.*/STATUS sysTffsFormat (void) { STATUS status; tffsDevFormatParams params = {#undef HALF_FORMAT /* lower 1.0MB for bootimage, upper 3.0MB for TFFS */#ifdef HALF_FORMAT {0x100000l, 99, 1, 0x10000l, NULL, {0,0,0,0}, NULL, 2, 0, NULL},#else {0x000000l, 99, 1, 0x10000l, NULL, {0,0,0,0}, NULL, 2, 0, NULL},#endif /* HALF_FORMAT */ FTL_FORMAT }; /* we assume that the drive number 0 is SIMM */ params.formatParams.percentUse = 98; /*100 - (NV_RAM_SIZE*100/TFFS_SIZE + 1) - 1;*/ /*DONLEO:FOR NVRAM USE*/ sysFlashWriteEnable(); sysFlashErase1(params.formatParams.bootImageLen); status = tffsDevFormat (0, (int)¶ms); return (status); }STATUS sysTffsFormat1 (void) { STATUS status; tffsDevFormatParams params = { {0x000000l, 99, 1, 0x10000l, NULL, {0,0,0,0}, NULL, 2, 0, NULL},FTL_FORMAT }; /* we assume that the drive number 0 is SIMM */ params.formatParams.percentUse = 98; /*100 - (NV_RAM_SIZE*100/TFFS_SIZE + 1) - 1;*/ /*DONLEO:FOR NVRAM USE*/ sysFlashWriteEnable(); /* sysFlashErase2(0);*/ status = tffsDevFormat (1, (int)¶ms); return (status); }STATUS sysTffsFormat2 (void) { STATUS status; tffsDevFormatParams params = { {0x000000l, 99, 1, 0x10000l, NULL, {0,0,0,0}, NULL, 2, 0, NULL},FTL_FORMAT }; /* we assume that the drive number 0 is SIMM */ params.formatParams.percentUse = 98; /*100 - (NV_RAM_SIZE*100/TFFS_SIZE + 1) - 1;*/ /*DONLEO:FOR NVRAM USE*/ sysFlashWriteEnable(); /* sysFlashErase2(0);*/ status = tffsDevFormat (2, (int)¶ms); return (status); }/*donleo1121, add some function for lock and unlock */#define FLASH28_CMD_CONFIGURATION_SETUP (FLASH_DEF) 0x60606060#define FLASH28_CMD_UNLOCK (FLASH_DEF) 0xd0d0d0d0#define FLASH28_STAT_WSMS (FLASH_DEF) 0x00800080#define FLASH28_CMD_READ_STATUS (FLASH_DEF) 0x70707070#define FLASH28_CMD_RESET (FLASH_DEF) 0xffffffffint iFirstFlash=0;int sysFlashWriteEnable1(){ int i; volatile FLASH_DEF * pFA = FLASH_CAST (TFFS_BASE_ADRS); if(iFirstFlash==1) return OK; iFirstFlash=1; for(i=0;i<TFFS_SIZE;i+= 0x20000) { /*donleo: bit related*/ pFA = FLASH_CAST (TFFS_BASE_ADRS + i); *pFA = FLASH28_CMD_CONFIGURATION_SETUP; *pFA = FLASH28_CMD_UNLOCK; do *pFA = FLASH28_CMD_READ_STATUS; while ((*pFA & FLASH28_STAT_WSMS) != FLASH28_STAT_WSMS); } *pFA = FLASH28_CMD_RESET; return OK;}int sysFlashWriteDisable1(){ int i; volatile FLASH_DEF * pFA = FLASH_CAST (TFFS_BASE_ADRS); if(iFirstFlash==1) return OK; for(i=0;i<TFFS_SIZE;i+= 0x20000) { /*donleo :bit width*/ pFA = FLASH_CAST (TFFS_BASE_ADRS + i) ; *pFA = FLASH28_CMD_RESET; do *pFA = FLASH28_CMD_READ_STATUS; while ((*pFA & FLASH28_STAT_WSMS) != FLASH28_STAT_WSMS); *pFA = FLASH28_CMD_RESET; } *pFA = FLASH28_CMD_RESET; return OK;}int sysFlashErase1(int iOffset){ FLASH_DEF * pFA = FLASH_CAST (TFFS_BASE_ADRS + iOffset); *pFA = SETUP_ERASE; *pFA = CONFIRM_ERASE; do *pFA = FLASH28_CMD_READ_STATUS; while ((*pFA & FLASH28_STAT_WSMS) != FLASH28_STAT_WSMS); *pFA = FLASH28_CMD_RESET; return OK;}#ifdef FLASH_PARTITION2int iFirstFlash1=0;int sysFlashWriteEnable2(){ int i; volatile FLASH_DEF * pFA = FLASH_CAST (TFFS_BASE_ADRS1); if(iFirstFlash1==1) return OK; iFirstFlash1=1; for(i=0;i<TFFS_SIZE1;i+= 0x20000) { pFA = FLASH_CAST (TFFS_BASE_ADRS1 + i); *pFA = FLASH28_CMD_CONFIGURATION_SETUP; *pFA = FLASH28_CMD_UNLOCK; do *pFA = FLASH28_CMD_READ_STATUS; while ((*pFA & FLASH28_STAT_WSMS) != FLASH28_STAT_WSMS); } *pFA = FLASH28_CMD_RESET; return OK;}int sysFlashWriteDisable2(){ int i; volatile FLASH_DEF * pFA = FLASH_CAST (TFFS_BASE_ADRS1); if(iFirstFlash1==1) return OK; for(i=0;i<TFFS_SIZE1;i+= 0x20000) { /*bit width by luhb */ pFA = FLASH_CAST (TFFS_BASE_ADRS1 + i) ; *pFA = FLASH28_CMD_RESET; do *pFA = FLASH28_CMD_READ_STATUS; while ((*pFA & FLASH28_STAT_WSMS) != FLASH28_STAT_WSMS); *pFA = FLASH28_CMD_RESET; } *pFA = FLASH28_CMD_RESET; return OK;}int sysFlashErase2(int iOffset){ FLASH_DEF * pFA = FLASH_CAST (TFFS_BASE_ADRS1 + iOffset); *pFA = SETUP_ERASE; *pFA = CONFIRM_ERASE; do *pFA = FLASH28_CMD_READ_STATUS; while ((*pFA & FLASH28_STAT_WSMS) != FLASH28_STAT_WSMS); *pFA = FLASH28_CMD_RESET; return OK;}#endif /* FLASH_PARTITION2 by luhb 2007-03-21 */#ifdef INCLUDE_FLASH_NO2int iFirstFlashNO2=0;int sysFlashWriteEnableNO2(){ int i; volatile FLASH_DEF * pFA = FLASH_CAST (TFFS_BASE_ADRS_NO2); if(iFirstFlashNO2==1) return OK; iFirstFlashNO2=1; for(i=0;i<TFFS_SIZE_NO2;i+= 0x20000) { /* bit related by luhb */ pFA = FLASH_CAST (TFFS_BASE_ADRS_NO2 + i); *pFA = FLASH28_CMD_CONFIGURATION_SETUP; *pFA = FLASH28_CMD_UNLOCK; do *pFA = FLASH28_CMD_READ_STATUS; while ((*pFA & FLASH28_STAT_WSMS) != FLASH28_STAT_WSMS); } *pFA = FLASH28_CMD_RESET; return OK;}#endif /* INCLUDE_FLASH_NO2 by luhb 2007-03-21 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -