📄 fdi_bkgd.c
字号:
/*
* Check if this data is opened, if yes, we could use the information
* recorded in the FDI_OpenParam instead of scaning over one block
* to find the corresponding multi-instance/single instance/group table,
* thus, performance would be improved.
* This operation is performed only when CONSISTENT_ACCESS_TIME option
* is FALSE.
* To guarantee the FDI_OpenParam information is not corrupt by the high
* priority task interrupting the low priority task, in the background and
* reclaim, when update FDI_OpenParam, we need to take SEM_LookupTable to
* protect it. The reason why we use SEM_LookupTable here is each place of
* calling LookupToHeader will be pending until SEM_LookupTable is
* available.
*/
if (((EMPTY_LOOKUP_TABLE_OSFIELD(type, identifier)) ||
(FDI_OpenParam[LOOKUP_TABLE_OSFIELD(type, identifier)].
identifier != identifier)) ||
(NIBBLE_HIGH(FDI_OpenParam[LOOKUP_TABLE_OSFIELD(type, identifier)].
type_attribute) != type)
/* E.5.0.656 Begin */
|| (FDI_OpenParam[LOOKUP_TABLE_OSFIELD(type, identifier)].logical_block == WORDMAX)
/* E.5.0.656 End */
)
{
opened = FALSE;
}
else
{
stream_index = LOOKUP_TABLE_OSFIELD(type, identifier);
}
/* E.5.0.629 End */
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);
/* E.5.0.629 Begin */
/* If opened, use FDI_OpenParam to calculate the outputs */
if (opened)
{
*block_addr_ptr = FDI_OpenParam[stream_index].block_addr;
*unit_addr_ptr = *block_addr_ptr +
FDI_OpenParam[stream_index].b_begin_unit_offset;
*header_offset_ptr = FDI_OpenParam[stream_index].b_hdr_offset;
/* Read the unit header. */
status = FlashDevRead((BYTE_PTR)unit_header_ptr,
*block_addr_ptr + *header_offset_ptr,
sizeof(UNIT_HEADER));
}
else
{
/* E.5.0.629 End */
/*
* 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)
{
/* E 5.1.849 START */
*unit_addr_ptr = (*block_addr_ptr + FDV_BLOCK_SIZE - sizeof(BLOCK_INFO)) -
TO_BYTES(unit_header_ptr->g_unit_offset_bottom);
/* E 5.1.849 END */
}
/* E.5.0.629 Begin */
}
/* E.5.0.629 End */
/* E.5.0.656 Begin */
SEM_MTX_POST(SEM_OpenStream);
/* E.5.0.656 End */
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;
/* E.5.5.5.987 Begin */
#if( (SEM_CREATE_DESTROY == TRUE) || defined(CUSTOM_SEM_MTX) )
/* E.5.5.5.987 End */
#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;
}
/* E.5.5.5.987 Begin */
#if(SEM_CREATE_DESTROY == TRUE)
/* E.5.5.5.987 End */
#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)
{
/* E.5.5.5.987 Begin */
/* E.5.5.5.987 End */
SEM_MTX_DESTROY(SEM_LookupTable);
SEM_MTX_DESTROY(SEM_BlockTable);
SEM_MTX_DESTROY(SEM_WriteInProg);
SEM_MTX_DESTROY(SEM_AccumSize_Mutex);
/* E.5.5.5.987 Begin */
#if(SEM_CREATE_DESTROY == TRUE)
/* E.5.5.5.987 End */
#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 */
/* E.5.5.5.987 Begin */
#endif /* SEM_CREATE_DESTROY and CUSTOM_SEM_MTX */
/* E.5.5.5.987 End */
#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
*###*/
HW_ERROR
BKGD_Terminate(void)
{
#ifdef TESTING
/* Make task safe during plr testing to ensure TID is updated
prior to preemption during power loss emulation. */
taskSafe();
#endif
#if(TASK_CREATE_DESTROY == TRUE)
/* destroy the background task. Only do this if the task still exists */
if (BKGD_TaskId != 0)
{
TASK_DESTROY(BKGD_TaskId);
}
#endif /* TASK_CREATE_DESTROY */
/* E.5.5.5.987 Begin */
#if( (SEM_CREATE_DESTROY == TRUE) || defined(CUSTOM_SEM_MTX) )
/* E.5.5.5.987 End */
/* destroy mutex semaphore for the global data lookup table */
if (SEM_LookupTable != SEM_NULL)
{
SEM_MTX_DESTROY(SEM_LookupTable);
}
/* destroy mutex semaphore for the global logical block table */
if (SEM_BlockTable != SEM_NULL)
{
SEM_MTX_DESTROY(SEM_BlockTable);
}
/* destroy mutex semaphore for writing during the reclaim block copy */
if (SEM_WriteInProg != SEM_NULL)
{
SEM_MTX_DESTROY(SEM_WriteInProg);
}
if (SEM_AccumSize_Mutex != SEM_NULL)
{
SEM_MTX_DESTROY(SEM_AccumSize_Mutex);
}
/* E.5.5.5.987 Begin */
#if(SEM_CREATE_DESTROY == TRUE)
/* E.5.5.5.987 End */
#if (PACKET_DATA == TRUE) /* PACKET_DATA */
#if (OPTIMAL_TASKDELAY == TRUE) /* OPTIMAL_TASKDELAY */
if (SEM_QueueEmpty != SEM_NULL)
{
SEM_DESTROY(SEM_QueueEmpty);
}
#endif /* OPTIMAL_TASKDELAY */
#endif /* PACKET_DATA */
#if (PERF_TEST == TRUE)
if (PERF_SEM_Bkgd != SEM_NULL)
{
SEM_DESTROY(PERF_SEM_Bkgd);
}
#endif /* PERF_TEST */
#endif /* SEM_CREATE_DESTROY */
/* E.5.5.5.987 Begin */
#endif /* SEM_CREATE_DESTROY and CUSTOM_SEM_MTX */
/* E.5.5.5.987 End */
#ifdef TESTING
taskUnsafe();
#endif
return HW_ERR_NONE;
} /* END BKGD_Terminate */
/*############################################################################
*### BKGD_GetTotalSpace
*###
*### DESCRIPTION:
*### Scans the FDI_LogicalBlockTable and adds up the total free space or
*### dirty space in bytes depending on the input parameter.
*###
*### USAGE:
*### total_free = BKGD_GetTotalSpace(FREE_UNITS);
*### total_dirty = BKGD_GetTotalSpace(DIRTY_UNITS);
*###
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -