📄 fdi_ext.c
字号:
### if a data stream or parameter is open. FDI_close returns an error if
### no data stream or parameter is open. FDI_close clears the open_param
### structure to indicate closing a data stream or parameter.
###
### PARAMETERS:
### IN:
### 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_CLOSE ERR_NOTOPEN ERR_NOTEXISTS ERR_PARAM
###
*/
ERR_CODE
FDI_Close(const COMMAND_CONTROL * cmd_cntrl)
{
ERR_CODE status = ERR_NOTOPEN;
#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->type > MAX_TYPE) ||
(cmd_cntrl->identifier >= NUM_PARMS[cmd_cntrl->type]) ||
((cmd_cntrl->identifier == ERASE_COUNT_ID) &&
(cmd_cntrl->type == ERASE_COUNT_TYPE))||
(cmd_cntrl->priority < FDI_MIN_PRIORITY) ||
(cmd_cntrl->priority > FDI_MAX_PRIORITY))
{
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. */
if(!(EMPTY_LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier)))
{
status = ERR_NONE;
/* Clear the Open_Param structure. */
FDI_OpenParamPtr =
&FDI_OpenParam[LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, \
cmd_cntrl->identifier)];
MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
(DWORD)sizeof(OPEN_PARAM));
/*
* Clear 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);
CLEAR_LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier);
SEM_MTX_POST(SEM_LookupTable);
}
/* return error if data was not opened previously. */
/* 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);
#ifdef TIMING
/* Get timestamp for start of update */
COMM_getTimestamp(&FDI_APIend);
#ifdef writeToFile
fprintf(rw,"time to close data %1.0f usecs \n",
((float)(FDI_APIend.low - FDI_API.low)) * 163.84);
#endif
logMsg("time for closing data is %d ticks\n", (int) (FDI_APIend.low -
FDI_API.low), 0, 0, 0, 0, 0);
#endif
return status;
} /* END OF FDI_Close */
/*
#############################################################################
### FDI_Get
###
### DESCRIPTION:
### FDI_Get locates the first or next data parameter or stream of the
### specified type or it will find a matched data parameter or stream
### using the type and identifier fields. FDI_get updates theFDI_GetDataFound
### structure. FDI_get calls the DataFind routine and fills in
### the structure FDI_GetDataFound defined from the Data Location
### structure type. FDI_get uses FDI_GetDataFound to find the next data item
### of the same type if the input sub-command is GET_NEXT. Once found,FDI_Get
### calls GetDataSize function, to get the data size and fills in the
### type_attribute information into the cmd_cntrl->type field and the total
### data size in the cmd_cntrl->count field.
###
### PARAMETERS:
### IN:
### cmd_cntrl->sub_cmd : GET_FIRST:
### finds the first data parameter of
### a given type
### GET_NEXT:
### finds the matching data parameter of
### a given type, priority and identifier
### GET_MATCHED: finds the matching data parameter
### of a given type, priority and
### identifier
### cmd_cntrl->identifier: unique data parameter identifier
### cmd_cntrl->type : This field indicates a data type_attribute.
### The options are:
### any value between 0x00 to 0xF.
###
### OUT:
### cmd_cntrl->type: type and attribute
### cmd_cntrl->count: total data size
### error: a descriptive error code
###
### RETURNS:
### ERR_NONE ERR_CLOSE ERR_NOTOPEN ERR_NOTEXISTS ERR_PARAM
###
*/
ERR_CODE
FDI_Get(CMD_CNTRL_PTR cmd_cntrl)
{
BYTE priority;
ERR_CODE status;
#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->type > MAX_TYPE)
{
return ERR_PARAM;
}
if (cmd_cntrl->sub_command == GET_MATCHED)
{
if ((cmd_cntrl->identifier >= NUM_PARMS[cmd_cntrl->type]) ||
((cmd_cntrl->type == ERASE_COUNT_TYPE) &&
(cmd_cntrl->identifier == ERASE_COUNT_ID)) ||
(cmd_cntrl->identifier == NEW_DATA_STREAM_ID) ||
(cmd_cntrl->priority < FDI_MIN_PRIORITY) ||
(cmd_cntrl->priority > FDI_MAX_PRIORITY))
return ERR_PARAM;
}
else if ((cmd_cntrl->sub_command != GET_FIRST) &&
(cmd_cntrl->sub_command != GET_NEXT))
{
return ERR_PARAM;
}
/* lock the API_sem_cntrl_mutex. */
SEM_MTX_WAIT(SEM_APIMutexSemaphore);
/*
* Verify that the data exists and update the FDI_GetDataFound structure
* with appropriate data information.
*/
#if (PACKET_DATA == TRUE)
if( (FDI_Pckt.ID != WORDMAX) && (cmd_cntrl->identifier == FDI_Pckt.ID) &&
(cmd_cntrl->type == FDI_Pckt.type) &&
(cmd_cntrl->sub_command == GET_MATCHED) )
{
SEM_MTX_POST(SEM_APIMutexSemaphore);
return ERR_PCKTID_MUTEX; /* the found is FDI_Pckt */
}
status = DataFind(cmd_cntrl->identifier, cmd_cntrl->type,
cmd_cntrl->sub_command);
if ( (status == ERR_NONE) && (FDI_Pckt.ID != WORDMAX) &&
(FDI_GetDataFound.identifier == FDI_Pckt.ID) &&
((NIBBLE_HIGH(FDI_GetDataFound.type_attribute)) == FDI_Pckt.type) )
{
if( cmd_cntrl->sub_command == GET_NEXT )
{
status = DataFind(FDI_GetDataFound.identifier, cmd_cntrl->type,
cmd_cntrl->sub_command);
} /* PacketID is first */
if( cmd_cntrl->sub_command == GET_FIRST )
{ /* GET_FIRST */
cmd_cntrl->sub_command = GET_NEXT;
status = DataFind(cmd_cntrl->identifier, cmd_cntrl->type,
cmd_cntrl->sub_command);
cmd_cntrl->sub_command = GET_FIRST;
} /* PacketID is next */
}
#else /* PACKET_DATA */
status = DataFind(cmd_cntrl->identifier, cmd_cntrl->type,
cmd_cntrl->sub_command);
#endif /* PACKET_DATA */
if (status == ERR_NONE)
{
if (cmd_cntrl->sub_command != GET_MATCHED)
{
cmd_cntrl->identifier = FDI_GetDataFound.identifier;
cmd_cntrl->type = NIBBLE_HIGH(FDI_GetDataFound.type_attribute);
priority = BYTEMAX;
}
else
{
priority = cmd_cntrl->priority;
}
status = GetDataSize(&cmd_cntrl->count, cmd_cntrl->identifier,
cmd_cntrl->type, priority);
}
if ((cmd_cntrl->identifier == ERASE_COUNT_ID) &&
(cmd_cntrl->type == ERASE_COUNT_TYPE))
{
status = ERR_NOTEXISTS;
}
/* 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 get data of type %d is %1.0f usecs \n",
cmd_cntrl->type,((float)(FDI_APIend.low - FDI_API.low)) * 163.84);
#endif
logMsg("time for getting data of type %d is %d ticks\n", cmd_cntrl->type,
(int) (FDI_APIend.low - FDI_API.low), 0, 0, 0, 0);
#endif
return status;
} /* END OF FDI_Get */
/*
#############################################################################
### FDI_Write
###
### DESCRIPTION:
### FDI_Write checks the Open_Param structure to verify that the data
### has been opened. Otherwise, calls DataFind routine to verify the
### existence of the data. FDI_Write queues the command and data information
### into the RAM buffer.
###
### PARAMETERS:
### IN:
### 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 0xF.
### cmd_cntrl->buffer_ptr:
###
### OUT:
### error : a descriptive error code
###
### RETURNS:
### ERR_NONE ERR_WRITE ERR_QFULL ERR_NOTEXISTS ERR_PARAM
###
*/
ERR_CODE
FDI_Write(CMD_CNTRL_PTR cmd_cntrl)
{
COMMAND command_buffer;
DWORD size = 0;
WORD index;
WORD initial_gran = 0;
WORD new_gran;
BYTE append_to_replace_flag = FALSE;
BYTE data_found = 0;
ERR_CODE status = ERR_NONE;
volatile HW_ERROR hw_status;
Q_ERROR q_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 != WRITE_RESERVED) &&
#if (PACKET_DATA == TRUE)
(cmd_cntrl->sub_command != WRITE_RSRVPCKT) &&
#endif /* PACKET_DATA */
(cmd_cntrl->sub_command != WRITE_APPEND)) ||
(cmd_cntrl->type > MAX_TYPE) ||
(cmd_cntrl->count == 0) ||
( (cmd_cntrl->count > MAX_QUEUE_ITEM_SIZE) &&
#if (PACKET_DATA == TRUE)
(cmd_cntrl->sub_command != WRITE_RSRVPCKT) &&
#endif /* PACKET_DATA */
(cmd_cntrl->sub_command != WRITE_RESERVED) ) ||
((cmd_cntrl->identifier >= NUM_PARMS[cmd_cntrl->type])&&
(cmd_cntrl->identifier != NEW_DATA_STREAM_ID)) ||
(NUM_PARMS[cmd_cntrl->type] == 0 ) ||
((cmd_cntrl->identifier == ERASE_COUNT_ID) &&
(cmd_cntrl->type == ERASE_COUNT_TYPE)) ||
((cmd_cntrl->sub_command != WRITE_APPEND) &&
(cmd_cntrl->sub_command != WRITE_RESERVED) &&
#if (PACKET_DATA == TRUE)
(cmd_cntrl->sub_command != WRITE_RSRVPCKT) &&
#endif /* PACKET_DATA */
(cmd_cntrl->sub_command != WRITE_MODIFY) &&
(cmd_cntrl->sub_command != WRITE_REPLACE)) ||
(cmd_cntrl->priority < FDI_MIN_PRIORITY) ||
(cmd_cntrl->priority > FDI_MAX_PRIORITY) ||
(cmd_cntrl->count > (WORDMAX-sizeof(COMMAND))))
{
return ERR_PARAM;
}
#if (INCLUDE_FRAGMENTED_DATA == FALSE)
if ((cmd_cntrl->offset + cmd_cntrl->count) >
(MAX_NUM_UNITS_PER_FRAG * UNIT_GRANULARITY))
{
return ERR_PARAM;
}
#endif
#if (INCLUDE_FRAGMENTED_DATA == TRUE)
if ((cmd_cntrl->identifier != WORDMAX) && ((cmd_cntrl->sub_command ==
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -