/****************************************************************************** 版权所有: 文件名称: my_rtc.h 文件版本: 01.01 创建作者: sunxi 创建日期: 2008-07-09 功能说明: rtc驱动程序。 其它说明: 修改记录: */ #ifndef _MY_RTC_H #define _MY_RTC_H // 从1970-01-01开始的秒,转化出当前秒的星期几,"+3"是因为起始天为周四,CP56Time2a格式的星期是1~7 #define WEEK_DAY(second) ((((second/86400)+3)%7)+1) //类似于IEC标准(101、103及104规约)的日历时钟格式 struct rtc_time_t { unsigned short ms; //0~59999。struct tm允许60S(闰秒) unsigned char min; //0~59 unsigned char hour; //0~23 unsigned char day; //1~31 unsigned char month; //1~12。struct tm为0~11 unsigned short year; //0~99。以2000年为起点。struct tm以1900为起点。 }; //以下结构是标准Linux时间接口使用的,放在这儿仅供参考,注意和rtc_time_t不同的地方。 #if 0 struct tm { int tm_sec; /* Seconds. [0-60] (1 leap second) */ int tm_min; /* Minutes. [0-59] */ int tm_hour; /* Hours. [0-23] */ int tm_mday; /* Day. [1-31] */ int tm_mon; /* Month. [0-11] */ int tm_year; /* Year - 1900. */ int tm_wday; /* Day of week. [0-6] */ int tm_yday; /* Days in year.[0-365] */ int tm_isdst; /* DST. [-1/0/1]*/ }; #endif #ifndef _STRUCT_TIMESPEC #define _STRUCT_TIMESPEC typedef struct timespec1 { long tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ }; /* Parameters used to convert the timespec values: */ #endif // sunxi 20220408 从 #ifndef _STRUCT_TIMESPEC 里面移出来 #define MSEC_PER_SEC 1000L #define USEC_PER_MSEC 1000L #define NSEC_PER_USEC 1000L #define NSEC_PER_MSEC 1000000L #define USEC_PER_SEC 1000000L #define NSEC_PER_SEC 1000000000L #define FSEC_PER_SEC 1000000000000000L //兼容以前应用程序 #define TIME struct rtc_time_t int rtc_init(void); int rtc_time_read(struct rtc_time_t *p_tm); int rtc_time_write(struct rtc_time_t *p_tm); void rtc_time_write_5ms(void); int rtc_nvram_read(uint32_t offset, unsigned char *buffer, uint32_t length); int rtc_nvram_write(uint32_t offset, unsigned char *buffer, uint32_t length); int rtc_to_timespec(struct rtc_time_t * p_rtc, struct timespec * p_ts); int timespec_to_rtc(struct timespec ts, struct rtc_time_t * p_rtc,int is_round); int rtc_test(void); #endif // _MY_RTC_H