#ifndef DS1683_INC
#define DS1683_INC				1

#include 	<string.h>
#include	<io_regs.h>
#include	<io_i2c.h>
#include	<my_defs.h>


/* Routines to access DS1683 Elapsed-Time and Event Recorder */

// DS1683 I2C ADDRESS BYTES
#define DS1683_ADDR_WR         	0xD6
#define DS1683_ADDR_RD         	0xD7

// DS1683 COMMAND BYTE REGISTER ADDRESSES
#define DS1683_COMMAND_REG      0x00
#define DS1683_STATUS_REG       0x01

#define DS1683_PASSWDSET_REG0   0x02
#define DS1683_PASSWDSET_REG1   0x03
#define DS1683_PASSWDSET_REG2   0x04
#define DS1683_PASSWDSET_REG3   0x05

#define DS1683_EVENTCTR_REG0    0x08	
#define DS1683_EVENTCTR_REG1    0x09	

#define DS1683_ELAPSEDTIME_REG0 0x0A	
#define DS1683_ELAPSEDTIME_REG1 0x0B
#define DS1683_ELAPSEDTIME_REG2 0x0C
#define DS1683_ELAPSEDTIME_REG3 0x0D
	
#define DS1683_EVENTALM_REG0    0x10	
#define DS1683_EVENTALM_REG1    0x11
#define DS1683_ELAPSEDALM_REG0  0x12	
#define DS1683_ELAPSEDALM_REG1  0x13
#define DS1683_ELAPSEDALM_REG2  0x14
#define DS1683_ELAPSEDALM_REG3  0x15

#define DS1683_CONFIG_REG       0x16	

#define DS1683_PASSWDVAL_REG0   0x1A
#define DS1683_PASSWDVAL_REG1   0x1B
#define DS1683_PASSWDVAL_REG2   0x1C
#define DS1683_PASSWDVAL_REG3   0x1D

#define DS1683_USERMEM_REG0     0x20
#define DS1683_USERMEM_REG1     0x21
#define DS1683_USERMEM_REG2     0x22
#define DS1683_USERMEM_REG3     0x23
#define DS1683_USERMEM_REG4     0x24
#define DS1683_USERMEM_REG5     0x25
#define DS1683_USERMEM_REG6     0x26
#define DS1683_USERMEM_REG7     0x27
#define DS1683_USERMEM_REG8     0x28
#define DS1683_USERMEM_REG9     0x29
#define DS1683_USERMEM_REG10    0x2A
#define DS1683_USERMEM_REG11    0x2B
#define DS1683_USERMEM_REG12    0x2C
#define DS1683_USERMEM_REG13    0x2D
#define DS1683_USERMEM_REG14    0x2E
#define DS1683_USERMEM_REG15    0x2F


// DS1683 CONFIG REGISTER DEFAULT VALUE
#define DS1683_CONFIG_VAL       0x00	

// DS1683 COMMAND REGISTER BIT VALUE
#define CLEAR_ALARM_VAL			0x01

// DS1683 STATUS REGISTER BIT VALUES
#define ETC_ALARM_FLAG			0x01
#define EVENT_ALARM_FLAG		0x02
#define EVENT_PIN_STATE			0x04

// DS1683 CONFIG REGISTER BIT VALUES
#define ALARM_POLARITY			0x01
#define EVENT_ALARM_ENABLE		0x02
#define ETC_ALARM_ENABLE		0x04

#define EEPROM_WR_TIME			20		//20 ms


// DS1683 prototypes
int DS1683_Init(void);
int DS1683_ReadReg(uchar Reg, uchar *Data);
int DS1683_RdEventCounter(ushort *Events);
int DS1683_WrEventCounter(ushort *Events);
int DS1683_RdElapsedTimer(ulong *ElapsedSecs);
int DS1683_WrElapsedTimer(ulong *ElapsedSecs);

#endif