mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-06-01 04:14:28 +08:00
[rtc] use gmtime_r to replace gmtime (#6012)
* [rtc] use gmtime_r to replace gmtime
This commit is contained in:
committed by
GitHub
parent
4f1f8566f4
commit
2c10d5ad01
@@ -49,21 +49,21 @@ static rt_err_t set_rtc_time_stamp(time_t time_stamp)
|
|||||||
{
|
{
|
||||||
RTC_TimeTypeDef RTC_TimeStruct = {0};
|
RTC_TimeTypeDef RTC_TimeStruct = {0};
|
||||||
RTC_DateTypeDef RTC_DateStruct = {0};
|
RTC_DateTypeDef RTC_DateStruct = {0};
|
||||||
struct tm *p_tm;
|
struct tm now;
|
||||||
|
|
||||||
p_tm = gmtime(&time_stamp);
|
gmtime_r(&time_stamp, &now);
|
||||||
if (p_tm->tm_year < 100)
|
if (now.tm_year < 100)
|
||||||
{
|
{
|
||||||
return -RT_ERROR;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
RTC_TimeStruct.u8_Seconds = dec2hex(p_tm->tm_sec);
|
RTC_TimeStruct.u8_Seconds = dec2hex(now.tm_sec);
|
||||||
RTC_TimeStruct.u8_Minutes = dec2hex(p_tm->tm_min);
|
RTC_TimeStruct.u8_Minutes = dec2hex(now.tm_min);
|
||||||
RTC_TimeStruct.u8_Hours = dec2hex(p_tm->tm_hour);
|
RTC_TimeStruct.u8_Hours = dec2hex(now.tm_hour);
|
||||||
RTC_DateStruct.u8_Date = dec2hex(p_tm->tm_mday);
|
RTC_DateStruct.u8_Date = dec2hex(now.tm_mday);
|
||||||
RTC_DateStruct.u8_Month = dec2hex(p_tm->tm_mon + 1);
|
RTC_DateStruct.u8_Month = dec2hex(now.tm_mon + 1);
|
||||||
RTC_DateStruct.u8_Year = dec2hex(p_tm->tm_year - 100);
|
RTC_DateStruct.u8_Year = dec2hex(now.tm_year - 100);
|
||||||
RTC_DateStruct.u8_WeekDay = dec2hex(p_tm->tm_wday) + 1;
|
RTC_DateStruct.u8_WeekDay = dec2hex(now.tm_wday) + 1;
|
||||||
|
|
||||||
HAL_RTC_SetTime(&RTC_TimeStruct);
|
HAL_RTC_SetTime(&RTC_TimeStruct);
|
||||||
HAL_RTC_SetDate(&RTC_DateStruct);
|
HAL_RTC_SetDate(&RTC_DateStruct);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||||||
{
|
{
|
||||||
time_t *time;
|
time_t *time;
|
||||||
struct tm time_temp;
|
struct tm time_temp;
|
||||||
struct tm* time_new;
|
struct tm time_new;
|
||||||
am_hal_rtc_time_t hal_time;
|
am_hal_rtc_time_t hal_time;
|
||||||
|
|
||||||
RT_ASSERT(dev != RT_NULL);
|
RT_ASSERT(dev != RT_NULL);
|
||||||
@@ -71,16 +71,16 @@ static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||||||
|
|
||||||
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
||||||
time = (time_t *)args;
|
time = (time_t *)args;
|
||||||
time_new = gmtime(time);
|
gmtime_r(time, &time_new);
|
||||||
|
|
||||||
hal_time.ui32Hour = time_new->tm_hour;
|
hal_time.ui32Hour = time_new.tm_hour;
|
||||||
hal_time.ui32Minute = time_new->tm_min;
|
hal_time.ui32Minute = time_new.tm_min;
|
||||||
hal_time.ui32Second = time_new->tm_sec;
|
hal_time.ui32Second = time_new.tm_sec;
|
||||||
hal_time.ui32Hundredths = 00;
|
hal_time.ui32Hundredths = 00;
|
||||||
hal_time.ui32Weekday = time_new->tm_wday;
|
hal_time.ui32Weekday = time_new.tm_wday;
|
||||||
hal_time.ui32DayOfMonth = time_new->tm_mday;
|
hal_time.ui32DayOfMonth = time_new.tm_mday;
|
||||||
hal_time.ui32Month = time_new->tm_mon + 1;
|
hal_time.ui32Month = time_new.tm_mon + 1;
|
||||||
hal_time.ui32Year = time_new->tm_year + 1900 - 2000;
|
hal_time.ui32Year = time_new.tm_year + 1900 - 2000;
|
||||||
hal_time.ui32Century = 0;
|
hal_time.ui32Century = 0;
|
||||||
|
|
||||||
am_hal_rtc_time_set(&hal_time);
|
am_hal_rtc_time_set(&hal_time);
|
||||||
|
|||||||
@@ -49,22 +49,22 @@ static rt_err_t set_rtc_time_stamp(time_t time_stamp)
|
|||||||
{
|
{
|
||||||
#if defined (SOC_SERIES_AT32F435) || defined (SOC_SERIES_AT32F437) || \
|
#if defined (SOC_SERIES_AT32F435) || defined (SOC_SERIES_AT32F437) || \
|
||||||
defined (SOC_SERIES_AT32F415)
|
defined (SOC_SERIES_AT32F415)
|
||||||
struct tm *p_tm;
|
struct tm now;
|
||||||
|
|
||||||
p_tm = gmtime(&time_stamp);
|
gmtime_r(&time_stamp, &now);
|
||||||
if (p_tm->tm_year < 100)
|
if (now.tm_year < 100)
|
||||||
{
|
{
|
||||||
return -RT_ERROR;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set time */
|
/* set time */
|
||||||
if(ertc_time_set(p_tm->tm_hour, p_tm->tm_min, p_tm->tm_sec, ERTC_AM) != SUCCESS)
|
if(ertc_time_set(now.tm_hour, now.tm_min, now.tm_sec, ERTC_AM) != SUCCESS)
|
||||||
{
|
{
|
||||||
return -RT_ERROR;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set date */
|
/* set date */
|
||||||
if(ertc_date_set(p_tm->tm_year - 100, p_tm->tm_mon + 1, p_tm->tm_mday, p_tm->tm_wday + 1) != SUCCESS)
|
if(ertc_date_set(now.tm_year - 100, now.tm_mon + 1, now.tm_mday, now.tm_wday + 1) != SUCCESS)
|
||||||
{
|
{
|
||||||
return -RT_ERROR;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,9 +55,7 @@ static void __rtc_init(rtc_init_t *init)
|
|||||||
static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
|
static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
rt_err_t result = RT_EOK;
|
rt_err_t result = RT_EOK;
|
||||||
|
|
||||||
struct tm time_temp;
|
struct tm time_temp;
|
||||||
struct tm *pNow;
|
|
||||||
rtc_date_t date;
|
rtc_date_t date;
|
||||||
rtc_time_t time;
|
rtc_time_t time;
|
||||||
|
|
||||||
@@ -76,15 +74,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
||||||
|
gmtime_r((const time_t *)args, &time_temp);
|
||||||
rt_enter_critical();
|
|
||||||
/* converts calendar time time into local time. */
|
|
||||||
pNow = gmtime((const time_t *)args);
|
|
||||||
/* copy the statically located variable */
|
|
||||||
memcpy(&time_temp, pNow, sizeof(struct tm));
|
|
||||||
/* unlock scheduler. */
|
|
||||||
rt_exit_critical();
|
|
||||||
|
|
||||||
time.hour = time_temp.tm_hour;
|
time.hour = time_temp.tm_hour;
|
||||||
time.minute = time_temp.tm_min;
|
time.minute = time_temp.tm_min;
|
||||||
time.second = time_temp.tm_sec;
|
time.second = time_temp.tm_sec;
|
||||||
|
|||||||
@@ -54,9 +54,7 @@ static void __rtc_init(rtc_init_t *init)
|
|||||||
static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
|
static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
rt_err_t result = RT_EOK;
|
rt_err_t result = RT_EOK;
|
||||||
|
|
||||||
struct tm time_temp;
|
struct tm time_temp;
|
||||||
struct tm *pNow;
|
|
||||||
rtc_date_t date;
|
rtc_date_t date;
|
||||||
rtc_time_t time;
|
rtc_time_t time;
|
||||||
|
|
||||||
@@ -75,15 +73,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
||||||
|
gmtime_r((const time_t *)args, &time_temp);
|
||||||
rt_enter_critical();
|
|
||||||
/* converts calendar time time into local time. */
|
|
||||||
pNow = gmtime((const time_t *)args);
|
|
||||||
/* copy the statically located variable */
|
|
||||||
memcpy(&time_temp, pNow, sizeof(struct tm));
|
|
||||||
/* unlock scheduler. */
|
|
||||||
rt_exit_critical();
|
|
||||||
|
|
||||||
time.hour = time_temp.tm_hour;
|
time.hour = time_temp.tm_hour;
|
||||||
time.minute = time_temp.tm_min;
|
time.minute = time_temp.tm_min;
|
||||||
time.second = time_temp.tm_sec;
|
time.second = time_temp.tm_sec;
|
||||||
|
|||||||
@@ -45,18 +45,18 @@ static time_t get_timestamp(void)
|
|||||||
|
|
||||||
static int set_timestamp(time_t timestamp)
|
static int set_timestamp(time_t timestamp)
|
||||||
{
|
{
|
||||||
struct tm *p_tm;
|
struct tm now;
|
||||||
snvs_hp_rtc_datetime_t rtcDate = {0};
|
snvs_hp_rtc_datetime_t rtcDate = {0};
|
||||||
|
|
||||||
p_tm = gmtime(×tamp);
|
gmtime_r(×tamp, &now);
|
||||||
|
|
||||||
rtcDate.second = p_tm->tm_sec ;
|
rtcDate.second = now.tm_sec ;
|
||||||
rtcDate.minute = p_tm->tm_min ;
|
rtcDate.minute = now.tm_min ;
|
||||||
rtcDate.hour = p_tm->tm_hour;
|
rtcDate.hour = now.tm_hour;
|
||||||
|
|
||||||
rtcDate.day = p_tm->tm_mday;
|
rtcDate.day = now.tm_mday;
|
||||||
rtcDate.month = p_tm->tm_mon + 1;
|
rtcDate.month = now.tm_mon + 1;
|
||||||
rtcDate.year = p_tm->tm_year + 1900;
|
rtcDate.year = now.tm_year + 1900;
|
||||||
|
|
||||||
if (SNVS_HP_RTC_SetDatetime(SNVS, &rtcDate) != kStatus_Success)
|
if (SNVS_HP_RTC_SetDatetime(SNVS, &rtcDate) != kStatus_Success)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
@@ -50,18 +50,18 @@ static time_t get_timestamp(void)
|
|||||||
|
|
||||||
static int set_timestamp(time_t timestamp)
|
static int set_timestamp(time_t timestamp)
|
||||||
{
|
{
|
||||||
struct tm *p_tm;
|
struct tm now;
|
||||||
RTC_TimeTypeDef rtcDate;
|
RTC_TimeTypeDef rtcDate;
|
||||||
|
|
||||||
p_tm = gmtime(×tamp);
|
gmtime_r(×tamp, &now);
|
||||||
|
|
||||||
rtcDate.Seconds= p_tm->tm_sec ;
|
rtcDate.Seconds= now.tm_sec ;
|
||||||
rtcDate.Minutes= p_tm->tm_min ;
|
rtcDate.Minutes= now.tm_min ;
|
||||||
rtcDate.Hours= p_tm->tm_hour;
|
rtcDate.Hours= now.tm_hour;
|
||||||
|
|
||||||
rtcDate.Date= p_tm->tm_mday;
|
rtcDate.Date= now.tm_mday;
|
||||||
rtcDate.Month= p_tm->tm_mon + 1;
|
rtcDate.Month= now.tm_mon + 1;
|
||||||
rtcDate.Year= p_tm->tm_year + 1900 - 2000;
|
rtcDate.Year= now.tm_year + 1900 - 2000;
|
||||||
|
|
||||||
RTC_SetTime(RTC_Handler, &rtcDate);
|
RTC_SetTime(RTC_Handler, &rtcDate);
|
||||||
rt_kprintf("\r\nrtcDate is %d.%d.%d - %d:%d:%d",rtcDate.Year, rtcDate.Month, rtcDate.Date, rtcDate.Hours, rtcDate.Minutes, rtcDate.Seconds);
|
rt_kprintf("\r\nrtcDate is %d.%d.%d - %d:%d:%d",rtcDate.Year, rtcDate.Month, rtcDate.Date, rtcDate.Hours, rtcDate.Minutes, rtcDate.Seconds);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2019, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -128,7 +128,6 @@ static rt_err_t rt_rtc_ioctl(rt_device_t dev, int cmd, void *args)
|
|||||||
hw_rtc = dev->user_data;
|
hw_rtc = dev->user_data;
|
||||||
|
|
||||||
t = (time_t *)args;
|
t = (time_t *)args;
|
||||||
time = *gmtime(t);
|
|
||||||
|
|
||||||
rtctm.sys_toyread0 = hw_rtc->sys_toyread0;
|
rtctm.sys_toyread0 = hw_rtc->sys_toyread0;
|
||||||
rtctm.sys_toyread1 = hw_rtc->sys_toyread1;
|
rtctm.sys_toyread1 = hw_rtc->sys_toyread1;
|
||||||
@@ -141,6 +140,7 @@ static rt_err_t rt_rtc_ioctl(rt_device_t dev, int cmd, void *args)
|
|||||||
*t = timegm(&tmptime);
|
*t = timegm(&tmptime);
|
||||||
break;
|
break;
|
||||||
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
||||||
|
gmtime_r(t, &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;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2020, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -43,18 +43,18 @@ static time_t get_timestamp(void)
|
|||||||
|
|
||||||
static int set_timestamp(time_t timestamp)
|
static int set_timestamp(time_t timestamp)
|
||||||
{
|
{
|
||||||
struct tm *p_tm;
|
struct tm now;
|
||||||
rtc_datetime_t rtcDate;
|
rtc_datetime_t rtcDate;
|
||||||
|
|
||||||
p_tm = gmtime(×tamp);
|
gmtime_r(×tamp, &now);
|
||||||
|
|
||||||
rtcDate.second = p_tm->tm_sec ;
|
rtcDate.second = now.tm_sec ;
|
||||||
rtcDate.minute = p_tm->tm_min ;
|
rtcDate.minute = now.tm_min ;
|
||||||
rtcDate.hour = p_tm->tm_hour;
|
rtcDate.hour = now.tm_hour;
|
||||||
|
|
||||||
rtcDate.day = p_tm->tm_mday;
|
rtcDate.day = now.tm_mday;
|
||||||
rtcDate.month = p_tm->tm_mon + 1;
|
rtcDate.month = now.tm_mon + 1;
|
||||||
rtcDate.year = p_tm->tm_year + 1900;
|
rtcDate.year = now.tm_year + 1900;
|
||||||
|
|
||||||
/* RTC time counter has to be stopped before setting the date & time in the TSR register */
|
/* RTC time counter has to be stopped before setting the date & time in the TSR register */
|
||||||
RTC_StopTimer(RTC);
|
RTC_StopTimer(RTC);
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ static rt_err_t nu_rtc_is_date_valid(const time_t t)
|
|||||||
/* Register rt-thread device.control() entry. */
|
/* Register rt-thread device.control() entry. */
|
||||||
static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
struct tm tm_out, *tm_in;
|
struct tm tm_out, tm_in;
|
||||||
time_t *time;
|
time_t *time;
|
||||||
S_RTC_TIME_DATA_T hw_time;
|
S_RTC_TIME_DATA_T hw_time;
|
||||||
|
|
||||||
@@ -236,13 +236,13 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||||||
if (nu_rtc_is_date_valid(*time) != RT_EOK)
|
if (nu_rtc_is_date_valid(*time) != RT_EOK)
|
||||||
return -(RT_ERROR);
|
return -(RT_ERROR);
|
||||||
|
|
||||||
tm_in = gmtime(time);
|
gmtime_r(time, &tm_in);
|
||||||
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in->tm_year);
|
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in.tm_year);
|
||||||
hw_time.u32Month = CONV_FROM_TM_MON(tm_in->tm_mon);
|
hw_time.u32Month = CONV_FROM_TM_MON(tm_in.tm_mon);
|
||||||
hw_time.u32Day = tm_in->tm_mday;
|
hw_time.u32Day = tm_in.tm_mday;
|
||||||
hw_time.u32Hour = tm_in->tm_hour;
|
hw_time.u32Hour = tm_in.tm_hour;
|
||||||
hw_time.u32Minute = tm_in->tm_min;
|
hw_time.u32Minute = tm_in.tm_min;
|
||||||
hw_time.u32Second = tm_in->tm_sec;
|
hw_time.u32Second = tm_in.tm_sec;
|
||||||
hw_time.u32TimeScale = RTC_CLOCK_24;
|
hw_time.u32TimeScale = RTC_CLOCK_24;
|
||||||
hw_time.u32AmPm = 0;
|
hw_time.u32AmPm = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ static rt_err_t nu_rtc_is_date_valid(const time_t t)
|
|||||||
/* Register rt-thread device.control() entry. */
|
/* Register rt-thread device.control() entry. */
|
||||||
static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
struct tm tm_out, *tm_in;
|
struct tm tm_out, tm_in;
|
||||||
time_t *time;
|
time_t *time;
|
||||||
S_RTC_TIME_DATA_T hw_time;
|
S_RTC_TIME_DATA_T hw_time;
|
||||||
|
|
||||||
@@ -239,13 +239,13 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||||||
if (nu_rtc_is_date_valid(*time) != RT_EOK)
|
if (nu_rtc_is_date_valid(*time) != RT_EOK)
|
||||||
return -(RT_ERROR);
|
return -(RT_ERROR);
|
||||||
|
|
||||||
tm_in = gmtime(time);
|
gmtime_r(time, &tm_in);
|
||||||
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in->tm_year);
|
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in.tm_year);
|
||||||
hw_time.u32Month = CONV_FROM_TM_MON(tm_in->tm_mon);
|
hw_time.u32Month = CONV_FROM_TM_MON(tm_in.tm_mon);
|
||||||
hw_time.u32Day = tm_in->tm_mday;
|
hw_time.u32Day = tm_in.tm_mday;
|
||||||
hw_time.u32Hour = tm_in->tm_hour;
|
hw_time.u32Hour = tm_in.tm_hour;
|
||||||
hw_time.u32Minute = tm_in->tm_min;
|
hw_time.u32Minute = tm_in.tm_min;
|
||||||
hw_time.u32Second = tm_in->tm_sec;
|
hw_time.u32Second = tm_in.tm_sec;
|
||||||
hw_time.u32TimeScale = RTC_CLOCK_24;
|
hw_time.u32TimeScale = RTC_CLOCK_24;
|
||||||
hw_time.u32AmPm = 0;
|
hw_time.u32AmPm = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ static rt_err_t nu_rtc_is_date_valid(const time_t t)
|
|||||||
/* Register rt-thread device.control() entry. */
|
/* Register rt-thread device.control() entry. */
|
||||||
static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
struct tm tm_out, *tm_in;
|
struct tm tm_out, tm_in;
|
||||||
time_t *time;
|
time_t *time;
|
||||||
S_RTC_TIME_DATA_T hw_time;
|
S_RTC_TIME_DATA_T hw_time;
|
||||||
|
|
||||||
@@ -238,13 +238,13 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||||||
if (nu_rtc_is_date_valid(*time) != RT_EOK)
|
if (nu_rtc_is_date_valid(*time) != RT_EOK)
|
||||||
return -(RT_ERROR);
|
return -(RT_ERROR);
|
||||||
|
|
||||||
tm_in = gmtime(time);
|
gmtime_r(time, &tm_in);
|
||||||
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in->tm_year);
|
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in.tm_year);
|
||||||
hw_time.u32Month = CONV_FROM_TM_MON(tm_in->tm_mon);
|
hw_time.u32Month = CONV_FROM_TM_MON(tm_in.tm_mon);
|
||||||
hw_time.u32Day = tm_in->tm_mday;
|
hw_time.u32Day = tm_in.tm_mday;
|
||||||
hw_time.u32Hour = tm_in->tm_hour;
|
hw_time.u32Hour = tm_in.tm_hour;
|
||||||
hw_time.u32Minute = tm_in->tm_min;
|
hw_time.u32Minute = tm_in.tm_min;
|
||||||
hw_time.u32Second = tm_in->tm_sec;
|
hw_time.u32Second = tm_in.tm_sec;
|
||||||
hw_time.u32TimeScale = RTC_CLOCK_24;
|
hw_time.u32TimeScale = RTC_CLOCK_24;
|
||||||
hw_time.u32AmPm = 0;
|
hw_time.u32AmPm = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ static rt_err_t nu_rtc_is_date_valid(const time_t t)
|
|||||||
/* Register rt-thread device.control() entry. */
|
/* Register rt-thread device.control() entry. */
|
||||||
static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
struct tm tm_out, *tm_in;
|
struct tm tm_out, tm_in;
|
||||||
time_t *time;
|
time_t *time;
|
||||||
S_RTC_TIME_DATA_T hw_time = {0};
|
S_RTC_TIME_DATA_T hw_time = {0};
|
||||||
|
|
||||||
@@ -261,14 +261,14 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||||||
if (nu_rtc_is_date_valid(*time) != RT_EOK)
|
if (nu_rtc_is_date_valid(*time) != RT_EOK)
|
||||||
return -(RT_ERROR);
|
return -(RT_ERROR);
|
||||||
|
|
||||||
tm_in = gmtime(time);
|
gmtime_r(time, &tm_in);
|
||||||
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in->tm_year);
|
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in.tm_year);
|
||||||
hw_time.u32cMonth = CONV_FROM_TM_MON(tm_in->tm_mon);
|
hw_time.u32cMonth = CONV_FROM_TM_MON(tm_in.tm_mon);
|
||||||
hw_time.u32cDay = tm_in->tm_mday;
|
hw_time.u32cDay = tm_in.tm_mday;
|
||||||
hw_time.u32cHour = tm_in->tm_hour;
|
hw_time.u32cHour = tm_in.tm_hour;
|
||||||
hw_time.u32cMinute = tm_in->tm_min;
|
hw_time.u32cMinute = tm_in.tm_min;
|
||||||
hw_time.u32cSecond = tm_in->tm_sec;
|
hw_time.u32cSecond = tm_in.tm_sec;
|
||||||
hw_time.u32cDayOfWeek = tm_in->tm_wday;
|
hw_time.u32cDayOfWeek = tm_in.tm_wday;
|
||||||
hw_time.u8cClockDisplay = RTC_CLOCK_24;
|
hw_time.u8cClockDisplay = RTC_CLOCK_24;
|
||||||
hw_time.u8cAmPm = 0;
|
hw_time.u8cAmPm = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ static rt_err_t nu_rtc_is_date_valid(const time_t t)
|
|||||||
/* Register rt-thread device.control() entry. */
|
/* Register rt-thread device.control() entry. */
|
||||||
static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
struct tm tm_out, *tm_in;
|
struct tm tm_out, tm_in;
|
||||||
time_t *time;
|
time_t *time;
|
||||||
S_RTC_TIME_DATA_T hw_time;
|
S_RTC_TIME_DATA_T hw_time;
|
||||||
|
|
||||||
@@ -239,13 +239,13 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
|
|||||||
if (nu_rtc_is_date_valid(*time) != RT_EOK)
|
if (nu_rtc_is_date_valid(*time) != RT_EOK)
|
||||||
return -(RT_ERROR);
|
return -(RT_ERROR);
|
||||||
|
|
||||||
tm_in = gmtime(time);
|
gmtime_r(time, &tm_in);
|
||||||
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in->tm_year);
|
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in.tm_year);
|
||||||
hw_time.u32Month = CONV_FROM_TM_MON(tm_in->tm_mon);
|
hw_time.u32Month = CONV_FROM_TM_MON(tm_in.tm_mon);
|
||||||
hw_time.u32Day = tm_in->tm_mday;
|
hw_time.u32Day = tm_in.tm_mday;
|
||||||
hw_time.u32Hour = tm_in->tm_hour;
|
hw_time.u32Hour = tm_in.tm_hour;
|
||||||
hw_time.u32Minute = tm_in->tm_min;
|
hw_time.u32Minute = tm_in.tm_min;
|
||||||
hw_time.u32Second = tm_in->tm_sec;
|
hw_time.u32Second = tm_in.tm_sec;
|
||||||
hw_time.u32TimeScale = RTC_CLOCK_24;
|
hw_time.u32TimeScale = RTC_CLOCK_24;
|
||||||
hw_time.u32AmPm = 0;
|
hw_time.u32AmPm = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -193,16 +193,16 @@ static time_t raspi_get_timestamp(void)
|
|||||||
|
|
||||||
static int raspi_set_timestamp(time_t timestamp)
|
static int raspi_set_timestamp(time_t timestamp)
|
||||||
{
|
{
|
||||||
struct tm *tblock;
|
struct tm tblock;
|
||||||
tblock = gmtime(×tamp);
|
gmtime_r(×tamp, &tblock);
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
buf[1] = tblock->tm_sec;
|
buf[1] = tblock.tm_sec;
|
||||||
buf[2] = tblock->tm_min;
|
buf[2] = tblock.tm_min;
|
||||||
buf[3] = tblock->tm_hour;
|
buf[3] = tblock.tm_hour;
|
||||||
buf[4] = tblock->tm_wday;
|
buf[4] = tblock.tm_wday;
|
||||||
buf[5] = tblock->tm_mday;
|
buf[5] = tblock.tm_mday;
|
||||||
buf[6] = tblock->tm_mon;
|
buf[6] = tblock.tm_mon;
|
||||||
buf[7] = tblock->tm_year;
|
buf[7] = tblock.tm_year;
|
||||||
|
|
||||||
i2c_write(buf, 8);
|
i2c_write(buf, 8);
|
||||||
|
|
||||||
|
|||||||
@@ -40,16 +40,16 @@ static time_t raspi_get_timestamp(void)
|
|||||||
|
|
||||||
static int raspi_set_timestamp(time_t timestamp)
|
static int raspi_set_timestamp(time_t timestamp)
|
||||||
{
|
{
|
||||||
struct tm *tblock;
|
struct tm tblock;
|
||||||
tblock = gmtime(×tamp);
|
gmtime_r(×tamp, &tblock);
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
buf[1] = tblock->tm_sec;
|
buf[1] = tblock.tm_sec;
|
||||||
buf[2] = tblock->tm_min;
|
buf[2] = tblock.tm_min;
|
||||||
buf[3] = tblock->tm_hour;
|
buf[3] = tblock.tm_hour;
|
||||||
buf[4] = tblock->tm_wday;
|
buf[4] = tblock.tm_wday;
|
||||||
buf[5] = tblock->tm_mday;
|
buf[5] = tblock.tm_mday;
|
||||||
buf[6] = tblock->tm_mon;
|
buf[6] = tblock.tm_mon;
|
||||||
buf[7] = tblock->tm_year;
|
buf[7] = tblock.tm_year;
|
||||||
bcm283x_i2c_write((PER_BASE + BCM283X_BSC0_BASE) ,buf, 8);
|
bcm283x_i2c_write((PER_BASE + BCM283X_BSC0_BASE) ,buf, 8);
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user