提交 f073911c 编写于 作者: mysterywolf's avatar mysterywolf

解决底层驱动格林威治时间与当地时间胡乱使用的问题 mktime函数改为timegm函数

上级 852d7d75
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include "am_mcu_apollo.h" #include "am_mcu_apollo.h"
#include <sys/time.h>
#define XT 1 #define XT 1
#define LFRC 2 #define LFRC 2
...@@ -78,7 +79,7 @@ static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args) ...@@ -78,7 +79,7 @@ static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args)
/* Seconds 0-59 : the 0-59 range */ /* Seconds 0-59 : the 0-59 range */
time_temp.tm_sec = hal_time.ui32Second; time_temp.tm_sec = hal_time.ui32Second;
*time = mktime(&time_temp); *time = timegm(&time_temp);
break; break;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "board.h" #include "board.h"
#include <rtthread.h> #include <rtthread.h>
#include <sys/time.h>
#ifdef BSP_USING_RTC #ifdef BSP_USING_RTC
...@@ -42,7 +43,7 @@ static time_t get_rtc_timestamp(void) ...@@ -42,7 +43,7 @@ static time_t get_rtc_timestamp(void)
tm_new.tm_year = ERTC_DateStruct.ERTC_Year + 100; tm_new.tm_year = ERTC_DateStruct.ERTC_Year + 100;
LOG_D("get rtc time."); LOG_D("get rtc time.");
return mktime(&tm_new); return timegm(&tm_new);
#else #else
return RTC_GetCounter(); return RTC_GetCounter();
#endif #endif
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "board.h" #include "board.h"
#include <time.h> #include <time.h>
#include <sys/time.h>
#ifdef BSP_USING_ONCHIP_RTC #ifdef BSP_USING_ONCHIP_RTC
...@@ -26,7 +27,7 @@ static struct rt_device rtc; ...@@ -26,7 +27,7 @@ static struct rt_device rtc;
uint8_t get_weekday(struct tm *const _tm) uint8_t get_weekday(struct tm *const _tm)
{ {
uint8_t weekday; uint8_t weekday;
time_t secs = mktime(_tm); time_t secs = timegm(_tm);
weekday = (secs / 86400 + 4) % 7; weekday = (secs / 86400 + 4) % 7;
return weekday; return weekday;
...@@ -115,7 +116,7 @@ void hal_rtc_init(void) ...@@ -115,7 +116,7 @@ void hal_rtc_init(void)
tm_new.tm_mday = 29; tm_new.tm_mday = 29;
tm_new.tm_mon = 1 - 1; tm_new.tm_mon = 1 - 1;
tm_new.tm_year = 2021 - 1900; tm_new.tm_year = 2021 - 1900;
sec = mktime(&tm_new); sec = timegm(&tm_new);
irtc_time_write(RTCCNT_CMD, sec); irtc_time_write(RTCCNT_CMD, sec);
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include <string.h> #include <string.h>
#include <sys/time.h>
#include "board.h" #include "board.h"
#include "drv_rtc.h" #include "drv_rtc.h"
...@@ -96,7 +97,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args) ...@@ -96,7 +97,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
time_temp.tm_mday = date->day; time_temp.tm_mday = date->day;
time_temp.tm_mon = date->month - 1; time_temp.tm_mon = date->month - 1;
time_temp.tm_year = date->year - 1900 + 2000; time_temp.tm_year = date->year - 1900 + 2000;
*((time_t *)args) = mktime(&time_temp); *((time_t *)args) = timegm(&time_temp);
break; break;
} }
case RT_DEVICE_CTRL_RTC_SET_TIME: case RT_DEVICE_CTRL_RTC_SET_TIME:
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <rthw.h> #include <rthw.h>
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include <sys/time.h>
#include <string.h> #include <string.h>
#include "board.h" #include "board.h"
#include "drv_rtc.h" #include "drv_rtc.h"
...@@ -59,7 +60,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args) ...@@ -59,7 +60,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
time_temp.tm_mday = date.day; time_temp.tm_mday = date.day;
time_temp.tm_mon = date.month - 1; time_temp.tm_mon = date.month - 1;
time_temp.tm_year = date.year - 1900 + 2000; time_temp.tm_year = date.year - 1900 + 2000;
*((time_t *)args) = mktime(&time_temp); *((time_t *)args) = timegm(&time_temp);
break; break;
case RT_DEVICE_CTRL_RTC_SET_TIME: case RT_DEVICE_CTRL_RTC_SET_TIME:
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <rthw.h> #include <rthw.h>
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include <sys/time.h>
#include <string.h> #include <string.h>
#include "board.h" #include "board.h"
#include "drv_rtc.h" #include "drv_rtc.h"
...@@ -59,7 +60,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args) ...@@ -59,7 +60,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
time_temp.tm_mday = date.day; time_temp.tm_mday = date.day;
time_temp.tm_mon = date.month - 1; time_temp.tm_mon = date.month - 1;
time_temp.tm_year = date.year - 1900 + 2000; time_temp.tm_year = date.year - 1900 + 2000;
*((time_t *)args) = mktime(&time_temp); *((time_t *)args) = timegm(&time_temp);
break; break;
case RT_DEVICE_CTRL_RTC_SET_TIME: case RT_DEVICE_CTRL_RTC_SET_TIME:
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <rthw.h> #include <rthw.h>
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include <sys/time.h>
#include <string.h> #include <string.h>
#include "board.h" #include "board.h"
#include "drv_rtc.h" #include "drv_rtc.h"
...@@ -59,7 +60,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args) ...@@ -59,7 +60,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
time_temp.tm_mday = date.day; time_temp.tm_mday = date.day;
time_temp.tm_mon = date.month - 1; time_temp.tm_mon = date.month - 1;
time_temp.tm_year = date.year - 1900 + 2000; time_temp.tm_year = date.year - 1900 + 2000;
*((time_t *)args) = mktime(&time_temp); *((time_t *)args) = timegm(&time_temp);
break; break;
case RT_DEVICE_CTRL_RTC_SET_TIME: case RT_DEVICE_CTRL_RTC_SET_TIME:
......
...@@ -8,8 +8,11 @@ ...@@ -8,8 +8,11 @@
* 2020-10-30 CDT first version * 2020-10-30 CDT first version
*/ */
#include "board.h" #include <board.h>
#include <rtdbg.h> #include <rtdbg.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <sys/time.h>
#ifdef BSP_USING_RTC #ifdef BSP_USING_RTC
...@@ -33,7 +36,7 @@ static time_t hc32_rtc_get_time_stamp(void) ...@@ -33,7 +36,7 @@ static time_t hc32_rtc_get_time_stamp(void)
tm_new.tm_wday = stcRtcDate.u8Weekday; tm_new.tm_wday = stcRtcDate.u8Weekday;
LOG_D("get rtc time."); LOG_D("get rtc time.");
return mktime(&tm_new); return timegm(&tm_new);
} }
static rt_err_t hc32_rtc_set_time_stamp(time_t time_stamp) static rt_err_t hc32_rtc_set_time_stamp(time_t time_stamp)
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
* *
*/ */
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h>
#include <sys/time.h>
#ifdef BSP_USING_RTC #ifdef BSP_USING_RTC
...@@ -39,7 +41,7 @@ static time_t get_timestamp(void) ...@@ -39,7 +41,7 @@ static time_t get_timestamp(void)
tm_new.tm_mon = rtcDate.month - 1; tm_new.tm_mon = rtcDate.month - 1;
tm_new.tm_year = rtcDate.year - 1900; tm_new.tm_year = rtcDate.year - 1900;
return mktime(&tm_new); return timegm(&tm_new);
} }
static int set_timestamp(time_t timestamp) static int set_timestamp(time_t timestamp)
......
...@@ -8,12 +8,13 @@ ...@@ -8,12 +8,13 @@
* 2018-03-15 Liuguang the first version. * 2018-03-15 Liuguang the first version.
* 2019-07-19 Magicoe The first version for LPC55S6x * 2019-07-19 Magicoe The first version for LPC55S6x
*/ */
#include <rtthread.h>
#include <rtdevice.h>
#include <sys/time.h>
#include "drv_rtc.h" #include "drv_rtc.h"
#include "fsl_common.h" #include "fsl_common.h"
#include "fsl_rtc.h" #include "fsl_rtc.h"
#include <time.h>
#ifdef RT_USING_RTC #ifdef RT_USING_RTC
...@@ -37,7 +38,7 @@ static time_t get_timestamp(void) ...@@ -37,7 +38,7 @@ static time_t get_timestamp(void)
tm_new.tm_mon = rtcDate.month - 1; tm_new.tm_mon = rtcDate.month - 1;
tm_new.tm_year = rtcDate.year - 1900; tm_new.tm_year = rtcDate.year - 1900;
return mktime(&tm_new); return timegm(&tm_new);
} }
static int set_timestamp(time_t timestamp) static int set_timestamp(time_t timestamp)
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "board.h" #include "board.h"
#include "drv_rtc.h" #include "drv_rtc.h"
#include <rtdevice.h> #include <rtdevice.h>
#include <sys/time.h>
#include "../libraries/ls1c_regs.h" #include "../libraries/ls1c_regs.h"
#include "../libraries/ls1c_rtc.h" #include "../libraries/ls1c_rtc.h"
...@@ -44,7 +45,7 @@ static time_t get_timestamp(void) ...@@ -44,7 +45,7 @@ static time_t get_timestamp(void)
tm_new.tm_mon = rtcDate.Month- 1; tm_new.tm_mon = rtcDate.Month- 1;
tm_new.tm_year = rtcDate.Year + 2000 - 1900; tm_new.tm_year = rtcDate.Year + 2000 - 1900;
return mktime(&tm_new); return timegm(&tm_new);
} }
static int set_timestamp(time_t timestamp) static int set_timestamp(time_t timestamp)
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <rthw.h> #include <rthw.h>
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include <rtthread.h> #include <sys/time.h>
#include "ls2k1000.h" #include "ls2k1000.h"
#ifdef RT_USING_RTC #ifdef RT_USING_RTC
...@@ -137,29 +137,29 @@ static rt_err_t rt_rtc_ioctl(rt_device_t dev, int cmd, void *args) ...@@ -137,29 +137,29 @@ static rt_err_t rt_rtc_ioctl(rt_device_t dev, int cmd, void *args)
switch (cmd) switch (cmd)
{ {
case RT_DEVICE_CTRL_RTC_GET_TIME: case RT_DEVICE_CTRL_RTC_GET_TIME:
*t = mktime(&tmptime); *t = timegm(&tmptime);
break; break;
case RT_DEVICE_CTRL_RTC_SET_TIME: case RT_DEVICE_CTRL_RTC_SET_TIME:
tmptime.tm_hour = time.tm_hour; tmptime.tm_hour = time.tm_hour;
tmptime.tm_min = time.tm_min; tmptime.tm_min = time.tm_min;
tmptime.tm_sec = time.tm_sec; tmptime.tm_sec = time.tm_sec;
tmptime.tm_year = time.tm_year; tmptime.tm_year = time.tm_year;
tmptime.tm_mon = time.tm_mon; tmptime.tm_mon = time.tm_mon;
tmptime.tm_mday = time.tm_mday; tmptime.tm_mday = time.tm_mday;
rtctm = mkrtctime(&tmptime); rtctm = mkrtctime(&tmptime);
/* write to hw RTC */ /* write to hw RTC */
hw_rtc->sys_toywrite0 = rtctm.sys_toyread0; hw_rtc->sys_toywrite0 = rtctm.sys_toyread0;
hw_rtc->sys_toywrite1 = rtctm.sys_toyread1; hw_rtc->sys_toywrite1 = rtctm.sys_toyread1;
break; break;
case RT_DEVICE_CTRL_RTC_GET_ALARM: case RT_DEVICE_CTRL_RTC_GET_ALARM:
break; break;
case RT_DEVICE_CTRL_RTC_SET_ALARM: case RT_DEVICE_CTRL_RTC_SET_ALARM:
break; break;
default: default:
break; break;
} }
return RT_EOK; return RT_EOK;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "board.h" #include "board.h"
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include <sys/time.h>
#include <nrfx_rtc.h> #include <nrfx_rtc.h>
#include <nrfx_clock.h> #include <nrfx_clock.h>
...@@ -118,7 +118,7 @@ static rt_err_t rt_hw_rtc_register(rt_device_t device, const char *name, rt_uint ...@@ -118,7 +118,7 @@ static rt_err_t rt_hw_rtc_register(rt_device_t device, const char *name, rt_uint
RT_ASSERT(device != RT_NULL); RT_ASSERT(device != RT_NULL);
init_time = mktime(&time_new); init_time = timegm(&time_new);
if (rt_rtc_config(device) != RT_EOK) if (rt_rtc_config(device) != RT_EOK)
{ {
return -RT_ERROR; return -RT_ERROR;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#if defined (BSP_USING_RTC) #if defined (BSP_USING_RTC)
#include <rtdevice.h> #include <rtdevice.h>
#include <sys/time.h>
#include <NuMicro.h> #include <NuMicro.h>
/* Private define ---------------------------------------------------------------*/ /* Private define ---------------------------------------------------------------*/
...@@ -183,8 +184,8 @@ static rt_err_t nu_rtc_is_date_valid(const time_t *const t) ...@@ -183,8 +184,8 @@ static rt_err_t nu_rtc_is_date_valid(const time_t *const t)
if (!initialised) if (!initialised)
{ {
t_upper = mktime((struct tm *)&tm_upper); t_upper = timegm((struct tm *)&tm_upper);
t_lower = mktime((struct tm *)&tm_lower); t_lower = timegm((struct tm *)&tm_lower);
initialised = RT_TRUE; initialised = RT_TRUE;
} }
...@@ -225,7 +226,7 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args) ...@@ -225,7 +226,7 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
tm_out.tm_hour = hw_time.u32Hour; tm_out.tm_hour = hw_time.u32Hour;
tm_out.tm_min = hw_time.u32Minute; tm_out.tm_min = hw_time.u32Minute;
tm_out.tm_sec = hw_time.u32Second; tm_out.tm_sec = hw_time.u32Second;
*time = mktime(&tm_out); *time = timegm(&tm_out);
break; break;
case RT_DEVICE_CTRL_RTC_SET_TIME: case RT_DEVICE_CTRL_RTC_SET_TIME:
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#if defined (BSP_USING_RTC) #if defined (BSP_USING_RTC)
#include <rtdevice.h> #include <rtdevice.h>
#include <sys/time.h>
#include <NuMicro.h> #include <NuMicro.h>
#include <drv_sys.h> #include <drv_sys.h>
...@@ -184,8 +185,8 @@ static rt_err_t nu_rtc_is_date_valid(const time_t *const t) ...@@ -184,8 +185,8 @@ static rt_err_t nu_rtc_is_date_valid(const time_t *const t)
if (!initialised) if (!initialised)
{ {
t_upper = mktime((struct tm *)&tm_upper); t_upper = timegm((struct tm *)&tm_upper);
t_lower = mktime((struct tm *)&tm_lower); t_lower = timegm((struct tm *)&tm_lower);
initialised = RT_TRUE; initialised = RT_TRUE;
} }
...@@ -226,7 +227,7 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args) ...@@ -226,7 +227,7 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
tm_out.tm_hour = hw_time.u32Hour; tm_out.tm_hour = hw_time.u32Hour;
tm_out.tm_min = hw_time.u32Minute; tm_out.tm_min = hw_time.u32Minute;
tm_out.tm_sec = hw_time.u32Second; tm_out.tm_sec = hw_time.u32Second;
*time = mktime(&tm_out); *time = timegm(&tm_out);
break; break;
case RT_DEVICE_CTRL_RTC_SET_TIME: case RT_DEVICE_CTRL_RTC_SET_TIME:
......
...@@ -8,12 +8,15 @@ ...@@ -8,12 +8,15 @@
* 2019-07-29 zdzn first version * 2019-07-29 zdzn first version
*/ */
#include <rtthread.h>
#include <rtdevice.h>
#include <sys/time.h>
#include "drv_rtc.h" #include "drv_rtc.h"
#ifdef BSP_USING_RTC #ifdef BSP_USING_RTC
#define RTC_I2C_BUS_NAME "i2c0" #define RTC_I2C_BUS_NAME "i2c0"
#define RTC_ADDR 0x68 #define RTC_ADDR 0x68
static struct rt_device rtc_device; static struct rt_device rtc_device;
static struct rt_i2c_bus_device *i2c_bus = RT_NULL; static struct rt_i2c_bus_device *i2c_bus = RT_NULL;
...@@ -185,7 +188,7 @@ static time_t raspi_get_timestamp(void) ...@@ -185,7 +188,7 @@ static time_t raspi_get_timestamp(void)
tm_new.tm_min = ((buf[1] & 0x7F) / 16 + 0x30) + (buf[1] & 0x7F) % 16+ 0x30; tm_new.tm_min = ((buf[1] & 0x7F) / 16 + 0x30) + (buf[1] & 0x7F) % 16+ 0x30;
tm_new.tm_sec = ((buf[0] & 0x7F) / 16 + 0x30) + (buf[0] & 0x7F) % 16+ 0x30; tm_new.tm_sec = ((buf[0] & 0x7F) / 16 + 0x30) + (buf[0] & 0x7F) % 16+ 0x30;
return mktime(&tm_new); return timegm(&tm_new);
} }
static int raspi_set_timestamp(time_t timestamp) static int raspi_set_timestamp(time_t timestamp)
......
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
* 2019-07-29 zdzn first version * 2019-07-29 zdzn first version
*/ */
#include <rtthread.h>
#include <rtdevice.h>
#include <sys/time.h>
#include "drv_rtc.h" #include "drv_rtc.h"
#ifdef BSP_USING_RTC #ifdef BSP_USING_RTC
...@@ -33,7 +35,7 @@ static time_t raspi_get_timestamp(void) ...@@ -33,7 +35,7 @@ static time_t raspi_get_timestamp(void)
tm_new.tm_min = ((buf[1] & 0x7F) / 16 + 0x30) + (buf[1] & 0x7F) % 16+ 0x30; tm_new.tm_min = ((buf[1] & 0x7F) / 16 + 0x30) + (buf[1] & 0x7F) % 16+ 0x30;
tm_new.tm_sec = ((buf[0] & 0x7F) / 16 + 0x30) + (buf[0] & 0x7F) % 16+ 0x30; tm_new.tm_sec = ((buf[0] & 0x7F) / 16 + 0x30) + (buf[0] & 0x7F) % 16+ 0x30;
return mktime(&tm_new); return timegm(&tm_new);
} }
static int raspi_set_timestamp(time_t timestamp) static int raspi_set_timestamp(time_t timestamp)
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include <rtdevice.h> #include <rtdevice.h>
#include <board.h> #include <board.h>
#include <string.h> #include <string.h>
#include <time.h> #include <sys/time.h>
/** /**
* This function will get the weed day from a date. * This function will get the weed day from a date.
...@@ -92,7 +92,7 @@ static rt_err_t swm320_rtc_control(rt_device_t dev, int cmd, void *args) ...@@ -92,7 +92,7 @@ static rt_err_t swm320_rtc_control(rt_device_t dev, int cmd, void *args)
time_temp.tm_mday = dateTime.Date; time_temp.tm_mday = dateTime.Date;
time_temp.tm_mon = dateTime.Month - 1; time_temp.tm_mon = dateTime.Month - 1;
time_temp.tm_year = dateTime.Year - 1900; time_temp.tm_year = dateTime.Year - 1900;
*((time_t *)args) = mktime(&time_temp); *((time_t *)args) = timegm(&time_temp);
break; break;
case RT_DEVICE_CTRL_RTC_SET_TIME: case RT_DEVICE_CTRL_RTC_SET_TIME:
rt_enter_critical(); rt_enter_critical();
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <rtdevice.h> #include <rtdevice.h>
#include <rtthread.h> #include <rtthread.h>
#include <time.h> #include <sys/time.h>
#include "wm_regs.h" #include "wm_regs.h"
#include "wm_irq.h" #include "wm_irq.h"
#include "tls_common.h" #include "tls_common.h"
...@@ -42,7 +42,7 @@ static time_t wm_get_timestamp(void) ...@@ -42,7 +42,7 @@ static time_t wm_get_timestamp(void)
tm_new.tm_min = (ctrl1 & 0x00003f00) >> 8; tm_new.tm_min = (ctrl1 & 0x00003f00) >> 8;
tm_new.tm_sec = ctrl1 & 0x0000003f; tm_new.tm_sec = ctrl1 & 0x0000003f;
return mktime(&tm_new); return timegm(&tm_new);
} }
static int wm_set_timestamp(time_t timestamp) static int wm_set_timestamp(time_t timestamp)
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "ffconf.h" #include "ffconf.h"
#include "ff.h" #include "ff.h"
#include <string.h> #include <string.h>
#include <time.h> #include <sys/time.h>
/* ELM FatFs provide a DIR struct */ /* ELM FatFs provide a DIR struct */
#define HAVE_DIR_STRUCTURE #define HAVE_DIR_STRUCTURE
...@@ -800,7 +800,7 @@ int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) ...@@ -800,7 +800,7 @@ int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
tm_file.tm_min = min; /* Minutes: 0-59 */ tm_file.tm_min = min; /* Minutes: 0-59 */
tm_file.tm_sec = sec; /* Seconds: 0-59 */ tm_file.tm_sec = sec; /* Seconds: 0-59 */
st->st_mtime = mktime(&tm_file); st->st_mtime = timegm(&tm_file);
} /* get st_mtime. */ } /* get st_mtime. */
} }
......
...@@ -13,10 +13,7 @@ ...@@ -13,10 +13,7 @@
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#ifndef _WIN32
#include <sys/time.h> #include <sys/time.h>
#endif
#define RT_RTC_YEARS_MAX 137 #define RT_RTC_YEARS_MAX 137
#ifdef RT_USING_SOFT_RTC #ifdef RT_USING_SOFT_RTC
...@@ -98,8 +95,8 @@ static void alarm_wakeup(struct rt_alarm *alarm, struct tm *now) ...@@ -98,8 +95,8 @@ static void alarm_wakeup(struct rt_alarm *alarm, struct tm *now)
{ {
case RT_ALARM_ONESHOT: case RT_ALARM_ONESHOT:
{ {
sec_alarm = mktime(&alarm->wktime); sec_alarm = timegm(&alarm->wktime);
sec_now = mktime(now); sec_now = timegm(now);
if (((sec_now - sec_alarm) <= RT_ALARM_DELAY) && (sec_now >= sec_alarm)) if (((sec_now - sec_alarm) <= RT_ALARM_DELAY) && (sec_now >= sec_alarm))
{ {
/* stop alarm */ /* stop alarm */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* 2018-01-30 armink the first version * 2018-01-30 armink the first version
*/ */
#include <time.h> #include <sys/time.h>
#include <string.h> #include <string.h>
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
...@@ -126,7 +126,7 @@ int rt_soft_rtc_init(void) ...@@ -126,7 +126,7 @@ int rt_soft_rtc_init(void)
#endif #endif
init_tick = rt_tick_get(); init_tick = rt_tick_get();
init_time = mktime(&time_new); init_time = timegm(&time_new);
soft_rtc_dev.type = RT_Device_Class_RTC; soft_rtc_dev.type = RT_Device_Class_RTC;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册