net/fsfram.h File Reference

FSFRAM Module for Modtronix TCP/IP Stack. More...


Data Structures

struct  _FSFRAM_FILE_INFO

Defines

#define FSFRAM_FILE   BYTE
#define FSFRAM_FILE_INVALID   0xfful
#define FSFRAM_FILE_POS   WORD
#define FSFRAM_MAX_FILES   1
#define FSFRAM_NOT_AVAILABLE   0xfeul
#define FSFRAM_POS   SWORD
#define FSFRAMFILE_EOF   0x40ul
#define FSFRAMFILE_ERROR   0x20ul
#define FSFRAMFILE_READING   0x02ul
#define FSFRAMFILE_RES   0x80ul
#define FSFRAMFILE_USED   0x01ul
#define FSFRAMFILE_WRITING   0x04ul
#define FSFRAMFLAG_AVAILABLE   0x01ul
#define FSFRAMFLAG_READING_WRITING   0x02ul
#define fsframHasError(fhandle)   (fsframFCB[0].flags & FSFRAMFILE_ERROR)
#define fsframIsEOF(fhandle)   (fsframFCB[0].flags & FSFRAMFILE_EOF)
#define fsframIsInUse()   ((fsframFlags & FSFRAMFLAG_AVAILABLE) == 0)
#define fsframIsOK(fhandle)   (fsframFCB[0].flags & (FSFRAMFILE_ERROR | FSFRAMFILE_EOF))
#define fsframIsValidHandle(fhandle)   (fhandle < FSFRAM_MAX_FILES)

Typedefs

typedef struct _FSFRAM_FILE_INFO FSFRAM_FILE_INFO

Functions

void fsframClose (FSFRAM_FILE fhandle)
BOOL fsframCloseImage (void)
void fsframFlush (FSFRAM_FILE fhandle)
BOOL fsframFormat (void)
BYTE fsframGetByte (FSFRAM_FILE fhandle)
FSFRAM_POS fsframGetFAT (BYTE *name)
FSFRAM_FILE_POS fsframGetPos (FSFRAM_FILE fhandle)
BOOL fsframInit (void)
FSFRAM_FILE fsframOpen (BYTE *name, BYTE mode)
FSFRAM_FILE fsframOpenFAT (FSFRAM_POS fatPos)
BOOL fsframOpenImage (void)
BOOL fsframPutByte (FSFRAM_FILE fhandle, BYTE b)
BOOL fsframPutByteImage (BYTE b)
void fsframRelease (FSFRAM_FILE fhandle)
void fsframSetPos (FSFRAM_FILE fhandle, FSFRAM_FILE_POS put)

Variables

FSFRAM_FILE_INFO fsframFCB [FSFRAM_MAX_FILES]
BYTE fsframFlags
BYTE fsframOpenCount


Detailed Description

FSFRAM Module for Modtronix TCP/IP Stack.

Author:
Modtronix Engineering
Dependencies:
stacktsk.h
Compiler:
MPLAB C18 v2.10 or higher
HITECH PICC-18 V8.35PL3 or higher

Description

This module contains the code for integrating a FRAM into the Modtronix File System.
For a detailed description, see the File System FSFRAM section of this document - in [Modules] [System Modules].

Configuration

The following defines are used to configure this module, and should be placed in the projdefs.h (or similar) file. For details, see Project Configuration. To configure the module, the required defines should be uncommended, and the rest commented out.
//*********************************************************************
//--------------------  File System Configuration --------------------
//*********************************************************************
//Defines the maximum size of a file used in the file system.
//When FSFRAM_FILE_SIZE_16MB is defined, the file system can handle files with a size of up to 16 Mbytes.
//When not defined, the maximum size of a file is 64 Kbyte.
//When defined, the FSFRAM16M File System will be created.
//when NOT defined, the FSFRAM File System will be created.
#define FSFRAM_FILE_SIZE_16MB

//Specifies the maximum number of files that can be open at any one time. When defined as 1, the code
//will be much faster and smaller. This value should not be much less then the the number of HTTP
//Connections, seeing that each HTTP connection can have a open file. If most web page files are
//small (below 2 kbytes) then this is not so important.
#define FSFRAM_MAX_FILES 1

//When this define is present, the FSFRAM File System is used as the primary file system. All functions
//Will be remapped to general names, for example fsframOpen() will be mapped to fileOpen. This makes switching
//between different File System much simpler.
//#define FSFRAM_IS_PRIMARY_FS

Define Documentation

#define FSFRAM_FILE   BYTE

FILE handle. Each open files is assigned a file handle.

  • Valid values are from 0 - 127
  • FSFRAM_FILE_INVALID indicates an invalid file
  • FSFRAM_NOT_AVAILABLE indicates that the File System is not available

#define FSFRAM_FILE_INVALID   0xfful

When FILE Handle has this value, it indicates an invalid file

#define FSFRAM_FILE_POS   WORD

FILE position pointer. A variable that can be used to give the offset anywhere in a file. File length

#define FSFRAM_MAX_FILES   1

#define FSFRAM_NOT_AVAILABLE   0xfeul

When FILE Handle has this value, it indicates that the File System is not available

#define FSFRAM_POS   SWORD

File System position pointer. A variable that can be used to give the offset anywhere in the File System. File address in the File System

#define FSFRAMFILE_EOF   0x40ul

FILE flag. When set, indicates that then end of file has been reached.

#define FSFRAMFILE_ERROR   0x20ul

FILE flag. When set, indicates that an error has occured with this file.

#define FSFRAMFILE_READING   0x02ul

FILE flag. Indicates that we are currently reading from this file. For SPI devices, this means that the memory chip is in sequencial read mode and has control of the SPI bus! Before the bus can be used by any other node, it has to be released!

#define FSFRAMFILE_RES   0x80ul

FILE flag. Reserve (don't use) signed bit, is implemented differently by different compilers

#define FSFRAMFILE_USED   0x01ul

FILE flag. When set, indicates that this file is being used.

#define FSFRAMFILE_WRITING   0x04ul

FILE flag. Indicates that we are currently writing to this file. For SPI devices, this means that the memory chip is in sequencial write mode and has control of the SPI bus! Before the bus can be used by any other node, it has to be released!

#define FSFRAMFLAG_AVAILABLE   0x01ul

File System flag. When set, indicates that the File System is available.

#define FSFRAMFLAG_READING_WRITING   0x02ul

File System flag. When set, indicates that the File System is currently busy with a read or write operation. This File System can only perform a single read or write operation at any time. This flag is set as soon as a open file is read from or written to. It is cleared as soon as the open file is released or closed.

#define fsframHasError ( fhandle   )     (fsframFCB[0].flags & FSFRAMFILE_ERROR)

Tests if the last operation on the given file generated an error.

Returns:
TRUE if last operation on file generated and error.
FALSE if otherwise.

#define fsframIsEOF ( fhandle   )     (fsframFCB[0].flags & FSFRAMFILE_EOF)

Tests if the given file has reached it's EOF. This will happen:

  • After the last byte has been read from an open file.
  • After the last byte has been written to an open file.

Returns:
TRUE if given file has reached end of file.
FALSE if otherwise.

 
#define fsframIsInUse (  )     ((fsframFlags & FSFRAMFLAG_AVAILABLE) == 0)

Indicates if the File System is currently in use.

Returns:
TRUE if it is currently being used FALSE if not

#define fsframIsOK ( fhandle   )     (fsframFCB[0].flags & (FSFRAMFILE_ERROR | FSFRAMFILE_EOF))

Tests if the last operation on the given file completed without an EOF or Error. If this function returns false, use the fileIsEOF() and fileIsOK() functions to determine exact condition.

Returns:
TRUE if last operation on file was successfull
FALSE if the last operation on the file generated and EOF or Error

#define fsframIsValidHandle ( fhandle   )     (fhandle < FSFRAM_MAX_FILES)

Tests if the given FILE handle is a valid handle. A valid FILE handle is a value that could be assigned to an open file. Possible invalid FILE handles are FILE_INVALID and FSYS_NOT_AVAILABLE

Returns:
TRUE if given FILE handle value could be a valid FILE handle
FALSE if it is not a possible FILE handle value


Typedef Documentation

FILE structure. Each file that is opened is assigned a FILE structure by the File System.


Function Documentation

void fsframClose ( FSFRAM_FILE  fhandle  ) 

Closes the given file. Seeing that the File System can only have a limited amount of files open at any time (defined by FSFRAM_MAX_FILES), it is very important to call this function after finished with a file!

Parameters:
fhandle FSFRAM_FILE handle of the file to be released

BOOL fsframCloseImage ( void   ) 

Finishes writing the File System Image

Returns:
TRUE if successful
FALSE otherwise

void fsframFlush ( FSFRAM_FILE  fhandle  ) 

Finishes writing any data that has not yet been written to the File System. When writing data to a file via the filePutByte() function, it is not always written straight to the File System Media, but some times to an intermediate buffer. This function will write all pending data from the buffer to the File System Media.

BOOL fsframFormat ( void   ) 

Deletes all files present on the File System

Returns:
TRUE if successful
FALSE otherwise

BYTE fsframGetByte ( FSFRAM_FILE  fhandle  ) 

Reads the next byte from current open file.

Caller must call fileIsEOF() to check for end of file condition before calling this function to make sure the file has not reached it's end. If the fileIsEOF() returns true, then this function will have no affect!

Caller must call fileHasError() function after calling this function to ensure byte was read without error!

This function will place the FRAM in sequencial read mode and take control of the SPI bus! To allow other devices to use the SPI bus while the file is open, call fileRelease() when finished reading some data. When calling fileRead() after calling fileRelease(), the EEPROM will automatically be placed in sequencial read mode again and take control of the bus.

To read multiple bytes, see ex_file_read.c example file.

Pre-Condition:
fileOpen() != FSFRAM_FILE_INVALID and
fileGetByteBegin() == TRUE
Parameters:
fhandle FSFRAM_FILE handle of the file to be released
Returns:
Data byte from current address.

FSFRAM_POS fsframGetFAT ( BYTE name  ) 

Gets the address in the File System of the requested file's FAT entry. This address can be used as a fast way to open files in the future with the fileOpenFAT() function.

!!! IMPORTANT !!! The File System FAT entry address obtained with the fileGetFAT() function will only be valid as long as no modifications are made to the File System! If after obtaining a address with the fileGetFAT() function the File System is modified, this value might not be valid any more!

FSFRAM_FILE_POS fsframGetPos ( FSFRAM_FILE  fhandle  ) 

Get the current file pointer for the given file. This is the offset in the given file that the next read or write will be performed on. This value can be used as a parameter to the fileSetPos() function at a later stage to restore the current file position. This is NOT the file address in the file system.

BOOL fsframInit ( void   ) 

Initializes the Modtronix File System

Returns:
TRUE, if File System Storage access is initialized and File System is is ready to be used
FALSE otherwise

FSFRAM_FILE fsframOpen ( BYTE name,
BYTE  mode 
)

Opens the given file for reading or writing, and returns a handle to the file. The file pointer (where next read or write will occur) will be positioned at the beginning of the file. To modify the file pointer use the fileSetPos() function.

Parameters:
name NULL terminate file name.
mode Currently not used. All files are opened with read and write permission. When writing to a file, no data can be appended to it!
Returns:
- A FILE Handle (value 0 - 127) if the file is found
  • FSFRAM_FILE_INVALID if file could not be opened
  • FSFRAM_NOT_AVAILABLE if the File System is not available

FSFRAM_FILE fsframOpenFAT ( FSFRAM_POS  fatPos  ) 

Opens the given file for reading or writing, and returns a handle to the file. The file pointer (where next read or write will occur) will be positioned at the beginning of the file. To modify the file pointer use the fileSetPos() function.

!!! IMPORTANT !!! The File System FAT entry address obtained with the fileGetFAT() function will only be valid as long as no modifications are made to the File System! If after obtaining a address with the fileGetFAT() function the File System is modified, this value might not be valid any more!

Parameters:
fatPos The requested File's FAT address in the File System. This value has to be obtained from a fileGetFAT() function.
Returns:
- A FSFRAM_FILE Handle (value 0 - 127) if the file is found
  • FSFRAM_FILE_INVALID if file could not be opened
  • FSFRAM_NOT_AVAILABLE if the File System is not available

BOOL fsframOpenImage ( void   ) 

Prepares the File System to receive a new Image via following calls to fsframPutByteImage()

!!! IMPORTANT !!! This function will overwrite the entire File System! All data will be lost!

Pre-Condition:
No files are allowed to be open! If there are any open files when calling this function, it will return FALSE!
Returns:
TRUE if successful
FALSE otherwise

BOOL fsframPutByte ( FSFRAM_FILE  fhandle,
BYTE  b 
)

Writes a byte to the given file.

Caller must call fileIsEOF() to check for end of file condition before calling this function to make sure the file has not reached it's end. If the fileIsEOF() returns true, then this function will have no affect!

Writes a byte to the current output. Actual write may not get started until internal write page is full. To ensure that previously data gets written, caller must call fileFlush() after last call to filePutByte().

Pre-Condition:
fileOpen() was successfully called.
Parameters:
fhandle FSFRAM_FILE handle to the file to be activated
b byte to be written
Returns:
TRUE if successful
FALSE if otherwise

BOOL fsframPutByteImage ( BYTE  b  ) 

Writes a byte to the File System Image. The File System Image contains the following "FSYS Header", "FAT Entries" and "File Data".

!!! IMPORTANT !!! This function will overwrite the entire File System! All data will be lost!

Pre-Condition:
fsframOpenImage() must have been called.
Returns:
TRUE if successful
FALSE if otherwise

void fsframRelease ( FSFRAM_FILE  fhandle  ) 

Releases any resources that the given open file might be reserving. On certian File Systems, like ones that use FRAMs on a shared SPI bus for example, the File System will take control of the bus once a file is opened. To release the bus so it can be used by other modules, the fileRelease() function has to be called. At a later stage, when the file has to be used again, the fileActive() function has to be called.

This function should be called when a file has been opened, and we don't want to close it now, but still want to use it at a later stage. In this case, we can call fileRelease() and suspend operation to the system to perform other tasks. When at a later stage we want to use this file again, fileActivate() will automatically be called by the file read and write functions.

Pre-Condition:
fileOpen() was successfully called.
Parameters:
fhandle FSFRAM_FILE handle of the file to be released

void fsframSetPos ( FSFRAM_FILE  fhandle,
FSFRAM_FILE_POS  put 
)

Set the current file pointer for the given file. This is the offset in the given file that the next read or write will be performed on.


Variable Documentation

FSFRAM_FILE_INFO fsframFCB[FSFRAM_MAX_FILES]


Generated on Wed Feb 3 12:45:34 2010 for SBC65EC Web Server by  doxygen 1.5.8