rtc.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2024, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-xx-xx user first version
  9. */
  10. #ifndef __RTC_H__
  11. #define __RTC_H__
  12. #include <rtthread.h>
  13. #include <stm32f4xx_hal.h>
  14. /* RTC备份寄存器标记地址 - 使用RTC_BKP_DR0 */
  15. #define RTC_BKP_FLAG RTC_BKP_DR0
  16. /* RTC已初始化标记值 */
  17. #define RTC_INIT_FLAG 0x3568
  18. /* 默认日期时间: 2024-01-01 00:00:00 */
  19. #define RTC_DEFAULT_YEAR 26 /* 2000 + 24 = 2024 */
  20. #define RTC_DEFAULT_MONTH 1
  21. #define RTC_DEFAULT_DATE 1
  22. #define RTC_DEFAULT_HOUR 0
  23. #define RTC_DEFAULT_MINUTE 0
  24. #define RTC_DEFAULT_SECOND 0
  25. /* RTC时间结构体 */
  26. struct rtc_time
  27. {
  28. rt_uint16_t year; /* 年份: 2000-2099 */
  29. rt_uint8_t month; /* 月份: 1-12 */
  30. rt_uint8_t date; /* 日期: 1-31 */
  31. rt_uint8_t hour; /* 小时: 0-23 */
  32. rt_uint8_t minute; /* 分钟: 0-59 */
  33. rt_uint8_t second; /* 秒钟: 0-59 */
  34. rt_uint8_t weekday; /* 星期: 0-6 */
  35. };
  36. /* RTC初始化函数 */
  37. int rt_hw_rtc_init(void);
  38. /* 获取RTC时间 */
  39. int rtc_get_time(struct rtc_time *time);
  40. /* 设置RTC时间 */
  41. int rtc_set_time(struct rtc_time *time);
  42. /* 将RTC时间转换为字符串 */
  43. void rtc_time_to_str(const struct rtc_time *time, char *buf, rt_size_t size);
  44. struct TM {
  45. uint8_t tm_sec;
  46. uint8_t tm_min;
  47. uint8_t tm_hour;
  48. uint8_t tm_mday;
  49. uint8_t tm_mon;
  50. uint8_t tm_year;
  51. };
  52. // typedef struct
  53. // {
  54. // struct TM Time_Stampe; // 时间戳
  55. // uint16_t code; // 异常码
  56. // uint16_t para; // 附带参数
  57. // uint32_t num; // 序号
  58. // char detail[52]; // 内容
  59. // } Record;
  60. // typedef enum
  61. // {
  62. // e_reboot = 1,
  63. // e_clearecode,
  64. // e_test_fun,
  65. // e_typeMAX
  66. // } ecode_list;
  67. #endif /* __RTC_H__ */