📄 fdi_mpll.c
字号:
/*#############################################################################
### FlashDevRead
###
### DESCRIPTION:
### Fills the specified buffer with the number of bytes defined by 'size'
### from the device's absolute physical address. The Background Manager,
### Reclaim Task, and Foreground Manager determine the relative address
### by using the FDI mapping structure. The FlashDevRead() function
### translates the relative address into a physical system address and
### verifies the address range. The function reads the data into the
### buffer and returns the appropriate value.
###
### PARAMETERS:
### IN: buffer_ptr (BYTE_PTR) - The buffer to use while reading data.
### address (DWORD) - The starting address within flash to read from.
### size (DWORD) - The amount of data, in bytes, to read.
### OUT: buffer_ptr - Contains the contents read.
###
### RETURNS:
### If the entire source buffer does not lie within the data managed area
### (or code managed area if DAV is enabled), the function returns
### HW_ERR_PARAM. Otherwise, the function returns HW_ERR_NONE.
###
*/
HW_ERROR FlashDevRead(BYTE_PTR buffer_ptr, DWORD address, DWORD size)
{
volatile FLASH_DATA_PTR flash_data_ptr;
volatile BYTE_PTR flash_byte_ptr;
FLASH_DATA_PTR ram_data_ptr;
BYTE_PTR ram_byte_ptr;
DWORD flash_offset, ram_offset;
DWORD preempted_state;
BYTE suspended = (BYTE) FALSE;
/* validate address */
address += LOWLVL_FLASH_START_ADDRESS;
VALIDATE_ADDRESS(address, size);
/* return if nothing to read */
if (size == 0)
{
return HW_ERR_NONE;
}
/* set up pointers */
flash_data_ptr = (FLASH_DATA_PTR) ALIGN_ADDRESS(address);
flash_byte_ptr = (BYTE_PTR) address;
ram_byte_ptr = buffer_ptr;
/* calculate alignment offsets */
flash_offset = (DWORD) UNALIGNED_BYTES(address);
ram_offset = (DWORD) UNALIGNED_BYTES((DWORD) buffer_ptr);
/* set current flash state */
preempted_state = CurrentFlashState;
CurrentFlashState = SET_PARTITION_STATE(address, HW_STATE_STATUS);
/* suspend if partition is busy */
*flash_data_ptr = FLASH_COMMAND_STATUS;
if (IS_PARTITION_BUSY(flash_data_ptr))
{
*flash_data_ptr = FLASH_COMMAND_SUSPEND;
*flash_data_ptr = FLASH_COMMAND_STATUS;
while ((*flash_data_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY)
{
}
if (*flash_data_ptr & (FLASH_STATUS_WRITE_SUSPENDED |
FLASH_STATUS_ERASE_SUSPENDED))
{
suspended = (BYTE) TRUE;
}
}
/*
* determine if source and destination addresses allow the reading on
* aligned addresses
*/
CurrentFlashState = SET_PARTITION_STATE(address, HW_STATE_READ);
*flash_data_ptr = FLASH_COMMAND_READ;
if ((flash_offset == ram_offset) && (size > sizeof(FLASH_DATA)))
{
/* read initial unaligned bytes */
if (flash_offset != 0)
{
while (flash_offset < sizeof(FLASH_DATA))
{
*ram_byte_ptr = *flash_byte_ptr;
ram_byte_ptr++;
flash_byte_ptr++;
size--;
flash_offset++;
}
}
/* read aligned data */
ram_data_ptr = (FLASH_DATA_PTR) ram_byte_ptr;
flash_data_ptr = (FLASH_DATA_PTR) flash_byte_ptr;
while (size >= sizeof(FLASH_DATA))
{
*ram_data_ptr = *flash_data_ptr;
ram_data_ptr++;
flash_data_ptr++;
size -= sizeof(FLASH_DATA);
}
/* read remaining unaligned bytes */
if (size > 0)
{
ram_byte_ptr = (BYTE_PTR) ram_data_ptr;
flash_byte_ptr = (BYTE_PTR) flash_data_ptr;
while (size > 0)
{
*ram_byte_ptr = *flash_byte_ptr;
ram_byte_ptr++;
flash_byte_ptr++;
size--;
}
}
}
/*
* source and destination addresses do not allow the reading on aligned
* addresses; therefore, a byte-by-byte copy needs to be done
*/
else
{
while (size > 0)
{
*ram_byte_ptr = *flash_byte_ptr;
ram_byte_ptr++;
flash_byte_ptr++;
size--;
}
}
/* if suspended, resume */
if (suspended)
{
/* E5.0.480 START */
CurrentFlashState = SET_PARTITION_STATE((DWORD) flash_data_ptr,
HW_STATE_STATUS);
*flash_data_ptr = FLASH_COMMAND_STATUS;
if (*flash_data_ptr & FLASH_STATUS_WRITE_SUSPENDED)
{
RESUME_WRITE_SUSPENDED_FLASH(flash_data_ptr);
}
else
{
*flash_data_ptr = FLASH_COMMAND_RESUME;
}
/* E5.0.480 END */
}
/* restore flash state */
CurrentFlashState = preempted_state;
flash_data_ptr = (FLASH_DATA_PTR) GET_PARTITION_ADDRESS(CurrentFlashState);
switch (GET_PARTITION_STATE(CurrentFlashState))
{
case HW_STATE_READ:
*flash_data_ptr = FLASH_COMMAND_READ;
break;
case HW_STATE_STATUS:
*flash_data_ptr = FLASH_COMMAND_STATUS;
break;
default:
break;
}
return HW_ERR_NONE;
}
#if (CONSISTENT_ACCESS_TIME == TRUE)
/*#############################################################################
### FlashDevUpdateDLT
###
### DESCRIPTION:
### Allows the Reclaim Task to update the data lookup table when the
### status of the spare block is BLOCK_ERASING. It scans the unit
### headers in the spare block and updates the header index field in
### the data lookup table.
###
### PARAMETERS:
### IN: address (DWORD) - The starting address within flash of the
### block to scan the unit headers.
### OUT:
###
### RETURNS:
### HW_ERR_NONE function execution is successful
###
*/
HW_ERROR
FlashDevUpdateDLT(DWORD address)
{
volatile FLASH_DATA_PTR flash_ptr;
UNIT_HDR_PTR pHdr;
DWORD preempted_state;
DWORD hdr_offset;
WORD hdr_status; /* local buf for hdr status */
WORD hdr_id; /* local buf for identifier */
BYTE hdr_type_attribute; /* local buf for hdr type_attribute */
BYTE suspended = (BYTE) FALSE;
/* validate address */
address += LOWLVL_FLASH_START_ADDRESS;
VALIDATE_ADDRESS(address, FDV_BLOCK_SIZE);
flash_ptr = (FLASH_DATA_PTR) ALIGN_ADDRESS(address);
/* Build pointer to first header in block */
pHdr = (UNIT_HDR_PTR) (address + FIRST_HEADER_OFFSET);
/* set current flash state */
preempted_state = CurrentFlashState;
CurrentFlashState = SET_PARTITION_STATE(address, HW_STATE_STATUS);
/* suspend if partition is busy */
*flash_ptr = FLASH_COMMAND_STATUS;
if (IS_PARTITION_BUSY(flash_ptr))
{
*flash_ptr = FLASH_COMMAND_SUSPEND;
*flash_ptr = FLASH_COMMAND_STATUS;
while ((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY) { }
if (*flash_ptr & (FLASH_STATUS_WRITE_SUSPENDED |
FLASH_STATUS_ERASE_SUSPENDED))
{
suspended = (BYTE) TRUE;
}
}
CurrentFlashState = SET_PARTITION_STATE(address, HW_STATE_READ);
*flash_ptr = FLASH_COMMAND_READ;
/* Scan headers to locate requested header */
while (!(HDR_STATE(HDR_EMPTY, (hdr_status = pHdr->status))))
{
hdr_id = pHdr->identifier;
hdr_type_attribute = pHdr->type_attribute;
/* Compare status to header valid.
* In the case of Packet Data, also allow HDR_VALID_HDR
* for the active Packet Data unit header(s). */
if (HDR_STATE(HDR_VALID, hdr_status)
#if (PACKET_DATA == TRUE)
|| HDR_STATE(HDR_VALID_HDR, hdr_status)
#endif /* PACKET_DATA */
)
{
/* Status valid */
/* Compare attribute, must be grp table or multi/single instance */
if ((NIBBLE_LOW(hdr_type_attribute) != ATTR_SEQ_TABLE) &&
(NIBBLE_LOW(hdr_type_attribute) != ATTR_DATA_FRAG) &&
(NOT_EMPTY_LOOKUP_TABLE(NIBBLE_HIGH(hdr_type_attribute),hdr_id)))
{
/* update header index for the corresponding header
* according to id, type and hdr offset. */
hdr_offset = (WORD)((DWORD)(pHdr)&(DWORD)(FDV_BLOCK_SIZE - 1));
SET_LOOKUP_TABLE_HDR(NIBBLE_HIGH(hdr_type_attribute), hdr_id,
hdr_offset);
}
}
/* increment offset pointer by size of the UNIT_HEADER */
pHdr = (UNIT_HDR_PTR)((BYTE_PTR)pHdr + sizeof(UNIT_HEADER));
} /* end while */
/* if suspended, resume */
if (suspended)
{
/* E5.0.480 START */
CurrentFlashState = SET_PARTITION_STATE((DWORD) flash_ptr,
HW_STATE_STATUS);
*flash_ptr = FLASH_COMMAND_STATUS;
if (*flash_ptr & FLASH_STATUS_WRITE_SUSPENDED)
{
RESUME_WRITE_SUSPENDED_FLASH(flash_ptr);
}
else
{
*flash_ptr = FLASH_COMMAND_RESUME;
}
/* E5.0.480 END */
}
/* restore flash state */
CurrentFlashState = preempted_state;
flash_ptr = (FLASH_DATA_PTR) GET_PARTITION_ADDRESS(CurrentFlashState);
switch (GET_PARTITION_STATE(CurrentFlashState))
{
case HW_STATE_READ:
*flash_ptr = FLASH_COMMAND_READ;
break;
case HW_STATE_STATUS:
*flash_ptr = FLASH_COMMAND_STATUS;
break;
default:
break;
}
return HW_ERR_NONE;
}
#endif /* CONSISTENT_ACCESS_TIME */
/*#############################################################################
### FlashDevReadHeader
###
### DESCRIPTION:
### Scans all unit headers in the block designated by the address
### specified looking for a valid header that matches the specified type
### and identifier. The Background Manager determines the relative
### address by using the FDI mapping structure. The FlashDevReadHeader()
### function translates the relative address into a physical system
### address and verifies the address range. The function the scans the
### block for the specified header and returns the appropriate value.
###
### PARAMETERS:
### IN: hdr_offset_ptr (DWORD_PTR) - A pointer to the DWORD that will
### contain the header's offset into the block.
### hdr_data_ptr (UNIT_HDR_PTR) - A pointer to the UNIT_HEADER that
### will contain the header found.
### address (DWORD) - The starting address within flash of the block
### in which to search for the unit header.
### identifier (WORD) - The identifier to look for in the unit
### header.
### type (BYTE) - The type to look for in the unit header.
### OUT: hdr_offset_ptr - Contains the offset of the header into the
### block if a valid instance can be found; otherwise, the contents
### are unknown.
### hdr_data_ptr - Contains the unit header being searched for if
### a valid instance can be found; otherwise, the contents are
### unknown.
###
### RETURNS:
### If the address does noe lie within the data managed area (or the code
### managed area if DAV is enabled), the function returns HW_ERR_PARAM.
### If a header whose type and identifier match the values passed in
### cannot be found, the function returns HW_ERR_SYSTEM. Finally, if a
### valid or allocated header is found, the function returns HW_ERR_NONE.
###
*/
HW_ERROR FlashDevReadHeader(DWORD_PTR hdr_offset_ptr,
UNIT_HDR_PTR hdr_data_ptr, DWORD address,
WORD identifier, BYTE type)
{
volatile FLASH_DATA_PTR flash_ptr;
UNIT_HDR_PTR pHdr;
DWORD preempted_state;
HW_ERROR status = HW_ERR_SYSTEM;
BYTE suspended = (BYTE) FALSE;
/* validate address */
address += LOWLVL_FLASH_START_ADDRESS;
VALIDATE_ADDRESS(address, FDV_BLOCK_SIZE);
flash_ptr = (FLASH_DATA_PTR) ALIGN_ADDRESS(address);
pHdr = (UNIT_HDR_PTR) (address + FIRST_HEADER_OFFSET);
/* set current flash state */
preempted_state = CurrentFlashState;
CurrentFlashState = SET_PARTITION_STATE(address, HW_STATE_STATUS);
/* suspend if partition is busy */
*flash_ptr = FLASH_COMMAND_STATUS;
if (IS_PARTITION_BUSY(flash_ptr))
{
*flash_ptr = FLASH_COMMAND_SUSPEND;
*flash_ptr = FLASH_COMMAND_STATUS;
while ((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY) { }
if (*flash_ptr & (FLASH_STATUS_WRITE_SUSPENDED |
FLASH_STATUS_ERASE_SUSPENDED))
{
suspended = (BYTE) TRUE;
}
}
CurrentFlashState = SET_PARTITION_STATE(address, HW_STATE_READ);
*flash_ptr = FLASH_COMMAND_READ;
/* Scan headers to located requested header */
while (!(HDR_STATE(HDR_EMPTY, pHdr->status)))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -