
//****************************************************************************
// @Module        Project Settings
// @Filename     Lcd_Yddc8189.h
// @Project        Sem3000 
//----------------------------------------------------------------------------
// @Controller    SI1010
//
// @Compiler      KEIL uVision V
//
// @ Frequency   Using internal clock MHz
//
// @Codegenerator 0.1
//
// @Description   This file contains the Project voice recoding  function.
//
//----------------------------------------------------------------------------
// @Date          2013-05-28  
//
//****************************************************************************


//****************************************************************************
// @Project Includes
//****************************************************************************

#ifndef _RTC__H___ 
#define _RTC__H___

#ifdef  _Rtc__C_
#define  Rtc_C
#else
#define Rtc_C	extern
#endif

#define RTC_STOP  	0
#define RTC_RUN  	1

#define FLAG_CLEAR	0
#define FLAG_SET	1


// SmaRTClock Internal Registers
#define CAPTURE0  0x00                 // RTC address of CAPTURE0 register
#define CAPTURE1  0x01                 // RTC address of CAPTURE1 register
#define CAPTURE2  0x02                 // RTC address of CAPTURE2 register
#define CAPTURE3  0x03                 // RTC address of CAPTURE3 register
#define RTC0CN     0x04                 // RTC address of RTC0CN register
#define RTC0XCN   0x05                 // RTC address of RTC0XCN register
#define RTC0XCF   0x06                 // RTC address of RTC0XCF register
#define RTC0PIN   0x07                 // RTC address of RTC0PIN register
#define ALARM0    0x08                 // RTC address of ALARM0 register
#define ALARM1    0x09                 // RTC address of ALARM1 register
#define ALARM2    0x0A                 // RTC address of ALARM2 register
#define ALARM3    0x0B                 // RTC address of ALARM3 register

// SmaRTClock Bit Definitions
#define RTC0CAP   0x01
#define RTC0SET   0x02
#define ALRM        0x04
#define RTC0AEN   0x08
#define RTC0TR     0x10
#define OSCFAIL   0x20
#define MCLKEN    0x40
#define RTC0EN    0x80


#define Max_level 6

typedef struct DATE_INFO {
	U8 State;                                    // 1 BYTE
//----------- Time  관련 변수 정의 ------------
	U16 years;					// 3 BYTE
	U16 days;					// 5 BYTE   Total_Day   365일
	U8  output_month;                  // 6 BYTE
	U8  output_days;                    // 7 BYTE
	U8  seconds;                          // 8 BYTE
	U8  Week;                              // 9 BYTE
	U8  hours;         // 0~23         // 10 BYTE
	U8  minutes;                        // 11 BYTE
	U8  Pm_Am;                        // 12 BYTE

//----------- Pairing Chennel ID  관련 변수 정의 ------------
	U16 Channel_ID[Max_CHANNEL_ID];    // 10 x 2  = 20      // 32
//-----------------------------------------	
	U16  SW_Version;
	U16  Pass_code;
	U8   Temperature_C_F;       //Dummy_2_1;
#if 0
	U8 frequency_no ;        // greq no 1~21				1
      U32 deviation ;             // 2400					4
	U32 data_rate ;           //2800						4	
	U8 power_level;           // 1~7						1
	int compensate_temp;  //							2
	U8 plus_minus;   			//						1
//====================================
	U8  Pairing_select;         //  1: Pairing       0: Non pairing 
	U8 osc_value;
#endif
#ifdef SET_CRT_VOLTAGE
	U8 device_type[Max_CHANNEL_ID];
	U16 AC_voltage[Max_CHANNEL_ID];
#endif

//====================================
    U8 wifi_id[30];
    U8 wifi_id_size;
    U8 wifi_pwd[30];
    U8 wifi_pwd_size;
    U8 device_info[90];
    U8 device_info_size;
    U8 my_ip[20];
    U8 find_crypto;
} DATE_INFO;

Rtc_C DATE_INFO event1;               


typedef struct POWR_DATA{

	U8 Year;
	U8 Month;
	U8 Day;						
	
	U8  Week;                             
	
	U8  Hour;            
	U8  Minutes;                      

      U32 Power_Data;
	  
} POWR_DATA;


Rtc_C bit fRTC_Run ;
Rtc_C bit fWeek_Set ;

Rtc_C idata UU32 RTC_Time;

//****************************************************************************
// @Macros
//****************************************************************************

//****************************************************************************
// @Defines
//****************************************************************************


Rtc_C idata U8 HOUR_INIT;              	// Valid range of HOUR_INIT is 0-23
Rtc_C idata U8 MINUTE_INIT;    		// Valid range of MINUTE_INIT is 0-59
Rtc_C idata U8 SECOND_INIT;       	// Valid range of SECOND_INIT is 0-59
Rtc_C idata U8 Time_SetUp_Sqc;
	

#define HOUR_INIT_           	12   	// Valid range of HOUR_INIT is 0-23
#define MINUTE_INIT_          	0   	// Valid range of MINUTE_INIT is 0-59


#define RTC_DAY      2831155200        // Number of RTC counts in a day
#define RTC_HOUR      117964800       // Number of RTC counts in an hour
#define RTC_MINUTE      1966080       // Number of RTC counts in a minute
#define RTC_SECOND        32768        // Number of RTC counts in a second
#define RTC_HUNDRETH        328       // Number of RTC counts in a hundreth of a second (rounded up)


#define AM_0_HOUR	0
#define AM_12_HOUR	12


#define WEEK_  1
#define DAY_     0



#ifdef WEEK_START_MONDAY
enum Week_Define{
 		 Mon =0,Tue, Wed, Thu, Fri, Sat ,Sun
};
#else     // LCD  1차       
enum Week_Define{
 		 Sun=0, Mon, Tue, Wed, Thu, Fri, Sat
};
#endif

enum Time_Define{
 		   PM=0, AM
};


// Convert initial time settings to RTC alarm counts. Used in RTC_Init()

#define TIME_INIT    ((RTC_HOUR*HOUR_INIT)+(RTC_MINUTE*MINUTE_INIT)+  (RTC_SECOND*SECOND_INIT))

Rtc_C void RTC_Init (void);
Rtc_C unsigned char RTC_Read (unsigned char reg);
Rtc_C void RTC_Write (unsigned char reg, unsigned char value);

Rtc_C void Compute_Month (U8* month, U8* days, U16 total, U16 year);

Rtc_C void RTC_ReadTime(void);

Rtc_C void RTC_Timer_Stop(void);
Rtc_C void RTC_Timer_Run(void);
Rtc_C U8 RTC_SetTimer(U32 time);

Rtc_C void RTC_WriteAlarm (U32 alarm);
Rtc_C void RTC0CN_SetBits(U8 bits);

Rtc_C void RTC_SleepTicks(U32 ticks);
Rtc_C void RTC_Processing_Year_Day(void);
Rtc_C void Put_One_Hour_Chk(U8 One_Hour);
Rtc_C U8 Get_One_Hour_Chk(void);

Rtc_C void Put_One_Minute_Chk(U8 One_Minute);
Rtc_C U8 Get_One_Minute_Chk(void);

Rtc_C void Put_Sec_Chk(U8 Sec);
Rtc_C U8 Get_Sec_Chk(void);
Rtc_C void Chk_Sec(U8 Check_Time_Sec);
Rtc_C void Compute_365_Total_Day(U16 year,  U8 month, U8 days, U16 *Total_Day);

Rtc_C void Default_Set_Time_And_Day(void);
Rtc_C U8 Leap_Year (U16 year);

Rtc_C  U8 Compute_Week_zeller(U16 year,U8 month,U8 day);
Rtc_C void Search_Weekly_SunDay( POWR_DATA* Search, U8 fGet);

#endif	//


