📄 fdi_int.h
字号:
/*
* For data streaming we must use the include fragmented data define
*/
#if (DATA_STREAM == TRUE)
#undef INCLUDE_FRAGMENTED_DATA
#define INCLUDE_FRAGMENTED_DATA TRUE
#endif /* DATA_STREAM */
/*
* The following is used to increase the allowable open params array size
* to the sum of OPEN_ARRAY_SIZE and NUM_OPEN_FILES to guarantee the
* File Open operations from the file manager as well as the direct FDI calls
*/
#ifndef FILE_MANAGER
#define FILE_MANAGER FALSE
#endif
#if(FILE_MANAGER == TRUE)
#define OPEN_ARRAY_SIZE (NUM_OPEN_PARAMS + NUM_OPEN_FILES)
#else
#define OPEN_ARRAY_SIZE NUM_OPEN_PARAMS
#endif
#define SET_LAST_HEADER_OFFSET(block, hdr_addr) \
(FDI_LogicalBlockTable[(block)].last_header_offset = \
(WORD)(((hdr_addr)-FIRST_HEADER_OFFSET)/(sizeof(UNIT_HEADER))))
#define LAST_HEADER_OFFSET(block) \
(((DWORD)(FDI_LogicalBlockTable[(block)].last_header_offset) * \
(DWORD)(sizeof(UNIT_HEADER))) + FIRST_HEADER_OFFSET)
/* Used to set all fields of a DLT entry. */
#if (CONSISTENT_ACCESS_TIME == TRUE)
/* if the input header offset is DWORDMAX, the header index will be set to
* WORDMAX, which means the index is empty */
#define SET_LOOKUP_TABLE( type, id, block, hdr_offset, stream ) \
{ \
(FDI_DataLookupPtrTable[(type)]+(id))->logical_blk_num = (block);\
if((hdr_offset) != DWORDMAX)\
{\
(FDI_DataLookupPtrTable[(type)] + (id))->hdr_index = \
(WORD)(((hdr_offset)-FIRST_HEADER_OFFSET)/sizeof(UNIT_HEADER));\
}\
else\
{\
(FDI_DataLookupPtrTable[(type)] + (id))->hdr_index = WORDMAX;\
}\
(FDI_DataLookupPtrTable[(type)]+(id))->open_stream_index=(stream);\
(FDI_DataLookupPtrTable[(type)]+(id))->paraExist = 0; \
}
#else
#define SET_LOOKUP_TABLE(id, block, stream, type) \
{ \
(FDI_DataLookupPtrTable[(type)]+(id))->logical_blk_num = (block); \
(FDI_DataLookupPtrTable[(type)]+(id))->open_stream_index=(stream);\
(FDI_DataLookupPtrTable[(type)]+(id))->paraExist = 0; \
}
#endif
/* Used to get the logical block number from a DLT entry. */
#define LOOKUP_TABLE_BLOCK(type, id) \
((WORD)((FDI_DataLookupPtrTable[(type)] + (id))->logical_blk_num))
/* Used to initialize all fields of a DLT entry. */
#if (CONSISTENT_ACCESS_TIME == TRUE)
#define INIT_LOOKUP_TABLE(type, id) \
{ \
(FDI_DataLookupPtrTable[(type)]+(id))->logical_blk_num = WORDMAX;\
(FDI_DataLookupPtrTable[(type)]+(id))->hdr_index = WORDMAX; \
(FDI_DataLookupPtrTable[(type)]+(id))->open_stream_index=BYTEMAX;\
(FDI_DataLookupPtrTable[(type)]+(id))->paraExist = BYTEMAX; \
}
#else
#define INIT_LOOKUP_TABLE(type, id) \
{ \
(FDI_DataLookupPtrTable[(type)]+(id))->logical_blk_num = WORDMAX;\
(FDI_DataLookupPtrTable[(type)]+(id))->open_stream_index=BYTEMAX;\
(FDI_DataLookupPtrTable[(type)]+(id))->paraExist = BYTEMAX; \
}
#endif
/* Used to test if a DLT entry is empty, it returns TRUE if a DLT entry empty.
* Can't check just the paramexists field because fdi_delete fails if only
* exists field is checked. Not sure why. This needs to be investigated.
*/
#define EMPTY_LOOKUP_TABLE(type, id) \
(((FDI_DataLookupPtrTable[(type)]+(id))->paraExist == BYTEMAX ) &&\
((FDI_DataLookupPtrTable[(type)]+(id))->logical_blk_num==WORDMAX) &&\
((FDI_DataLookupPtrTable[(type)]+(id))->open_stream_index==BYTEMAX))
/* Used to test if the logical block number field of a DLT entry is empty,
* it returns TRUE if logical block entry is empty. i.e. WORDMAX */
#define NO_LOOKUP_TABLE_BLOCK(type, id) \
((FDI_DataLookupPtrTable[(type)] + (id))->logical_blk_num == WORDMAX)
/* Used to test if a DLT entry is not empty, it returns TRUE if the entry
* is not empty. */
#define NOT_EMPTY_LOOKUP_TABLE(type, id) \
(((FDI_DataLookupPtrTable[(type)]+(id))->paraExist == 0 ) || \
((FDI_DataLookupPtrTable[(type)]+(id))->logical_blk_num != WORDMAX))
/* Used to get the open stream field of a DLT entry. */
#define LOOKUP_TABLE_OSFIELD(type, id) \
((BYTE)((FDI_DataLookupPtrTable[(type)] + (id))->open_stream_index))
/* Used to set the open stream field of a DLT entry. */
#define SET_LOOKUP_TABLE_OSFIELD(type, id, open) \
(FDI_DataLookupPtrTable[(type)] + (id))->open_stream_index = (open)
/* Used to clear the open stream field of a DLT entry. */
#define CLEAR_LOOKUP_TABLE_OSFIELD(type, id) \
(FDI_DataLookupPtrTable[(type)] + (id))->open_stream_index = BYTEMAX
/*Used to check if the OSFIELD of a DLT entry is empty */
#define EMPTY_LOOKUP_TABLE_OSFIELD(type, id) \
((FDI_DataLookupPtrTable[(type)] + (id))->open_stream_index == BYTEMAX)
/* Used to set the PE field( i.e. 0: valid;
* other value: invalid )
*/
#define SET_LOOKUP_TABLE_PEBIT(type, id) \
(FDI_DataLookupPtrTable[(type)] + (id))->paraExist = 0
#if (CONSISTENT_ACCESS_TIME == TRUE)
/* Used to set the hdr index field of a DLT entry */
#define SET_LOOKUP_TABLE_HDR(type, id, hdr_offset) \
if((hdr_offset) != DWORDMAX)\
{\
(FDI_DataLookupPtrTable[(type)] + (id))->hdr_index = \
(WORD)(((hdr_offset)-FIRST_HEADER_OFFSET)/sizeof(UNIT_HEADER));\
}\
else\
{\
(FDI_DataLookupPtrTable[(type)] + (id))->hdr_index = WORDMAX;\
}
/* Used to get the hdr offset from a DLT entry */
#define LOOKUP_TABLE_HDR(type, id) \
(((FDI_DataLookupPtrTable[(type)] + \
(id))->hdr_index ) * sizeof(UNIT_HEADER) + FIRST_HEADER_OFFSET)
#endif /* end of CONSISTENT_ACCESS_TIME == TRUE */
/*
* calculate the number of instances that fit in this unit: (unit size
* in bytes minus size of MULTI_INSTANCE structure) divided by
* (parameter size plus a byte for status)
*/
#define INSTANCES(a,b) (((a)-sizeof(MULTI_INSTANCE))/((b)+1))
#define GRAN_REMAINING(a) (UNIT_GRANULARITY-((a)%UNIT_GRANULARITY))
#define MAX_DATA_BLOCKS (FDV_BLOCKCOUNT-1) /* last block to skip */
#define BLOCK_INTEGRITY 0xf0f0 /* block's data integrity */
#define BLK_INTEGRITY_INVALID 0xf0c0 /* invalidated block data integrity */
#define LAST_BLOCK_ADDR (FDV_BLOCK_SIZE-1) /* maximum block offset value */
#define MAX_QUEUE_ITEM_SIZE ((((FDI_QUEUE_SIZE-sizeof(COMMAND))-\
sizeof(Q_DESCRIPTOR))-sizeof(Q_PRIORITY_HEADER))-sizeof(Q_ITEM_INFO))
/* maximum number of sequence table entries in one unit = 16 */
#define MAX_SEQ_ENTRY (UNIT_GRANULARITY/sizeof(ENTRY_TABLE))
#define ERASE_COUNT_UNIT_SIZE (TO_BYTES(TO_SIZE((sizeof(MULTI_INSTANCE)+\
(sizeof(DWORD)*MIN_INSTANCES)+TO_SIZE(MIN_INSTANCES,2)),UNIT_GRANULARITY))+\
sizeof(UNIT_HEADER))
#if (BUFFER_SIZE > 0)
#define BUFFER_OFFSET_MASK BUFFER_SIZE-1
#define BUFFER_OFFSET(a) ((BYTE)BUFFER_SIZE - (BYTE)((DWORD)(a)&((DWORD)BUFFER_OFFSET_MASK)))
/* returns 0 if on buffer boundary. Otherwise,
the number of bytes from the next boundary */
#endif
#if ((DATA_STREAM == TRUE) && (INCLUDE_FRAGMENTED_DATA == TRUE))
/* in B/S */
#define DATA_RATE (14400/8)
/* derived from excel spreadsheet in seconds */
#if PARTITIONS == SINGLE
#define RECLAIM_TIME 10
#else
#define RECLAIM_TIME 8
#endif
/* in Bytes */
#define DATA_STREAM_OVERHEAD (RECLAIM_TIME*DATA_RATE)
/* number of fragments */
#define FDI_DATA_STREAM_FRAG ((DATA_STREAM_OVERHEAD)/\
(UNIT_GRANULARITY+sizeof(UNIT_HEADER)))
/* maximum number of sequence table units = 20 */
#define FDI_DATA_STREAM_SEQ_UNIT ((FDI_DATA_STREAM_FRAG/MAX_SEQ_ENTRY)+\
(((FDI_DATA_STREAM_FRAG/MAX_SEQ_ENTRY)%UNIT_GRANULARITY)?1:0)+\
((FDI_DATA_STREAM_FRAG/MAX_SEQ_ENTRY)?0:1))
/* maximum units needed based on biggest sequence table unit = 20 */
#define FDI_DATA_STREAM_GRP_UNIT ((FDI_DATA_STREAM_SEQ_UNIT/MAX_SEQ_ENTRY)+\
(((FDI_DATA_STREAM_SEQ_UNIT/MAX_SEQ_ENTRY)%UNIT_GRANULARITY)?1:0)+\
((FDI_DATA_STREAM_SEQ_UNIT/MAX_SEQ_ENTRY)?0:1))
/* in Bytes */
#define FDI_DATA_STREAM_STRUCTURE_OVERHEAD ((FDI_DATA_STREAM_SEQ_UNIT+\
FDI_DATA_STREAM_GRP_UNIT)*(UNIT_GRANULARITY+sizeof(UNIT_HEADER)))+\
(FDI_DATA_STREAM_FRAG*sizeof(UNIT_HEADER))
#define FDI_OVERHEAD_PER_BLOCK (DATA_STREAM_OVERHEAD+\
FDI_DATA_STREAM_STRUCTURE_OVERHEAD)
/* available space for the data after format */
#define MAX_MEDIA_SIZE ((MAX_DATA_BLOCKS*(FDV_BLOCK_SIZE-sizeof(BLOCK_INFO)-\
FDI_OVERHEAD_PER_BLOCK-sizeof(UNIT_HEADER)))-ERASE_COUNT_UNIT_SIZE)
/* for erase count parameter and it's header */
#define FDI_THRESHOLD (MAX_DATA_BLOCKS*FDI_OVERHEAD_PER_BLOCK)
#endif /* DATA_STREAM and FRAGMENTED_DATA*/
/*
* There are 8 data blocks defined in fdi_type.h, 7 are used for storing data
* and one is used for the spare block. Each of the 7 data blocks has a 16
* byte block information structure and a 8 byte unit header terminator used
* to separate unit headers and data. On the flash a 1 byte parameter is used
* to store the flash wear leveling cycle count. This byte is maintained by
* the FDI software system. Since unit granularity is defined as 128 bytes, it
* will take 128 bytes of flash to store this parameter, plus 8 bytes for the
* associated unit header.
* Therefore, the free units after format is...
* (7 blocks for data)(8192 bytes per block - 16 bytes per block info struc. -
* 8 bytes per unit header/data separator) -
* 128 bytes for wear leveling cycle count parameter - 8 bytes for unit header
* equals 57,040 free bytes (0xded0)
*/
#if ((DATA_STREAM == FALSE) && (INCLUDE_FRAGMENTED_DATA == TRUE))
/* available space for the data after format */
#define MAX_MEDIA_SIZE ((MAX_DATA_BLOCKS*(FDV_BLOCK_SIZE-sizeof(BLOCK_INFO)-\
sizeof(UNIT_HEADER)))-ERASE_COUNT_UNIT_SIZE)
/* for erase count parameter and it's header */
#endif /* !DATA_STREAM && INCLUDE_FRAGMENTED_DATA */
#if (INCLUDE_FRAGMENTED_DATA == FALSE)
/* available space for the data after format */
#define MAX_MEDIA_SIZE ((MAX_DATA_BLOCKS*(FDV_BLOCK_SIZE-sizeof(BLOCK_INFO)-\
sizeof(UNIT_HEADER)))-ERASE_COUNT_UNIT_SIZE)
/* for erase count parameter and it's header */
#endif /* !INCLUDE_FRAGMENTED_DATA */
/* maximum 3 unit chunks of data that can be queued = 3 */
#define MAX_FRAG ((MAX_QUEUE_ITEM_SIZE/\
(UNIT_GRANULARITY*MAX_NUM_UNITS_PER_FRAG))+(((MAX_QUEUE_ITEM_SIZE%\
(UNIT_GRANULARITY*MAX_NUM_UNITS_PER_FRAG))!=0)?1:0))
/*maximum units needed for the fragments of the biggest data in the media=21*/
#define MAX_FRAG_UNITS ((MAX_DATA_BLOCKS*MAX_NUM_UNITS_PER_FRAG)*\
((MAX_FRAG/MAX_DATA_BLOCKS)+1))
/* maximum fragment units of a biggest data possible in the media = 419 */
/*
* maximum number of fragments and associated headers that can fit in
* MAX_MEDIA_SIZE
*/
#define MAX_MEDIA_FRAG (MAX_MEDIA_SIZE-sizeof(UNIT_HEADER))/\
(UNIT_GRANULARITY+sizeof(UNIT_HEADER))
#if (INCLUDE_FRAGMENTED_DATA == TRUE)
/*The Maximum Number of Entries in a Group Table is limited to a BYTE*/
/* Based on the Above limitation the size of the Group table is calculated*/
/*This define is added to limit the MAX_GRP_UNIT to 65536 */
#define MAX_GRP_UNIT_ENTRIES (((((FDV_BLOCK_SIZE - sizeof(BLOCK_INFO)) - 2*sizeof(UNIT_HEADER)) \
/sizeof(ENTRY_TABLE)) < 65536)? (((FDV_BLOCK_SIZE - \
sizeof(BLOCK_INFO)) - sizeof(UNIT_HEADER)) \
/sizeof(ENTRY_TABLE)): 65536 )
#define MAX_GRP_UNIT_SIZE ((((MAX_GRP_UNIT_ENTRIES *(sizeof(ENTRY_TABLE)))+ \
sizeof(UNIT_HEADER))/UNIT_GRANULARITY))
/* maximum number of sequence table units = 20 */
#define MAX_SEQ_UNIT ((MAX_MEDIA_FRAG/MAX_SEQ_ENTRY)+\
(((MAX_MEDIA_FRAG/MAX_SEQ_ENTRY)%UNIT_GRANULARITY)?1:0)+\
((MAX_MEDIA_FRAG/MAX_SEQ_ENTRY)?0:1))
/* maximum units needed based on biggest sequence table unit = 20 */
/*Maximum size of a Group Table based on the Size of the Media*/
#define MAX_GRP_UNIT_MEDIA_SIZE ((MAX_SEQ_UNIT/MAX_SEQ_ENTRY)+\
(((MAX_SEQ_UNIT/MAX_SEQ_ENTRY)%UNIT_GRANULARITY)?1:0)+\
((MAX_SEQ_UNIT/MAX_SEQ_ENTRY)?0:1))
/* Size of the Maximum Group Table is fixed based on whether
the size of the Group Table exceeds 65536 entries or not */
#define MAX_GRP_UNIT ((MAX_GRP_UNIT_MEDIA_SIZE>MAX_GRP_UNIT_SIZE)?\
MAX_GRP_UNIT_SIZE:MAX_GRP_UNIT_MEDIA_SIZE)
#endif /* INCLUDE_FRAGMENTED_DATA */
#if (DATA_STREAM == FALSE)
#if (INCLUDE_FRAGMENTED_DATA == TRUE)
#define SEQ_REPLACE_UNITS ((MAX_FRAG/MAX_SEQ_ENTRY)+1+\
((MAX_FRAG%MAX_SEQ_ENTRY)?1:0))
#define MAX_THRESHOLD_UNIT (MAX_FRAG_UNITS+FDI_MaxGrpUnit+SEQ_REPLACE_UNITS)
#else /* !INCLUDE_FRAGMENTED_DATA */
/* threshold in units = 21 */
#define MAX_THRESHOLD_UNIT ((MAX_MEDIA_FRAG<MAX_FRAG_UNITS)?\
MAX_MEDIA_FRAG:MAX_FRAG_UNITS)
#endif /* !INCLUDE_FRAGMENTED_DATA */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -