📄 fdi_bkgd.c
字号:
*### header, the beginning address of the unit and the logical block number.
*###
*### USAGE:
*### status = LookupToHeader(&block_addr, &unit_addr, &header_offset,
*### &unit_header, &logical_block, identifier, type);
*###
*### PARAMETERS:
*### IN:
*### identifier - unique id for each data parameter or stream
*### type - data parameter or data stream type
*###
*### OUT:
*### block_addr_ptr - pointer to the block's first address
*### unit_addr_ptr - pointer to the data unit's physical address
*### header_offset_ptr - pointer to the offset of the unit header
*### unit_header_ptr - pointer to UNIT_HEADER info
*### logical_blk_ptr - pointer to the current logical block number
*###
*### RETURNS:
*### Returns the following errors codes:
*### HW_ERR_NONE things are cool...
*### HW_ERR_PARAM input parameter error
*### HW_ERR_EMPTY_LKUP logical block number field of the DLT entry is
*### empty
*### HW_ERR_DELETE the DLT entry is empty
*###
*###*/
#if (CONSISTENT_ACCESS_TIME == TRUE)
HW_ERROR
LookupToHeader(DWORD_PTR block_addr_ptr,
DWORD_PTR unit_addr_ptr,
DWORD_PTR header_offset_ptr,
UNIT_HDR_PTR unit_header_ptr,
WORD_PTR logical_blk_ptr,
IDTYPE identifier,
BYTE type)
{
WORD physical_block;
HW_ERROR status = HW_ERR_NONE;
/* IF the identifier is out of range THEN return error RD_ERR_MAX_ID */
/* if it is the erase count, then allow */
if (identifier >= NUM_PARMS[type])
{
if(identifier != ERASE_COUNT_ID || type != ERASE_COUNT_TYPE)
return HW_ERR_PARAM;
}
SEM_MTX_WAIT(SEM_LookupTable);
/* IF the byte read was empty THEN return with a parameter error */
if (EMPTY_LOOKUP_TABLE(type, identifier))
{
SEM_MTX_POST(SEM_LookupTable);
return HW_ERR_DELETE;
}
/*
* ELSE IF the lookup table has a new entry THEN return with an empty
* lookup error this means we must create a new parameter
*/
else if (NO_LOOKUP_TABLE_BLOCK(type,identifier))
{
*block_addr_ptr = DWORDMAX;
*unit_addr_ptr = DWORDMAX;
*header_offset_ptr = DWORDMAX;
*logical_blk_ptr = WORDMAX;
SEM_MTX_POST(SEM_LookupTable);
return HW_ERR_EMPTY_LKUP;
}
/* get the block number and hdr offset from the DLT entry */
*logical_blk_ptr = LOOKUP_TABLE_BLOCK(type,identifier);
*header_offset_ptr = LOOKUP_TABLE_HDR(type,identifier);
SEM_MTX_POST(SEM_LookupTable);
SEM_MTX_WAIT(SEM_BlockTable);
physical_block =
FDI_LogicalBlockTable[*logical_blk_ptr].physical_block_number;
SEM_MTX_POST(SEM_BlockTable);
/* Calculate the actual start address of the media. */
*block_addr_ptr = BLOCK_ADDRESS(physical_block);
/* Read the unit header. */
status = FlashDevRead((BYTE_PTR)unit_header_ptr,
*block_addr_ptr + *header_offset_ptr,
sizeof(UNIT_HEADER));
if (status == HW_ERR_NONE)
{
*unit_addr_ptr = *block_addr_ptr + ((FDV_BLOCK_SIZE - sizeof(BLOCK_INFO)) -
TO_BYTES(unit_header_ptr->g_unit_offset_bottom));
}
return status;
} /* END LookupToHeader */
#else /* CONSISTENT_ACCESS_TIME == FALSE */
HW_ERROR
LookupToHeader(DWORD_PTR block_addr_ptr,
DWORD_PTR unit_addr_ptr,
DWORD_PTR header_offset_ptr,
UNIT_HDR_PTR unit_header_ptr,
WORD_PTR logical_blk_ptr,
IDTYPE identifier,
BYTE type)
{
WORD physical_block;
HW_ERROR status = HW_ERR_NONE;
/* IF the identifier is out of range THEN return error RD_ERR_MAX_ID */
/* if it is the erase count, then allow */
if (identifier >= NUM_PARMS[type])
{
if(identifier != ERASE_COUNT_ID || type != ERASE_COUNT_TYPE)
return HW_ERR_PARAM;
}
SEM_MTX_WAIT(SEM_LookupTable);
/* IF the byte read was empty THEN return with a parameter error */
if (EMPTY_LOOKUP_TABLE(type, identifier))
{
SEM_MTX_POST(SEM_LookupTable);
return HW_ERR_DELETE;
}
/*
* ELSE IF the lookup table has a new entry THEN return with an empty
* lookup error this means we must create a new parameter
*/
else if (NO_LOOKUP_TABLE_BLOCK(type,identifier))
{
*block_addr_ptr = DWORDMAX;
*unit_addr_ptr = DWORDMAX;
*header_offset_ptr = DWORDMAX;
*logical_blk_ptr = WORDMAX;
SEM_MTX_POST(SEM_LookupTable);
return HW_ERR_EMPTY_LKUP;
}
/* mask the block number from the location in lookup table */
*logical_blk_ptr = LOOKUP_TABLE_BLOCK(type,identifier);
SEM_MTX_POST(SEM_LookupTable);
SEM_MTX_WAIT(SEM_BlockTable);
physical_block =
FDI_LogicalBlockTable[*logical_blk_ptr].physical_block_number;
SEM_MTX_POST(SEM_BlockTable);
/* Calculate the actual start address of the media. */
*block_addr_ptr = BLOCK_ADDRESS(physical_block);
/*
* DO a scan of all the unit headers in the block looking for a valid
* matching unit header or until we run out of headers.
*/
status = FlashDevReadHeader(header_offset_ptr, unit_header_ptr,
*block_addr_ptr, identifier, type);
if (status == HW_ERR_NONE)
{
*unit_addr_ptr = *block_addr_ptr + FDV_BLOCK_SIZE - sizeof(BLOCK_INFO) -
TO_BYTES(unit_header_ptr->g_unit_offset_bottom);
}
return status;
} /* END LookupToHeader */
#endif /* !CONSISTENT_ACCESS_TIME */
/*############################################################################
*### BKGD_Init
*###
*### DESCRIPTION:
*### Creates the three semaphores used to control the FDI_LogicalBlockTable
*### and FDI_DataLookupTable access as well as control writes during the
*### reclaim block copy process. Spawns the BKGD_Task() function task
*### and sets BKGD_TaskId to the identifier. This identifier is later used
*### to terminate the task.
*###
*### USAGE:
*### hw_status = BKGD_Init();
*###
*### PARAMETERS:
*### IN: void
*### OUT: N.A.
*###
*### RETURNS:
*### Returns the following errors codes:
*### HW_ERR_PARAM - failure to create semaphores or task id
*### HW_ERR_NONE
*###*/
HW_ERROR
BKGD_Init(void)
{
HW_ERROR hw_status = HW_ERR_NONE;
#if(SEM_CREATE_DESTROY == TRUE)
#ifdef TESTING
/* Make task safe during plr testing to ensure TID is updated
* prior to preemption during power loss emulation.
*/
taskSafe();
#endif
/* E.5.0.596 START */
if ((SEM_LookupTable == SEM_NULL) &&
/* E.5.0.596 END */
/* create a mutex semaphore for the data lookup table functions. */
((SEM_LookupTable = SEM_MTX_CREATE()) == SEM_NULL))
{
hw_status = HW_ERR_PARAM;
}
/* E.5.0.596 START */
else if ((SEM_BlockTable == SEM_NULL) &&
/* E.5.0.596 END */
/* create a mutex semaphore for the logical block table functions. */
((SEM_BlockTable = SEM_MTX_CREATE()) == SEM_NULL))
{
SEM_MTX_DESTROY(SEM_LookupTable);
hw_status = HW_ERR_PARAM;
}
/* E.5.0.596 START */
else if ((SEM_WriteInProg == SEM_NULL) &&
/* E.5.0.596 END */
/* create a mutex semaphore for the reclaim copy process */
((SEM_WriteInProg = SEM_MTX_CREATE()) == SEM_NULL))
{
SEM_MTX_DESTROY(SEM_LookupTable);
SEM_MTX_DESTROY(SEM_BlockTable);
hw_status = HW_ERR_PARAM;
}
/* E.5.0.596 START */
else if ((SEM_AccumSize_Mutex == SEM_NULL) &&
/* E.5.0.596 END */
((SEM_AccumSize_Mutex = SEM_MTX_CREATE()) == SEM_NULL))
{
SEM_MTX_DESTROY(SEM_LookupTable);
SEM_MTX_DESTROY(SEM_BlockTable);
SEM_MTX_DESTROY(SEM_WriteInProg);
hw_status = HW_ERR_PARAM;
}
#if (PACKET_DATA == TRUE) /* PACKET_DATA */
#if (OPTIMAL_TASKDELAY == TRUE) /* OPTIMAL_TASKDELAY */
/* E.5.0.596 START */
else if ((SEM_QueueEmpty == SEM_NULL) &&
/* E.5.0.596 END */
((SEM_QueueEmpty = SEM_BIN_CREATE()) == SEM_NULL))
{
SEM_MTX_DESTROY(SEM_LookupTable);
SEM_MTX_DESTROY(SEM_BlockTable);
SEM_MTX_DESTROY(SEM_WriteInProg);
SEM_MTX_DESTROY(SEM_AccumSize_Mutex);
hw_status = HW_ERR_PARAM;
}
#endif /* OPTIMAL_TASKDELAY */
#endif /* PACKET_DATA */
#if (PERF_TEST == TRUE)
/* E.5.0.596 START */
else if ((PERF_SEM_Bkgd == SEM_NULL) &&
/* E.5.0.596 END */
((PERF_SEM_Bkgd = SEM_BIN_CREATE()) == SEM_NULL))
{
SEM_MTX_DESTROY(SEM_LookupTable);
SEM_MTX_DESTROY(SEM_BlockTable);
SEM_MTX_DESTROY(SEM_WriteInProg);
SEM_MTX_DESTROY(SEM_AccumSize_Mutex);
#if (PACKET_DATA == TRUE) /* PACKET_DATA */
#if (OPTIMAL_TASKDELAY == TRUE) /* OPTIMAL_TASKDELAY */
SEM_DESTROY(SEM_QueueEmpty);
#endif /* OPTIMAL_TASKDELAY */
#endif /* PACKET_DATA */
hw_status = HW_ERR_PARAM;
}
#endif /* PERF_TEST */
#endif /* SEM_CREATE_DESTROY */
/* spawn the back ground task */
#if(TASK_CREATE_DESTROY == TRUE)
/* else if((BKGD_TaskId = SPAWN("tFDIbkgnd", BKGD_PRIORITY, TASK_OPTIONS,
BKGD_STACK_SIZE, BKGD_Task)) == SPAWN_ERROR) */ /* commented by jjs */
else if((BKGD_TaskId = SPAWN("tFDIbkgnd", BKGD_PRIORITY, TASK_OPTIONS,
BKGD_STACK_SIZE, (DWORD)BKGD_Task)) == SPAWN_ERROR) /* added by jjs */
{
#if(SEM_CREATE_DESTROY == TRUE)
SEM_MTX_DESTROY(SEM_LookupTable);
SEM_MTX_DESTROY(SEM_BlockTable);
SEM_MTX_DESTROY(SEM_WriteInProg);
SEM_MTX_DESTROY(SEM_AccumSize_Mutex);
#if (PACKET_DATA == TRUE) /* PACKET_DATA */
#if (OPTIMAL_TASKDELAY == TRUE) /* OPTIMAL_TASKDELAY */
SEM_DESTROY(SEM_QueueEmpty);
#endif /* OPTIMAL_TASKDELAY */
#endif /* PACKET_DATA */
#if (PERF_TEST == TRUE)
SEM_DESTROY(PERF_SEM_Bkgd);
#endif /* PERF_TEST */
#endif /* SEM_CREATE_DESTROY */
hw_status = HW_ERR_PARAM;
}
#endif /* TASK_CREATE_DESTROY */
#ifdef TESTING
taskUnsafe();
#endif
return hw_status;
} /* END FDI_BkGDInit */
/*############################################################################
*### BKGD_Terminate
*###
*### DESCRIPTION:
*### Terminates the semaphores used to control the background manager
*### process and the background manager task that runs in the background.
*###
*### USAGE:
*### hw_status = BKGD_Terminate();
*###
*### PARAMETERS:
*### IN: void
*### OUT: N.A.
*###
*### RETURNS:
*### Returns the following errors codes:
*### HW_ERR_NONE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -