📄 lld.c
字号:
status = HalWrite(base_addr + offset, NOR_SECTOR_ERASE_CMD,
err_code_ptr, err_buf);
#ifdef AMD_DRIVER_FLASH_FOR_SW
int_enable(cpsr);
#endif
if(status != LLD_OK)
break;
#ifdef MIRRORBIT
#ifdef USING_ERASE_SUSPEND
status = lld_pauseWhileEraseBegins(base_addr, offset, data_cfg, err_code_ptr, err_buf);
if(status != LLD_OK)
break;
#endif
#endif
/* drop through */
break;
}
return(status);
}
/******************************************************************************
*
* lld_ChipErsCmd - Writes a Chip Erase Command to Flash Device
*
* This function only issues the Chip Erase Command sequence.
* Data bar polling is not implemented in this function.
*
*
* RETURNS: LLD_OK, or LLD_ERROR
*
* ERRNO:
* errors from UnlockAddrsInit
* errors generated by HAL functions
*/
int lld_ChipErsCmd
(
ADDRESS base_addr, /* device base address in system */
DWORD offset, /* address offset from base address */
PARAM data_cfg, /* flash data width and # of devices */
PARAM *err_code_ptr, /* variable to store error code */
char *err_buf /* buffer to store error text */
)
{
int status = LLD_OK;
DWORD ulock_addr1;
DWORD ulock_addr2;
/*
* Reserved for Future Use.
* Trivial assignment to avoid compiler warnings
*/
offset = offset;
status = UnlockAddrsInit(&ulock_addr1, &ulock_addr2, data_cfg,
err_code_ptr, err_buf);
if(status != LLD_OK)
return(status);
/* Issue Chip Erase Command Sequence */
for(; ; )
/* dummy loop for "break" */
{
status = HalWrite(base_addr + ulock_addr1, NOR_UNLOCK_DATA1,
err_code_ptr, err_buf);
if(status != LLD_OK)
break;
status = HalWrite(base_addr + ulock_addr2, NOR_UNLOCK_DATA2,
err_code_ptr, err_buf);
if(status != LLD_OK)
break;
status = HalWrite(base_addr + ulock_addr1, NOR_ERASE_SETUP_CMD,
err_code_ptr, err_buf);
if(status != LLD_OK)
break;
status = HalWrite(base_addr + ulock_addr1, NOR_UNLOCK_DATA1,
err_code_ptr, err_buf);
if(status != LLD_OK)
break;
status = HalWrite(base_addr + ulock_addr2, NOR_UNLOCK_DATA2,
err_code_ptr, err_buf);
if(status != LLD_OK)
break;
/* Write Chip Erase Command to Base Address */
status = HalWrite(base_addr + ulock_addr1, NOR_CHIP_ERASE_CMD,
err_code_ptr, err_buf);
if(status != LLD_OK)
break;
/* drop through */
break;
}
return(status);
}
/******************************************************************************
*
* lld_PgmCmd - Writes a Program Command to Flash Device
*
* This function only issues the Program Command sequence.
* Data bar polling is not implemented in this function.
*
*
* RETURNS: LLD_OK, or LLD_ERROR
*
* ERRNO:
* errors from UnlockAddrsInit
* errors generated by HAL functions
*/
int lld_PgmCmd
(
ADDRESS base_addr, /* device base address in system */
DWORD offset, /* address offset from base address */
PARAM data_cfg, /* flash data width and # of devices */
FLASHDATA *pgm_data_ptr, /* variable containing data to program */
PARAM *err_code_ptr, /* variable to store error code */
char *err_buf /* buffer to store error text */
)
{
int status = LLD_OK;
DWORD ulock_addr1;
DWORD ulock_addr2;
uint32 cpsr;
status = UnlockAddrsInit(&ulock_addr1, &ulock_addr2, data_cfg,
err_code_ptr, err_buf);
if(status != LLD_OK)
return(status);
#if 1
/* Issue Program Command Sequence */
#ifdef AMD_DRIVER_FLASH_FOR_SW
cpsr = int_disable();
dev.state = DEV_WRITE;
#endif
for(; ; )
/* dummy loop for "break" */
{
status = HalWrite(base_addr + ulock_addr1, NOR_UNLOCK_DATA1,
err_code_ptr, err_buf);
if(status != LLD_OK)
break;
status = HalWrite(base_addr + ulock_addr2, NOR_UNLOCK_DATA2,
err_code_ptr, err_buf);
if(status != LLD_OK)
break;
/* Write Program Command */
status = HalWrite(base_addr + ulock_addr1, NOR_PROGRAM_CMD,
err_code_ptr, err_buf);
if(status != LLD_OK)
break;
/* Write Data */
status = HalWrite(base_addr + offset, *pgm_data_ptr,
err_code_ptr, err_buf);
#ifdef AMD_DRIVER_FLASH_FOR_SW
int_enable(cpsr);
#endif
if(status != LLD_OK)
break;
#ifdef MIRRORBIT_DEVICE
/* Make sure we are not program suspended (E1) */
status = lld_ProgramResumeCmd(base_addr, offset, data_cfg,
err_code_ptr, err_buf);
if(status != LLD_OK)
break;
#endif
/* drop through */
break;
}
#else
*(volatile Uint16 *)(0x0c000000+0x555) = 0xAA; // unlock cycle 1
*(volatile Uint16 *)(0x0c000000+0x2AA) = 0x55; // unlock cycle 2
*(volatile Uint16 *)(0x0c000000+0x555) = 0xA0;
*(volatile Uint16 *)(0x0c000020) = 0xabcd;
#endif
return(status);
}
/******************************************************************************
*
* lld_UnlockBypassEnterCmd - Writes Unlock Bypass Enter command to flash
*
*
* RETURNS: LLD_OK, or LLD_ERROR
*
* ERRNO:
* errors generated by HAL functions
*/
int lld_UnlockBypassEnterCmd
(
ADDRESS base_addr, /* device base address in system */
DWORD offset, /* address offset from base address */
PARAM data_cfg, /* flash data width and # of devices */
PARAM *err_code_ptr, /* variable to store error code */
char *err_buf /* buffer to store error text */
)
{
int status = LLD_OK;
DWORD ulock_addr1;
DWORD ulock_addr2;
/*
* Reserved for Future Use.
* Trivial assignment to avoid compiler warnings
*/
offset = offset;
status = UnlockAddrsInit(&ulock_addr1, &ulock_addr2, data_cfg,
err_code_ptr, err_buf);
if(status != LLD_OK)
return(status);
/* Issue Unlock Bypass Enter Command Sequence */
for(; ; )
/* dummy loop for "break" */
{
status = HalWrite(base_addr + ulock_addr1, NOR_UNLOCK_DATA1,
err_code_ptr, err_buf);
if(status != LLD_OK)
return(status);
status = HalWrite(base_addr + ulock_addr2, NOR_UNLOCK_DATA2,
err_code_ptr, err_buf);
if(status != LLD_OK)
return(status);
status = HalWrite(base_addr + ulock_addr1, NOR_UNLOCK_BYPASS_ENTRY_CMD,
err_code_ptr, err_buf);
if(status != LLD_OK)
return(status);
/* drop through */
break;
}
return(status);
}
/******************************************************************************
*
* lld_UnlockBypassPgmCmd - Writes Unlock Bypass Pgm Sequence to Flash
*
* This function issues the Unlock Bypass Programming Sequence to device.
* Device must be in Unlock Bypass mode before using this function.
* Data bar polling is not implemented in this function.
*
*
* RETURNS: LLD_OK, or LLD_ERROR
*
* ERRNO:
* errors from UnlockAddrsInit
* errors generated by HAL functions
*/
int lld_UnlockBypassPgmCmd
(
ADDRESS base_addr, /* device base address in system */
DWORD offset, /* address offset from base address */
PARAM data_cfg, /* flash data width and # of devices */
FLASHDATA *pgm_data_ptr, /* variable containing data to program */
PARAM *err_code_ptr, /* variable to store error code */
char *err_buf /* buffer to store error text */
)
{
int status = LLD_OK;
DWORD ulock_addr1;
DWORD ulock_addr2;
status = UnlockAddrsInit(&ulock_addr1, &ulock_addr2, data_cfg,
err_code_ptr, err_buf);
if(status != LLD_OK)
return(status);
/* Issue Unlock Bypass Program Command Sequence */
for(; ; )
/* dummy loop for "break" */
{
/* Write Program Command */
status = HalWrite(base_addr + ulock_addr1, NOR_PROGRAM_CMD,
err_code_ptr, err_buf);
if(status != LLD_OK)
break;
/* Write Data */
status = HalWrite(base_addr + offset, *pgm_data_ptr,
err_code_ptr, err_buf);
if(status != LLD_OK)
break;
/* drop through */
break;
}
return(status);
}
/******************************************************************************
*
* lld_UnlockBypassExitCmd - Writes Unlock Bypass Exit command to flash
*
* Issues Unlock Bypass Exit command sequence to Flash Device.
*
*
* RETURNS: LLD_OK, or LLD_ERROR
*
* ERRNO:
* errors generated by HAL functions
*/
int lld_UnlockBypassExitCmd
(
ADDRESS base_addr, /* device base address in system */
DWORD offset, /* address offset from base address */
PARAM data_cfg, /* flash data width and # of devices */
PARAM *err_code_ptr, /* variable to store error code */
char *err_buf /* buffer to store error text */
)
{
int status = LLD_OK;
/*
* Reserved for Future Use.
* Trivial assignment to avoid compiler warnings
*/
data_cfg = data_cfg;
/* Issue Unlock Bypass Exit Command Sequence */
for(; ; )
/* dummy loop for "break" */
{
/* First Unlock Bypass Reset Command */
status = HalWrite(base_addr + offset, NOR_UNLOCK_BYPASS_RESET_CMD1,
err_code_ptr, err_buf);
if(status != LLD_OK)
break;
/* Second Unlock Bypass Reset Command */
status = HalWrite(base_addr + offset, NOR_UNLOCK_BYPASS_RESET_CMD2,
err_code_ptr, err_buf);
if(status != LLD_OK)
break;
/* drop through */
break;
}
return(status);
}
/******************************************************************************
*
* lld_AutoselectEnterCmd - Writes Autoselect Command Sequence to Flash
*
* This function issues the Autoselect Command Sequence to device.
*
*
* RETURNS: LLD_OK, or LLD_ERROR
*
* ERRNO:
* errors from UnlockAddrsInit
* errors generated by HAL functions
*/
int lld_AutoselectEnterCmd
(
ADDRESS base_addr, /* device base address in system */
DWORD offset, /* address offset from base address */
PARAM data_cfg, /* flash data width and # of devices */
PARAM *err_code_ptr, /* variable to store error code */
char *err_buf /* buffer to store error text */
)
{
int status = LLD_OK;
DWORD ulock_addr1;
DWORD ulock_addr2;
status = UnlockAddrsInit(&ulock_addr1, &ulock_addr2, data_cfg,
err_code_ptr, err_buf);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -