#ifndef _RTC_H_
#define _RTC_H_

#include "stdint.h"

/*RTC引脚定义*/
#define RTC_SDA_INPUT	GPIOB_ModeCfg(GPIO_Pin_8,GPIO_ModeIN_PU)
#define RTC_SCL_INPUT	GPIOB_ModeCfg(GPIO_Pin_9,GPIO_ModeIN_PU)
#define RTC_SDA_OUTPUT	GPIOB_ModeCfg(GPIO_Pin_8,GPIO_ModeOut_PP_20mA)
#define RTC_SCL_OUTPUT	GPIOB_ModeCfg(GPIO_Pin_9,GPIO_ModeOut_PP_20mA)
#define RTC_SDA_H		GPIOB_SetBits(GPIO_Pin_8)
#define RTC_SCL_H		GPIOB_SetBits(GPIO_Pin_9)
#define RTC_SDA_L		GPIOB_ResetBits(GPIO_Pin_8)
#define RTC_SCL_L		GPIOB_ResetBits(GPIO_Pin_9)
#define RTC_SDA			GPIOB_ReadPortPin(GPIO_Pin_8)
#define RTC_SCL			GPIOB_ReadPortPin(GPIO_Pin_9)

//RTC器件地址
#define RTC_Address 		0x64       

typedef struct{
	uint8_t	second;
	uint8_t  minute;
	uint8_t  hour;
	uint8_t  week;
	uint8_t  day;
	uint8_t  month;
	uint8_t  year;
}S_RTC;

typedef struct{
	uint32_t hour;
	uint16_t minute;
	uint16_t second;
}G_CORE_RTC;

typedef struct{
    uint8_t time_select;        //当前时间选择 0x00:当前未选择，0x01: 选择本地定时器计数，0x02:硬件CSIO RTC时间
    uint8_t csio_rtc_cnt;       //CSIO RTC时钟计数
    
	int16_t timezone;			//时区偏移量
    uint32_t Mcu_GetTime_tick;
}TIME_INFO_T;

#if (USE_CORE_TYPE == 1)    //使用C1F核心板 - 使用MCU RTC计时


#endif


void RTC_Init(void);
uint8_t RTC_ReadDate(S_RTC *psRTC);
uint8_t RTC_WriteDate(S_RTC SetRTC);
uint8_t RTC_DATA_Type_Cast_DEC(uint8_t data);
void RTC_TASK(void);
uint8_t RTC_TimeDate_Correct_Figure(uint8_t data);
uint8_t HEX_Conversion_To_DEC(uint8_t c_num);
uint8_t DEV_Conversion_To_HEX(uint8_t c_num);

uint32_t RTC_Conversion_To_Unix(S_RTC *rtc_time);
void Unix_Conversion_To_RTC(S_RTC *rtc_time,uint32_t utc_tick);

extern S_RTC RTC_Raw_Data;
extern S_RTC MCU_RTC_Data;
extern S_RTC Net_RTC_Data;
extern TIME_INFO_T g_time_info;

uint8_t NetRTC_WriteDate(S_RTC SetRTC);

#endif
