Atmel Software Framework

file.c File Reference
#include "conf_explorer.h"
#include "file.h"
#include "navigation.h"
#include <LIB_MEM>
#include <LIB_CTRLACCESS>

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...
 
static void file_load_segment_value (Fs_file_segment _MEM_TYPE_SLOW_ *segment)
 This function stores the global segment variable in other variable. More...
 
bool file_open (uint8_t fopen_mode)
 This function opens the selected 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...
 

Variables

_MEM_TYPE_SLOW_ uint8_t fs_g_sector [FS_CACHE_SIZE]
 Use "FAT sector cache" to store a sector from a file (see file_putc(), file_getc(), file_read_buf(), file_write_buf()) More...
 

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().

static void file_load_segment_value ( Fs_file_segment _MEM_TYPE_SLOW_ segment)
static

This function stores the global segment variable in other variable.

Parameters
segmentPointer on the variable to fill

References fs_g_nav, fs_g_seg, Fs_segment::u32_addr, Fs_segment::u32_size_or_pos, and Fs_management::u8_lun.

Referenced by file_read().

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_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().