📄 fdi_recl.c
字号:
/* ###########################################################################
### Intel Confidential
### Copyright (c) Intel Corporation 1995-2002
### All Rights Reserved.
### -------------------------------------------------------------------------
### Project: Flash Data Integrator
###
### Module: FDIRECLM.C - FDI Reclamation Task and supporting functions
###
### $Archive: /FDI/SRC/FDI/fdi_recl.c $
### $Revision: 90 $
### $Date: 10/21/04 11:39a $
### $Author: Pcmcgint $
### $NoKeywords $
########################################################################### */
/*
*****************************************************************
* NOTICE OF LICENSE AGREEMENT
*
* This code is provided by Intel Corp., and the use is governed
* under the terms of a license agreement. See license agreement
* for complete terms of license.
*
* YOU MAY ONLY USE THE SOFTWARE WITH INTEL FLASH PRODUCTS. YOUR
* USE OF THE SOFTWARE WITH ANY OTHER FLASH PRODUCTS IS EXPRESSLY
* PROHIBITED UNLESS AND UNTIL YOU APPLY FOR, AND ARE GRANTED IN
* INTEL'S SOLE DISCRETION, A SEPARATE WRITTEN SOFTWARE LICENSE
* FROM INTEL LICENSING ANY SUCH USE.
*****************************************************************
*/
#define CURRENT_FILE_BEING_COMPILED FDI_RECL
/* ### Include Files
* ################################# */
#include "fdi_type.h"
#ifdef CUSTOM_SEM_MTX
#include "fdi_mutx.h"
#endif
#include "fdi_ext.h"
#include "fdi_int.h"
#ifdef TEST_MSGS
#include "logLib.h"
#endif
#ifdef TIMING
#include "comm.h"
#endif
#include "fdi_lowl.h"
/* added by Young Wang, on June 29, 1999 */
#if (PACKET_DATA == TRUE)
#include "fdi_pckt.h"
#endif /* PACKET_DATA */
#define RECL_WEARLEVEL_DIFFERENTIAL 20
#define BITS_PER_BYTE 8
#define HDR_MASK_SIZE ((((FDV_BLOCK_SIZE - sizeof(UNIT_HEADER))\
- sizeof(BLOCK_INFO))/ \
((UNIT_GRANULARITY + \
sizeof(UNIT_HEADER)) * \
BITS_PER_BYTE)) + 1)
#ifdef writeToFile
extern FILE *rw;
#endif
/* ### Local Declarations
* ################################# */
#define BOTTOM_OF_UNITS ((DWORD)(FDV_BLOCK_SIZE - sizeof(BLOCK_INFO)))
typedef struct RECL_IN_PROG
{
DWORD reclaim_block_addr;
DWORD spare_block_addr;
DWORD reclaim_header_offset;
DWORD spare_header_offset;
DWORD spare_free;
DWORD spare_dirty;
WORD pad;
BYTE recl_in_prog_flag;
BYTE recl_header_mask[HDR_MASK_SIZE];
} RECL_IN_PROG;
static RECL_IN_PROG Rip;
static RECL_STATES RECL_State; /* keeps track of reclaim progress */
static WORD RECL_ReclaimBlock; /* current block being reclaimed */
/* ### Local Functions
* ################################# */
void RECL_Task(void); /* called by RECL_Init() */
/* E.5.0.652 Begin */
static WORD countBitMask(BYTE *, WORD);
/* E.5.0.652 End */
static void setBitMask(BYTE_PTR, WORD);
static void RIP_OpenStreamUpdate(OPEN_STREAM_PTR);
/* ### Global Declarations
* ################################# */
int RECL_TaskId; /* Task identifier for reclaim task */
SEM_ID RECL_Request; /* background task asks for reclaim */
SEM_ID RECL_Enable; /* reclamation is pending on this */
SEM_ID RECL_Done; /* after reclaim is completed */
SEM_MTX_ID SEM_ReclaimInProg; /* mutex semaphore for globals */
extern SEM_MTX_ID SEM_WriteInProg; /* semaphore used during valid copy */
extern SEM_MTX_ID SEM_BlockTable; /* mutex semaphore for logical block
* table */
extern OPEN_PARAM FDI_OpenParam[];
extern SEM_MTX_ID SEM_OpenStream; /* mutex semaphore for FDI_OpenParam
* structure. */
extern LOGICAL_BLOCK FDI_LogicalBlockTable[];
/* extern WORD NUM_PARMS[]; */
#if (CONSISTENT_ACCESS_TIME == TRUE)
extern SEM_MTX_ID SEM_LookupTable;
#endif
#ifdef TIMING
COMM_TIMESTAMP RECL_Start;
COMM_TIMESTAMP RECL_End;
#endif
/* ### Global Functions
* ################################# */
/*############################################################################
*### RECL_SetState MACRO
*###
*### DESCRIPTION:
*### Function returns the current state of the reclaim process
*###
*### PARAMETERS:
*### IN: RECL_STATES state - current state of reclaim
*### OUT:
*###
*### RETURNS:
*### void
*###*/
#if (PACKET_DATA == TRUE) /* modified by Young Wang, Aug 20, 1999 */
void RECL_SetState(RECL_STATES a)
{
RECL_State = a;
}
#else
#define RECL_SetState(a) \
{ \
RECL_State = a; \
}
#endif
/*############################################################################
*### RECL_GetState
*###
*### DESCRIPTION:
*### Function returns the current state of the reclaim process
*###
*### PARAMETERS:
*### IN: void
*### OUT:
*###
*### RETURNS:
*### RECL_STATES
*###*/
RECL_STATES
RECL_GetState(void)
{
RECL_STATES current_state;
current_state = RECL_State;
return current_state;
}
/*############################################################################
*### RECL_GetBlock
*###
*### DESCRIPTION:
*### Function returns the Physical Block number of the block being reclaimed.
*###
*### PARAMETERS:
*### IN: void
*### OUT:
*###
*### RETURNS:
*### a byte containing the physical block number
*###*/
WORD
RECL_GetBlock(void)
{
return RECL_ReclaimBlock;
}
/*############################################################################
*### setBitMask
*###
*### DESCRIPTION:
*###
*### PARAMETERS:
*### IN:
*### mask_ptr - pointer to the array to be modified
*### count - number of bit in the array to set
*### OUT:
*###
*### RETURNS:
*###*/
static void
setBitMask(BYTE_PTR mask_ptr, WORD count)
{
*(mask_ptr + (count / BITS_PER_BYTE)) |= (1 << (count % BITS_PER_BYTE));
} /* END of setBitMask */
/*############################################################################
*### countBitMask
*###
*### DESCRIPTION:
*###
*### PARAMETERS:
*### IN:
*### mask_ptr - pointer to the array
*### stop_count - the last header count
*### OUT:
*###
*### RETURNS:
*### num_valids - number of bits valid in the array
*###*/
/* E.5.0.652 Begin */
static WORD
countBitMask(BYTE * mask_ptr, WORD stop_count)
/* E.5.0.652 End */
{
WORD num_valids = 0;
WORD each_byte;
BYTE each_bit;
for (each_byte = 0; stop_count; each_byte++)
{
for (each_bit = 0; each_bit < BITS_PER_BYTE && stop_count; each_bit++)
{
if (*(mask_ptr + each_byte) & (1 << each_bit))
num_valids++;
stop_count--;
}
}
return num_valids;
} /* END of countBitMask */
/*############################################################################
*### RECL_Init
*###
*### DESCRIPTION:
*### Initializes the three semaphores used to control the reclamation
*### process and spawns the reclamation task that runs in the background.
*###
*### PARAMETERS:
*### IN: void
*### OUT:
*###
*### RETURNS:
*### Returns the following errors codes:
*### BKGD_ERR_NONE
*### BKGD_ERR_SEMAPHORE
*###*/
HW_ERROR
RECL_Init(void)
{
HW_ERROR status = HW_ERR_NONE;
#ifdef TESTING
/* Make task safe during plr testing to ensure TID is updated
* prior to preemption during power loss emulation.
*/
taskSafe();
#endif
/* E.5.5.5.987 Begin */
#if( (SEM_CREATE_DESTROY == TRUE) || defined(CUSTOM_SEM_MTX) )
/* E.5.5.5.987 End */
#if(SEM_CREATE_DESTROY == TRUE)
/* E.5.0.596 START */
if ((RECL_Request == SEM_NULL) &&
/* E.5.0.596 END */
/* create a binary semaphore for the global ReclaimRequest */
((RECL_Request = SEM_BIN_CREATE()) == SEM_NULL))
{
status = HW_ERR_PARAM;
}
/* E.5.0.596 START */
else if ((RECL_Enable == SEM_NULL) &&
/* E.5.0.596 END */
/* create a binary semaphore for the global ReclaimEnable */
((RECL_Enable = SEM_BIN_CREATE()) == SEM_NULL))
{
SEM_DESTROY(RECL_Request);
status = HW_ERR_PARAM;
}
/* E.5.0.596 START */
else if ((RECL_Done == SEM_NULL) &&
/* E.5.0.596 END */
/* create a binary semaphore for the global ReclaimDone */
((RECL_Done = SEM_BIN_CREATE()) == SEM_NULL))
{
SEM_DESTROY(RECL_Request);
SEM_DESTROY(RECL_Enable);
status = HW_ERR_PARAM;
}
/* E.5.0.596 START */
else if ((SEM_ReclaimInProg == SEM_NULL) &&
/* E.5.0.596 END */
#else
/* E.5.0.596 START */
if ((SEM_ReclaimInProg == SEM_NULL) &&
/* E.5.0.596 END */
/* E.5.5.5.987 Begin */
#endif /* SEM_CREATE_DESTROY */
/* E.5.5.5.987 End */
/* create a mutex semaphore for the reclaim copy process */
((SEM_ReclaimInProg = SEM_MTX_CREATE()) == SEM_NULL))
{
/* E.5.5.5.987 Begin */
#if(SEM_CREATE_DESTROY == TRUE)
/* E.5.5.5.987 End */
SEM_DESTROY(RECL_Request);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -