nandfdrv.c
来自「嵌入式系统中文件系统源代码」· C语言 代码 · 共 150 行
C
150 行
/*************************************************************
File Name: NANDfdrv.C
Last Modified Date: 2001/03/19
Programmer: MSC
Compiler:
Platform:
Usage:
Flash erase & program functions that is loadable to
RAM for execution.
Other Information:
Only for intel flash
**************************************************************/
#include <sys/syscall.h>
//#include "../../nflash/include/nflash.h"
//#include "nflash/include/nflash.h"
#ifdef __WIN32__
#include "../../diskEmu/include/nfshEmu.h"
#else
#include "nflash/include/nflash.h"
#endif
#include "../include/FFS_NAND.h"
#include "../include/NANDfdrv.h"
#ifdef NAND_FLASH_DISK_ID
/*************************************************************
Function: NAND_FFS_fshFrameRead
Description:
read a flash frame
Input:
frame - the frame number
Output:
0 SUCCESS
-1 FAILURE
**************************************************************/
int NAND_FFS_fshFrameRead(int frame, unsigned char *pData)
{
unsigned long offset;
offset = frame * NFLASH_FRAME_SIZE;
sc_disableInt();
nfshReadFrame(offset, pData);
sc_enableInt();
return 0;
}
/*************************************************************
Function: NAND_FFS_fshBlockRead
Description:
read a flash block
Input:
block - the block number
Output:
0 SUCCESS
-1 FAILURE
**************************************************************/
int NAND_FFS_fshBlockRead(int block, unsigned char *pData)
{
unsigned long offset;
unsigned long frameNO;
unsigned long i;
offset = block * NAND_FLASH_BLOCK_SIZE;
frameNO = NAND_FLASH_BLOCK_SIZE / NFLASH_FRAME_SIZE;
for (i = 0; i < frameNO; i++)
{
sc_disableInt();
nfshReadFrame(offset, pData);
sc_enableInt();
offset += NFLASH_FRAME_SIZE;
pData += NFLASH_FRAME_SIZE;
}
return 0;
}
/*************************************************************
Function: NAND_FFS_fshBlockErase
Description:
erase a flash sector
Input:
block - the block number
Output:
0 SUCCESS
-1 FAILURE
**************************************************************/
int NAND_FFS_fshBlockErase(int block)
{
unsigned long offset;
offset = block * NAND_FLASH_BLOCK_SIZE;
sc_disableInt();
nfshEraseBlock(offset);
sc_enableInt();
return 0;
}
/*************************************************************
Function: NAND_FFS_fshBlockProgram
Description:
program a flash sector
Input:
block - the block number
Output:
0 SUCCESS
-1 FAILURE
**************************************************************/
int NAND_FFS_fshBlockProgram(int block, unsigned char *pData)
{
unsigned long offset;
unsigned long frameNO;
unsigned long i;
offset = block * NAND_FLASH_BLOCK_SIZE;
frameNO = NAND_FLASH_BLOCK_SIZE / NFLASH_FRAME_SIZE;
// printf("{P_Block=%d}", offset);//jason
for (i = 0; i < frameNO; i++)
{
sc_disableInt();
nfshProgramFrame(offset, pData);
sc_enableInt();
offset += NFLASH_FRAME_SIZE;
pData += NFLASH_FRAME_SIZE;
}
return 0;
}
#endif // #ifdef NAND_FLASH_DISK_ID
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?