[rtc] use gmtime_r to replace gmtime (#6012)
* [rtc] use gmtime_r to replace gmtime
This commit is contained in:
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,24 +69,22 @@ static rt_err_t ra_get_secs(void *args)
|
||||||
|
|
||||||
static rt_err_t set_rtc_time_stamp(time_t time_stamp)
|
static rt_err_t set_rtc_time_stamp(time_t time_stamp)
|
||||||
{
|
{
|
||||||
struct tm *p_tm;
|
struct tm now;
|
||||||
rtc_time_t g_current_time = {0};
|
rtc_time_t g_current_time = {0};
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_current_time.tm_sec = p_tm->tm_sec ;
|
g_current_time.tm_sec = now.tm_sec ;
|
||||||
g_current_time.tm_min = p_tm->tm_min ;
|
g_current_time.tm_min = now.tm_min ;
|
||||||
g_current_time.tm_hour = p_tm->tm_hour;
|
g_current_time.tm_hour = now.tm_hour;
|
||||||
|
g_current_time.tm_mday = now.tm_mday;
|
||||||
g_current_time.tm_mday = p_tm->tm_mday;
|
g_current_time.tm_mon = now.tm_mon;
|
||||||
g_current_time.tm_mon = p_tm->tm_mon;
|
g_current_time.tm_year = now.tm_year;
|
||||||
g_current_time.tm_year = p_tm->tm_year;
|
g_current_time.tm_wday = now.tm_wday;
|
||||||
|
g_current_time.tm_yday = now.tm_yday;
|
||||||
g_current_time.tm_wday = p_tm->tm_wday;
|
|
||||||
g_current_time.tm_yday = p_tm->tm_yday;
|
|
||||||
|
|
||||||
if (R_RTC_CalendarTimeSet(&g_rtc_ctrl, &g_current_time) != FSP_SUCCESS)
|
if (R_RTC_CalendarTimeSet(&g_rtc_ctrl, &g_current_time) != FSP_SUCCESS)
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,17 +63,16 @@ static time_t swm_get_rtc_time_stamp(void)
|
||||||
static rt_err_t swm_set_rtc_time_stamp(time_t time_stamp)
|
static rt_err_t swm_set_rtc_time_stamp(time_t time_stamp)
|
||||||
{
|
{
|
||||||
RTC_DateTime set_datetime = {0};
|
RTC_DateTime set_datetime = {0};
|
||||||
struct tm *p_tm;
|
struct tm now;
|
||||||
|
|
||||||
p_tm = gmtime(&time_stamp);
|
gmtime_r(&time_stamp, &now);
|
||||||
|
set_datetime.Second = now.tm_sec;
|
||||||
set_datetime.Second = p_tm->tm_sec;
|
set_datetime.Minute = now.tm_min;
|
||||||
set_datetime.Minute = p_tm->tm_min;
|
set_datetime.Hour = now.tm_hour;
|
||||||
set_datetime.Hour = p_tm->tm_hour;
|
set_datetime.Date = now.tm_mday;
|
||||||
set_datetime.Date = p_tm->tm_mday;
|
set_datetime.Month = now.tm_mon;
|
||||||
set_datetime.Month = p_tm->tm_mon;
|
set_datetime.Year = now.tm_year;
|
||||||
set_datetime.Year = p_tm->tm_year;
|
// set_datetime.Day = now.tm_wday;
|
||||||
// set_datetime.Day = p_tm->tm_wday;
|
|
||||||
|
|
||||||
RTC_Stop(RTC);
|
RTC_Stop(RTC);
|
||||||
while (RTC->CFGABLE == 0)
|
while (RTC->CFGABLE == 0)
|
||||||
|
|
|
@ -50,23 +50,23 @@ static int wm_set_timestamp(time_t timestamp)
|
||||||
int ctrl1 = 0;
|
int ctrl1 = 0;
|
||||||
int ctrl2 = 0;
|
int ctrl2 = 0;
|
||||||
|
|
||||||
struct tm *tblock;
|
struct tm tblock;
|
||||||
|
|
||||||
tblock = gmtime(×tamp);
|
gmtime_r(×tamp, &tblock);
|
||||||
|
|
||||||
ctrl2 = tls_reg_read32(HR_PMU_RTC_CTRL2); /* disable */
|
ctrl2 = tls_reg_read32(HR_PMU_RTC_CTRL2); /* disable */
|
||||||
ctrl2 &= ~(1 << 16);
|
ctrl2 &= ~(1 << 16);
|
||||||
tls_reg_write32(HR_PMU_RTC_CTRL2, ctrl2);
|
tls_reg_write32(HR_PMU_RTC_CTRL2, ctrl2);
|
||||||
|
|
||||||
ctrl1 |= tblock->tm_sec;
|
ctrl1 |= tblock.tm_sec;
|
||||||
ctrl1 |= tblock->tm_min << 8;
|
ctrl1 |= tblock.tm_min << 8;
|
||||||
ctrl1 |= tblock->tm_hour << 16;
|
ctrl1 |= tblock.tm_hour << 16;
|
||||||
ctrl1 |= tblock->tm_mday << 24;
|
ctrl1 |= tblock.tm_mday << 24;
|
||||||
tls_reg_write32(HR_PMU_RTC_CTRL1, ctrl1);
|
tls_reg_write32(HR_PMU_RTC_CTRL1, ctrl1);
|
||||||
|
|
||||||
ctrl2 = 0;
|
ctrl2 = 0;
|
||||||
ctrl2 |= tblock->tm_mon;
|
ctrl2 |= tblock.tm_mon;
|
||||||
ctrl2 |= tblock->tm_year << 8;
|
ctrl2 |= tblock.tm_year << 8;
|
||||||
tls_reg_write32(HR_PMU_RTC_CTRL2, ctrl2);
|
tls_reg_write32(HR_PMU_RTC_CTRL2, ctrl2);
|
||||||
|
|
||||||
ctrl2 = tls_reg_read32(HR_PMU_RTC_CTRL2);/* enable */
|
ctrl2 = tls_reg_read32(HR_PMU_RTC_CTRL2);/* enable */
|
||||||
|
@ -80,21 +80,21 @@ static int wm_alarm_set_timestamp(struct rt_rtc_wkalarm *wkalarm)
|
||||||
{
|
{
|
||||||
int ctrl1 = 0;
|
int ctrl1 = 0;
|
||||||
int ctrl2 = 0;
|
int ctrl2 = 0;
|
||||||
struct tm *tblock;
|
struct tm tblock;
|
||||||
time_t timestamp = 0;
|
time_t timestamp = 0;
|
||||||
|
|
||||||
timestamp = wm_get_timestamp();
|
timestamp = wm_get_timestamp();
|
||||||
tblock = gmtime(×tamp);
|
gmtime_r(×tamp, &tblock);
|
||||||
|
|
||||||
tls_irq_enable(PMU_RTC_INT);
|
tls_irq_enable(PMU_RTC_INT);
|
||||||
|
|
||||||
ctrl1 |= wkalarm->tm_sec;
|
ctrl1 |= wkalarm->tm_sec;
|
||||||
ctrl1 |= wkalarm->tm_min << 8;
|
ctrl1 |= wkalarm->tm_min << 8;
|
||||||
ctrl1 |= wkalarm->tm_hour << 16;
|
ctrl1 |= wkalarm->tm_hour << 16;
|
||||||
ctrl1 |= tblock->tm_mday << 24;
|
ctrl1 |= tblock.tm_mday << 24;
|
||||||
|
|
||||||
ctrl2 |= tblock->tm_mon;
|
ctrl2 |= tblock.tm_mon;
|
||||||
ctrl2 |= tblock->tm_year << 8;
|
ctrl2 |= tblock.tm_year << 8;
|
||||||
|
|
||||||
tls_reg_write32(HR_PMU_RTC_CTRL2, ctrl2 | BIT(16));
|
tls_reg_write32(HR_PMU_RTC_CTRL2, ctrl2 | BIT(16));
|
||||||
|
|
||||||
|
|
|
@ -944,22 +944,11 @@ DRESULT disk_ioctl(BYTE drv, BYTE ctrl, void *buff)
|
||||||
DWORD get_fattime(void)
|
DWORD get_fattime(void)
|
||||||
{
|
{
|
||||||
DWORD fat_time = 0;
|
DWORD fat_time = 0;
|
||||||
|
|
||||||
time_t now;
|
time_t now;
|
||||||
struct tm *p_tm;
|
|
||||||
struct tm tm_now;
|
struct tm tm_now;
|
||||||
|
|
||||||
/* get current time */
|
|
||||||
now = time(RT_NULL);
|
now = time(RT_NULL);
|
||||||
|
gmtime_r(&now, &tm_now);
|
||||||
/* lock scheduler. */
|
|
||||||
rt_enter_critical();
|
|
||||||
/* converts calendar time time into local time. */
|
|
||||||
p_tm = gmtime(&now);
|
|
||||||
/* copy the statically located variable */
|
|
||||||
rt_memcpy(&tm_now, p_tm, sizeof(struct tm));
|
|
||||||
/* unlock scheduler. */
|
|
||||||
rt_exit_critical();
|
|
||||||
|
|
||||||
fat_time = (DWORD)(tm_now.tm_year - 80) << 25 |
|
fat_time = (DWORD)(tm_now.tm_year - 80) << 25 |
|
||||||
(DWORD)(tm_now.tm_mon + 1) << 21 |
|
(DWORD)(tm_now.tm_mon + 1) << 21 |
|
||||||
|
|
|
@ -126,7 +126,7 @@ 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)
|
static rt_err_t rtc_control(rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
struct tm tm, *tm_ptr;
|
struct tm tmp;
|
||||||
time_t *time;
|
time_t *time;
|
||||||
RT_ASSERT(dev != RT_NULL);
|
RT_ASSERT(dev != RT_NULL);
|
||||||
|
|
||||||
|
@ -135,14 +135,14 @@ static rt_err_t rtc_control(rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
case RT_DEVICE_CTRL_RTC_GET_TIME:
|
case RT_DEVICE_CTRL_RTC_GET_TIME:
|
||||||
/* read device */
|
/* read device */
|
||||||
rt_hw_rtc_get(&tm);
|
rt_hw_rtc_get(&tmp);
|
||||||
*((rt_time_t *)args) = timegm(&tm);
|
*((rt_time_t *)args) = timegm(&tmp);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
||||||
/* write device */
|
/* write device */
|
||||||
tm_ptr = gmtime(time);
|
gmtime_r(time, &tmp);
|
||||||
rt_hw_rtc_set(tm_ptr);
|
rt_hw_rtc_set(&tmp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue