Atmel Software Framework

file.h File Reference
#include "fs_com.h"
#include "fat.h"

Data Structures

struct  Fs_file_segment
 

Macros

options for file_seek() routine
#define FS_SEEK_SET   0x00
 start at the beginning More...
 
#define FS_SEEK_END   0x01
 start at the end of file and rewind More...
 
#define FS_SEEK_CUR_RE   0x02
 start at the current position and rewind More...
 
#define FS_SEEK_CUR_FW   0x03
 start at the current position and forward More...
 

Functions

uint8_t file_bof (void)
 This function checks the beginning of file. More...
 
void file_close (void)
 This function closes the file. More...
 
uint8_t file_eof (void)
 This function checks the end of file. More...
 
void file_flush (void)
 This function flushes the internal cache (file data and file information) More...
 
uint16_t file_getc (void)
 This function returns the next byte of file. More...
 
uint32_t file_getpos (void)
 This function returns the position in the file. More...
 
bool file_ispresent (void)
 This function checks if a file is selected. More...
 
bool file_open (uint8_t fopen_mode)
 This function opens the selected file. More...
 
bool file_putc (uint8_t u8_byte)
 This function writes a byte in the file. More...
 
bool file_read (Fs_file_segment _MEM_TYPE_SLOW_ *segment)
 This function returns a segment (position & size) in a physical memory corresponding at the file. More...
 
uint16_t file_read_buf (uint8_t _MEM_TYPE_SLOW_ *buffer, uint16_t u16_buf_size)
 This function copies in a buffer the file data corresponding at the current position. More...
 
bool file_seek (uint32_t u32_pos, uint8_t u8_whence)
 This function changes the position in the file. More...
 
bool file_set_eof (void)
 This function sets the end of file at the current position. More...
 
bool file_write (Fs_file_segment _MEM_TYPE_SLOW_ *segment)
 This function allocs and returns a segment (position & size) in a physical memory corresponding at the file. More...
 
uint16_t file_write_buf (uint8_t _MEM_TYPE_SLOW_ *buffer, uint16_t u16_buf_size)
 This function transfer a buffer to a file at the current file position. More...
 

#define FS_SEEK_CUR_FW   0x03

start at the current position and forward

Referenced by file_seek(), play_wav(), reader_id3_size(), and reader_id3_v2_findtag().

#define FS_SEEK_CUR_RE   0x02

start at the current position and rewind

Referenced by file_seek(), pl_rem_sel(), play_wav(), reader_txt_get_line(), and wav_file_get_data().

#define FS_SEEK_END   0x01

uint8_t file_bof ( void  )

This function checks the beginning of file.

Returns
1 the position is at the beginning of file
0 the position isn't at the beginning of file
FFh error

References fat_check_mount_select_open(), fs_g_nav_entry, and Fs_management_entry::u32_pos_in_file.

uint8_t file_eof ( void  )

This function checks the end of file.

Returns
1 the position is at the end of file
0 the position isn't at the end of file
FFh error

References fat_check_mount_select_open(), fs_g_nav_entry, Fs_management_entry::u32_pos_in_file, and Fs_management_entry::u32_size.

Referenced by file_read(), file_read_buf(), input(), main(), pl_main_open(), pl_nav_readentry(), pl_nav_setpos(), read(), reader_txt_get_line(), reader_txt_jump_line(), ushell_cmd_cat(), and wav_file_get_data().

void file_flush ( void  )

This function flushes the internal cache (file data and file information)

References file_close(), fs_g_nav_entry, and Fs_management_entry::u8_open_mode.

uint32_t file_getpos ( void  )

This function returns the position in the file.

Returns
Position in file

References fat_check_mount_select_open(), fs_g_nav_entry, and Fs_management_entry::u32_pos_in_file.

Referenced by ai_usb_ms_audio_context_save(), input(), pl_main_readline(), pl_nav_readentry(), and reader_id3_v2_picture().

bool file_ispresent ( void  )

This function checks if a file is selected.

Returns
true, a file is selected
false, otherwise

References fat_check_is_file(), and fat_check_mount_select().

bool file_open ( uint8_t  fopen_mode)

This function opens the selected file.

Parameters
fopen_modeoption to open the file :
FOPEN_MODE_R R access, flux pointer = 0, size not modify
FOPEN_MODE_R_PLUS R/W access, flux pointer = 0, size not modify
FOPEN_MODE_W W access, flux pointer = 0, size = 0
FOPEN_MODE_W_PLUS R/W access, flux pointer = 0, size = 0
FOPEN_MODE_APPEND W access, flux pointer = at the end, size not modify
Returns
false in case of error, see global value "fs_g_status" for more detail
true otherwise

References fat_check_is_file(), fat_check_mount_select_noopen(), fat_check_nav_access_file, FOPEN_CLEAR_PTR, FOPEN_CLEAR_SIZE, FOPEN_WRITE_ACCESS, FS_ATTR_READ_ONLY, FS_ERR_MODE_NOAVIALABLE, FS_ERR_READ_ONLY, fs_g_nav, fs_g_nav_entry, fs_g_status, FS_LUN_WP, mem_wr_protect(), Fs_management_entry::u32_pos_in_file, Fs_management_entry::u32_size, Fs_management_entry::u8_attr, Fs_management::u8_lun, and Fs_management_entry::u8_open_mode.

Referenced by jpeg_lib_decode(), main(), open(), play_mp3(), play_wav(), prv_append(), prv_cat(), reader_id3_getver(), reader_id3_size(), reader_txt_open(), ushell_cmd_append_file(), ushell_cmd_cat(), and ushell_cmd_perform_alloc().

bool file_putc ( uint8_t  u8_byte)

This function writes a byte in the file.

Parameters
u8_bytebyte to write
Returns
false in case of error, see global value "fs_g_status" for more detail
true otherwise

Referenced by fat_example_append_file(), pl_rem_sel(), prv_append(), and ushell_cmd_append_file().

bool file_read ( Fs_file_segment _MEM_TYPE_SLOW_ segment)

This function returns a segment (position & size) in a physical memory corresponding at the file.

@param     segment  Pointer on the segment structure: <br>
                    ->u32_size_or_pos    IN,   shall contains maximum number of sector to read in file (0 = unlimited) <br>
                    ->u32_size_or_pos    OUT,  contain the segment size (unit sector) <br>
                    ->other              IN,   ignored <br>
                    ->other              OUT,  contains the segment position <br>

@return    false in case of error, see global value "fs_g_status" for more detail
@return    true otherwise
//! This routine is interesting to read a file via a DMA and avoid the file system decode
//! because this routine returns a physical memory segment without File System information.
//! Note: the file can be fragmented and you must call file_read() for each fragments.
//! 

References fat_check_mount_select_open(), fat_read_file(), file_eof(), file_load_segment_value(), FOPEN_READ_ACCESS, FS_512B, FS_512B_MASK, FS_512B_SHIFT_BIT, FS_CLUST_ACT_SEG, FS_ERR_EOF, FS_ERR_OUT_LIST, FS_ERR_WRITE_ONLY, fs_g_nav, fs_g_nav_entry, fs_g_seg, fs_g_status, LSB1, Fs_management_entry::u32_pos_in_file, Fs_management_entry::u32_size, Fs_segment::u32_size_or_pos, Fs_management::u8_BPB_SecPerClus, and Fs_management_entry::u8_open_mode.

uint16_t file_read_buf ( uint8_t _MEM_TYPE_SLOW_ buffer,
uint16_t  u16_buf_size 
)
bool file_seek ( uint32_t  u32_pos,
uint8_t  u8_whence 
)

This function changes the position in the file.

Parameters
u32_posnumber of byte to seek
u8_whencedirection of seek
FS_SEEK_SET , start at the beginning and forward
FS_SEEK_END , start at the end of file and rewind
FS_SEEK_CUR_RE, start at the current position and rewind
FS_SEEK_CUR_FW, start at the current position and forward
Returns
false in case of error, see global value "fs_g_status" for more detail
true otherwise

References fat_check_mount_select_open(), FS_ERR_BAD_POS, fs_g_nav_entry, fs_g_status, FS_SEEK_CUR_FW, FS_SEEK_CUR_RE, FS_SEEK_END, FS_SEEK_SET, Fs_management_entry::u32_pos_in_file, and Fs_management_entry::u32_size.

Referenced by header(), jpeg_lib_decode(), pl_main_readline(), pl_nav_readentry(), pl_rem_sel(), pl_rem_sel_all(), play_mp3(), play_wav(), reader_id3_getver(), reader_id3_size(), reader_id3_v1_genre(), reader_id3_v1_string(), reader_id3_v1_track(), reader_id3_v2_findtag(), reader_txt_beg(), reader_txt_get_line(), and wav_file_get_data().

bool file_set_eof ( void  )

This function sets the end of file at the current position.

@return    false in case of error, see global value "fs_g_status" for more detail
@return    true otherwise
//! This routine is usually used after the last file_write() call.
//! The file_write() routine uses the sector unit (512B),
//! and you can set a specific byte size with a file_seek() call and fiel_set_eof() call.
//! 

Referenced by pl_rem_sel_all().

bool file_write ( Fs_file_segment _MEM_TYPE_SLOW_ segment)

This function allocs and returns a segment (position & size) in a physical memory corresponding at the file.

@param     segment  Pointer on the segment structure: <br>
                    ->u32_size_or_pos    IN,   shall contains the maximum number of sector to write in file <br>
                    ->u32_size_or_pos    OUT,  contains the segment size (unit sector) <br>
                    ->other              IN,   ignored <br>
                    ->other              OUT,  contains the segment position <br>

@return    false in case of error, see global value "fs_g_status" for more detail
@return    true otherwise
//! This routine is interesting to write a file via a DMA and avoid the file system decode
//! because this routine returns a physical memory segment without File System information.
//! Note: the file can be fragmented and you must call file_write() for each fragments.
//! 

Referenced by ushell_cmd_perform_alloc().

uint16_t file_write_buf ( uint8_t _MEM_TYPE_SLOW_ buffer,
uint16_t  u16_buf_size 
)

This function transfer a buffer to a file at the current file position.

Parameters
bufferdata buffer
u16_buf_sizedata size
Returns
number of byte write
0, in case of error

Referenced by main(), reader_txt_new(), and write().