📄 fdi_ext.c
字号:
FDI_OpenParamPtr->type_attribute =
BYTEMASK(cmd_cntrl->type, BYTEMAX);
/*
* the data offset of the begin of the sequence table unit or single
* instance unit or multiple instance unit being accessed
*/
FDI_OpenParamPtr->b_begin_unit_offset = DWORDMAX;
}
else /* sub_command is not OPEN_CREATE */
{
/*
* the begin address of the block which has the group table or single
* instance or multiple instance unit header
*/
hw_status = LookupToHeader(&(FDI_OpenParamPtr->block_addr),
&unit_address,
&(FDI_OpenParamPtr->b_hdr_offset),
&unit_header_information,
&(FDI_OpenParamPtr->logical_block),
cmd_cntrl->identifier, cmd_cntrl->type);
if (hw_status == HW_ERR_NONE)
{
/* type and attribute */
FDI_OpenParamPtr->type_attribute =
unit_header_information.type_attribute;
/*
* the data offset of the begin of the group table unit or single
* instance unit or multiple instance unit being accessed
*/
FDI_OpenParamPtr->b_begin_unit_offset =
(unit_address - FDI_OpenParamPtr->block_addr);
/* If the attribute is a single instance OR a multi-instance */
if ((NIBBLE_LOW(unit_header_information.type_attribute) ==
ATTR_SINGL_INST) ||
(NIBBLE_LOW(unit_header_information.type_attribute) ==
ATTR_MULTI_INST))
{
/* Moved GetDataSize outside of OPEN_MODIFY condition below,
* needed for both modifies and reads */
/*
* the data offset into the data stream(file) being accessed to
* begin next access
*/
status = GetDataSize(&(FDI_OpenParamPtr->b_current_file_offset),
cmd_cntrl->identifier,
cmd_cntrl->type, cmd_cntrl->priority);
if (status != ERR_NONE)
{
/* Clear the Open_Param structure. */
MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
(DWORD)(sizeof(OPEN_PARAM)));
/*
* 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;
}
if (cmd_cntrl->sub_command == OPEN_MODIFY)
{
/*the size of the data left remaining in the data unit bytes*/
FDI_OpenParamPtr->b_remaining_in_unit = 0;
}
else /* OPEN_READ */
{
/* the size of the data left remaining in the data unit bytes */
FDI_OpenParamPtr->b_remaining_in_unit =
(WORD)FDI_OpenParamPtr->b_current_file_offset;
/*
* the data offset into the data stream(file) being accessed to
* begin next access
*/
FDI_OpenParamPtr->b_current_file_offset = 0;
}
SEM_MTX_WAIT(SEM_TotalSize);
FDI_OpenTotalSize[MOF_index] =
FDI_OpenParamPtr->b_current_file_offset;
SEM_MTX_POST(SEM_TotalSize);
/* sequence table unit size or single instance data unit size */
FDI_OpenParamPtr->b_unit_size =
TO_BYTES(unit_header_information.g_unit_size);
} /* endif single or multi-instance */
#if (INCLUDE_FRAGMENTED_DATA == TRUE)
/* If the attribute is a group table, */
else if (NIBBLE_LOW(unit_header_information.type_attribute) ==
ATTR_GRP_TABLE)
{
/*
* the data offset into the group table unit being accessed
* to begin next access
*/
FDI_OpenParamPtr->b_grp_table_entry_offset =
FDI_OpenParamPtr->b_begin_unit_offset;
/* sequence table unit size or single instance data unit size */
FDI_OpenParamPtr->b_unit_size =
TO_BYTES(unit_header_information.g_unit_size);
/* Read the group table's first entry. */
hw_status = FlashDevRead((BYTE_PTR) &table, unit_address,
sizeof(ENTRY_TABLE));
if (hw_status != HW_ERR_NONE)
{
/* Clear the Open_Param structure. */
MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
(DWORD)sizeof(OPEN_PARAM));
/*
* 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_READ;
}
/*
* the data offset into the data stream(file) being accessed to
* begin next access
*/
status = GetDataSize(&(FDI_OpenParamPtr->b_total_size),
cmd_cntrl->identifier,
cmd_cntrl->type, cmd_cntrl->priority);
if (status != ERR_NONE)
{
/* Clear the Open_Param structure. */
MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
(DWORD)sizeof(OPEN_PARAM));
/*
* 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;
}
SEM_MTX_WAIT(SEM_TotalSize);
FDI_OpenTotalSize[MOF_index] = FDI_OpenParamPtr->b_total_size;
SEM_MTX_POST(SEM_TotalSize);
if (cmd_cntrl->sub_command == OPEN_READ)
{
/*
* the data offset into the data stream(file) being accessed to
* begin next access
*/
FDI_OpenParamPtr->b_current_file_offset = 0;
/*
* Scan the block for a matching instance referred by the first
* group table entry, and get the block address and the
* header offset of the sequence table.
*/
hw_status = FlashDevFindInstance(
&(FDI_OpenParamPtr->tabl_block_addr),
&(FDI_OpenParamPtr->b_tabl_hdr_offset),
&index, cmd_cntrl->identifier,
0, table.entry_instance, table.block_number,
HDR_VALID, cmd_cntrl->type, ATTR_SEQ_TABLE,
FIND_INSTANCE);
if (hw_status != HW_ERR_NONE)
{
/* Clear the Open_Param structure. */
MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
(DWORD)sizeof(OPEN_PARAM));
/*
* 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_READ;
}
/* need to read the first sequence table's entry for the
b_remaining_in_unit value */
/*
* the data offset into the sequence table unit being accessed
* to begin next access
*/
FDI_OpenParamPtr->b_begin_tabl_offset = index;
FDI_OpenParamPtr->b_seq_table_entry_offset = index;
/* Read the sequence table's first entry. */
hw_status =
FlashDevRead((BYTE_PTR) & table,
FDI_OpenParamPtr->tabl_block_addr + index,
sizeof(ENTRY_TABLE));
if (hw_status != HW_ERR_NONE)
{
/* Clear the Open_Param structure. */
MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
(DWORD)sizeof(OPEN_PARAM));
/*
* 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_READ;
}
/* the size of the data left remaining in the data unit bytes */
FDI_OpenParamPtr->b_remaining_in_unit =
TO_BYTES(table.entry_size);
}
else /* OPEN_MODIFY */
{
table_size = TO_BYTES(unit_header_information.g_unit_size);
block = FDI_OpenParamPtr->logical_block;
/*
* fill in the group table, sequence table variables
*/
hw_status = BKGD_GetTableEntry(FDI_OpenParamPtr,
&dummy_word,
(BYTE_PTR) & dummy_word,
&dummy_word,
(BYTE_PTR) & dummy_word,
DWORDMAX,
table_size /
sizeof(ENTRY_TABLE));
if (hw_status != HW_ERR_NONE)
{
/* Clear the Open_Param structure. */
MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
(DWORD)sizeof(OPEN_PARAM));
/*
* 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_READ;
}
/* restore the logical_block and b_unit_size fields */
FDI_OpenParamPtr->logical_block = block;
FDI_OpenParamPtr->b_unit_size = table_size;
/* read back last sequence table entry */
hw_status =
FlashDevRead((BYTE_PTR) & table,
FDI_OpenParamPtr->tabl_block_addr +
FDI_OpenParamPtr->b_seq_table_entry_offset,
sizeof(ENTRY_TABLE));
if (hw_status != HW_ERR_NONE)
{
/* Clear the Open_Param structure. */
MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
(DWORD)sizeof(OPEN_PARAM));
/*
* 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_READ;
}
/* open at the end of the file... */
FDI_OpenParamPtr->b_current_file_offset =
FDI_OpenParamPtr->b_total_size;
} /* ENDELSE !OPEN_READ */
} /* ENDIF attribute == ATTR_GRP_TABLE */
#endif /* INCLUDE_FRAGMENTED_DATA */
}
else if (hw_status != HW_ERR_EMPTY_LKUP)
{
/* Clear the Open_Param structure. */
MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
(DWORD)sizeof(OPEN_PARAM));
/*
* 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);
if (hw_status == HW_ERR_PARAM)
{
return ERR_PARAM;
}
else
{
return ERR_SYSTEM;
}
}
else
{
FDI_OpenParamPtr->b_current_file_offset = 0;
FDI_OpenParamPtr->type_attribute =
BYTEMASK(cmd_cntrl->type, BYTEMAX);
}
} /* end of else. */
/*
* Set the OpenStream bit in the DLT. This bit reserves the associated ID
* for this open stream in case the DLT is scanned in write.
*/
SEM_MTX_WAIT(SEM_LookupTable);
SET_LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier, MOF_index);
SEM_MTX_POST(SEM_LookupTable);
SEM_MTX_POST(SEM_OpenStream);
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
#ifdef TIMING
/* Get timestamp for start of update */
COMM_getTimestamp(&FDI_APIend);
#ifdef writeToFile
fprintf(rw,"time to open data sub command %d of type %d is %1.0f usecs \n",
cmd_cntrl->sub_command,cmd_cntrl->type,
((float)(FDI_APIend.low - FDI_API.low)) * 163.84);
#endif
logMsg("time for opening data sub command %d, of type %d is %d ticks\n",
cmd_cntrl->sub_command, cmd_cntrl->type, (int) (FDI_APIend.low -
FDI_API.low), 0, 0, 0);
#endif
/*
* Opened to create a non_existing data or to read/edit an existing data.
* Hence, indicate successfull completion of data open to the system
* function
*/
return ERR_NONE;
} /* END OF FDI_Open */
/*
#############################################################################
### FDI_Close
###
### DESCRIPTION:
### FDI_Close closes an open data parameter or stream. FDI_close determines
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -