📄 flash_nand_samsung_k9k1208q0c.c
字号:
/*****************************************************************************
*
* TEXAS INSTRUMENTS INCORPORATED PROPRIETARY INFORMATION
*
* Property of Texas Instruments
* For Unrestricted Internal Use Only
* Unauthorized reproduction and/or distribution is strictly prohibited.
* This product is protected under copyright law and trade secret law
* as an unpublished work.
* Created 2002, (C) Copyright 2002 Texas Instruments. All rights reserved.
*
* Filename : NAND_flash_SAMSUNG_K9K1208Q0C_display_id_a9.c
*
* Project : NEPTUNE
*
* =========================================================================== */
#include "flash_a9.h"
#include "nand_samsung_k9k1208.h"
void NAND_flash_SAMSUNG_K9K1208Q0C_read_test_a9(UWORD32 block, UWORD32 page,UWORD32 size);
static UWORD32 *const tab_in = (UWORD32 *const) 0x20000000 ;
static UWORD32 *const tab_out = (UWORD32 *const) 0x20001000 ;
static UWORD32 *const ndWTxBuffer = (UWORD32 *const)0x10116000;
static UWORD32 *const ndRRxBuffer = (UWORD32 *const)0x10118000;
unsigned int nAND_RD_DATA[ 32 ] = { 0 };;
/*-----------------------------------------------------
* GROUP : System Validation
* Name : nand_flash_erase_a9
* return value : Flase if succeed
True if failed
*-----------------------------------------------------*/
static WORD16 nand_flash_erase_a9(UWORD32 flash_size_in_bytes)
{
WORD16 Result = 0;
UWORD16 i;
UWORD32 write_address;
char st[80];
UART_Printf(UART2,"Erased address : ");
/* program the 64kW blocks */
for (i=0; i < INTEL_STRATA_FLASH_L18_256Mb_NB_BLOCK_64KW ; i++) {
/* Verification erased address / flash size */
if (write_address >= (INTEL_STRATA_FLASH_L18_ADDRESS+flash_size_in_bytes)) break;
/* Unlock the written block */
if (flash_intel_28f256l18top_unlock_one_block(write_address)) {
UART_Printf(UART2,"\n\r Unlock Failed \n\r");
Result = -1;
break;
}
/* Erase the block */
if (flash_intel_28f256l18top_erase_one_block(write_address)) {
UART_Printf(UART2,"\n\r Erase Failed \n\r");
Result = -1;
break;
}
/* Update the written address */
write_address += INTEL_STRATA_FLASH_L18_BLOCK_SIZE_64KW;
}
/* program the 16kW blocks */
for (i=0; i < INTEL_STRATA_FLASH_L18_256Mb_NB_BLOCK_16KW ; i++) {
/* If an error occured, break the loop */
if (Result) break;
/* Verification erased address / flash size */
if (write_address >= (INTEL_STRATA_FLASH_L18_ADDRESS+flash_size_in_bytes)) break;
/* Unlock the written block */
if (flash_intel_28f256l18top_unlock_one_block(write_address)) {
UART_Printf(UART2," \n\r Unlock Failed \n\r");
Result = -1;
break;
}
/* Erase the block */
if (flash_intel_28f256l18top_erase_one_block(write_address)) {
UART_Printf(UART2,"\n\r Erase Failed \n\r");
Result = -1;
break;
}
/* Update adress of the written block */
write_address += INTEL_STRATA_FLASH_L18_BLOCK_SIZE_16KW;
}
/* Forbid the flash write */
MIF_MifSetWriteProtect((BOOL)WRITE_FORBIDEN);
\
return(Result);
}
/**********************************************************
dev_addr routine ....
***********************************************************/
UWORD32 devadd( UWORD32 block, UWORD32 page)
{
REG_UWORD32 dev_add;
/* form the device address */
dev_add = (block<<14 ) + (page<<9);
return(dev_add);
}/* end of devadd */
/* ----------------------------------------------------------------------
* GROUP : System Validation
*
* NAME : NAND_flash_SAMSUNG_K9K1208Q0C_display_id_a9
* DESCRIPTION :
*
* PARAMETERS : None
* RETURN VALUE: 0 if succeed
* other if failed
*
* LIMITATIONS : None
* ---------------------------------------------------------------------- */
WORD16 NAND_flash_SAMSUNG_K9K1208Q0C_display_id_a9(void)
{
UWORD16 reg_val;
int i;
UWORD32 ManufactureId;
UWORD32 DeviceId;
char st[80];
Setgroup32bit( 0xfffbcc10, 5, 2, 0x03);
*(unsigned int*)(0xfffbcc24) = 0xff ; //reset the NNAND FLASH.
for (i=0;i<10000;i++);
/* Read Manufactre Id and Device Id */
UART_Printf(UART2,"Identify NAND Flash SAMSUNG:\n\r");
NAND_FLASH_NND_ADDR_SRC = 0x00000000;
NAND_FLASH_NND_COMMAND = 0x90;
while( !(( *(unsigned int*)(0xfffbcc1c))&0x01));
ManufactureId = NAND_FLASH_NND_ACCESS;
DeviceId = NAND_FLASH_NND_ACCESS;
/* Display Manufacture Id */
UART_Printf(UART2,"0X%x \n\r",ManufactureId); // try to printf mid
UART_Printf(UART2,"0X%x \n\r",DeviceId);
return 0;
}
WORD16 NAND_flash_SAMSUNGl_K9K1208Q0C_copy_sdram_a9(void)
{
}
void NAND_flash_SAMSUNG_K9K1208Q0C_erase_test_a9(UWORD32 block)
{
int i;
unsigned int nand_status = 0xffffffff;
REG_UWORD32 devadd;
Setgroup32bit( 0xfffbcc10, 5, 2, 0x00); //4 TIMES ADDRESS
*(unsigned int*)(0xfffbcc24) = 0xff ; //reset the NNAND FLASH.
for (i=0;i<10000;i++);
devadd = ( block<<14 ) + block;
/* read the page to address */
NAND_FLASH_NND_ADDR_SRC = devadd;
/* issue the command to erase */
NAND_FLASH_NND_COMMAND = 0x0060;
NAND_FLASH_NND_COMMAND_SEC = 0x00d0;
/* wait until ready */
while (!(NAND_FLASH_NND_READY)){};
NAND_FLASH_NND_COMMAND_SEC = 0x70; // poll the status.
nand_status = NAND_FLASH_NND_ACCESS;
while (!(NAND_FLASH_NND_READY)){};
if( nand_status&0x01 == 1 ) //poll the erase status.
UART_Printf( UART2, " erase error.\n\r");
else
UART_Printf( UART2, " ERASE succed.\n\r" );
}
/**********************************************************/
/* nand_write page routine .... */
/**********************************************************/
void NAND_flash_SAMSUNG_K9K1208Q0C_write_test_a9(UWORD32 block, UWORD32 page,UWORD32 size)
{
UWORD32 lvCounter;
unsigned int write_status = 0xfffffff;
/* read the page to address */
NAND_FLASH_NND_ADDR_SRC = devadd(block,page);
/* Return to Area A */
NAND_FLASH_NND_COMMAND_SEC = 0x00;
/* issue the command to read */
NAND_FLASH_NND_COMMAND = 0x80;
/* now write the page from address */
for( lvCounter=0;
lvCounter< size;
lvCounter++ )
{
// NAND_FLASH_NND_ACCESS = tab_in[lvCounter];
NAND_FLASH_NND_ACCESS = 0x55aa55aa;
}
/* issue the sec command to stop */
NAND_FLASH_NND_COMMAND_SEC = 0x10;
/* read status register*/
/* wait until ready */
while (!(NAND_FLASH_NND_READY)){};
NAND_FLASH_NND_COMMAND_SEC = 0x70;
write_status = NAND_FLASH_NND_ACCESS;
if( write_status&0x01 == 1)
UART_Printf( UART2, " ERROR WRTIE.\n\r" );
else
UART_Printf( UART2, " WRITE IS SUCCESS.\n\r");
NAND_flash_SAMSUNG_K9K1208Q0C_read_test_a9(0,0,4);
}
/**********************************************************/
/* nand_read page routine .... */
/**********************************************************/
void NAND_flash_SAMSUNG_K9K1208Q0C_read_test_a9(UWORD32 block, UWORD32 page,UWORD32 size)
{
UWORD32 lvCounter;
/* read the page to address */
NAND_FLASH_NND_ADDR_SRC = devadd(block,page);
/* issue the command to read */
NAND_FLASH_NND_COMMAND = 0x00;
/* wait until ready */
while (!(NAND_FLASH_NND_READY)){};
/* now read the page to address */
for( lvCounter=0;
lvCounter< size;
lvCounter++ )
{
nAND_RD_DATA[lvCounter] = NAND_FLASH_NND_ACCESS;
}
}
//NAND FLASH FUNCTION ENTRY.
void NAND_TEST()
{
unsigned short Result_Test = 0;
int option;
Setgroup16bit( 0xfffece14,0,1,1 );
Setgroup16bit( 0xfffece00,0,2,0 );
Setgroup32bit( 0xfffbcc64,1,1, 1); //software reset the nand module.
while( !((*(unsigned int*)(0xfffbcc68))&0x01));
/*NAND flash Pin configuration,setting these pin work at NAND flash mode*/
IO_CONFIGURATION_CONF_EMIFS_FDATA_0 = 0x01;
IO_CONFIGURATION_CONF_EMIFS_FDATA_1 = 0x01;
IO_CONFIGURATION_CONF_EMIFS_FDATA_2 = 0x01;
IO_CONFIGURATION_CONF_EMIFS_FDATA_3 = 0x01;
IO_CONFIGURATION_CONF_EMIFS_FDATA_4 = 0x01;
IO_CONFIGURATION_CONF_EMIFS_FDATA_5 = 0x01;
IO_CONFIGURATION_CONF_EMIFS_FDATA_6 = 0x01;
IO_CONFIGURATION_CONF_EMIFS_FDATA_7 = 0x01;
IO_CONFIGURATION_CONF_EMIFS_FRDY = 0x19;
IO_CONFIGURATION_CONF_EMIFS_NFBE_0 = 0x01;
IO_CONFIGURATION_CONF_EMIFS_NFBE_1 = 0x01;
IO_CONFIGURATION_CONF_EMIFS_NFCS_3 = 0x19; //change 0x19 to 0x01 //SET V9 AS NAND FLASH CS SIGNAL.
IO_CONFIGURATION_CONF_EMIFS_NFOE = 0x01;
IO_CONFIGURATION_CONF_EMIFS_NFWE = 0x01;
IO_CONFIGURATION_CONF_EMIFS_NFWP = 0x01;
//IO_CONFIGURATION_CONF_GPIO_19 = 0x19;
//Setgroup32bit( 0xfffe11d8, 0, 2, 0x01 ); // select mode1.
//Setgroup32bit( 0xfffe100c, 0, 32,0xeaff); // enable pin mux.
Setgroup32bit( 0xfffbcc5c,0,4,0x1); //nand prc divide clock by 2.
Setgroup32bit( 0xfffbcc8c,0,4,0x7); //nand psc1
Setgroup32bit( 0xfffbcc90,0,5,0x7); //nand psc2
Setgroup32bit( 0xfffbcc10, 3, 1, 0 ); // little endian.
Setgroup32bit( 0xfffbcc10, 9, 1, 1 ); //set wp0 to high.
Setgroup32bit( 0xfffbcc10, 4, 1, 0 ); // a8 will not be sent.
Setgroup32bit( 0xfffbcc10, 8, 1, 0 ); //set chipen0 to low.
UART_Printf(UART2,"==================================================\n");
UART_Printf(UART2,"= NAND Flash TEST =\n");
UART_Printf(UART2,"==================================================\n");
UART_Printf(UART2,"\t 0: Return to main menu \n\r");
UART_Printf(UART2,"\t 1: Read NAND(K9K1208Q0C) DEVICE ID\n\r");
UART_Printf(UART2,"\t 2: Erase NAND Flash Test.\n\r ");
UART_Printf(UART2,"\t 3: Write NAND Flash Test.\n\r ");
UART_Printf(UART2,"\t 4: Read NAND Flash Test.\n\r");
option=UART_GetNum(UART2);
switch (option)
{
case 0 : break ;
case 1 :
UART_Printf(UART2,"Read ID ...\n\r");
NAND_flash_SAMSUNG_K9K1208Q0C_display_id_a9();
break ;
case 2:
UART_Printf(UART2,"Erase NAND FLASH ...\n\r");
NAND_flash_SAMSUNG_K9K1208Q0C_erase_test_a9(0);
break ;
case 3:
UART_Printf(UART2,"Write NAND FLASH ...\n\r");
NAND_flash_SAMSUNG_K9K1208Q0C_write_test_a9(0,0,4);
break ;
case 4:
UART_Printf(UART2,"Read NAND Flash ...\n\r");
NAND_flash_SAMSUNG_K9K1208Q0C_read_test_a9(0,0,4);
break ;
default:
break;
}
/* Wait press key*/
UART_Printf( UART2, " PRESS A KEY TO RETURN T ABOVE MENU.\n\r" );
UART_GetNum( UART2 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -