| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /*
- * Copyright (c) 2024, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2024-xx-xx user first version
- */
- #ifndef __RTC_H__
- #define __RTC_H__
- #include <rtthread.h>
- #include <stm32f4xx_hal.h>
- /* RTC备份寄存器标记地址 - 使用RTC_BKP_DR0 */
- #define RTC_BKP_FLAG RTC_BKP_DR0
- /* RTC已初始化标记值 */
- #define RTC_INIT_FLAG 0x3568
- /* 默认日期时间: 2024-01-01 00:00:00 */
- #define RTC_DEFAULT_YEAR 26 /* 2000 + 24 = 2024 */
- #define RTC_DEFAULT_MONTH 1
- #define RTC_DEFAULT_DATE 1
- #define RTC_DEFAULT_HOUR 0
- #define RTC_DEFAULT_MINUTE 0
- #define RTC_DEFAULT_SECOND 0
- /* RTC时间结构体 */
- struct rtc_time
- {
- rt_uint16_t year; /* 年份: 2000-2099 */
- rt_uint8_t month; /* 月份: 1-12 */
- rt_uint8_t date; /* 日期: 1-31 */
- rt_uint8_t hour; /* 小时: 0-23 */
- rt_uint8_t minute; /* 分钟: 0-59 */
- rt_uint8_t second; /* 秒钟: 0-59 */
- rt_uint8_t weekday; /* 星期: 0-6 */
- };
- struct TM {
- uint8_t tm_sec;
- uint8_t tm_min;
- uint8_t tm_hour;
- uint8_t tm_mday;
- uint8_t tm_mon;
- uint8_t tm_year;
- };
- /* RTC初始化函数 */
- int rt_hw_rtc_init(void);
- /* 获取RTC时间 */
- int rtc_get_time(struct rtc_time *time);
- /* 设置RTC时间 */
- int rtc_set_time(struct rtc_time *time);
- /* 将RTC时间转换为字符串 */
- void rtc_time_to_str(const struct rtc_time *time, char *buf, rt_size_t size);
- #endif /* __RTC_H__ */
|