📄 fdi_ext.c
字号:
SEM_ID SEM_FDIErrorIndicator;
SEM_MTX_ID SEM_FlashWrite;
SEM_MTX_ID SEM_FlashErase; /* added by jjs */
#if(DIRECT_ACCESS_VOLUME == TRUE)
/* SEM_MTX_ID SEM_FlashErase; */ /* commented by jjs */
SEM_MTX_ID SEM_DAVReclLock;
SEM_ID SEM_DAVReclRequest;
SEM_MTX_ID SEM_DAVAPILock;
#endif /* DIRECT_ACCESS_VOLUME */
ERROR_INFO FDI_Error;
#if (FREE_SPACE_FUNCTIONS == TRUE) /* FREE_SPACE_FUNCTIONS */
extern SEM_MTX_ID SEM_BlockTable;
extern LOGICAL_BLOCK FDI_LogicalBlockTable[];
#endif /* FREE_SPACE_FUNCTIONS */
#ifdef TIMING
COMM_TIMESTAMP FDI_API;
COMM_TIMESTAMP FDI_APIend;
#endif
/*
* If needed (based on configuration options), create space needed by
* low-level to store the relocated code.
*/
#if (RELOCATE_CODE == TRUE)
#if (FDI_RAM_START == 0)
#if (PARTITIONS != SINGLE)
#define DOWNLOAD_SIZE 1024
#else /* PARTITIONS == SINGLE */
#define DOWNLOAD_SIZE 1024
#endif /* PATITIONS */
static DWORD lowlvlRAMLocation[(DOWNLOAD_SIZE / sizeof(DWORD)) + 1];
#else /* FDI_RAM_START != 0 */
#define lowlvlRAMLocation FDI_RAM_START
#endif /* FDI_RAM_START */
#endif /* RELOCATE_CODE */
extern volatile BOOL LowLvlFDIInitializing; /* added by jjs - defined in fdi_sprc.c */
/*
#############################################################################
### FDI_Open
###
### DESCRIPTION:
### FDI_Open opens a data parameter or stream for reading, editing, or
### creates a data stream for writing. Only one data parameter
### or stream can be opened at any given time. FDI_open improves
### performance when accessing a data stream multiple times by maintaining
### open stream information in RAM. FDI_open stores the opened data
### information in the global open_param structure.
### FDI_open returns an error if the system attempts to open multiple data
### parameters or streams. FDI_open calls dataFind to determine the
### existence of data with a matching identifier and type. If data
### already exists and is being opened for reading or modification, FDI_open
### updates the open_param structure to point to the beginning or the end of
### the data stream, based on the operation to be performed. Successive calls
### to FDI_read or FDI_write by pass the call to dataFind, and thus reducing
### overhead.
###
### PARAMETERS:
### IN:
### cmd_cntrl->sub_command : This field contains a command to indicate
### the data stream opening method:
### OPEN_READ: Open for read only.
### OPEN_MODIFY: Open for parameter data
### modification.
### OPEN_CREATE: Open for writing a new
### parameter.
### cmd_cntrl->identifier: This is a unique data parameter or stream
### identifier.
### cmd_cntrl->type : This field indicates a data type_attribute.
### The options are:
### any value between 0x00 to 0x0F.
###
### OUT:
### error : a descriptive error code
###
### RETURNS:
### ERR_NONE ERR_OPEN ERR_EXISTS ERR_NOTEXISTS ERR_PARAM
###
*/
ERR_CODE
FDI_Open(CMD_CNTRL_PTR cmd_cntrl)
{
UNIT_HEADER unit_header_information;
#if (INCLUDE_FRAGMENTED_DATA == TRUE)
ENTRY_TABLE table;
#endif
DWORD unit_address;
BYTE MOF_index;
#if (INCLUDE_FRAGMENTED_DATA == TRUE)
WORD table_size;
WORD dummy_word;
WORD block;
DWORD index;
#endif
ERR_CODE status;
HW_ERROR hw_status;
BYTE start;
#ifdef TIMING
/* Get timestamp for start of update */
COMM_getTimestamp((COMM_TIMESTAMP *) & FDI_API);
#endif
/*
* Check for completion of Initialization and if not yet complete return
* the proper error code.
*/
if (FDI_InitComplete != TRUE)
{
return ERR_INIT;
}
/*
* Check to see if the passed in parameters are valid. Otherwise return
* proper error code.
*/
if (((cmd_cntrl->identifier == NEW_DATA_STREAM_ID) &&
(cmd_cntrl->sub_command != OPEN_CREATE)) ||
(cmd_cntrl->type > MAX_TYPE) ||
( NUM_PARMS[cmd_cntrl->type] == 0 ) ||
((cmd_cntrl->identifier >= NUM_PARMS[cmd_cntrl->type])&&
(cmd_cntrl->identifier != NEW_DATA_STREAM_ID)) ||
((cmd_cntrl->identifier == ERASE_COUNT_ID) &&
(cmd_cntrl->type == ERASE_COUNT_TYPE))||
((cmd_cntrl->sub_command != OPEN_CREATE) &&
(cmd_cntrl->sub_command != OPEN_MODIFY) &&
(cmd_cntrl->sub_command != OPEN_READ)) ||
(cmd_cntrl->priority < FDI_MIN_PRIORITY) ||
(cmd_cntrl->priority > FDI_MAX_PRIORITY)
#if (DATA_STREAM == TRUE)
||
((cmd_cntrl->aux != TRUE ) &&
(cmd_cntrl->aux != FALSE))
#endif
)
{
return ERR_PARAM;
}
/* lock the API_sem_cntrl_mutex. */
SEM_MTX_WAIT(SEM_APIMutexSemaphore);
/* lock the global_sem_cntrl_mutex. */
SEM_MTX_WAIT(SEM_OpenStream);
/*
* Check to see if a data parameter or stream is already open and return
* proper error code.
*/
if(cmd_cntrl->identifier != NEW_DATA_STREAM_ID)
{
if(!EMPTY_LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier) )
{
/*
* unlock the global_sem_cntrl_mutex to give others access to the
* globals
*/
SEM_MTX_POST(SEM_OpenStream);
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
return ERR_OPEN;
}
}
#if (PACKET_DATA == TRUE)
/* when packet data is in progress give PCKTID_MUTEX error */
if ( FDI_Pckt.ID != WORDMAX && FDI_Pckt.ID == cmd_cntrl->identifier &&
FDI_Pckt.type == cmd_cntrl->type)
{
SEM_MTX_POST(SEM_OpenStream);
SEM_MTX_POST(SEM_APIMutexSemaphore);
return ERR_PCKTID_MUTEX;
}
#endif /* PACKET_DATA */
/*
* If opening to create, Look into the FDI_DataLookupTable and assign
* the first free identifier to the new data being created.
*/
if (cmd_cntrl->sub_command == OPEN_CREATE)
{
if (cmd_cntrl->identifier == NEW_DATA_STREAM_ID)
{
SEM_MTX_WAIT(SEM_LookupTable);
/* Scan the data lookup table. */
/* Changed ERASE_COUNT_ID to be NUM_TYPE14_PARMS */
start = 0;
for(MOF_index = start; MOF_index < NUM_PARMS[cmd_cntrl->type];MOF_index ++)
{
if (EMPTY_LOOKUP_TABLE(cmd_cntrl->type,MOF_index))
{
cmd_cntrl->identifier = MOF_index;
break;
}
}
SEM_MTX_POST(SEM_LookupTable);
}
/* Maximum identifiers has been reached. */
if (cmd_cntrl->identifier >= NUM_PARMS[cmd_cntrl->type])
{
/*
* unlock the global_sem_cntrl_mutex to give others access to the
* globals
*/
SEM_MTX_POST(SEM_OpenStream);
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
return ERR_MAX_EXISTS;
}
}
/*
* Verify that the data exists and update the FDI_GetDataFound structure
* with appropriate data information.
*/
status = DataFind(cmd_cntrl->identifier, cmd_cntrl->type, GET_MATCHED);
/* If opened to create, verify that the data does not exist already */
if ((status == ERR_NONE) && (cmd_cntrl->sub_command ==
OPEN_CREATE))
{
/*
* unlock the global_sem_cntrl_mutex to give others access to the
* globals
*/
SEM_MTX_POST(SEM_OpenStream);
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
return ERR_EXISTS;
}
/* If opened to access the existing data, verify that the data exists */
else if ((status != ERR_NONE) &&
(cmd_cntrl->sub_command != OPEN_CREATE))
{
/*
* unlock the global_sem_cntrl_mutex to give others access to the
* globals
*/
SEM_MTX_POST(SEM_OpenStream);
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
return status;
}
for(MOF_index = 0; MOF_index < OPEN_ARRAY_SIZE; MOF_index++)
{
if(FDI_OpenParam[MOF_index].identifier == WORDMAX)
{
break;
}
}
if(MOF_index >= OPEN_ARRAY_SIZE)
{
/*
* unlock the global_sem_cntrl_mutex to give others access to the
* globals
*/
SEM_MTX_POST(SEM_OpenStream);
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
return ERR_MAX_OPEN;
}
/*Update the DLT with the MOF_index number into the OpenParam Table*/
/* SET_LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier, MOF_index);*/
FDI_OpenParamPtr = &FDI_OpenParam[MOF_index];
/* Update the FDI_OpenParam structure. */
/* the logical block number of the block to be accesed */
FDI_OpenParamPtr->logical_block = WORDMAX;
/*
* the begin address of the block which has the unit header of the fragment
* unit header
*/
FDI_OpenParamPtr->frag_block_addr = DWORDMAX;
/* offset of the begin of the fragment data unit header */
FDI_OpenParamPtr->b_frag_hdr_offset = DWORDMAX;
/*
* the data offset into the sequence table unit being accessed to begin
* next access
*/
FDI_OpenParamPtr->b_seq_table_entry_offset = DWORDMAX;
/* identifier */
FDI_OpenParamPtr->identifier = cmd_cntrl->identifier;
FDI_OpenParamPtr->table_number = 0;
FDI_OpenParamPtr->b_tabl_hdr_offset = DWORDMAX;
FDI_OpenParamPtr->b_begin_tabl_offset = DWORDMAX;
FDI_OpenParamPtr->b_grp_table_entry_offset = DWORDMAX;
#if (DATA_STREAM == TRUE)
/* data_streaming */
if ( cmd_cntrl->aux == TRUE )
{
FDI_OpenParamPtr->data_streaming = FALSE;
}
else
{
FDI_OpenParamPtr->data_streaming = TRUE;
}
#endif
/*
* If the lookup table has a new entry, which means the data is being
* opened for create, fill in the open stream structure to represent the
* begining point of the data write in the flash media.
*/
if (cmd_cntrl->sub_command == OPEN_CREATE)
{
/* File points to the end/begin of the data stream. */
/*
* the data offset into the data stream(file) being accessed to begin
* next access
*/
FDI_OpenParamPtr->b_current_file_offset = 0;
/* the size of the data left remaining in the data unit bytes */
FDI_OpenParamPtr->b_remaining_in_unit = 0;
/*
* the begin address of the block which has the sequence table or single
* instance or multiple instance unit header
*/
FDI_OpenParamPtr->block_addr = DWORDMAX;
/*
* offset of the begin of the sequence table unit header or the single
* instance or the multiple instance data unit header
*/
FDI_OpenParamPtr->b_hdr_offset = DWORDMAX;
/*
* group table unit size or single instance or the multiple instance
* data unit size
*/
FDI_OpenParamPtr->b_unit_size = 0;
FDI_OpenParamPtr->b_total_size = 0;
SEM_MTX_WAIT(SEM_TotalSize);
FDI_OpenTotalSize[MOF_index] = 0;
SEM_MTX_POST(SEM_TotalSize);
/* type and attribute */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -