summaryrefslogtreecommitdiff
path: root/components/drivers
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2021-07-30 02:03:55 +0800
committerMeco Man <[email protected]>2021-07-30 02:03:55 +0800
commitfb31ab9c72f1b2cb966064523fc6aa103059b222 (patch)
treef9b6436c749cf933751fce5a8ee5f3d889afa4e7 /components/drivers
parentc255c49b8218a396e0561d094aaf3a853422bf86 (diff)
[rtc] localtime 改 localtime_r
Diffstat (limited to 'components/drivers')
-rw-r--r--components/drivers/rtc/rtc.c22
1 files changed, 2 insertions, 20 deletions
diff --git a/components/drivers/rtc/rtc.c b/components/drivers/rtc/rtc.c
index 3a843e2e0c..9e1305cdd7 100644
--- a/components/drivers/rtc/rtc.c
+++ b/components/drivers/rtc/rtc.c
@@ -20,8 +20,6 @@
#ifdef RT_USING_RTC
-
-
/**
* Set system date(time not modify, local timezone).
*
@@ -30,12 +28,10 @@
* @param rt_uint32_t day e.g: 31.
*
* @return rt_err_t if set success, return RT_EOK.
- *
*/
rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
{
time_t now;
- struct tm *p_tm;
struct tm tm_new;
rt_device_t device;
rt_err_t ret = -RT_ERROR;
@@ -43,14 +39,8 @@ rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
/* get current time */
now = time(RT_NULL);
- /* lock scheduler. */
- rt_enter_critical();
/* converts calendar time into local time. */
- p_tm = localtime(&now);
- /* copy the statically located variable */
- rt_memcpy(&tm_new, p_tm, sizeof(struct tm));
- /* unlock scheduler. */
- rt_exit_critical();
+ localtime_r(&now, &tm_new);
/* update date. */
tm_new.tm_year = year - 1900;
@@ -80,12 +70,10 @@ rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
* @param rt_uint32_t second e.g: 0~59.
*
* @return rt_err_t if set success, return RT_EOK.
- *
*/
rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second)
{
time_t now;
- struct tm *p_tm;
struct tm tm_new;
rt_device_t device;
rt_err_t ret = -RT_ERROR;
@@ -93,14 +81,8 @@ rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second)
/* get current time */
now = time(RT_NULL);
- /* lock scheduler. */
- rt_enter_critical();
/* converts calendar time into local time. */
- p_tm = localtime(&now);
- /* copy the statically located variable */
- rt_memcpy(&tm_new, p_tm, sizeof(struct tm));
- /* unlock scheduler. */
- rt_exit_critical();
+ localtime_r(&now, &tm_new);
/* update time. */
tm_new.tm_hour = hour;