/**************************************************************************************************
---------------------------------------------------------------------------------------------------
	Copyright (c) 2004, Jonathan Bagg
	All rights reserved.

	 Redistribution and use in source and binary forms, with or without modification, are permitted 
	 provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of 
	  conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of 
	  conditions and the following disclaimer in the documentation and/or other materials provided 
	  with the distribution.
    * Neither the name of Jonathan Bagg nor the names of its contributors may be used to 
	  endorse or promote products derived from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 
  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
  POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------------------------------
   Project name : Infidigm AVR Drivers
   Processor	: ATMega64, ATMega128
   File name    : eeprom.h
---------------------------------------------------------------------------------------------------
   Modifications: 

   Revision 1.0  2004/06/17 	Bagg
   - Cleaned up for release
   
   Revision 1.1  2004/12/15 	Bagg
   - Small optimizations made in checking EECR
---------------------------------------------------------------------------------------------------
   Created      : 24 March 2004     	           Author(s) : Jonathan Bagg
---------------------------------------------------------------------------------------------------
   EEprom poled read / write Driver with BlockWrites Interrupt based
---------------------------------------------------------------------------------------------------
**************************************************************************************************/

/**************************************************************************************************
*
*   Function          : ewrite
*
*   Description       : Function writes a byte to EEPROM
*
*   Parameters        : eeprom address, data byte
*
*   Functions Called  : ee_busy();
*
*   Returns           : None
*
**************************************************************************************************/
void ewrite(int address, char data);

/**************************************************************************************************
*
*   Function          : ewrite16
*
*   Description       : Function writes a word to EEPROM
*
*   Parameters        : eeprom address, data word
*
*   Functions Called  : ewrite()
*
*   Returns           : None
*
**************************************************************************************************/
void ewrite16(int address, int data);

/**************************************************************************************************
*
*   Function          : eread
*
*   Description       : Function reads byte from EEPROM
*
*   Parameters        : eeprom address
*
*   Functions Called  : ee_busy()
*
*   Returns           : data byte
*
**************************************************************************************************/
unsigned char eread(int address);

/**************************************************************************************************
*
*   Function          : eread16
*
*   Description       : Function reads word from EEPROM
*
*   Parameters        : eeprom address
*
*   Functions Called  : eread()
*
*   Returns           : data word
*
**************************************************************************************************/
unsigned int eread16(int address);

/**************************************************************************************************
*
*   Function          : ewriteblock
*
*   Description       : Function writes any type of array to eeprom, Interrupt based
*
*   Parameters        : array name, eeprom address, size of array in bytes
*
*   Functions Called  : ewrite()
*
*   Returns           : None
*
*	Usage			  :	ewriteblock(array name, eeprom address, sizeof(array name));		
*
**************************************************************************************************/
void ewriteblock(void *input, int ee_address, int size);

/**************************************************************************************************
*
*   Function          : ereadblock
*
*   Description       : Function reads any type of array from eeprom
*
*   Parameters        : array name, eeprom address, size of array in bytes
*
*   Functions Called  : eread()
*
*   Returns           : None
*
*	Usage			  :	ereadblock(array name, eeprom address, sizeof(array name));		
*
**************************************************************************************************/
void ereadblock(void *output, int ee_address, int size);

/**************************************************************************************************
*
*   Function          : ee_busy ( INTERNAL )
*
*   Description       : Function testes if an eeprom write or a block write is in progress
*
*   Parameters        : None
*
*   Functions Called  : None
*
*   Returns           : 1 = Write in progress, 0 = NO Write in progress
*
**************************************************************************************************/


/**************************************************************************************************
*
*   Signal	          : SIG_EEPROM_READY
*
*   Description       : EEprom Interrupt happens when a byte is finished beening written. The 
*						SIG_EEPROM_READY Interrupt Service Routine writes an array byte-by-byte
*						that pointer 'epnt' points to, until finished the entire length.
*
*   Parameters        : None
*
*   Functions Called  : None
*
*   Returns           : None
*
**************************************************************************************************/

