Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
nz_xEeprom.h File Reference

Interface for accessing an external SPI EEPROM. More...

#include "HardwareProfile.h"

Go to the source code of this file.

Macros

#define XEE_SUCCESS   FALSE
 
#define XEEInit   xeeInit
 
#define XEEBeginWrite   xeeBeginWrite
 
#define XEEWrite   xeeWrite
 
#define XEEWriteArray   xeeWriteArray
 
#define XEEEndWrite   xeeEndWrite
 
#define XEEBeginRead   xeeBeginRead
 
#define XEERead   xeeRead
 
#define XEEReadArray   xeeReadArray
 
#define XEEEndRead   xeeEndRead
 
#define XEEIsBusy   xeeIsBusy
 
#define xeeEndRead()
 

Typedefs

typedef BOOL XEE_RESULT
 

Functions

void xeeInit (void)
 
BOOL xeeBeginWrite (DWORD address)
 
BOOL xeeWrite (BYTE val)
 
void xeeWriteArray (BYTE *val, WORD wLen)
 
BOOL xeeEndWrite (void)
 
BOOL xeeBeginRead (DWORD address)
 
BYTE xeeRead (void)
 
BOOL xeeReadArray (DWORD address, BYTE *buffer, WORD length)
 
BOOL xeeIsBusy (void)
 

Detailed Description

Interface for accessing an external SPI EEPROM.

Author
Modtronix Engineering
Compiler:
MPLAB XC16

Description

Code for reading and writing to and from a external EEPROM chip on the SPI bus. This file defines an interface for an external SPI EEPROM chip. The implementation has to be done in a separate c file by creating instances of these functions. The Netcruzer library contains a default implementations which can be used.

External EEPROM Project Configuration

The following defines are used to configure this module, and should be placed in projdefs.h. Note that all items marked [-DEFAULT-] are defaults, and do not have to be placed in projdefs.h if they contain desired configuration! For details, see Project Configuration.

// *******************************************************
// ----------------- xEeprom Configuration -----------------
// ********************************************************
//#define XEEPROM_BUFFER_SIZE (32)

External EEPROM Hardware Configuration

The following defines the hardware used for this module, and is located in the board specific file in the "netcruzer/lib" folder (brd_sbc66ec-r2.h for example). They should only be changed if the default EEPROM is replaced with a custom one.

// ********************************************************
// ------------ xEeprom Hardware Configuration ------------
// ********************************************************
#define XEEPROM_SIZE (8192) //Default EEPROM is 25LC640 = 64kBits = 8kBytes
#define XEEPROM_PAGE_SIZE (32)

Software License Agreement

The software supplied herewith is owned by Modtronix Engineering, and is protected under applicable copyright laws. The software supplied herewith is intended and supplied to you, the Company customer, for use solely and exclusively on products manufactured by Modtronix Engineering. The code may be modified and can be used free of charge for commercial and non commercial applications. All rights are reserved. Any use in violation of the foregoing restrictions may subject the user to criminal sanctions under applicable laws, as well as to civil liability for the breach of the terms and conditions of this license.

THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.

File History

2011-12-10, David H. (DH):

  • Initial version, modified version of Microchip's nz_xEeprom.h file from their TCP/IP stack

Macro Definition Documentation

#define xeeEndRead ( )

Ends read

Returns
TRUE if successful, else FALSE

Function Documentation

BOOL xeeBeginRead ( DWORD  address)

Sets internal address counter to given address.

Parameters
addressAddress at which read is to be performed.
Returns
TRUE if successful, else FALSE
BOOL xeeBeginWrite ( DWORD  address)

Modifies internal address counter of EEPROM.

Parameters
addressaddress to be set for writing
Returns
TRUE if successful
BOOL xeeEndWrite ( void  )

Commits any last uncommitted bytes in cache to physical storage. Call this function when you no longer need to write any more bytes at the selected address.

Pre-Condition:
xeeInit() && xeeBeginWrite() are already called.
Returns
TRUE if successful, else FALSE
void xeeInit ( void  )

Initialize SPI module to communicate to serial EEPROM.

BOOL xeeIsBusy ( void  )

Indicates if the external EEPROM is busy

Returns
TRUE if busy, FALSE if available
BYTE xeeRead ( void  )

Reads next byte from EEPROM; internal address is incremented by one.

Pre-Condition:
xeeInit() && xeeBeginRead() are already called.
Returns
BYTE that was read
BOOL xeeReadArray ( DWORD  address,
BYTE *  buffer,
WORD  length 
)

Reads desired number of bytes in sequential mode. This function performs all necessary steps and releases the bus when finished.

Pre-Condition:
xeeInit() is already called.
Parameters
addressAddress from where array is to be read
bufferCaller supplied buffer to hold the data
lengthNumber of bytes to read.
Returns
TRUE if successful, else FALSE
BOOL xeeWrite ( BYTE  val)

Writes a byte to the write cache, and if full, commits the write. Also, if a write boundary is reached the write is committed. When finished writing, xeeEndWrite() must be called to commit any unwritten bytes from the write cache.

Pre-Condition:
xeeInit() && xeeBeginWrite() are already called.
Parameters
valByte to be written
Returns
TRUE if successful, else FALSE
void xeeWriteArray ( BYTE *  val,
WORD  wLen 
)

This function writes an array of bytes to the EEPROM at the address specified when xeeBeginWrite() was called. Page boundary crossing is handled internally.

Details: The internal write cache is flushed at completion, so it is unnecessary to call xeeEndWrite() after calling this function. However, if you do so, no harm will be done.

Pre-Condition:
xeeInit() was called once and xeeBeginWrite() was called.
Parameters
valThe array to write to the next memory location
wLenThe length of the data to be written