|
|
@@ -14,13 +14,14 @@
|
|
|
|
|
|
#ifdef BSP_USING_ONCHIP_RTC
|
|
|
|
|
|
-
|
|
|
+/*
|
|
|
#ifndef HAL_RTCEx_BKUPRead
|
|
|
#define HAL_RTCEx_BKUPRead(x1, x2) (~BKUP_REG_DATA)
|
|
|
#endif
|
|
|
#ifndef HAL_RTCEx_BKUPWrite
|
|
|
#define HAL_RTCEx_BKUPWrite(x1, x2, x3)
|
|
|
#endif
|
|
|
+*/
|
|
|
#ifndef RTC_BKP_DR1
|
|
|
#define RTC_BKP_DR1 RT_NULL
|
|
|
#endif
|
|
|
@@ -29,63 +30,68 @@
|
|
|
#define LOG_TAG "drv.rtc"
|
|
|
#include <drv_log.h>
|
|
|
|
|
|
-#define BKUP_REG_DATA 0xA5A5
|
|
|
+#define BKUP_REG_DATA 0xA0A0
|
|
|
|
|
|
static struct rt_device rtc;
|
|
|
|
|
|
static RTC_HandleTypeDef RTC_Handler;
|
|
|
-
|
|
|
+uint32_t RTC_ReadTimeCounter(RTC_HandleTypeDef *hrtc);
|
|
|
+HAL_StatusTypeDef RTC_WriteTimeCounter(RTC_HandleTypeDef *hrtc, uint32_t TimeCounter);
|
|
|
static time_t get_rtc_timestamp(void)
|
|
|
{
|
|
|
- RTC_TimeTypeDef RTC_TimeStruct = {0};
|
|
|
- RTC_DateTypeDef RTC_DateStruct = {0};
|
|
|
- struct tm tm_new;
|
|
|
-
|
|
|
- HAL_RTC_GetTime(&RTC_Handler, &RTC_TimeStruct, RTC_FORMAT_BIN);
|
|
|
- HAL_RTC_GetDate(&RTC_Handler, &RTC_DateStruct, RTC_FORMAT_BIN);
|
|
|
-
|
|
|
- tm_new.tm_sec = RTC_TimeStruct.Seconds;
|
|
|
- tm_new.tm_min = RTC_TimeStruct.Minutes;
|
|
|
- tm_new.tm_hour = RTC_TimeStruct.Hours;
|
|
|
- tm_new.tm_mday = RTC_DateStruct.Date;
|
|
|
- tm_new.tm_mon = RTC_DateStruct.Month - 1;
|
|
|
- tm_new.tm_year = RTC_DateStruct.Year + 100;
|
|
|
-
|
|
|
- LOG_D("get rtc time.");
|
|
|
- return mktime(&tm_new);
|
|
|
+// RTC_TimeTypeDef RTC_TimeStruct = {0};
|
|
|
+// RTC_DateTypeDef RTC_DateStruct = {0};
|
|
|
+// struct tm tm_new;
|
|
|
+//
|
|
|
+// HAL_RTC_GetTime(&RTC_Handler, &RTC_TimeStruct, RTC_FORMAT_BIN);
|
|
|
+// HAL_RTC_GetDate(&RTC_Handler, &RTC_DateStruct, RTC_FORMAT_BIN);
|
|
|
+//
|
|
|
+// tm_new.tm_sec = RTC_TimeStruct.Seconds;
|
|
|
+// tm_new.tm_min = RTC_TimeStruct.Minutes;
|
|
|
+// tm_new.tm_hour = RTC_TimeStruct.Hours;
|
|
|
+// tm_new.tm_mday = RTC_DateStruct.Date;
|
|
|
+// tm_new.tm_mon = RTC_DateStruct.Month - 1;
|
|
|
+// tm_new.tm_year = RTC_DateStruct.Year + 100;
|
|
|
+//
|
|
|
+// LOG_D("get rtc time.");
|
|
|
+// RTC_ReadTimeCounter(&RTC_Handler);
|
|
|
+ //return mktime(&tm_new);
|
|
|
+ return RTC_ReadTimeCounter(&RTC_Handler);
|
|
|
}
|
|
|
|
|
|
static rt_err_t set_rtc_time_stamp(time_t time_stamp)
|
|
|
{
|
|
|
- RTC_TimeTypeDef RTC_TimeStruct = {0};
|
|
|
- RTC_DateTypeDef RTC_DateStruct = {0};
|
|
|
- struct tm *p_tm;
|
|
|
-
|
|
|
- p_tm = localtime(&time_stamp);
|
|
|
- if (p_tm->tm_year < 100)
|
|
|
- {
|
|
|
- return -RT_ERROR;
|
|
|
- }
|
|
|
-
|
|
|
- RTC_TimeStruct.Seconds = p_tm->tm_sec ;
|
|
|
- RTC_TimeStruct.Minutes = p_tm->tm_min ;
|
|
|
- RTC_TimeStruct.Hours = p_tm->tm_hour;
|
|
|
- RTC_DateStruct.Date = p_tm->tm_mday;
|
|
|
- RTC_DateStruct.Month = p_tm->tm_mon + 1 ;
|
|
|
- RTC_DateStruct.Year = p_tm->tm_year - 100;
|
|
|
- RTC_DateStruct.WeekDay = p_tm->tm_wday + 1;
|
|
|
-
|
|
|
- if (HAL_RTC_SetTime(&RTC_Handler, &RTC_TimeStruct, RTC_FORMAT_BIN) != HAL_OK)
|
|
|
- {
|
|
|
- return -RT_ERROR;
|
|
|
- }
|
|
|
- if (HAL_RTC_SetDate(&RTC_Handler, &RTC_DateStruct, RTC_FORMAT_BIN) != HAL_OK)
|
|
|
- {
|
|
|
- return -RT_ERROR;
|
|
|
- }
|
|
|
-
|
|
|
- LOG_D("set rtc time.");
|
|
|
- HAL_RTCEx_BKUPWrite(&RTC_Handler, RTC_BKP_DR1, BKUP_REG_DATA);
|
|
|
+// RTC_TimeTypeDef RTC_TimeStruct = {0};
|
|
|
+// RTC_DateTypeDef RTC_DateStruct = {0};
|
|
|
+// struct tm *p_tm;
|
|
|
+//
|
|
|
+// p_tm = localtime(&time_stamp);
|
|
|
+// if (p_tm->tm_year < 100)
|
|
|
+// {
|
|
|
+// return -RT_ERROR;
|
|
|
+// }
|
|
|
+//
|
|
|
+// RTC_TimeStruct.Seconds = p_tm->tm_sec ;
|
|
|
+// RTC_TimeStruct.Minutes = p_tm->tm_min ;
|
|
|
+// RTC_TimeStruct.Hours = p_tm->tm_hour;
|
|
|
+// RTC_DateStruct.Date = p_tm->tm_mday;
|
|
|
+// RTC_DateStruct.Month = p_tm->tm_mon + 1 ;
|
|
|
+// RTC_DateStruct.Year = p_tm->tm_year - 100;
|
|
|
+// RTC_DateStruct.WeekDay = p_tm->tm_wday + 1;
|
|
|
+//
|
|
|
+// if (HAL_RTC_SetTime(&RTC_Handler, &RTC_TimeStruct, RTC_FORMAT_BIN) != HAL_OK)
|
|
|
+// {
|
|
|
+// return -RT_ERROR;
|
|
|
+// }
|
|
|
+// if (HAL_RTC_SetDate(&RTC_Handler, &RTC_DateStruct, RTC_FORMAT_BIN) != HAL_OK)
|
|
|
+// {
|
|
|
+// return -RT_ERROR;
|
|
|
+// }
|
|
|
+//
|
|
|
+// LOG_D("set rtc time.");
|
|
|
+ HAL_RTCEx_BKUPWrite(&RTC_Handler, RTC_BKP_DR1, BKUP_REG_DATA);
|
|
|
+// return RT_EOK;
|
|
|
+ RTC_WriteTimeCounter(&RTC_Handler,time_stamp);
|
|
|
return RT_EOK;
|
|
|
}
|
|
|
|
|
|
@@ -247,6 +253,6 @@ int rt_hw_rtc_init(void)
|
|
|
LOG_D("rtc init success");
|
|
|
return RT_EOK;
|
|
|
}
|
|
|
-INIT_DEVICE_EXPORT(rt_hw_rtc_init); //INIT_DEVICE_EXPORT
|
|
|
+INIT_APP_EXPORT(rt_hw_rtc_init);
|
|
|
|
|
|
#endif /* BSP_USING_ONCHIP_RTC */
|