chargeController/APP/functionalModule/Src/FM_RTC.c

92 lines
1.9 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "FM_RTC.h"
extern RTC_HandleTypeDef hrtc;
/**
* @brief 初始化rtc
* @param
* @retval
*/
void FM_RTC_Init(void)
{
HD_RTC_Init();
}
/**
* @brief 设置rtc时间
* @param
* @retval
*/
void setRTC_Time(timeInfo *time)
{
/* 日期结构体 */
RTC_DateTypeDef setData;
/* 时间结构体 */
RTC_TimeTypeDef setTime;
setData.Year = time->year;
setData.Month = time->month;
setData.Date = time->day;
setTime.Hours = time->hour;
setTime.Minutes = time->minute;
setTime.Seconds = time->second;
HAL_RTC_SetDate(&hrtc, &setData, RTC_FORMAT_BIN);
HAL_RTC_SetTime(&hrtc, &setTime, RTC_FORMAT_BIN);
}
/**
* @brief 得到rtc时间
* @param
* @retval
*/
void getRTC_Time(timeInfo *time)
{
/* 日期结构体 */
RTC_DateTypeDef getData;
/* 时间结构体 */
RTC_TimeTypeDef getTime;
HAL_RTC_GetDate(&hrtc, &getData, RTC_FORMAT_BIN);
HAL_RTC_GetTime(&hrtc, &getTime, RTC_FORMAT_BIN);
time->year = getData.Year;
time->month = getData.Month;
time->day = getData.Date;
time->hour = getTime.Hours;
time->minute = getTime.Minutes;
time->second = getTime.Seconds;
}
/**
* @brief time1 - time2的差值
* @param
* @retval 返回的时间单位为秒
*/
uint32_t differTime(timeInfo *time1, timeInfo *time2)
{
uint32_t differ_s;
differ_s = time1->second - time2->second
+ time1->minute * 60 - time2->minute * 60
+ time1->hour * 3600 - time2->hour * 3600
+ time1->day * 86400 - time2->day * 86400
+ (time1->month - time2->month) * 2592000
+ (time1->year - time2->year) * 31536000;
return differ_s;
}
// /**
// * @brief time3根据time1和time2差值得到time3time3 += time1 - time2
// * @param
// * @retval
// */
// void chargeTime(timeInfo *time1, timeInfo *time2, timeInfo *time3)
// {
// }