diff options
| author | Bernard Xiong <[email protected]> | 2021-02-15 09:26:52 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-02-15 09:26:52 +0800 |
| commit | 7d72bdf303f1b876c276694007f20622a126b19f (patch) | |
| tree | a62725c58b3ffdb96a6251e5b5fb581d32a048f5 /libcpu/arm | |
| parent | bfde38030b2f988c30b864f7cd8c7f4c53a9762c (diff) | |
| parent | 86ebf17a2360de740219cf9a5441cb72629c5a1d (diff) | |
Merge pull request #4314 from mysterywolf/mktime1
[bug][localtime]解决底层驱动格林威治时间与当地时间混乱使用的问题
Diffstat (limited to 'libcpu/arm')
| -rw-r--r-- | libcpu/arm/s3c24x0/rtc.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/libcpu/arm/s3c24x0/rtc.c b/libcpu/arm/s3c24x0/rtc.c index d0c80bce6b..73de840b37 100644 --- a/libcpu/arm/s3c24x0/rtc.c +++ b/libcpu/arm/s3c24x0/rtc.c @@ -12,7 +12,7 @@ */ #include <rtthread.h> -#include <time.h> +#include <sys/time.h> #include <s3c24x0.h> // #define RTC_DEBUG @@ -125,27 +125,27 @@ static rt_size_t rtc_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t static rt_err_t rtc_control(rt_device_t dev, int cmd, void *args) { - struct tm tm, *tm_ptr; + struct tm tm, *tm_ptr; time_t *time; - RT_ASSERT(dev != RT_NULL); + RT_ASSERT(dev != RT_NULL); - time = (time_t *)args; - switch (cmd) - { - case RT_DEVICE_CTRL_RTC_GET_TIME: - /* read device */ - rt_hw_rtc_get(&tm); - *((rt_time_t *)args) = mktime(&tm); - break; + time = (time_t *)args; + switch (cmd) + { + case RT_DEVICE_CTRL_RTC_GET_TIME: + /* read device */ + rt_hw_rtc_get(&tm); + *((rt_time_t *)args) = timegm(&tm); + break; - case RT_DEVICE_CTRL_RTC_SET_TIME: - tm_ptr = localtime(time); - /* write device */ - rt_hw_rtc_set(tm_ptr); - break; - } + case RT_DEVICE_CTRL_RTC_SET_TIME: + /* write device */ + tm_ptr = gmtime(time); + rt_hw_rtc_set(tm_ptr); + break; + } - return RT_EOK; + return RT_EOK; } void rt_hw_rtc_init(void) |
