/* 
 * File:   EEPROM.h
 * Author: phil
 *
 * Created on 4 August 2013, 6:50 PM
 */

#ifndef EEPROM_H
#define	EEPROM_H

#ifdef	__cplusplus
extern "C" {
#endif




#ifdef	__cplusplus
}
#endif

void EEPROM_Init(void);
void InitEEPROM(void);
//void WriteEnable(void);
#define  EEPROM_ChipSelect_Assert GPIO_PortClear(EEPROM_CHIPSEL_PORT, EEPROM_CHIPSEL_BIT)
#define EEPROM_ChipSelect_DeAssert GPIO_PortSet(EEPROM_CHIPSEL_PORT, EEPROM_CHIPSEL_BIT)
#define SPI_Poll_Timeout 1024             // read retries for SPI

//Function Prototypes
//void InitPIC(void);         // Initializes the PIC to POR defaults
//unsigned char PutStringSPI( unsigned char * );
void SPIWIPPolling( void );
void WriteEnable( void );
void ReadStatus( void );
//void getsSPI( unsigned char *, unsigned char );

//unsigned char LDByteWriteSPI ( unsigned char, unsigned char);
//unsigned char LDByteReadSPI ( unsigned char, unsigned char * , unsigned char);
//unsigned char LDPageWriteSPI ( unsigned char, unsigned char *);
//unsigned char LDSequentialReadSPI ( unsigned char, unsigned char *, unsigned char );
//
unsigned char HDByteWriteSPI( unsigned char, unsigned char, unsigned char );
unsigned char HDByteReadSPI( unsigned char, unsigned char, unsigned char * , unsigned char );
unsigned char HDWordReadSPI(unsigned int, int *, unsigned char );
unsigned char HDWordWriteSPI(unsigned int, unsigned int);
//unsigned char HDPageWriteSPI( unsigned char, unsigned char, unsigned char * );
//unsigned char HDSequentialReadSPI( unsigned char, unsigned char, unsigned char *, unsigned char );
//unsigned char MegaHDSequentialReadSPI( unsigned char, unsigned char, unsigned char, unsigned char *, unsigned char );
//********************************************************************
//Constant Definitions
//********************************************************************
//#define ChipSelect PORTFbits.RF2    // ChipSelect for SPI
#define PageSize 0x80       //PageSize is Physical page boundry from Datasheet. (0x10 = 16, 0x20 = 32)

/* EEPROM specifics*/
#define EEPROM_WRITE_BYTE 0x02
#define EEPROM_READ_BYTE 0x03
#define EEPROM_WREN 0x06
#define EEPROM_READSTAT 0x05
//#define EEPROM_WRITESTAT 0x01
#endif	/* EEPROM_H */


//#define EEPROM_WRITE(Offset_In, Data_In) HDByteWriteSPI(((unsigned char)((int)Offset_In >> 8) & 0xFF),(unsigned char)((int)Offset_In & 0xFF), (char)Data_In)
