/****************************************************************************/
/* Copyright 2003-2016 MBARI                                                */
/****************************************************************************/
/* Summary  : Definitions for RTC chip for OASIS5 on PIC32MX470F512L        */
/* Filename : rtc.h                                                         */
/* Author   : Robert Herlien (rah)                                          */
/* Project  : OASIS Mooring Replacement (OASIS5)                            */
/* Revision: 1.0                                                            */
/* Created  : 02/25/2016                                                    */
/*                                                                          */
/* MBARI provides this documentation and code "as is", with no warranty,    */
/* express or implied, of its quality or consistency. It is provided without*/
/* support and without obligation on the part of the Monterey Bay Aquarium  */
/* Research Institute to assist in its use, correction, modification, or    */
/* enhancement. This information should not be published or distributed to  */
/* third parties without specific written permission from MBARI.            */
/*                                                                          */
/****************************************************************************/
/* Modification History:                                                    */
/* 25feb2016 rah - created                                                  */
/* $Log: rtc.h,v $
/* Revision 1.1  2016/04/19 17:08:26  bobh
/* First Rev of fileTest
/*
/* Revision 1.1  2016/03/23 23:45:43  bobh
/* Initial revision of dbgTest.MX470
/*
 */
/****************************************************************************/

#ifndef RTC_H
#define RTC_H

#include <GenericTypeDefs.h>
#include <time.h>
#include "mbariTypes.h"


/********************************************/
/*      Typedefs and Constants              */
/********************************************/

#define RTC_ADDR_WR     0xd0
#define RTC_ADDR_RD     0xd1

typedef enum				/* Registers for DS3232 RTC chip*/	
{					
    RTC_SEC = 0, RTC_MIN, RTC_HOUR, RTC_WDAY, RTC_MDAY, RTC_MON, RTC_YEAR,
    RTC_ALM1_SEC, RTC_ALM1_MIN, RTC_ALM1_HOUR, RTC_ALM1_DAY,
    RTC_ALM2_MIN, RTC_ALM2_HOUR, RTC_ALM2_DAY,
    RTC_CTRL, RTC_CTRLSTAT, RTC_XTAL_AGING,
    RTC_TEMP, RTC_TEMPL, RTC_TEMPCTRL,
    RTC_RSVD1, RTC_RSVD2, RTC_RSVD3, RTC_RSVD4,
    RTC_ADDR, RTC_DATA
} RTCRegs;


/********************************************/
/*      Function Prototypes                 */
/********************************************/

void    rtcInit(void);
time_t  rtcTime(struct tm *tmptr);
void    rtcSetTime(time_t newTime);

Errno	rtcReadReg(UINT16 addr, BYTE *rdat);
Errno	rtcWriteReg(UINT16 addr, BYTE wdat);
Errno	rtcReadMultRegs(UINT16 addr, UINT16 numRegs, BYTE *rdat);
Errno	rtcWriteMultRegs(UINT16 addr, UINT16 numRegs, BYTE *wdat);

#endif
