File access layer for FatFS
Frontend functions to read/write files.
Optimized for Memory Size and Speed!
For the whole application only single file handlers for read and write operations are available. They are shared globally to save memory (because each FatFs handler allocates more than 512 bytes to store the last read sector)
For read operations it is possible to re-open a file via a file_t reference so that no directory access is required to find the first sector of the file (again).
NOTE: before accessing the SD Card, the upper level function should synchronize with a SD Card semaphore! E.g. (defined in tasks.h in various projects): MUTEX_SDCARD_TAKE; // to take the semaphore MUTEX_SDCARD_GIVE; // to release the semaphore
#define DEBUG_VERBOSE_LEVEL 1 |
#define SECTOR_SIZE _MAX_SS |
#define TMP_BUFFER_SIZE _MAX_SS |
s32 FILE_BrowserHandler | ( | mios32_midi_port_t | port, | |
char * | command | |||
) |
Handler for MIOS Studio Filebrowser accesses.
See $MIOS32_PATH/apps/controllers/midio128/src/terminal.c for usage example.
Installs the Browser Upload callback function which is executed whenever a file upload starts, and when it has been successfully finished.
[in] | filename | if != NULL, upload has been started for the given file, if NULL the upload has been finished. This means: if the application should do anything with the uploaded file (e.g. auto-load), then it has to store the filename in a temporary variable! |
s32 FILE_CheckSDCard | ( | void | ) |
This function should be called periodically to check the availability of the SD Card
s32 FILE_Copy | ( | char * | src_file, | |
char * | dst_file | |||
) |
This function copies a file
[in] | src_file | the source file which should be copied |
[in] | dst_file | the destination file |
s32 FILE_DirExists | ( | char * | path | ) |
Returns 1 if directory exists, 0 if it doesn't exist, < 0 on errors
s32 FILE_FileExists | ( | char * | filepath | ) |
Returns 1 if file exists, 0 if it doesn't exist, < 0 on errors
s32 FILE_FindNextFile | ( | char * | path, | |
char * | filename, | |||
char * | ext_filter, | |||
char * | next_filename | |||
) |
Returns a file next to the given filename with the given extension if filename == NULL, the first file will be returned in next_filename
[in] | path | directory in which we want to search |
[in] | filename | current file (if NULL, the first file will be returned) |
[in] | ext_filter | optional extension filter (if NULL: no extension) |
[out] | next_filename | the next file if return status is 1 |
s32 FILE_FindPreviousFile | ( | char * | path, | |
char * | filename, | |||
char * | ext_filter, | |||
char * | prev_filename | |||
) |
Returns a previous file of the given filename with the given extension if filename == NULL, no first file will be returned in prev_filename
[in] | path | directory in which we want to search |
[in] | filename | current file (if NULL, the last file will be returned) |
[in] | ext_filter | optional extension filter (if NULL: no extension) |
[out] | prev_filename | the previous file if return status is 1 |
s32 FILE_GetFiles | ( | char * | path, | |
char * | ext_filter, | |||
char * | file_list, | |||
u8 | num_of_items, | |||
u8 | file_offset | |||
) |
s32 FILE_MakeDir | ( | char * | path | ) |
Creates a directory
s32 FILE_PrintSDCardInfos | ( | void | ) |
This function prints some useful SD card informations on the MIOS terminal
Read from file
Read from file with unknown size
Read a 8bit value from file
Closes a file which has been read File can be re-opened if required thereafter w/o performance issues
u32 FILE_ReadGetCurrentPosition | ( | void | ) |
Returns current file pointer of the write file
u32 FILE_ReadGetCurrentSize | ( | void | ) |
Returns current size of write file
Read a 16bit value from file
Read a string (terminated with CR) from file
opens a file for reading Note: to save memory, one a single file is allowed to be opened per time - always use FILE_ReadClose() before opening a new file! Use FILE_ReadReOpen() to continue reading
reopens a file for reading
Changes to a new file position
Read a 32bit value from file
s32 FILE_Remove | ( | char * | path | ) |
Removes a file or directory
s32 FILE_SDCardAvailable | ( | void | ) |
s32 FILE_SendSyxDump | ( | char * | path, | |
mios32_midi_port_t | port, | |||
u32 | ms_delay_between_dumps | |||
) |
This function sends a .syx file to given MIDI out port
s32 FILE_UpdateFreeBytes | ( | void | ) |
This function updates the number of free bytes by scanning the FAT for unused clusters.
should be called before FILE_Volume* bytes are read
s32 FILE_VolumeAvailable | ( | void | ) |
u32 FILE_VolumeBytesFree | ( | void | ) |
u32 FILE_VolumeBytesTotal | ( | void | ) |
char* FILE_VolumeLabel | ( | void | ) |
u32 FILE_VolumeSectorsPerCluster | ( | void | ) |
Writes into a file with caching mechanism (actual write at end of sector) File has to be closed via FILE_WriteClose() after the last byte has been written
Writes a 8bit value into file
s32 FILE_WriteClose | ( | void | ) |
Closes a file by writing the last bytes
u32 FILE_WriteGetCurrentPosition | ( | void | ) |
Returns current file pointer of the write file
u32 FILE_WriteGetCurrentSize | ( | void | ) |
Returns current size of write file
Writes a 16bit value into file
Opens a file for writing
Changes to a new file position
Writes a 32bit value into file