This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ATA_fopen and ATA_fcheck in C5515

If I use ATA_fopen or ATA_fcheck to open/search SD card data when the SD card has 500 over data.

The SD card performance was very slow.

Could you provide some suggestion to improve SD card performance?

Could you provide an example for fast searching data on SD card?

//=====================================================


AtaError ATA_fopen(AtaFile *pAtaFile, char *name/*, char *ext*/)
{
char nameUp[FileName_Length] = {0};
short counter;
AtaError ata_error;
Uint16 g_i16ErrorCNT = 0;

ata_error = ATA_ERROR_MEDIA_REMOVED;


for (counter=0; counter<strlen(name); counter++)
{
nameUp[counter] = toupper(name[counter]);
}
nameUp[counter] = 0;


ATA_findFirst(pAtaFile);


// find the file, if it exists
do
{

g_i16ErrorCNT++;
// get the file name for this entry
ata_error = ATA_getLongName(pAtaFile, &ATA_FileName[0], 0, strlen(name)/*+strlen(ext)*/+1);

// file name is the same?
if ((strncmp(ATA_FileName,name,strlen(name)) != 0)&&(strncmp(ATA_FileName,nameUp,strlen(nameUp)) != 0))
{
// if the file name is not the same, get the next entry
ata_error = ATA_findNext(pAtaFile);
// have we get the empty entry?
if(ata_error==ATA_ERROR_FILE_NOT_FOUND)
{
break;
}
if(ata_error==ATA_ERROR_NONE && g_i16ErrorCNT>REC_Files_Number)
return ATA_ERROR_DISK_FULL;
}
else
{
// we have a match
return ata_error;
}
}
while (1);

// if the file does not exist, then create it using the empty entry and return the file descriptor
if (ata_error==ATA_ERROR_FILE_NOT_FOUND)
{
// set the file name and extension name
ata_error = ATA_setLongFileName(pAtaFile, (char*)name);

/* Create a file, returns 0 for successful creation*/
ata_error |= ATA_createLong(pAtaFile, (char*)name);
}

return ata_error;
}

//=========================================================


AtaError ATA_fcheck(AtaFile *pAtaFile, char *name,char FileName[FileName_Length],Uint8 islogo)
{

char nameUp[10];

short counter;
AtaError ata_error = ATA_ERROR_NONE;

for (counter=0; counter<strlen(name); counter++)
{
nameUp[counter] = toupper(name[counter]);
}
nameUp[counter] = 0;


ATA_findFirst(pAtaFile);


// find the file, if it exists
do
{

// get the file name for this entry
ata_error = ATA_getLongName(pAtaFile, &FileName[0], 0, FileName_Length); // Log.txt

// file name is the same?
if ((strncmp(FileName,name,3) != 0)&&(strncmp(FileName,nameUp,3) != 0))
{
// if the file name is not the same, get the next entry
ata_error = ATA_findNext(pAtaFile);
// have we get the empty entry?
if(ata_error==ATA_ERROR_FILE_NOT_FOUND)
{
break;
}
}
else
{
// we have a match
return ata_error;
}

}
while (1);

//ata_error = ATA_getLongName(pAtaFile, &FileName[0], 0, strlen(name)/*+strlen(ext)*/+1);

return ata_error;
}