/****************************************************************************/
/* 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/05/09 17:18:26  bobh
/* First rev of dbgTest ported to FreeRTOS
/*
/* Revision 1.1  2016/03/23 23:45:43  bobh
/* Initial revision of dbgTest.MX470
/*
 */
/****************************************************************************/

#ifndef RTC_H
#define RTC_H

#include <mbariTypes.h>
#include <time.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);
Errno   rtcSetTime(time_t newTime);
Errno   rtcSetAlarm1(time_t almTime);

Nat16	toBCD(Nat16 inw);
Nat16	fromBCD(Nat16 bcd);
Errno	rtcReadReg(Nat16 addr, Byte *rdat);
Errno	rtcWriteReg(Nat16 addr, Byte wdat);
Errno	rtcReadMultRegs(Nat16 addr, Nat16 numRegs, Byte *rdat);
Errno	rtcWriteMultRegs(Nat16 addr, Nat16 numRegs, Byte *wdat);

#endif
