my_rtc.h 2.2 KB

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