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 File System, Setting date time for a file

Hello,

How is date-time set for a file to be written in SD card? Date and Time attributes are declared as AtaUint16 in AtaFileStruct in Ata.h.  Any example is welcome.

 

Sukru

  • Have you checked out the ATAFS examples in CSL?

    Regards.

  • Examples write file content. However, when you view SD Card contents in the Windows Explorer, there is no file attribute except the file name and extension. Is there any example which saves date, time info?

  • You can use the function ATA_setDateTime() to set date and time for a file. You need to pass date and time parameters in the format defined by FAT as described below.

    Date Format.
    A FAT directory entry date stamp is a 16-bit field that is basically a date relative to the MS-DOS epoch of 01/01/1980. Here is the format (bit 0 is the LSB of the 16-bit word, bit 15 is the MSB of the 16-bit word):

    Bits 0–4: Day of month, valid value range 1-31 inclusive.
    Bits 5–8: Month of year, 1 = January, valid value range 1–12 inclusive.
    Bits 9–15: Count of years from 1980, valid value range 0–127 inclusive (1980–2107).

    Time Format.
    A FAT directory entry time stamp is a 16-bit field that has a granularity of 2 seconds.
    Here is the format (bit 0 is the LSB of the 16-bit word, bit 15 is the MSB of the 16-bit word).

    Bits 0–4: 2-second count, valid value range 0–29 inclusive (0 – 58 seconds).
    Bits 5–10: Minutes, valid value range 0–59 inclusive.
    Bits 11–15: Hours, valid value range 0–23 inclusive.

    The valid time range is from Midnight 00:00:00 to 23:59:58. 

    Regards,

    Pratap.

  • Thanks for the detailed info, Pratap. When should date-time info be passed?

    Before-After ATA_setFileName(), ATA_create(), ATA_close() ?

  • Just checking the implementation of ATA_setDateTime(). It is slightly indirect and you need to configure the date and time function pointers for the file system to set date and time.

    There will be two fields for date/time in the file info structure as defined by FAT specs i.e created date/time and modified date/time. You need to set the date and time function pointers to get proper date and time setting while executing ATA_create(). You may change the modified date and time fields after ATA_create() or when you modify the file contents or for any other purpose using ATA_setDateTime() function.

    Check for AtaState structure in ata.h file. Configure date and time function pointers (get_mod_time, get_mod_date, get_time, get_date) with your functions which returs date and time as per the FAT format. These function pointers will be used by ATA_create() and ATA_setDateTime() functions to set proper date and time.

    Hope this helps.

     - Pratap.

     

  • Configuring the function pointers resolved the problem. Thank you, Pratap.

    Sukru