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.

SD Card - Long File Name Support, PreScaler Formula

Other Parts Discussed in Thread: TMS320C5505

Hello,

Two questions:

1) I did not see any formula in the documentation for calculating timer prescaler values. Only statement is in the Timer n Control Register (TCR) section of TMS320C5505 Watchdog Timer User Guide.pdf pp17 Table15 :

5-2 PSCDIV 0-Fh Prescaler divider. The range is 0000 = divide by 2 to 1100 = divide by 8192


Is there any formula how to calculate the prescaler values in between 0000 and 1100?

2) For the SD Card, ATA_fopen() requires 8 char long FileName, and 3 char extension only. Is there a possibility to use longer file names?

Thanks,

Sukru


 

  • Hello Sukru,

    For a PSCDIV of n, the formula is going to be 2(n+1) .

    As far as extended filenames are concerned, let me look into this a bit and I will follow up.

  • Thanks, Micheal.

  • Michael,

    Could you test  2(n+1)  on your machine. I checked Timer0 with the values below. Basically I am counting the number of intterupts in the isr. The board is set up at 12288000 Hz. Timer period is set to 5DC000 h = 6144000, which is half of the system clock. So it should correspond to 1 s. but I get 30 seconds of run instead of 60s. The formula, according to the experiments here, should be 2n .

    *CPU_TIM0_CTRL = 0x8002;

    *CPU_TIM0_PLWR = 0xC000;

    *CPU_TIM0_PHWR = 0x005D;

    Timer1_Start();

    while(1)

                if(Timer1_InterruptCounter == 60)

                          break;

    Timer1_Stop();

    printf("Timer1 Interrupt Counter = %d\n", Timer1_InterruptCounter);

  • ATA_fopen can very easily be modified to use long filenames. Here is an excerpt of the relevant section in my code :

        ata_error = ATA_findFirst(pAtaFile);

        // find the file, if it exists
        do
        {
            // get the file name for this entry
            ata_error = ATA_getLongName(pAtaFile, FileName, 0, 255);

            // file name is the same? (and file is not deleted)
            if ((strncmp(FileName, name, 255) == 0) && pAtaFile->Filename[0] != 0xE5)
                return ata_error; // We have a match

    HTH,

    - Thomas

  • I tried that but it did not work.

  • Maybe if you change some lines in your code then it will work...

    Seriously though, you really need to provide more information / insight into what is happening if you want us to be able to help you. Try running the code step-by-step to see what is happening.

  • Yes, it may work. I think TI engineers should do this job for the sake of the completeness of the API.

    Sukru

  • Hello All,

    This solution probably will find an already created file.

    But I would like to create a such file (with long file name). I have tried ATA_setLongFileName() and ATA_createLong() but the program stuck and after SD card  is no more detected as formated in my computer.

    Can you help - how to create file with long file name?

    Regards,

    Markov

  • Hi Marcho,

    Indeed, setLongFileName and createLong are the right functions in this case. See my code below which I have been using successfully for some time :

    AtaError ATA_fopen(AtaFile *pAtaFile, const char *name, int create)
    {
        char FileName[256];
        AtaError ata_error;

        ata_error = ATA_ERROR_NONE;

        // find the first file in this drive
        ata_error = ATA_fileInit(gpstrAtaDrive, pAtaFile);

        /* Set the temp write buffer */
        pAtaFile->pDrive->_AtaWriteBuffer = AtaWrBuf;

        ata_error = ATA_findFirst(pAtaFile);

        // find the file, if it exists
        do
        {
            // get the file name for this entry
            ata_error = ATA_getLongName(pAtaFile, FileName, 0, 255);

            // file name is the same? (and file is not deleted)
            if ((strncmp(FileName, name, 255) == 0) && pAtaFile->Filename[0] != 0xE5)
                return ata_error; // We have a match

            // 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;
            }
        } 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 && create)
        {
            // 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;
    }

    The 'create' argument can be 1 to force creation, or 0 to return FILENOTFOUND error.

    HTH,

    - Thomas

    EDIT: TI really need to add <code> tags to this editor...

  • Hello Thomas,

    Thank you! This variant works! 

    Thanks again!

    Regards,

    Marcho

  • How do you open a file in read mode? The fopen() in atafs_ext_func() creates a file.

  • Sukru,

    The fopen() variant that I posted above will open a file in read mode, provided that file exists. So will the original one in the atafs example, IIRC.

    Note that in my version, the filename is case-sensitive. If you need a case-insensitive one, you will have to modify the strncmp() call with your own, case-insensitive version of the function.

    Regards,

    - Thomas

  • Thanks, Thomas.  I will try.