mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-02-06 00:45:22 +08:00
bsp: stm32: drv_rtc: add local time conversion for get timeval and set stamp
Some checks failed
pkgs_test / change (push) Has been skipped
ToolsCI / Tools (push) Has been cancelled
AutoTestCI / components/cpp11 (push) Has been cancelled
AutoTestCI / kernel/atomic (push) Has been cancelled
AutoTestCI / kernel/atomic/riscv64 (push) Has been cancelled
AutoTestCI / kernel/atomic_c11 (push) Has been cancelled
AutoTestCI / kernel/atomic_c11/riscv64 (push) Has been cancelled
AutoTestCI / kernel/device (push) Has been cancelled
AutoTestCI / kernel/ipc (push) Has been cancelled
AutoTestCI / kernel/irq (push) Has been cancelled
AutoTestCI / kernel/mem (push) Has been cancelled
AutoTestCI / kernel/mem/riscv64 (push) Has been cancelled
AutoTestCI / kernel/thread (push) Has been cancelled
AutoTestCI / kernel/timer (push) Has been cancelled
AutoTestCI / rtsmart/aarch64 (push) Has been cancelled
AutoTestCI / rtsmart/arm (push) Has been cancelled
AutoTestCI / rtsmart/riscv64 (push) Has been cancelled
AutoTestCI / components/utest (push) Has been cancelled
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
Some checks failed
pkgs_test / change (push) Has been skipped
ToolsCI / Tools (push) Has been cancelled
AutoTestCI / components/cpp11 (push) Has been cancelled
AutoTestCI / kernel/atomic (push) Has been cancelled
AutoTestCI / kernel/atomic/riscv64 (push) Has been cancelled
AutoTestCI / kernel/atomic_c11 (push) Has been cancelled
AutoTestCI / kernel/atomic_c11/riscv64 (push) Has been cancelled
AutoTestCI / kernel/device (push) Has been cancelled
AutoTestCI / kernel/ipc (push) Has been cancelled
AutoTestCI / kernel/irq (push) Has been cancelled
AutoTestCI / kernel/mem (push) Has been cancelled
AutoTestCI / kernel/mem/riscv64 (push) Has been cancelled
AutoTestCI / kernel/thread (push) Has been cancelled
AutoTestCI / kernel/timer (push) Has been cancelled
AutoTestCI / rtsmart/aarch64 (push) Has been cancelled
AutoTestCI / rtsmart/arm (push) Has been cancelled
AutoTestCI / rtsmart/riscv64 (push) Has been cancelled
AutoTestCI / components/utest (push) Has been cancelled
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
- include the year, month, and day for rtc_alarm_time_set API - add local time conversion for get timeval and set stamp Signed-off-by: Runcheng Lu <runcheng.lu@hpmicro.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
* 2020-10-14 Dozingfiretruck Porting for stm32wbxx
|
||||
* 2021-02-05 Meco Man fix the problem of mixing local time and UTC time
|
||||
* 2021-07-05 iysheng implement RTC framework V2.0
|
||||
* 2025-06-05 RCSN add local time conversion for get timeval and set stamp
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
@@ -71,8 +72,11 @@ static rt_err_t stm32_rtc_get_timeval(struct timeval *tv)
|
||||
tm_new.tm_mon = RTC_DateStruct.Month - 1;
|
||||
tm_new.tm_year = RTC_DateStruct.Year + 100;
|
||||
|
||||
#ifdef RT_ALARM_USING_LOCAL_TIME
|
||||
tv->tv_sec = mktime(&tm_new);
|
||||
#else
|
||||
tv->tv_sec = timegm(&tm_new);
|
||||
|
||||
#endif
|
||||
#if defined(SOC_SERIES_STM32H7)
|
||||
tv->tv_usec = (255.0 - RTC_TimeStruct.SubSeconds * 1.0) / 256.0 * 1000.0 * 1000.0;
|
||||
#endif
|
||||
@@ -85,8 +89,11 @@ static rt_err_t set_rtc_time_stamp(time_t time_stamp)
|
||||
RTC_TimeTypeDef RTC_TimeStruct = {0};
|
||||
RTC_DateTypeDef RTC_DateStruct = {0};
|
||||
struct tm tm = {0};
|
||||
|
||||
#ifdef RT_ALARM_USING_LOCAL_TIME
|
||||
localtime_r(&time_stamp,&tm);
|
||||
#else
|
||||
gmtime_r(&time_stamp, &tm);
|
||||
#endif
|
||||
if (tm.tm_year < 100)
|
||||
{
|
||||
return -RT_ERROR;
|
||||
@@ -318,6 +325,11 @@ static rt_err_t stm32_rtc_set_alarm(struct rt_rtc_wkalarm *alarm)
|
||||
rtc_device.wkalarm.tm_hour = alarm->tm_hour;
|
||||
rtc_device.wkalarm.tm_min = alarm->tm_min;
|
||||
rtc_device.wkalarm.tm_sec = alarm->tm_sec;
|
||||
/* must include the year, month, and day */
|
||||
/* as the alarm in RT_ALARM_ONESHOT mode compares the current timestamp with the alarm timestamp */
|
||||
rtc_device.wkalarm.tm_year = alarm->tm_year;
|
||||
rtc_device.wkalarm.tm_mon = alarm->tm_mon;
|
||||
rtc_device.wkalarm.tm_mday = alarm->tm_mday;
|
||||
rtc_alarm_time_set(&rtc_device);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user