📄 fdi_ext.c
字号:
*/
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 ERR_WIP, the file is being deleted by BKGD */
else if ( status == ERR_WIP )
{
status = ERR_NOTEXISTS;
}
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;
DWORD shift_offset;
DWORD temp_size;
DWORD truncate_count = 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_TRUNCATE) &&
(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->sub_command != WRITE_TRUNCATE)
) ||
(cmd_cntrl->priority < FDI_MIN_PRIORITY) ||
(cmd_cntrl->priority > FDI_MAX_PRIORITY) ||
((cmd_cntrl->sub_command != WRITE_TRUNCATE) &&
(cmd_cntrl->count > (WORDMAX-sizeof(COMMAND)))
)
)
{
return ERR_PARAM;
}
#if (INCLUDE_FRAGMENTED_DATA == FALSE)
/* E.5.1.759 Begin */
/* E 5.1.849 START */
/* Indentation */
if ((cmd_cntrl->offset + cmd_cntrl->count) > FDI_MAX_FRAG_SIZE)
/* E.5.1.759 End */
{
return ERR_PARAM;
}
/* E 5.1.849 END */
#endif
if(cmd_cntrl->sub_command == WRITE_TRUNCATE)
{
truncate_count = cmd_cntrl->count;
}
#if (INCLUDE_FRAGMENTED_DATA == TRUE)
if(cmd_cntrl->sub_command != WRITE_TRUNCATE)
{
if ((cmd_cntrl->identifier != WORDMAX) && ((cmd_cntrl->sub_command ==
WRITE_APPEND) ||
#if (PACKET_DATA == TRUE)
(cmd_cntrl->sub_command == WRITE_RSRVPCKT) ||
#endif /* PACKET_DATA */
(cmd_cntrl->sub_command == WRITE_RESERVED)))
{
/* Maximum size, in bytes, that a fragment can be before an overflow of
the group table can occur. */
/* E.5.1.759 Begin */
if ( (cmd_cntrl->offset + cmd_cntrl->count)>
(MAX_GRP_UNIT_ENTRIES*MAX_SEQ_ENTRY*
FDI_MAX_FRAG_SIZE ) )
/* E.5.1.759 End */
{
/*
* unlock the global_sem_cntrl_mutex to give others access to the
* globals
*/
/* Unlock the API_sem_cntrl_mutex. */
/* E5.0.642 START */
/* Do not post a semaphore that has not been taken */
/* SEM_MTX_POST(SEM_APIMutexSemaphore); */
/* E5.0.642 END */
return ERR_MAXITEMSIZE;
}
/* this data size check for reserve will result in early report of
* ERR_MAXITEMSIZE. So it is removed from here. A more accurate check
* has been added to BKGD_CheckForSpace
*/
/* move the data size check to BLKGD_CheckForSpace */
}
}
#endif /* if INCLUDE_FRAGMENTED_DATA */
/* Check to see if a data parameter or stream is not open. */
/* lock the API_sem_cntrl_mutex. */
SEM_MTX_WAIT(SEM_APIMutexSemaphore);
#if (PACKET_DATA == TRUE)
if ( FDI_Pckt.ID != WORDMAX && FDI_Pckt.ID == cmd_cntrl->identifier &&
FDI_Pckt.type == cmd_cntrl->type &&
cmd_cntrl->sub_command != WRITE_RSRVPCKT )
{
SEM_MTX_POST(SEM_APIMutexSemaphore);
return ERR_PCKTID_MUTEX;
}
#endif /* PACKET_DATA */
/*
* Look into the FDI_DataLookupTable and assign the first free
* identifier to the new data being created.
*/
if (cmd_cntrl->identifier == NEW_DATA_STREAM_ID)
{
/* Check if the offset specified is zero for the first append. */
if (cmd_cntrl->offset != 0)
{
/*
* unlock the global_sem_cntrl_mutex to give others access to the
* globals
*/
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
return ERR_PARAM;
}
/* lock the global_sem_cntrl_mutex. */
SEM_MTX_WAIT(SEM_LookupTable);
/* Scan the data lookup table. */
/* ERASE_COUNT_ID changed from type 14 ID 0 to type 14 ID NUM_TYPE14_PARMS */
start = 0;
for (index = start; index < NUM_PARMS[cmd_cntrl->type]; index++)
{
if (EMPTY_LOOKUP_TABLE(cmd_cntrl->type, index))
{
cmd_cntrl->identifier = index;
break;
}
}
/* unlock the global_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_LookupTable);
if (index >= NUM_PARMS[cmd_cntrl->type])
{
/*
* unlock the global_sem_cntrl_mutex to give others access to the
* globals
*/
/* 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.
*/
hw_status = DataFind(cmd_cntrl->identifier, cmd_cntrl->type, GET_MATCHED);
if ( hw_status != ERR_NONE )
{
/* if ERR_WIP, file is being deleted by BKGD */
if ( hw_status == ERR_WIP )
{
SEM_MTX_POST(SEM_APIMutexSemaphore);
return ERR_EXISTS;
}
/* Tried to append to the data parameter that is not yet created. */
else if ((cmd_cntrl->sub_command == WRITE_APPEND) ||
#if (PACKET_DATA == TRUE)
(cmd_cntrl->sub_command == WRITE_RSRVPCKT) ||
#endif /* PACKET_DATA */
(cmd_cntrl->sub_command == WRITE_RESERVED))
{
/* Check if the offset specified is zero for the first append. */
if (cmd_cntrl->offset != 0)
{
/*
* unlock the global_sem_cntrl_mutex to give others access to the
* globals
*/
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
return ERR_PARAM;
}
}
/* Tried to replace or modify the data that does not exist. */
else if ((cmd_cntrl->sub_command == WRITE_REPLACE) ||
(cmd_cntrl->sub_command == WRITE_TRUNCATE) ||
(cmd_cntrl->sub_command == WRITE_MODIFY))
{
/*
* unlock the global_sem_cntrl_mutex to give others access to the
* globals
*/
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
return ERR_NOTEXISTS;
}
} else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -