summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorkurisaw <[email protected]>2024-12-23 15:23:19 +0800
committerMeco Man <[email protected]>2024-12-23 19:40:11 -0500
commitb23d667ba406cc3daade69f22e32d332261767bc (patch)
treeb7cf97b1a28a9d41bbe23489ac446686cc528c2b /components
parentc9ed7841310eef42050865b5df9dd8e309ad2205 (diff)
Specification of rtc synchronization functions
Diffstat (limited to 'components')
-rw-r--r--components/drivers/rtc/dev_soft_rtc.c30
1 files changed, 2 insertions, 28 deletions
diff --git a/components/drivers/rtc/dev_soft_rtc.c b/components/drivers/rtc/dev_soft_rtc.c
index abe35633b9..cd5a37ee02 100644
--- a/components/drivers/rtc/dev_soft_rtc.c
+++ b/components/drivers/rtc/dev_soft_rtc.c
@@ -35,7 +35,6 @@
#endif
static struct rt_work rtc_sync_work;
-static rt_device_t source_device = RT_NULL;
static struct rt_device soft_rtc_dev;
static rt_tick_t init_tick;
@@ -82,18 +81,6 @@ static void set_rtc_time(time_t t)
#endif
}
-static void _source_device_control(int cmd, void *args)
-{
- if (source_device == RT_NULL)
- return;
-
- if (rt_device_open(source_device, 0) == RT_EOK)
- {
- rt_device_control(source_device, cmd, args);
- rt_device_close(source_device);
- }
-}
-
static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
{
time_t *t;
@@ -114,7 +101,6 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
{
t = (time_t *) args;
set_rtc_time(*t);
- _source_device_control(RT_DEVICE_CTRL_RTC_SET_TIME, t);
break;
}
#ifdef RT_USING_ALARM
@@ -143,7 +129,6 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
rt_ktime_boottime_get_us(&_tv);
set_rtc_time(tv->tv_sec);
init_tv.tv_usec = tv->tv_usec - _tv.tv_usec;
- _source_device_control(RT_DEVICE_CTRL_RTC_SET_TIME, &(tv->tv_sec));
break;
}
case RT_DEVICE_CTRL_RTC_GET_TIMESPEC:
@@ -162,7 +147,6 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
rt_ktime_boottime_get_ns(&_ts);
set_rtc_time(ts->tv_sec);
init_ts.tv_nsec = ts->tv_nsec - _ts.tv_nsec;
- _source_device_control(RT_DEVICE_CTRL_RTC_SET_TIME, &(ts->tv_sec));
break;
}
case RT_DEVICE_CTRL_RTC_GET_TIMERES:
@@ -187,7 +171,6 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
rt_tick_t tick = rt_tick_get() - init_tick;
set_rtc_time(tv->tv_sec);
init_tv.tv_usec = tv->tv_usec - ((tick % RT_TICK_PER_SECOND) * (1000000 / RT_TICK_PER_SECOND));
- _source_device_control(RT_DEVICE_CTRL_RTC_SET_TIME, &(tv->tv_sec));
break;
}
case RT_DEVICE_CTRL_RTC_GET_TIMERES:
@@ -227,7 +210,7 @@ static int rt_soft_rtc_init(void)
return 0;
}
/* make sure only one 'rtc' device */
-#if defined(RT_USING_SOFT_RTC) && defined(RT_USING_RTC)
+#if defined(RT_USING_SOFT_RTC) && defined(BSP_USING_ONCHIP_RTC)
#warning "Please note: Currently only one RTC device is allowed in the system, and the name is "rtc"."
#endif
RT_ASSERT(!rt_device_find("rtc"));
@@ -263,8 +246,6 @@ static int rt_soft_rtc_init(void)
rt_device_register(&soft_rtc_dev, "rtc", RT_DEVICE_FLAG_RDWR);
- source_device = &soft_rtc_dev;
-
init_ok = RT_TRUE;
return 0;
@@ -277,13 +258,7 @@ rt_err_t rt_soft_rtc_sync(void)
{
time_t time = 0;
- if (source_device == RT_NULL)
- {
- rt_kprintf("error: rtc source not found, please set it!!!\n");
- return RT_ENOSYS;
- }
-
- _source_device_control(RT_DEVICE_CTRL_RTC_GET_TIME, &time);
+ rt_device_control(&soft_rtc_dev, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
set_rtc_time(time);
return RT_EOK;
}
@@ -299,7 +274,6 @@ rt_err_t rt_soft_rtc_set_source(const char *name)
RT_ASSERT(name != RT_NULL);
RT_ASSERT(rt_device_find(name)); /* make sure source is exist*/
- source_device = rt_device_find(name);
rt_work_init(&rtc_sync_work, rtc_sync_work_func, RT_NULL);
rt_work_submit(&rtc_sync_work, rt_tick_from_millisecond(RTC_AUTO_SYNC_FIRST_DELAY * 1000));