/* * RTC.h * * Created on: 2024. 2. 20. * Author: user */ /* * RTC.h * * Created on: 2017. 1. 25. * Author: kdkor */ #ifndef MAIN_RESOURCE_INCLUDE_RTC_H_ #define MAIN_RESOURCE_INCLUDE_RTC_H_ #ifdef __cplusplus extern "C" { #endif extern unsigned int Spid_Rx(unsigned int Read_addr); extern void Spid_Tx(unsigned int Tx_Data); //RTC DEVICE MODEL // DS3234 SPI 4-Wire RTC #define M48T35Y 0 #define DS3234 1 #define DS1390 0 #if(DS3234) // Read, Write Mode #define RTC_RD 0x0000 #define RTC_WR 0x8000 // ADDR Preset #define RTC_SEC 0x0000 #define RTC_MIN 0x0100 #define RTC_HOUR 0x0200 #define RTC_DAY 0x0300 #define RTC_DATE 0x0400 #define RTC_MONTH 0x0500 #define RTC_YEAR 0x0600 #define RTC_ALARM1_SEC 0x0700 #define RTC_ALARM1_MIN 0x0800 #define RTC_ALARM1_HOUR 0x0900 #define RTC_ALARM1_DAY_DATE 0x0A00 #define RTC_ALARM2_MIN 0x0B00 #define RTC_ALARM2_HOUR 0x0C00 #define RTC_ALARM2_DATE 0x0D00 #define RTC_CTRL 0x0E00 #define RTC_CTRL_STATUS 0x0F00 #define RTC_XTAL_AGING_OFFSET 0x1000 #define RTC_TEMP_MSB 0x1100 #define RTC_TEMP_LSB 0x1200 struct sDS3234_SEC_BIT { Uint16 Unit :4; // 0:3 Seconds 일의 자리 Uint16 Tens :3; // 4:6 Seconds 10의 자리 Uint16 rsvd1 :9; // 7:15 rsvd }; // union sDS3234_SEC { Uint16 all; struct sDS3234_SEC_BIT bit; }; struct sDS3234_MIN_BIT { Uint16 Unit :4; // 0:3 Minutes 일의 자리 Uint16 Tens :3; // 4:6 Minutes 10의 자리 Uint16 rsvd1 :9; // 7:15 rsvd }; union sDS3234_MIN { Uint16 all; struct sDS3234_MIN_BIT bit; }; struct sDS3234_HOUR_BIT { Uint16 Unit :4; // 0:3 Hour 일의 자리 Uint16 Tens :2; // 4:5 Hour 10의 자리 Uint16 Mode_24_12 :1; // 6 12/24 Mode Uint16 rsvd1 :9; // 7:15 rsvd }; // union sDS3234_HOUR { Uint16 all; struct sDS3234_HOUR_BIT bit; }; struct sDS3234_DAY_BIT { Uint16 Day :3; // 0:2 Day (요일) 1~7 Uint16 rsvd4 :13; // 3:15 rsvd }; // union sDS3234_DAY { Uint16 all; struct sDS3234_DAY_BIT bit; }; struct sDS3234_DATE_BIT { Uint16 Unit :4; // 0:3 1 Date (날짜) Uint16 Tens :2; // 4:5 10 Date (날짜) Uint16 rsvd5 :10; // 6:15 rsvd }; // union sDS3234_DATE { Uint16 all; struct sDS3234_DATE_BIT bit; }; struct sDS3234_MONTH_BIT { Uint16 Unit :4; // 0:3 Month Uint16 Tens :1; // 4 Month 10의 자리 Uint16 rsvd6 :2; // 5:6 rsvd Uint16 Century :1; // 7 Century Uint16 rsvd7 :8; // 8:15 rsvd }; // union sDS3234_MONTH { Uint16 all; struct sDS3234_MONTH_BIT bit; }; struct sDS3234_YEAR_BIT { Uint16 Unit :4; // 0:3 Year Uint16 Tens :4; // 4:7 Year 10의 자리 Uint16 rsvd8 :8; // 8:15 rsvd }; union sDS3234_YEAR { Uint16 all; struct sDS3234_YEAR_BIT bit; }; struct sDS3234_TEMP_BIT { Uint16 LSB :8; // 4:7 Month 10의 자리 Uint16 MSB :8; // 0:3 Month }; union sDS3234_TEMP { Uint16 all; struct sDS3234_TEMP_BIT bit; }; struct sDS3234_REGS { volatile union sDS3234_SEC SecDAT; volatile int16 Sec; volatile union sDS3234_MIN MinDAT; volatile int16 Min; volatile union sDS3234_HOUR HourDAT; volatile int16 Hour; volatile union sDS3234_DAY DayDAT; volatile int16 Day; volatile union sDS3234_DATE DateDAT; volatile int16 Date; volatile union sDS3234_MONTH MonthDAT; volatile int16 Month; volatile union sDS3234_YEAR YearDAT; volatile int16 Year; volatile union sDS3234_TEMP TempDAT; volatile float Temp; }; struct sRTC_DATA_BUF { int Sec; int Min; int Hour; int Date; int Day; int Month; int Year; int Temp; }; extern struct sDS3234_REGS RTCRegs; extern struct sDS3234_REGS RTCWrBuf; #endif #if(DS1390) // Read, Write Mode #define RTC_RD 0x00 #define RTC_WR 0x80 // ADDR Preset #define RTC_HUNDREDTHS_SEC 0x00 #define RTC_SEC 0x01 #define RTC_MIN 0x02 #define RTC_HOUR 0x03 #define RTC_DAY 0x04 #define RTC_DATE 0x05 #define RTC_MONTH 0x06 #define RTC_YEAR 0x07 #define RTC_ALARM1_HUNDREDTHS_SEC 0x08 #define RTC_ALARM1_SEC 0x09 #define RTC_ALARM1_MIN 0x0A #define RTC_ALARM1_HOUR 0x0B #define RTC_ALARM1_DAY_DATE 0x0C #define RTC_CTRL 0x0D #define RTC_CTRL_STATUS 0x0E struct sDS1390_HUNDREDTH_SEC_BIT { Uint16 Hundredths :4; // 0:3 Seconds 일의 자리 Uint16 Tenths :4; // 4:7 Seconds 10의 자리 Uint16 rsvd1 :8; // 8:15 rsvd }; union sDS1390_HUNDREDTH_SEC { Uint16 all; struct sDS1390_HUNDREDTH_SEC_BIT bit; }; struct sDS1390_SEC_BIT { Uint16 Unit :4; // 0:3 Seconds 일의 자리 Uint16 Tens :3; // 4:7 Seconds 10의 자리 Uint16 rsvd1 :9; // 8:15 rsvd }; // union sDS1390_SEC { Uint16 all; struct sDS1390_SEC_BIT bit; }; struct sDS1390_MIN_BIT { Uint16 Unit :4; // 0:3 Minutes 일의 자리 Uint16 Tens :3; // 4:6 Minutes 10의 자리 Uint16 rsvd1 :9; // 7:15 rsvd }; union sDS1390_MIN { Uint16 all; struct sDS1390_MIN_BIT bit; }; struct sDS1390_HOUR_BIT { Uint16 Unit :4; // 0:3 Hour 일의 자리 Uint16 Tens :2; // 4:5 Hour 10의 자리 Uint16 Mode_24_12 :1; // 6 12/24 Mode Uint16 rsvd1 :9; // 7:15 rsvd }; // union sDS1390_HOUR { Uint16 all; struct sDS1390_HOUR_BIT bit; }; struct sDS1390_DAY_BIT { Uint16 Day :3; // 0:2 Day (요일) Uint16 rsvd4 :13; // 3:15 rsvd }; // union sDS1390_DAY { Uint16 all; struct sDS1390_DAY_BIT bit; }; struct sDS1390_DATE_BIT { Uint16 Unit :4; // 0:3 Date (날짜) Uint16 Tens :2; // 4:5 Date (날짜) Uint16 rsvd5 :10; // 6:15 rsvd }; // union sDS1390_DATE { Uint16 all; struct sDS1390_DATE_BIT bit; }; struct sDS1390_MONTH_BIT { Uint16 Unit :4; // 0:3 Month Uint16 Tens :1; // 4 Month 10의 자리 Uint16 rsvd6 :2; // 5:6 rsvd Uint16 Century :1; // 7 Century Uint16 rsvd7 :8; // 8:15 rsvd }; // union sDS1390_MONTH { Uint16 all; struct sDS1390_MONTH_BIT bit; }; struct sDS1390_YEAR_BIT { Uint16 Unit :4; // 0:3 Month Uint16 Tens :4; // 4:7 Month 10의 자리 Uint16 rsvd8 :8; // 8:15 rsvd }; union sDS1390_YEAR { Uint16 all; struct sDS1390_YEAR_BIT bit; }; struct sDS1390_REGS { volatile union sDS1390_SEC SecDAT; volatile int16 Sec; volatile union sDS1390_MIN MinDAT; volatile int16 Min; volatile union sDS1390_HOUR HourDAT; volatile int16 Hour; volatile union sDS1390_DAY DayDAT; volatile int16 Day; volatile union sDS1390_DATE DateDAT; volatile int16 Date; volatile union sDS1390_MONTH MonthDAT; volatile int16 Month; volatile union sDS1390_YEAR YearDAT; volatile int16 Year; }; struct sRTC_DATA_BUF { int Sec; int Min; int Hour; int Date; int Day; int Month; int Year; }; extern struct sDS1390_REGS RTCRegs; extern struct sDS1390_REGS RTCWrBuf; #endif extern void InitRTC(void); extern void RtcRunning(void); extern void RtcRun(void); extern void RtcReadTime(void); extern void RtcWriteTime(void); extern unsigned int Flag_Wr_RTC; extern unsigned long RTCDate; extern unsigned long RTCTime; #ifdef __cplusplus } #endif /* extern "C" */ #endif