Atmel Software Framework

fsaccess.c File Reference
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "fsaccess.h"
#include "compiler.h"
#include "file.h"
#include "navigation.h"
#include "ctrl_access.h"

Functions

bool b_fsaccess_init (void)
 This function initializes mutex and navigators. More...
 
int close (int fd)
 This function closes a file. More...
 
long fsaccess_alloc_nav_id (void)
 This function returns a free navigator id. More...
 
size_t fsaccess_file_get_size (int fd)
 This function returns the opened file size. More...
 
void fsaccess_free_nav_id (int fd)
 This function frees a navigator id. More...
 
void fsaccess_give_mutex (void)
 This function frees the mutex. More...
 
int8_t fsaccess_IsDirPresent (const char *pcStringDirName)
 Is a directory present? More...
 
void fsaccess_take_mutex (void)
 This function gives the mutex to the caller. More...
 
int open (const char *pathname, int flags,...)
 Mutex to access the File System. More...
 
ssize_t read (int fd, void *buf, size_t count)
 This function reads from a file. More...
 
ssize_t write (int fd, const void *buf, size_t count)
 This function writes to a file. More...
 

Variables

static unsigned int pvNavUsed = 0
 bitfield for navigator currently used. bit[0..31] is 1 if used, 0 if not. More...
 

bool b_fsaccess_init ( void  )

This function initializes mutex and navigators.

References nav_reset(), NULL, and vSemaphoreCreateBinary.

Referenced by main().

int close ( int  fd)
long fsaccess_alloc_nav_id ( void  )

This function returns a free navigator id.

Returns
long : Id navigator allocated or -1 if none free

References FS_NB_NAVIGATOR, FS_NB_RESERVED_NAV, j, pvNavUsed, Set_bits, and Tst_bits.

Referenced by fsaccess_IsDirPresent(), open(), portTASK_FUNCTION(), and vStartCom1Shell().

size_t fsaccess_file_get_size ( int  fd)

This function returns the opened file size.

Parameters
fdfile descriptor.
Returns
size_t : size of the file pointed to by the descriptor

References fsaccess_give_mutex(), fsaccess_take_mutex(), nav_file_lgt(), and nav_select().

Referenced by config_file_get_value(), config_file_set_value(), fsaccess_example_read(), fsaccess_example_write(), prv_cat(), and prv_xopen_current_logfile().

void fsaccess_free_nav_id ( int  fd)

This function frees a navigator id.

Parameters
fdfile descriptor.

References Clr_bits, and pvNavUsed.

Referenced by close(), fsaccess_IsDirPresent(), and open().

int8_t fsaccess_IsDirPresent ( const char *  pcStringDirName)

Is a directory present?

Parameters
pcStringDirNameInput. Directory name string.
Returns
1 if the directory exists, 0 if the directory doesn't exist, else -1

References false, fsaccess_alloc_nav_id(), fsaccess_free_nav_id(), fsaccess_give_mutex(), fsaccess_take_mutex(), nav_select(), and nav_setcwd().

Referenced by prv_xopen_current_logfile().

int open ( const char *  pathname,
int  flags,
  ... 
)

Mutex to access the File System.

This function opens a file.

This function opens a file.

Parameters
pathnamepath of the file to open.
flagsflags to give file access rights should be O_CREAT : create file if not exist O_APPEND : add data to the end of file O_RDONLY : Read Only O_WRONLY : Write Only O_RDWR : Read/Write
Returns
int : file descriptor (>= 0 if OK (NavID), -1 otherwise)

References error_exit(), file_open(), FOPEN_MODE_APPEND, FOPEN_MODE_R, FOPEN_MODE_R_PLUS, FOPEN_MODE_W, fsaccess_alloc_nav_id(), fsaccess_free_nav_id(), fsaccess_give_mutex(), fsaccess_take_mutex(), nav_select(), nav_setcwd(), O_APPEND, O_CREAT, O_RDWR, and O_WRONLY.

Referenced by config_file_get_value(), config_file_set_value(), fsaccess_example_read(), fsaccess_example_write(), init_mparams(), and prv_xopen_current_logfile().

ssize_t read ( int  fd,
void *  buf,
size_t  count 
)

This function reads from a file.

Parameters
fdfile descriptor.
bufpointer for data that are read.
countamount of bytes to read
Returns
ssize_t : amount of data read (-1 if error)

References buf, file_eof(), file_read_buf(), fsaccess_give_mutex(), fsaccess_take_mutex(), and nav_select().

Referenced by config_file_get_value(), config_file_set_value(), fsaccess_example_read(), fsaccess_example_write(), init_mparams(), prv_cat(), and sensor_read().

ssize_t write ( int  fd,
const void *  buf,
size_t  count 
)

This function writes to a file.

Parameters
fdfile descriptor.
bufpointer from where data are written.
countamount of bytes to write
Returns
ssize_t : amount of data written (-1 if error)

References buf, file_write_buf(), fsaccess_give_mutex(), fsaccess_take_mutex(), and nav_select().

Referenced by config_file_set_value(), fsaccess_example_write(), and prv_vsave_logs().

unsigned int pvNavUsed = 0
static

bitfield for navigator currently used. bit[0..31] is 1 if used, 0 if not.

Referenced by fsaccess_alloc_nav_id(), and fsaccess_free_nav_id().