📄 nflashwr.c
字号:
#include "general.h"
/*++
Copyright (c) 2004 GoldInfo Technology Co., Ltd.
Module Name:
NFlashWR.c
Abstract:
Module related to Nand Flash operation
Environment:
ccs2.0 IDE
Revision History:
02/3/20014 Mikal created
--*/
//*****************************************************************************
volatile USHORT *GPIOCR = (volatile USHORT *) 0x003c;
volatile USHORT *GPIOSR = (volatile USHORT *) 0x003d;
USHORT G_NFlash_DataBuff[512*9];
USHORT ID_DATA1,ID_DATA2;
USHORT G_NFlash_WR_Es_Flag=0 ; // 0 is sucessfule
ioport unsigned port5ffc;
//*****************************************************************************
/*++
Routine Description:
process DSP GPIO port and HPI interface
Arguments:
none
Return Value:
none
--*/
void Init_GPIO(void)
{
*GPIOCR = 0x40; /* Set GPIO6 as output */
*GPIOSR = 0x00;
}
//*****************************************************************************
/*++
Routine Description:
process DSP GPIO port and HPI interface
Arguments:
none
Return Value:
none
--*/
void Init_GPIO_Disable(void)
{
*GPIOSR = 0x40; // set GPIO6 is high output
}
//*****************************************************************************
/*++
Routine Description:
process The control function for reading the nand-flash data
Arguments:
none
Return Value:
none
--*/
USHORT Nand_Read_Data(void)
{
USHORT i ;
NFlashReadData();
i = G_NFlashData ;
// i=port5ffc;
return(i);
}
//*****************************************************************************
/*++
Routine Description:
process Read Nand Flash Identify
Arguments:
none
Return Value:
none
--*/
void Read_Nand_Flash_ID(void)
{
Init_GPIO(); /*GPIO6=CE=0*/
NandWrite_SET_CLE(0x90); /* resd nand_id */
NandWrite_SET_ALE(0);
ID_DATA1 = Nand_Read_Data(); // the first byte is marker code
ID_DATA2 = Nand_Read_Data(); //The sencod byte is ID
}
//*****************************************************************************
/*++
Routine Description:
process Write the nand-flash data
Arguments:
none
Return Value:
none
--*/
void Write_NFlash_Sector(ULONG WR_NFlash_PhySector,USHORT WR_Datalen,PUSHORT WR_DataBuffer,USHORT wFlag)
{
USHORT j,k;
ULONG NFlashPhySector;
NFlashPhySector = WR_NFlash_PhySector & 0x0FFFFL; //1fffff=64kpage=2048blockx32page/block
Init_GPIO();
NandWrite_SET_CLE(0x80); // Page Program
NandWrite_SET_ALE(0); // A0-A7
NandWrite_SET_ALE(NFlashPhySector & 0xFF); // A9-A16
NandWrite_SET_ALE((NFlashPhySector>>8)&0xFF); // A17-A24
if (wFlag==0x00)
{
for(j=0; j<WR_Datalen; j++)
{
k= WR_DataBuffer[j]&0x00ff;
Nand_Write_Data(k);
}
}
else if (wFlag==0x01)
{
for(j=0; j<WR_Datalen; j++)
{
k= WR_DataBuffer[0]&0x00ff;
Nand_Write_Data(k);
}
}
NandWrite_SET_CLE(0x10);
AtaBusyStatusCheck();
NandWrite_SET_CLE(0x70);
if(Nand_Read_Data() & 0x0001)
{
G_NFlash_WR_Es_Flag=1;
return ;
}
G_NFlash_WR_Es_Flag=0;
}
//*****************************************************************************
/*++
Routine Description:
process read the nand-flash page data
Arguments:
none
Return Value:
none
--*/
void Read_NFlash_Sector(ULONG RD_NFlash_PhySector,USHORT RD_Datalen,PUSHORT RD_DataBuffer,USHORT wFlag)
{
USHORT i,k;
ULONG NFlash_PhySector;
NFlash_PhySector = RD_NFlash_PhySector & 0x0FFFFL; //1fffff=128kpage=2048blockx32page/block
Init_GPIO(); //GPIO6=CE=0
if (wFlag==0x00)
{
NandWrite_SET_CLE(0x0);
}
else if (wFlag==0x01)
{
NandWrite_SET_CLE(0x01);
}
// read nand_id
NandWrite_SET_ALE(0); // A0-A7
NandWrite_SET_ALE(NFlash_PhySector & 0xFF); // A9-A16
NandWrite_SET_ALE((NFlash_PhySector>>8)&0xFF); // A17-A24
AtaBusyStatusCheck();
for(i=0; i<20000; i++)
{
for(k=0; k<2; k++)
i=i+1;
}
for(i=0; i<RD_Datalen; i++)
{
RD_DataBuffer[i]= Nand_Read_Data() ;
// RD_DataBuffer[i] = k | (~Nand_Read_Data() & 0xff);
// RD_DataBuffer[i] = k;
}
}
//*****************************************************************************
/*++
Routine Description:
process erase the nand flash
Arguments:
none
Return Value:
none
--*/
void Erase_NFlash(ULONG lfy_PhySector)
{
ULONG NandPhySector;
NandPhySector = lfy_PhySector & 0x0FFFFL; /*1fffff=128kpage=2048blockx32page/block*/
Init_GPIO(); //GPIO6=CE=0
NandWrite_SET_CLE(0x60); // resd nand_id
NandWrite_SET_ALE(NandPhySector & 0xFF); // A9-A16
NandWrite_SET_ALE((NandPhySector>>8)&0xFF); // A17-A24
NandWrite_SET_CLE(0xd0); /* Erase block commit */
AtaBusyStatusCheck();
NandWrite_SET_CLE(0x70); /* Erase block commit */
if(Nand_Read_Data() & 0x0001)
{
G_NFlash_WR_Es_Flag=1;
return ;
}
G_NFlash_WR_Es_Flag=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -