localtim改为gmtime
This commit is contained in:
parent
64bd41d654
commit
86ebf17a23
|
@ -85,7 +85,7 @@ static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||
|
||||
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
||||
time = (time_t *)args;
|
||||
time_new = localtime(time);
|
||||
time_new = gmtime(time);
|
||||
|
||||
hal_time.ui32Hour = time_new->tm_hour;
|
||||
hal_time.ui32Minute = time_new->tm_min;
|
||||
|
|
|
@ -57,7 +57,7 @@ static rt_err_t set_rtc_time_stamp(time_t time_stamp)
|
|||
|
||||
struct tm *p_tm;
|
||||
|
||||
p_tm = localtime(&time_stamp);
|
||||
p_tm = gmtime(&time_stamp);
|
||||
if (p_tm->tm_year < 100)
|
||||
{
|
||||
return -RT_ERROR;
|
||||
|
|
|
@ -104,7 +104,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||
{
|
||||
rt_enter_critical();
|
||||
/* converts calendar time time into local time. */
|
||||
pNow = localtime((const time_t *)args);
|
||||
pNow = gmtime((const time_t *)args);
|
||||
/* copy the statically located variable */
|
||||
memcpy(&time_temp, pNow, sizeof(struct tm));
|
||||
/* unlock scheduler. */
|
||||
|
|
|
@ -67,7 +67,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||
|
||||
rt_enter_critical();
|
||||
/* converts calendar time time into local time. */
|
||||
pNow = localtime((const time_t *)args);
|
||||
pNow = gmtime((const time_t *)args);
|
||||
/* copy the statically located variable */
|
||||
memcpy(&time_temp, pNow, sizeof(struct tm));
|
||||
/* unlock scheduler. */
|
||||
|
|
|
@ -67,7 +67,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||
|
||||
rt_enter_critical();
|
||||
/* converts calendar time time into local time. */
|
||||
pNow = localtime((const time_t *)args);
|
||||
pNow = gmtime((const time_t *)args);
|
||||
/* copy the statically located variable */
|
||||
memcpy(&time_temp, pNow, sizeof(struct tm));
|
||||
/* unlock scheduler. */
|
||||
|
|
|
@ -67,7 +67,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||
|
||||
rt_enter_critical();
|
||||
/* converts calendar time time into local time. */
|
||||
pNow = localtime((const time_t *)args);
|
||||
pNow = gmtime((const time_t *)args);
|
||||
/* copy the statically located variable */
|
||||
memcpy(&time_temp, pNow, sizeof(struct tm));
|
||||
/* unlock scheduler. */
|
||||
|
|
|
@ -45,7 +45,7 @@ static rt_err_t hc32_rtc_set_time_stamp(time_t time_stamp)
|
|||
stc_rtc_date_t stcRtcDate = {0};
|
||||
struct tm *p_tm;
|
||||
|
||||
p_tm = localtime(&time_stamp);
|
||||
p_tm = gmtime(&time_stamp);
|
||||
if (p_tm->tm_year < 100)
|
||||
{
|
||||
return -RT_ERROR;
|
||||
|
|
|
@ -49,7 +49,7 @@ static int set_timestamp(time_t timestamp)
|
|||
struct tm *p_tm;
|
||||
snvs_hp_rtc_datetime_t rtcDate = {0};
|
||||
|
||||
p_tm = localtime(×tamp);
|
||||
p_tm = gmtime(×tamp);
|
||||
|
||||
rtcDate.second = p_tm->tm_sec ;
|
||||
rtcDate.minute = p_tm->tm_min ;
|
||||
|
|
|
@ -46,7 +46,7 @@ static int set_timestamp(time_t timestamp)
|
|||
struct tm *p_tm;
|
||||
rtc_datetime_t rtcDate;
|
||||
|
||||
p_tm = localtime(×tamp);
|
||||
p_tm = gmtime(×tamp);
|
||||
|
||||
rtcDate.second = p_tm->tm_sec ;
|
||||
rtcDate.minute = p_tm->tm_min ;
|
||||
|
|
|
@ -53,7 +53,7 @@ static int set_timestamp(time_t timestamp)
|
|||
struct tm *p_tm;
|
||||
RTC_TimeTypeDef rtcDate;
|
||||
|
||||
p_tm = localtime(×tamp);
|
||||
p_tm = gmtime(×tamp);
|
||||
|
||||
rtcDate.Seconds= p_tm->tm_sec ;
|
||||
rtcDate.Minutes= p_tm->tm_min ;
|
||||
|
|
|
@ -128,7 +128,7 @@ static rt_err_t rt_rtc_ioctl(rt_device_t dev, int cmd, void *args)
|
|||
hw_rtc = dev->user_data;
|
||||
|
||||
t = (time_t *)args;
|
||||
time = *localtime(t);
|
||||
time = *gmtime(t);
|
||||
|
||||
rtctm.sys_toyread0 = hw_rtc->sys_toyread0;
|
||||
rtctm.sys_toyread1 = hw_rtc->sys_toyread1;
|
||||
|
|
|
@ -232,7 +232,7 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
||||
|
||||
time = (time_t *) args;
|
||||
tm_in = localtime(time);
|
||||
tm_in = gmtime(time);
|
||||
|
||||
if (nu_rtc_is_date_valid(time) != RT_EOK)
|
||||
return RT_ERROR;
|
||||
|
|
|
@ -233,7 +233,7 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
||||
|
||||
time = (time_t *) args;
|
||||
tm_in = localtime(time);
|
||||
tm_in = gmtime(time);
|
||||
|
||||
if (nu_rtc_is_date_valid(time) != RT_EOK)
|
||||
return -(RT_ERROR);
|
||||
|
|
|
@ -194,7 +194,7 @@ static time_t raspi_get_timestamp(void)
|
|||
static int raspi_set_timestamp(time_t timestamp)
|
||||
{
|
||||
struct tm *tblock;
|
||||
tblock = localtime(×tamp);
|
||||
tblock = gmtime(×tamp);
|
||||
buf[0] = 0;
|
||||
buf[1] = tblock->tm_sec;
|
||||
buf[2] = tblock->tm_min;
|
||||
|
|
|
@ -41,7 +41,7 @@ static time_t raspi_get_timestamp(void)
|
|||
static int raspi_set_timestamp(time_t timestamp)
|
||||
{
|
||||
struct tm *tblock;
|
||||
tblock = localtime(×tamp);
|
||||
tblock = gmtime(×tamp);
|
||||
buf[0] = 0;
|
||||
buf[1] = tblock->tm_sec;
|
||||
buf[2] = tblock->tm_min;
|
||||
|
|
|
@ -115,7 +115,7 @@ static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||
/* Change the current time */
|
||||
//RTC_SetCounter(*time);
|
||||
|
||||
to = localtime(time);
|
||||
to = gmtime(time);
|
||||
RTC_TimeStructure.RTC_Seconds = to->tm_sec;
|
||||
RTC_TimeStructure.RTC_Minutes = to->tm_min;
|
||||
RTC_TimeStructure.RTC_Hours = to->tm_hour;
|
||||
|
|
|
@ -97,7 +97,7 @@ static rt_err_t swm320_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
||||
rt_enter_critical();
|
||||
/* converts calendar time time into local time. */
|
||||
pNow = localtime((const time_t *)args);
|
||||
pNow = gmtime((const time_t *)args);
|
||||
/* copy the statically located variable */
|
||||
memcpy(&time_temp, pNow, sizeof(struct tm));
|
||||
/* unlock scheduler. */
|
||||
|
|
|
@ -52,7 +52,7 @@ static int wm_set_timestamp(time_t timestamp)
|
|||
|
||||
struct tm *tblock;
|
||||
|
||||
tblock = localtime(×tamp);
|
||||
tblock = gmtime(×tamp);
|
||||
|
||||
ctrl2 = tls_reg_read32(HR_PMU_RTC_CTRL2); /* disable */
|
||||
ctrl2 &= ~(1 << 16);
|
||||
|
@ -84,7 +84,7 @@ static int wm_alarm_set_timestamp(struct rt_rtc_wkalarm *wkalarm)
|
|||
time_t timestamp = 0;
|
||||
|
||||
timestamp = wm_get_timestamp();
|
||||
tblock = localtime(×tamp);
|
||||
tblock = gmtime(×tamp);
|
||||
|
||||
tls_irq_enable(PMU_RTC_INT);
|
||||
|
||||
|
|
|
@ -956,7 +956,7 @@ DWORD get_fattime(void)
|
|||
/* lock scheduler. */
|
||||
rt_enter_critical();
|
||||
/* converts calendar time time into local time. */
|
||||
p_tm = localtime(&now);
|
||||
p_tm = gmtime(&now);
|
||||
/* copy the statically located variable */
|
||||
memcpy(&tm_now, p_tm, sizeof(struct tm));
|
||||
/* unlock scheduler. */
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
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);
|
||||
*((rt_time_t *)args) = timegm(&tm);
|
||||
break;
|
||||
|
||||
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
||||
tm_ptr = localtime(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)
|
||||
|
|
Loading…
Reference in New Issue