提交 9809c138 编写于 作者: S sc943313837@gmail.com

add open operation

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2309 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 e0a5c0ae
...@@ -44,7 +44,11 @@ time_t time(time_t* t) ...@@ -44,7 +44,11 @@ time_t time(time_t* t)
/* read timestamp from RTC device. */ /* read timestamp from RTC device. */
if (device != RT_NULL) if (device != RT_NULL)
{ {
rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now); if (rt_device_open(device, 0) == RT_EOK)
{
rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now);
rt_device_close(device);
}
} }
/* if t is not NULL, write timestamp to *t */ /* if t is not NULL, write timestamp to *t */
...@@ -70,6 +74,7 @@ rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day) ...@@ -70,6 +74,7 @@ rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
struct tm * p_tm; struct tm * p_tm;
struct tm tm_new; struct tm tm_new;
rt_device_t device; rt_device_t device;
rt_err_t ret = RT_ERROR;
/* get current time */ /* get current time */
now = time(RT_NULL); now = time(RT_NULL);
...@@ -94,11 +99,13 @@ rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day) ...@@ -94,11 +99,13 @@ rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
device = rt_device_find("rtc"); device = rt_device_find("rtc");
if (device == RT_NULL) if (device == RT_NULL)
{ {
return -RT_ERROR; return RT_ERROR;
} }
ret = rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &now);
/* update to RTC device. */ /* update to RTC device. */
return rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &now); return ret;
} }
/** \brief set system time(date not modify). /** \brief set system time(date not modify).
...@@ -115,6 +122,7 @@ rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second) ...@@ -115,6 +122,7 @@ rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second)
struct tm * p_tm; struct tm * p_tm;
struct tm tm_new; struct tm tm_new;
rt_device_t device; rt_device_t device;
rt_err_t ret = RT_ERROR;
/* get current time */ /* get current time */
now = time(RT_NULL); now = time(RT_NULL);
...@@ -142,13 +150,15 @@ rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second) ...@@ -142,13 +150,15 @@ rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second)
return RT_ERROR; return RT_ERROR;
} }
ret = rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &now);
/* update to RTC device. */ /* update to RTC device. */
return rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &now); return ret;
} }
#ifdef RT_USING_FINSH #ifdef RT_USING_FINSH
#include <finsh.h> #include <finsh.h>
#include <rtdevice.h>
void list_date(void) void list_date(void)
{ {
time_t now; time_t now;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册