// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// File name    : rtc_drv.h
// Version      : V0.1
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#ifndef RTC_DRV_H_
#define RTC_DRV_H_

#include "memmap.h"
#include "rtc_reg.h"

#define RTC		                      ((RTC_TypeDef *)(PMURTC_BASE_ADDR))

#define RTC_SEL_MASK                (0x03 << 8)
#define RTC_LOW_LEVEL_INT           (0x00 << 8)
#define RTC_RISING_EDGE_INT         (0x01 << 8)
#define RTC_FALLING_EDGE_INT        (0x02 << 8)
#define RTC_RISING_FALLING_EDGE_INT (0x03 << 8)

#define DAY_ALARM                    0x01
#define HOUR_ALARM                   0x02
#define MINUTE_ALARM                 0x03
#define SECOND_ALARM                 0x04
#define ALL_ALARM                    0x05

#define IS_RTC_ALARM_MOD(MOD) (((MOD) == DAY_ALARM) ||    \
                               ((MOD) == HOUR_ALARM) ||   \
                               ((MOD) == MINUTE_ALARM) || \
                               ((MOD) == SECOND_ALARM) || \
                               ((MOD) == ALL_ALARM))


#define	Day_intf	    0x00400000
#define	Hou_intf	    0x00200000
#define	Min_intf	    0x00100000
#define	Sec_intf	    0x00080000
#define	Ala_intf	    0x00040000
#define	CLK_1KHz_intf	0x00020000
#define	CLK_32KHz_intf	0x00010000


typedef struct _tm{
	// date and time components
	UINT16 day;
	UINT8  hour;
	UINT8  minute;
	UINT8  second;
}tm;


extern UINT32 g_rtc_int_sta;
extern void RTC_ISR(void);
extern void RTC_SetTime_Org(tm t);
extern void RTC_SetAlarm(tm t, UINT8 AlarmMod);
extern void RTC_GetTime_Org(tm *t);


// ============================================================================
// Bert added 2023/09/12
extern void RTC_Init(bool clk_sel);
extern void RTC_SetTime(UINT8 hour,UINT8 minute,UINT8 second);
extern void RTC_GetTime(UINT8 *hour,UINT8 *minute,UINT8 *second);
extern void RTC_SetDate(UINT8 year,UINT8 month,UINT8 day);
extern void RTC_GetDate(UINT8 *year,UINT8 *month,UINT8 *day);
extern UINT8 RTC_GetDayOfWeek(void);





#endif /* RTC_DRV_H_ */
