📄 flash_strata.c
字号:
UINT8 *pdst ;
/* set addresses */
psrc = (UINT8*) p_param->buffer ;
pdst = (UINT8*) p_param->adr ;
len = p_param->length ;
/* call our speedy memcpy */
memcpy( pdst, psrc, len ) ;
return(OK) ;
}
/************************************************************************
*
* FLASH_STRATA_program_flash
* Description :
* -------------
* Programs a Intel 28Fxxx-compliant flash device.
*
*
* Parameters :
* ------------
*
* 'p_param', IN, variable of type, t_FLASH_write_descriptor.
*
*
* Return values :
* ---------------
*
* 'OK' = 0x00: FLASH programmed succesfully
* ERROR_FLASH_PROGRAM_ERROR Flash device failure
*
*
************************************************************************/
static
INT32 FLASH_STRATA_program_flash( t_FLASH_write_descriptor *p_param )
{
int rcode = OK ;
t_flash_access dw ; /* destination words */
int i, j, wc, len, rest ;
void volatile *psrc ;
void volatile *pdst ;
/* convert addresses to kseg1 */
psrc = p_param->buffer ;
pdst = (void*)KSEG1((UINT32)p_param->adr) ;
len = p_param->length ;
/* check any special case */
if (len <= 0)
{
return(OK) ;
}
/* test for initial alignment */
rest = (UINT32)pdst & 0x3 ;
if (rest)
{
/* Need for initial word alignment */
/* read destination word */
(UINT32)pdst = ((UINT32)pdst & 0xfffffffc) ;
dw.d32 = REG32(pdst) ;
/* calculate upper byte boundary inside word */
j = 4 ;
if (len < (4-rest))
{
j = rest + len ;
}
/* merge rest into last dest. word */
for (i=rest; i<j; i++)
{
/* copy source bytes into last word */
dw.d8[i] = REG8(psrc) ;
(UINT32)psrc += 1 ;
len-- ;
}
/* issue 'CLEAR STATUS: SR-5,4,3,1' command */
REG32(pdst) = FLASH_CLEAR_STATUS_COMMAND ;
/* program this word */
REG32(pdst) = FLASH_WRITE_WORD_COMMAND ;
REG32(pdst) = dw.d32 ;
/* await completion */
rcode = FLASH_STRATA_wait_ready( pdst, FLASH_RETRY_10);
if (rcode)
{
return(rcode) ;
}
/* Verify programmed word */
REG32(pdst) = FLASH_READ_COMMAND ;
if ( REG32(pdst) != dw.d32 )
{
memset( flash_diag_msg, 0, sizeof(flash_diag_msg) ) ;
sprintf( flash_diag_msg, "Data check read: (0x%08x)=0x%08x, Data written: 0x%08x", (UINT32)pdst, REG32(pdst), dw.d32) ;
return(ERROR_FLASH_VERIFY_ERROR) ;
}
/* adjust destination pointer */
(UINT32)pdst += 4 ;
}
/* calculate words to program and some rest of bytes */
wc = len / 4 ;
rest = len % 4 ;
/* now, destination is word aligned, check source */
/* issue 'CLEAR STATUS: SR-5,4,3,1' command */
REG32(pdst) = FLASH_CLEAR_STATUS_COMMAND ;
if ((UINT32)psrc & 0x3)
{
/* destination only is word aligned */
/* program word by word */
for (i=0; i<wc; i++)
{
/* copy source bytes into dest. word */
for (j=0; j<4; j++)
{
dw.d8[j] = REG8(psrc) ;
(UINT32)psrc += 1 ;
}
/* program this word */
REG32(pdst) = FLASH_WRITE_WORD_COMMAND ;
REG32(pdst) = dw.d32 ;
/* await completion */
rcode = FLASH_STRATA_wait_ready( pdst, FLASH_RETRY_10);
if (rcode != OK)
{
return(rcode) ;
}
/* Verify programmed word */
REG32(pdst) = FLASH_READ_COMMAND ;
if ( REG32(pdst) != dw.d32 )
{
memset( flash_diag_msg, 0, sizeof(flash_diag_msg) ) ;
sprintf( flash_diag_msg, "Data check read: (0x%08x)=0x%08x, Data written: 0x%08x", (UINT32)pdst, REG32(pdst), dw.d32) ;
return(ERROR_FLASH_VERIFY_ERROR) ;
}
/* next destination word */
(UINT32)pdst += 4 ;
}
}
else
{
/* both source and destination is word aligned */
/* program word by word */
for (i=0; i<wc; i++)
{
/* program this word */
dw.d32 = REG32(psrc) ; /* Source may be a FLASH device */
REG32(pdst) = FLASH_WRITE_WORD_COMMAND ;
REG32(pdst) = dw.d32 ;
/* await completion */
rcode = FLASH_STRATA_wait_ready( pdst, FLASH_RETRY_10);
if (rcode != OK)
{
return(rcode) ;
}
/* Verify programmed word */
REG32(pdst) = FLASH_READ_COMMAND ;
if ( REG32(pdst) != dw.d32 )
{
memset( flash_diag_msg, 0, sizeof(flash_diag_msg) ) ;
sprintf( flash_diag_msg, "Data check read: (0x%08x)=0x%08x, Data written: 0x%08x", (UINT32)pdst, REG32(pdst), dw.d32) ;
return(ERROR_FLASH_VERIFY_ERROR) ;
}
/* next destination and source word */
(UINT32)pdst += 4 ;
(UINT32)psrc += 4 ;
}
}
if (rest)
{
/* we still have some bytes left */
/* clear status and set flash to read mode */
/* issue 'CLEAR STATUS: SR-5,4,3,1' command */
REG32(pdst) = FLASH_CLEAR_STATUS_COMMAND ;
/* issue 'READ ARRAY' command */
REG32(pdst) = FLASH_READ_COMMAND ;
/* read destination word */
dw.d32 = REG32(pdst) ;
/* merge rest into last dest. word */
for (i=0; i<rest; i++)
{
/* copy source bytes into last word */
dw.d8[i] = REG8(psrc) ;
(UINT32)psrc += 1 ;
}
/* program this word */
REG32(pdst) = FLASH_WRITE_WORD_COMMAND ;
REG32(pdst) = dw.d32 ;
/* await completion */
rcode = FLASH_STRATA_wait_ready( pdst, FLASH_RETRY_10);
if (rcode != OK)
{
return(rcode) ;
}
/* Verify programmed word */
REG32(pdst) = FLASH_READ_COMMAND ;
if ( REG32(pdst) != dw.d32 )
{
memset( flash_diag_msg, 0, sizeof(flash_diag_msg) ) ;
sprintf( flash_diag_msg, "Data check read: (0x%08x)=0x%08x, Data written: 0x%08x", (UINT32)pdst, REG32(pdst), dw.d32 ) ;
return(ERROR_FLASH_VERIFY_ERROR) ;
}
}
return( rcode ) ;
}
/************************************************************************
*
* FLASH_STRATA_set_systemflash_read
* Description :
* -------------
* Set system flash device in read mode.
*
*
* Parameters :
* ------------
*
* -
*
*
* Return values :
* ---------------
*
* 'OK' = 0x00: System FLASH set to read mode
* ERROR_FLASH_PROGRAM_ERROR Flash device failure
*
*
************************************************************************/
static
INT32 FLASH_STRATA_set_systemflash_read( void )
{
int rcode ;
UINT32 bank ;
volatile UINT32 *pw ;
pw = (UINT32*) KSEG1(systemflash_phys_start) ;
for (bank = 0; bank < systemflash_bank_count; bank++)
{
/* issue 'CLEAR STATUS: SR-5,4,3,1' command */
REG32(pw) = FLASH_CLEAR_STATUS_COMMAND;
/* issue 'READ ARRAY' command */
REG32(pw) = FLASH_READ_COMMAND;
/* next bank: */
pw = (UINT32*)((UINT32)pw + (systemflash_block_count * systemflash_block_size)) ;
}
return( OK ) ;
}
/************************************************************************
*
* FLASH_STRATA_set_fileflash_read
* Description :
* -------------
* Set file flash device in read mode.
*
*
* Parameters :
* ------------
*
* -
*
*
* Return values :
* ---------------
*
* 'OK' = 0x00: File FLASH set to read mode
* ERROR_FLASH_PROGRAM_ERROR Flash device failure
*
*
************************************************************************/
static
INT32 FLASH_STRATA_set_fileflash_read( void )
{
int rcode ;
UINT32 bank ;
volatile UINT32 *pw ;
pw = (UINT32*) KSEG1(fileflash_phys_start) ;
/* issue 'CLEAR STATUS: SR-5,4,3,1' command */
REG32(pw) = FLASH_CLEAR_STATUS_COMMAND;
/* issue 'READ ARRAY' command */
REG32(pw) = FLASH_READ_COMMAND;
return( OK ) ;
}
/************************************************************************
*
* FLASH_STRATA_set_monitorflash_read
* Description :
* -------------
* Set monitor flash device in read mode.
*
*
* Parameters :
* ------------
*
* -
*
*
* Return values :
* ---------------
*
* 'OK' = 0x00: File FLASH set to read mode
* ERROR_FLASH_PROGRAM_ERROR Flash device failure
*
*
************************************************************************/
static
INT32 FLASH_STRATA_set_monitorflash_read( void )
{
int rcode ;
UINT32 bank ;
volatile UINT32 *pw ;
pw = (UINT32*) KSEG1(monitorflash_phys_start) ;
/* issue 'CLEAR STATUS: SR-5,4,3,1' command */
REG32(pw) = FLASH_CLEAR_STATUS_COMMAND;
/* issue 'READ ARRAY' command */
REG32(pw) = FLASH_READ_COMMAND;
return( OK ) ;
}
/************************************************************************
*
* FLASH_STRATA_erase_systemflash
* Description :
* -------------
* Erase complete system flash.
*
*
* Parameters :
* ------------
*
* -
*
* Return values :
* ---------------
*
* 'OK' = 0x00: System FLASH erased succesfully
* ERROR_FLASH_PROGRAM_ERROR Flash device failure
*
*
************************************************************************/
static
INT32 FLASH_STRATA_erase_systemflash( void )
{
int rcode ;
UINT32 block, bank ;
volatile UINT32 *pw ;
WRITE_ENABLE ;
pw = (UINT32*)KSEG1(systemflash_phys_start) ;
/* issue 'CLEAR STATUS: SR-5,4,3,1' command */
REG32(pw) = FLASH_CLEAR_STATUS_COMMAND ;
for (bank = 0; bank < systemflash_bank_count; bank++)
{
for (block = 0; block < systemflash_block_count; block++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -