/*
*********************************************************************************************************
*                                       IAR Development Kits
*                                              on the
*
*                                    M451
*
* Filename      : rtc_wakeup.h
* Version       : V1.00
* Programmer(s) : Qian Xianghong
*********************************************************************************************************
*/

#ifndef  USER_RTC_WAKEUP_PRESENT
#define  USER_RTC_WAKEUP_PRESENT

#include "type.h"

#pragma pack(push, 1)

// 本结构从Nuvoton芯片库移植而来
typedef struct {
    uint32_t u32Year;          /*!<  Year value */
    uint32_t u32Month;         /*!<  Month value */
    uint32_t u32Day;           /*!<  Day value */
    uint32_t u32DayOfWeek;     /*!<  Day of week value */
    uint32_t u32Hour;          /*!<  Hour value */
    uint32_t u32Minute;        /*!<  Minute value */
    uint32_t u32Second;        /*!<  Second value */
    uint32_t u32TimeScale;     /*!<  12-Hour, 24-Hour */
    uint32_t u32AmPm;          /*!<  Only Time Scale select 12-hr used */
} S_RTC_TIME_DATA_T;

#define RTC_YEAR2000         2000            /*!< RTC Reference */

#define RTC_CLOCK_12         0                /*!< RTC 12 Hour */
#define RTC_CLOCK_24         1                /*!< RTC 24 Hour */

#define RTC_SUNDAY       ((uint32_t) 0x00000000) /*!< Day of week is sunday */

// 获取日期时间：输出格式为Nuvoton芯片格式
void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sRTC);

#pragma pack(pop)

// RTC初始时间：固定为2016-01-01 00:00:00
#define INITIAL_YEAR	2016

// 实际启动时间和INITIAL_YEAR相差的秒数（当GPS定位或GPRS连接基站以后设置）
extern volatile uint32_t RTC_offsetSeconds;

void Wakeup_Open();

// 计算某月的天数
uint16_t get_month_days(uint16_t year, uint8_t month);
// 计算从某年开始以来经过的秒数
uint32_t Calc_SecondsFromYear(uint16_t startYear, uint16_t year, uint8_t mon, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec);
// 设定下次闹钟唤醒时间
void Wakeup_SetAlarm();
void Wakeup_SetAlarm_B();
// 将从INITIAL_YEAR开始的描述，转换成年月日
void Wakeup_CalcUTCTime(uint32_t totalSeconds, S_RTC_TIME_DATA_T *pRTC);

#endif
