MityDSP Documentation Index

FAT Filesystem Library

TODOs: 1) Thread Safety - what isn't handled at the OS (fopen/fread/etc.

) level? 2) Handle read-only permissions correctly.

Using FAT FS with MityDSP

The MityDSP FAT Filesystem allows a standard PC-readable FAT filesystem to be used with the MityDSP. The filesystem is tied into the standard IO library provided with the DSP/BIOS operating system, so the usual file manipulation routines may be used (fopen, fread, fwrite, fclose, etc.).

In addition, routines are provided to create or delete subdirectories, or list subdirectory contents. These functions are not part of the standard I/O library, but generally mimic the "usual" *nix implementations.

The FAT filesystem requires a storage device derived from the tcDspStorageBase class, such as tcDspFlash, tcDspAta, or tcDspMmc.

Currently the FAT16 filesystem (without long filenames) is supported.

Example code to register and use the MityDSP FAT Filesystem is shown in the code segment below:

 {
     int             rv, bytes, partition=0;
     unsigned int    sector=0, sector_sz, addr_start, size;
     char            buffer[128];
     unsigned char  *data;
     tsDevInfo       device;
     tcDspMmc       *mpMmc;

     // initialize SD/MMC driver (see tcDspMmc for details)
     ...

     sector_sz = mpMmc->getSize(sector);
     data = new unsigned char [sector_sz];

     bytes = mpMmc->read(sector, 0, data, sector_sz);
     printf("%1d bytes read from sector %1d...\r\n", bytes, sector);

     addr_start = GetPartitionStart((tsMBR *)data, partition);
     size = GetParitionSize((tsMBR *)data, partition);

     // set up device information
     device.mnRemovable = 1;
     device.mnHeads = 0;
     device.mnBytesPerSector = sector_sz;
     device.mnNumSectors = size;
     device.mnSectorsPerCylinder = 0;
     device.mnSectorOffset = addr_start;

     // create drive name
     buffer[0] = 'C' + partition;
     buffer[1] = 0;

     rv = RegisterFATDriver((RAWREAD)tcDspMmc::readDispatch,
                            (RAWWRITE)tcDspMmc::writeDispatch,
                            NULL, &device, buffer, (void *)mpMmc);

     printf("FAT Registered, partition %1d, drive %c, result = %1d\r\n",
            partition, (char)('C' + partition), rv);

     // can now perform "standard" file I/O operations as needed, such as...
     FILE *lhFile = fopen("C:/myfile.txt", "r");
     if (lhFile)
     {
         printf("C:/myfile.txt contents...\r\n");
         printf("=========================\r\n");
         do
         {
             bytes = fread(buffer, sizeof(char), 128, lhFile);
             printf("%s", buffer);
         } while (bytes == 128);
         printf("\r\n========================\r\n");
         fclose(lhFile);
     }
 } 

  
Generated on Fri Sep 23 16:33:58 2011 for FAT File System Library by  Doxygen Version 1.6.1
Copyright © 2009, Critical Link LLC, All rights reserved.