📄 fdi_sprc.c
字号:
HW_ERROR LowLvlEraseBlock(volatile FLASH_DATA_PTR flash_ptr)
{
static HW_ERROR status = HW_ERR_NONE;
/* check if previously suspended; if so, resume */
if (status == HW_ERR_SUSPEND)
{
*flash_ptr = FLASH_COMMAND_RESUME;
*flash_ptr = FLASH_COMMAND_STATUS;
}
/* otherwise, unlock block & issue erase command */
else
{
UNLOCK_BLOCK(flash_ptr);
*flash_ptr = FLASH_COMMAND_ERASE;
*flash_ptr = FLASH_COMMAND_CONFIRM;
}
/* wait until flash ready or interrupt occurs */
while (((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY) &&
(!(INTERRUPT_PENDING)))
{
#if (TIME_MONITOR_ENABLED == TRUE)
if (TICKS_TILL_NEXT_INTERRUPT() < LowLvlTimeNeeded)
{
break;
}
#endif
}
/* if an interrupt occurred, suspend */
if ((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY)
{
*flash_ptr = FLASH_COMMAND_SUSPEND;
*flash_ptr = FLASH_COMMAND_STATUS;
while ((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY)
{
}
status = HW_ERR_SUSPEND;
}
/* erase complete, check for errors */
else if (*flash_ptr & FLASH_STATUS_ERROR)
{
*flash_ptr = FLASH_COMMAND_CLEAR;
status = HW_ERR_ERASE;
}
/* erase was successful */
else
{
status = HW_ERR_NONE;
}
/* lock block (OK while erase suspended) */
LOCK_BLOCK(flash_ptr);
/* place back into read array mode */
*flash_ptr = FLASH_COMMAND_READ;
return status;
}
/*#############################################################################
### LowLvlReadStat
###
### DESCRIPTION:
### Reads the status register(s) of the flash hardware.
###
### PARAMETERS:
### IN: address (DWORD) - An absolute physical starting address of the
### partition to have its status register read.
### OUT:
###
### RETURNS:
### The value of the status register(s).
###
*/
FLASH_DATA LowLvlReadStat(volatile FLASH_DATA_PTR flash_ptr)
{
FLASH_DATA status_reg;
*flash_ptr = FLASH_COMMAND_STATUS;
status_reg = *flash_ptr;
*flash_ptr = FLASH_COMMAND_READ;
return status_reg;
}
/*#############################################################################
### LowLvlClearStat
###
### DESCRIPTION:
### Clears the status register(s) of the flash hardware.
###
### PARAMETERS:
### IN: address (DWORD) - An absolute physical address within the
### partition to have its status register(s) cleared.
### OUT:
###
### RETURNS:
### None.
###
*/
void LowLvlClearStat(volatile FLASH_DATA_PTR flash_ptr)
{
*flash_ptr = FLASH_COMMAND_CLEAR;
*flash_ptr = FLASH_COMMAND_READ;
}
#if (BLOCK_LOCK_SUPPORT == TRUE)
/*#############################################################################
### LowLvlLock
###
### DESCRIPTION:
### Performs one of the following operations on the flash hardware:
### lock a block, lock down a block, unlock a block, or read the lock
### status of a block.
###
### PARAMETERS:
### IN: block_status_ptr (FLASH_DATA_PTR) - A pointer to a buffer to
### store the lock status of the block.
### address (DWORD) - The starting address of the block within
### flash to perform the lock operation on.
### command (HW_CMD) - The lock-related command to issue: lock
### (HW_CMD_LOCK), lock down (HW_CMD_LOCKDOWN), unlock
### (HW_CMD_UNLOCK), or read the block's lock status
### (HW_CMD_READLOCKSTATUS).
### OUT: block_status_ptr - Contains the contents of the block's lock
### status if the command issued was HW_CMD_READLOCKSTATUS;
### otherwise, the contents are unknown.
###
### RETURNS:
### If the command is not appropriate, the function returns HW_ERR_PARAM;
### otherwise, the function returns HW_ERR_NONE.
###
*/
HW_ERROR LowLvlLock(volatile FLASH_DATA_PTR flash_ptr,
FLASH_DATA_PTR block_status_ptr,
HW_CMD command)
{
HW_ERROR status = HW_ERR_NONE;
/*E.5.0.633.START*/
if (command == HW_CMD_LOCK)
{
*flash_ptr = FLASH_COMMAND_LOCK;
*flash_ptr = FLASH_COMMAND_LOCK_CONFIRM;
}
else if (command == HW_CMD_UNLOCK)
{
*flash_ptr = FLASH_COMMAND_LOCK;
*flash_ptr = FLASH_COMMAND_UNLOCK_CONFIRM;
}
else if (command == HW_CMD_LOCKDOWN)
{
*flash_ptr = FLASH_COMMAND_LOCK;
*flash_ptr = FLASH_COMMAND_LOCKDOWN_CONFIRM;
}
else if (command == HW_CMD_READLOCKSTATUS)
{
*flash_ptr = FLASH_COMMAND_QUERY;
*block_status_ptr = *(flash_ptr + BLOCK_LOCK_STATUS_OFFSET);
}
else
{
status = HW_ERR_PARAM;
}
/*E.5.0.633.END*/
/* place part into read array mode */
*flash_ptr = FLASH_COMMAND_READ;
return status;
}
#endif /* BLOCK_LOCK_SUPPORT */
#if (ENABLE_PR != FDI_NONE)
/*#############################################################################
### LowLvlProtectReg
###
### DESCRIPTION:
### Reads/writes the protection registers and locks. When the
### configuration is paired 16-bit parts, the user will address the
### matching registers as a single 32-bit register, instead of addressing
### them as two 16-bit registers on a 32-bit bus.
###
### PARAMETERS:
### IN: data_ptr (FLASH_DATA_PTR) - The data value to write if the
### command is a write, or a buffer to store the value fetched
### if the command is a read.
### address (DWORD) - The absolute physical address of the protection
### register to read/write.
### command (HW_CMD) - The protection register related command to
### issue: write protection register lock (HW_CMD_WRITE_PR_LOCK),
### read protection register lock (HW_CMD_READ_PR_LOCK), write
### protection register (HW_CMD_WRITE_PR), or read protection
### registers (HW_CMD_READ_PR).
### OUT: data_ptr - Contains the contents of the protection lock register
### or protection register if the command issued was
### HW_CMD_READ_PR_LOCK or HW_CMD_READ_PR, respectively.
###
### RETURNS:
### If the command is not appropriate, the function returs HW_ERR_PARAM.
### If the maximum time limit expires or if an error occurred while
### programming the protection register or protection lock register,
### the function returns HW_ERR_WRITE. Otherwise, the function returns
### HW_ERR_NONE.
###
*/
HW_ERROR LowLvlProtectReg(volatile FLASH_DATA_PTR flash_ptr,
FLASH_DATA_PTR data_ptr, HW_CMD command)
{
HW_ERROR status;
/*E.5.0.633.START*/
/* issue command */
if ((command==HW_CMD_WRITE_PR_LOCK) || (command==HW_CMD_WRITE_PR))
{
*flash_ptr = FLASH_COMMAND_WRITE_PR;
*flash_ptr = *data_ptr;
/* wait until flash is ready */
*flash_ptr = FLASH_COMMAND_STATUS;
while ((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY)
{
}
/* check for errors */
if (*flash_ptr & FLASH_STATUS_ERROR)
{
*flash_ptr = FLASH_COMMAND_CLEAR;
status = HW_ERR_WRITE;
}
else
{
status = HW_ERR_NONE;
}
}
else if ((command==HW_CMD_READ_PR_LOCK) || (command==HW_CMD_READ_PR))
{
*flash_ptr = FLASH_COMMAND_READ_ID;
*data_ptr = *flash_ptr;
status = HW_ERR_NONE;
}
else
{
status = HW_ERR_PARAM;
}
/*E.5.0.633.END*/
/* place back into read array mode */
*flash_ptr = FLASH_COMMAND_READ;
return status;
}
#endif /* ENABLE_PR */
#if ((PACKET_DATA == TRUE) && (BUFFER_SIZE == 0))
/*#############################################################################
### LowLvlWritePacket
###
### DESCRIPTION:
### Writes as much data to flash before an interrupt occurs. The flash
### will be suspended if an interrupt occurs before the function is able
### to write all the data to flash.
###
### PARAMETERS:
### IN: dst_addr_ptr (DWORD_PTR) - Points to a variable containing
### the address to write to.
### src_addr_ptr (DWORD_PTR) - Points to a variable containing
### the address to read from.
### size_ptr (DWORD_PTR) - Points to a variable containing the
### number of FLASH_DATA units to write.
### OUT: dst_addr_ptr - Contains the next address to write to.
### src_addr_ptr - Contains the next address to read from.
### size_ptr - Contains the number of FLASH_DATA units that
### still need to be written.
###
### RETURNS:
### If an interrupt occurs before the function is able to write all
### the data to flash, HW_ERR_SUSPEND is returned. If an error occurred
### during any write, HW_ERR_WRITE is returned. If all the data is
### written to flash and no errors occurred, the function returns
### HW_ERR_NONE.
###
*/
HW_ERROR LowLvlWritePacket(DWORD_PTR dst_addr_ptr, DWORD_PTR src_addr_ptr,
DWORD_PTR size_ptr)
{
volatile FLASH_DATA_PTR flash_ptr = (FLASH_DATA_PTR) *dst_addr_ptr;
FLASH_DATA_PTR ram_ptr = (FLASH_DATA_PTR) *src_addr_ptr;
DWORD size = *size_ptr;
static HW_ERROR status = HW_ERR_NONE;
#if ((BLOCK_LOCK_SUPPORT == TRUE) && (ENABLE_FDI_BLOCKLOCKING == TRUE))
if (status != HW_ERR_SUSPEND)
{
UNLOCK_BLOCK(flash_ptr);
}
#endif /* BLOCK_LOCK_SUPPORT && ENABLE_FDI_BLOCKLOCKING */
while (size > 0)
{
if (status == HW_ERR_SUSPEND)
{
*flash_ptr = FLASH_COMMAND_RESUME;
*flash_ptr = FLASH_COMMAND_STATUS;
}
else
{
*flash_ptr = FLASH_COMMAND_WRITE;
*flash_ptr = *ram_ptr;
}
/* wait until flash is ready or interrupt occured */
while (((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY) &&
(!(INTERRUPT_PENDING)))
{
#if (TIME_MONITOR_ENABLED == TRUE)
if (TICKS_TILL_NEXT_INTERRUPT() < LowLvlTimeNeeded)
{
break;
}
#endif
}
/* check to see if an interrupt occurred */
if ((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY)
{
*flash_ptr = FLASH_COMMAND_SUSPEND;
*flash_ptr = FLASH_COMMAND_STATUS;
while ((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY)
{
}
status = HW_ERR_SUSPEND;
break;
}
/* check to see if an error occurred */
else if (*flash_ptr & FLASH_STATUS_ERROR)
{
*flash_ptr = FLASH_COMMAND_CLEAR;
status = HW_ERR_WRITE;
break;
}
/* the write was successful */
else
{
status = HW_ERR_NONE;
flash_ptr++;
ram_ptr++;
size--;
}
}
*dst_addr_ptr = (DWORD) flash_ptr;
*src_addr_ptr = (DWORD) ram_ptr;
*size_ptr = size;
#if ((BLOCK_LOCK_SUPPORT == TRUE) && (ENABLE_FDI_BLOCKLOCKING == TRUE))
if (status != HW_ERR_SUSPEND)
{
LOCK_BLOCK(flash_ptr);
}
#endif /* BLOCK_LOCK_SUPPORT && ENABLE_FDI_BLOCKLOCKING */
*flash_ptr = FLASH_COMMAND_READ;
return status;
}
#endif /* PACKET_DATA && BUFFER_SIZE */
#if (RELOCATE_CODE == TRUE)
/*#############################################################################
### LowLvlEnd
###
### DESCRIPTION:
### This function is used as a "bookmark," allowing the above functions
### to be relocated in memory.
###
### PARAMETERS:
### IN:
### OUT:
###
### RETURNS:
### None.
###
*/
void LowLvlEnd()
{
return;
}
#endif /* RELOCATE_CODE */
#endif /* PARTITIONS */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -