//----------------------------------------------------------------------------------
// <copyright file="timer.h" company="LiquidRobotics">
//	Copyright (c) Liquid Robotics Corporation.  All rights reserved.
// </copyright>
//
// <summary>
// 	Header file for TIMER.C and TIMER_ASM.S, the implmentation of the timer tick
//	ISR and for reading accumulated time (uses timer/counters 1 and 2)
// </summary>
//
// <owner>Mike Cookson</owner>
//---------------------------------------------------------------------------------

#ifndef __TIMER
# define __TIMER

# ifndef OSTMR_TICKS_PER_SECOND
#   define OSTMR_TICKS_PER_SECOND  (128)	// number of timer ticks per second
# endif
# ifndef OSTMR_NESTED_ISR
#   define OSTMR_NESTED_ISR (1)				// non-zero enables interrupts during execution of timer tick
# endif

// Function Prototypes

void OStmrDefault(void);
void OStmrInit(void);
uint16_t OStmrGetAccumulatedTime(void);
uint8_t OStmrToggleMask(uint8_t newVal);


#define YEAR0           1900                    /* the first year */
#define EPOCH_YR        1970            /* EPOCH = Jan 1 1970 00:00:00 */
#define SECS_DAY        (24L * 60L * 60L)
#define LEAPYEAR(year)  (!((year) % 4) && (((year) % 100) || !((year) % 400)))
#define YEARSIZE(year)  (LEAPYEAR(year) ? 366 : 365)

typedef int32_t time_t;

typedef struct _TM_
{
	int tm_sec;
	int tm_min;
	int tm_hour;
	int tm_mday;
	int tm_mon;
	int tm_year;
	int tm_wday;
	int tm_yday;
	int tm_isdst;
}tm;

//Time stamp structure
typedef struct
{
	int8_t	second;
	int8_t	minute;
	int8_t	hour;
	int8_t	day;
	int8_t	month;
	uint8_t	year;
}TIMESTAMP, *PTIMESTAMP;

time_t mktime(tm time);
tm*	gmtime(time_t *timer);

uint8_t settime(time_t time);
time_t gettime();

uint32_t getsecondtick();

// structure that holds the date and time with short year
typedef struct _DATE_TIME_
{
	uint8_t		hour;
	uint8_t		minute;
	uint8_t		second;
	uint8_t		month;
	uint8_t		day;
	uint8_t		year;		// since 2000
} DATE_TIME, *PDATE_TIME;

#endif
