📄 amd29lv400bt.c
字号:
// Set Timeout to fail
Timeout = -1;
}
}while( Timeout-- > 0 );
Faddr += sizeof(FLASH_DTYPE);
pBuf++;
Count--;
}while( Count && (Timeout > 0) );
if( Timeout <= 0 )
Error = -1;
FlsWrite( PATODA(FLASH_BASE), CMD_READ_ARRAY );
return( Error );
}
/*F***************************************************************************
* NAME: FLASH_Erase
*
* DESCRIPTION: Erase a segment of the flash.
*
* NOTES:
*
*F***************************************************************************/
int
FLASH_Erase( FLASH_ADDR Faddr )
{
int Error;
int Timeout;
unsigned Status;
FlsWrite( FLASH_CYC1_ADDR, 0xAA ); // Bus Cycle 1
FlsWrite( FLASH_CYC2_ADDR, 0x55 ); // Bus Cycle 2
FlsWrite( FLASH_CYC3_ADDR, CMD_ERASE_ARRAY); // Bus Cycle 3
FlsWrite( FLASH_CYC1_ADDR, 0xAA ); // Bus Cycle 4
FlsWrite( FLASH_CYC2_ADDR, 0x55 ); // Bus Cycle 5
FlsWrite( Faddr, CMD_CONFIRM_ERASE_SECTOR ); // Bus Cycle 6
/*-- Wait for Erase to complete or timeout. ----------------------------*/
Timeout = FLASH_ERASE_TIME_MS/10;
Error = 0;
do
{
Status = FlsRead( Faddr );
// If DQ7 match then good erase so break
if( ( Status & DQ7 ) == DQ7 )
break;
// If DQ5 == 1, recheck
if( (Status & DQ5 ) == DQ5 )
{
Status = FlsRead( Faddr );
// If DQ7 match then good erase so break
if( ( Status & DQ7 ) == DQ7 )
break;
// DQ5 == 1, and DQ7 != Data-DQ7 if FAILURE
// Set Timeout to fail
Timeout = -1;
}
Delay( CLK_DELAY_MS(10) );
}while( Timeout-- > 0 );
/*-- If timeout or Erase status failure, suspend erase. ----------------*/
if( Timeout <= 0 )
{
FlsWrite( Faddr, CMD_ERASE_SUSPEND );
Error = -1;
}
FlsWrite( PATODA(FLASH_BASE), CMD_READ_ARRAY );
return( Error );
}
/*F***************************************************************************
* NAME: Erase
*
* DESCRIPTION: Erase 1-N blocks of flash.
*
* NOTES: This routine is called by the assembly routine _PRG_erase.
* If the options field is set then erase the indicated section
* else erase all sections.
*
*F***************************************************************************/
void Erase( void )
{
int Error;
unsigned NumberBlocks = MyFlash.NumberBlocks;
unsigned Current = 0;
FLASH_ADDR Faddr;
// If PRG_options is not equal to -1 then only erase the
// block specified by PRG_options.
//
if( PRG_options != (unsigned)-1 )
{
if( PRG_options <= MyFlash.NumberBlocks )
{
Current = PRG_options;
NumberBlocks = PRG_options+1;
}
else
{
PRG_status = PRG_STATUS_FAIL_ERASE;
return;
}
}
PRG_status = PRG_STATUS_BUSY;
PRG_options = (unsigned)-1; // Reset for the next time
while( Current < NumberBlocks )
{
Faddr = MyFlash.Blocks[Current].Paddr;
Error = FLASH_Erase( PATODA(Faddr) );
if( Error )
{
// Do not fail if we are attempting to erase a boot block
// that is write protected.
if( MyFlash.Blocks[Current].Type != FLASH_TYPE_BOOT)
{
PRG_status = PRG_STATUS_FAIL_ERASE;
return;
}
}
Current++;
}
PRG_status = PRG_STATUS_SUCCESS;
return;
}
/*F***************************************************************************
* NAME: Program
*
* DESCRIPTION: Program a "buffer" of flash
*
* NOTES: This routine is called by the assembly routine _PRG_program.
*
*F***************************************************************************/
void Program( void )
{
int Error;
PRG_status = PRG_STATUS_BUSY;
Error = FLASH_Write( (FLASH_ADDR ) (PATODA(PRG_paddr)),
(FLASH_DTYPE *)(PATODA(PRG_bufaddr)),
BYTETOLOC(PRG_length) );
PRG_status = (Error != 0) ? PRG_STATUS_FAIL_PROGRAM
: PRG_STATUS_SUCCESS;
PRG_options = (unsigned)-1; // Reset for the next time
return;
}
/*F***************************************************************************
* NAME: Verify
*
* DESCRIPTION: Verify a "buffer" of flash
*
* NOTES: This routine is called by the assembly routine _PRG_verify
*
*F***************************************************************************/
void Verify( void )
{
int Error = 0;
unsigned Count = BYTETOLOC(PRG_length);
FLASH_DTYPE * pVer = (FLASH_DTYPE *)(PATODA(PRG_bufaddr));
FLASH_ADDR Faddr = (FLASH_ADDR )(PATODA(PRG_paddr));
PRG_status = PRG_STATUS_BUSY;
FlsWrite( FLASH_BASE, CMD_READ_ARRAY );
while( Count-- )
{
if( *pVer != FlsRead( Faddr ))
Error++;
pVer++;
Faddr += sizeof(FLASH_DTYPE);
}
PRG_status = (Error != 0) ? PRG_STATUS_FAIL_VERIFY
: PRG_STATUS_SUCCESS;
PRG_options = (unsigned)-1; // Reset for the next time
return;
}
#if defined( FLASH_DEBUG )
static int
FlashTestBlocks( void )
{
int Error;
int i;
FLASH_MFG_CODE MfgCode;
unsigned NumBlocks;
FLASH_DTYPE * pData = (FLASH_DTYPE *)PRG_bufaddr;
MfgCode.MfgId = 0;
MfgCode.DevId = 0;
// Read the id and check for AM29LV400B
Error = FLASH_MfgCode( &MfgCode );
if( ( MfgCode.MfgId != MyFlash.MfgId )
|| ( MfgCode.DevId != MyFlash.DevId ))
return( PRG_STATUS_FAIL_INIT );
Error = 0;
// Erase all the blocks
PRG_options = (unsigned)-1; // Erase all blocks
PRG_status = (unsigned)-1; // Set fail code
Erase();
if( PRG_status != PRG_STATUS_SUCCESS )
Error++;
NumBlocks = MyFlash.NumberBlocks;
// Program each block with a test id
for( i=0; i<NumBlocks; i++ )
{
pData[0] = i;
pData[1] = (FLASH_DTYPE)(MyFlash.Blocks[i].Paddr>>12);
/* We convert the address to program address and count to
* bytes
*/
PRG_paddr = MyFlash.Blocks[i].Paddr;
PRG_page = 0;
PRG_length = LOCTOBYTE(2);
PRG_status = (unsigned)-1;
PRG_options = (unsigned)-1;
Program();
if( PRG_status != PRG_STATUS_SUCCESS )
Error++;
}
// Verify each block with a test id
for( i=0; i<NumBlocks; i++ )
{
pData[0] = i;
pData[1] = (FLASH_DTYPE)(MyFlash.Blocks[i].Paddr>>12);
PRG_paddr = MyFlash.Blocks[i].Paddr;
PRG_page = 0;
PRG_length = LOCTOBYTE(2);
PRG_status = (unsigned)-1;
PRG_options = (unsigned)-1;
Verify();
if( PRG_status != PRG_STATUS_SUCCESS )
Error++;
}
return( ( Error == 0 ) ? PRG_STATUS_SUCCESS : PRG_STATUS_FAIL_INIT );
}
#endif // End of #if defined( FLASH_DEBUG )
#if defined ( SUBROUTINE_IF)
/*F***************************************************************************
* NAME: SubRoutineFlashTestMain
*
* DESCRIPTION: Subroutine interface.
*
* NOTES:
*
*F***************************************************************************/
int
SubRoutineFlashTestMain( void )
{
PRG_bufaddr = DATOPA((unsigned )&Buffer[0]);
PRG_bufsize = BYTES_IN_FLASH_BUFFER;
PRG_devsize = 0x8000; // Not used, here for history
PRG_paddr = FLASH_BASE;
PRG_page = 0;
PRG_length = 0;
PRG_status = 0;
PRG_options = (unsigned)-1;
PRG_status = FlashTestBlocks();
return( PRG_status );
}
#else
static
EmifInit( void )
{
// Add emif stuff here
}
/*F***************************************************************************
* NAME: main
*
* DESCRIPTION: Init the C64xflash programming arguments.
*
* NOTES:
*
*F***************************************************************************/
extern void PRG_exit(void);
void main( void )
{
EmifInit();
PRG_bufaddr = DATOPA((unsigned )&Buffer[0]);
PRG_bufsize = BYTES_IN_FLASH_BUFFER;
PRG_devsize = 0x8000; // Not used, here for history
PRG_paddr = FLASH_BASE;
PRG_page = 0;
PRG_length = 0;
PRG_status = 0;
PRG_options = (unsigned)-1;
#if defined( FLASH_DEBUG )
PRG_status = FlashTestBlocks();
#endif
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -