📄 fm_flt.c
字号:
* allocate the memory needed to maintain the table.
*
****************************************************************************/
FLT_Error FLT_Create()
{
/* reset the total number of entries in & search index into the FLT */
NumFilesInFlt = 0;
IndexIntoFlt = 0;
/* E.5.2.870 BEGIN */
NextIndexIntoFlt = 0;
/* E.5.2.870 END */
return FLT_ErrorNone;
}
/*****************************************************************************
*
* FLT_Destroy
*
* DESCRIPTION:
* Releases all the resources obtained by the File Lookup Table during
* its lifetime. When the File Lookup Table is created at boot time (as
* it is in this implementation), the function resets the variables needed
* to maintain the table. When the File Lookup Table is created
* dynamically, the function releases all the memory it obtained during
* its lifetime.
*
****************************************************************************/
FLT_Error FLT_Destroy()
{
/* reset the total number of entries in & search index into the FLT */
NumFilesInFlt = 0;
IndexIntoFlt = 0;
/* E.5.2.870 BEGIN */
NextIndexIntoFlt = 0;
/* E.5.2.870 END */
return FLT_ErrorNone;
}
/*****************************************************************************
*
* FLT_AddEntry
*
* DESCRIPTION:
* Adds a new mapping of a File Manager File to Data Manager Parameters.
*
****************************************************************************/
FLT_Error FLT_AddEntry(
const FDI_TCHAR * filename,
const UINT16 id
)
{
FLT_Error error;
UINT32 key;
UINT16 index;
FileLookup entry;
/* if memory is available to add the new entry to the FLT */
if (NumFilesInFlt < NUM_FILES)
{
/* generate key based on the filename */
key = GenerateKey(filename);
/* create a new lookup table entry */
CreateLookupTableEntry(&entry, key, id);
/* add the new entry to the lookup table */
error = AddToLookupTable(
FileLookupTable,
&NumFilesInFlt,
&index,
&entry
);
/* update the search index if needed */
/* E.5.2.870 BEGIN */
if ((error == FLT_ErrorNone) && (index <= IndexIntoFlt))
{
if (IndexIntoFlt < UINT16_MAX)
{
IndexIntoFlt++;
}
if (NextIndexIntoFlt < UINT16_MAX)
{
NextIndexIntoFlt++;
}
}
/* E.5.2.870 END */
}
else
{
/* declare there is not enough memory to add the entry */
error = FLT_ErrorNotEnoughMemory;
}
return error;
}
/*****************************************************************************
*
* FLT_GetNumEntries
*
* DESCRIPTION:
* Returns the number of entries currently in the File Lookup Table.
*
****************************************************************************/
UINT16 FLT_GetNumEntries()
{
return NumFilesInFlt;
}
/*****************************************************************************
*
* FLT_GetEntryID
*
* DESCRIPTION:
* Determines the Data Manager ID of the File Manager File.
*
****************************************************************************/
FLT_Error FLT_GetEntryID(
UINT16 * id,
const FDI_TCHAR * filename
)
{
FLT_Error error;
UINT32 key;
FileLookup entry;
/* generate key based on the filename */
key = GenerateKey(filename);
/* lookup the entry */
error = GetLookupTableEntry(
&entry,
key,
filename,
FileLookupTable,
NumFilesInFlt
);
/* if the entry is present in the FLT */
if (error == FLT_ErrorNone)
{
/* set the id to that of the entry's */
*id = entry.Id;
}
return error;
}
/*****************************************************************************
*
* FLT_GetFirstEntryID
*
* DESCRIPTION:
* Returns the Data Manager Parameter ID of the first entry in the File
* Lookup Table.
*
****************************************************************************/
FLT_Error FLT_GetFirstEntryID(
UINT16 * id
)
{
FLT_Error error;
/* set the index to the first entry */
IndexIntoFlt = 0;
/* E.5.2.870 BEGIN */
/* set the index to the next entry, if there is 0 or 1 entry, GetNextEtnry
* will return false if NextIndexIntoFlt is too high */
NextIndexIntoFlt = 1;
/* E.5.2.870 END */
/* if the FLT has at least on entry */
if (IndexIntoFlt < NumFilesInFlt)
{
/* set the id to the FLT's first entry's id and declare success */
*id = FileLookupTable[IndexIntoFlt].Id;
error = FLT_ErrorNone;
}
else
{
/* declare no entries in the FLT */
error = FLT_ErrorNoMoreEntries;
}
return error;
}
/*****************************************************************************
*
* FLT_GetNextEntryID
*
* DESCRIPTION:
* Returns the Data Manager Parameter ID of the next entry in the File
* Lookup Table.
*
****************************************************************************/
FLT_Error FLT_GetNextEntryID(
UINT16 * id
)
{
FLT_Error error;
/* increment the FLT index to the next entry */
/* E.5.2.870 BEGIN */
IndexIntoFlt = NextIndexIntoFlt;
/* E.5.2.870 END */
/* if the FLT has at least one more entry to scan */
if (IndexIntoFlt < NumFilesInFlt)
{
/* set the id to the FLT's next entry's id and declare success */
*id = FileLookupTable[IndexIntoFlt].Id;
error = FLT_ErrorNone;
/* E.5.2.870 BEGIN */
/* Set index to next entry. NextIndexIntoFlt will continue being
* incremented until it is equal to NumFilesInFlt */
NextIndexIntoFlt++;
/* E.5.2.870 END */
}
else
{
/* declare there are no more entries */
error = FLT_ErrorNoMoreEntries;
}
return error;
}
/*****************************************************************************
*
* FLT_GetFirstEntryName
*
* DESCRIPTION:
* Returns the File Manager filename of the first entry in the File
* Lookup Table.
*
****************************************************************************/
FLT_Error FLT_GetFirstEntryName(
FDI_TCHAR * filename
)
{
FLT_Error error;
FILE_INFO file_info;
/* Set the index into the FLT*/
IndexIntoFlt = 0;
/* E.5.2.870 BEGIN */
/* set the index to the next entry, if there is 0 or 1 entry, GetNextEtnry
* will return false if NextIndexIntoFlt is too high */
NextIndexIntoFlt = 1;
/* E.5.2.870 END */
/* if a single entries exists */
if (IndexIntoFlt < NumFilesInFlt)
{
/* if a read from flash was successful */
error = ReadFileInfo(&file_info, FileLookupTable[IndexIntoFlt].Id);
if (error == FLT_ErrorNone)
{
/* return the filename */
FM_CopyString(filename, file_info.file_name, (FILE_NAME_SIZE + 1));
}
}
else
{
/* declare there are no entries in the FLT */
error = FLT_ErrorNoMoreEntries;
}
return error;
}
/*****************************************************************************
*
* FLT_GetNextEntryName
*
* DESCRIPTION:
* Returns the File Manager filename of the next entry in the File
* Lookup Table.
*
****************************************************************************/
FLT_Error FLT_GetNextEntryName(
FDI_TCHAR * filename
)
{
FLT_Error error;
FILE_INFO file_info;
/* increment the index into the FLT */
/* E.5.2.870 BEGIN */
IndexIntoFlt = NextIndexIntoFlt;
/* E.5.2.870 END */
/* if at least one more entry exists */
if (IndexIntoFlt < NumFilesInFlt)
{
/* read the filename from flash */
error = ReadFileInfo(&file_info, FileLookupTable[IndexIntoFlt].Id);
if (error == FLT_ErrorNone)
{
/* return the filename */
FM_CopyString(filename, file_info.file_name, (FILE_NAME_SIZE + 1));
/* E.5.2.870 BEGIN */
NextIndexIntoFlt++;
/* E.5.2.870 END */
}
}
else
{
/* declare there are no entries in the FLT */
error = FLT_ErrorNoMoreEntries;
}
return error;
}
/*****************************************************************************
*
* FLT_DeleteEntryByID
*
* DESCRIPTION:
* Deletes the entry whose Data Manager Parameter ID matches the value
* specified.
*
****************************************************************************/
FLT_Error FLT_DeleteEntryByID(
const UINT16 id
)
{
FLT_Error error;
UINT16 index;
/* if there are entries in the FLT */
if (NumFilesInFlt > 0)
{
/* attempt to remove the entry with the specified id */
error = DeleteFromLookupTable(
FileLookupTable,
&NumFilesInFlt,
&index,
id
);
/* update search index if needed */
/* E.5.2.870 BEGIN */
if ((error == FLT_ErrorNone) &&
(index <= IndexIntoFlt))
{
if(IndexIntoFlt > 0)
{
IndexIntoFlt--;
}
if(NextIndexIntoFlt > 0)
{
NextIndexIntoFlt--;
}
}
/* E.5.2.870 END */
}
else
{
/* declare entry does not exist */
error = FLT_ErrorEntryDoesNotExist;
}
return error;
}
#endif /* FILE_MANAGER == TRUE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -