3535#endif
3636
3737static struct rt_work rtc_sync_work ;
38- static rt_device_t source_device = RT_NULL ;
3938
4039static struct rt_device soft_rtc_dev ;
4140static rt_tick_t init_tick ;
@@ -82,18 +81,6 @@ static void set_rtc_time(time_t t)
8281#endif
8382}
8483
85- static void _source_device_control (int cmd , void * args )
86- {
87- if (source_device == RT_NULL )
88- return ;
89-
90- if (rt_device_open (source_device , 0 ) == RT_EOK )
91- {
92- rt_device_control (source_device , cmd , args );
93- rt_device_close (source_device );
94- }
95- }
96-
9784static rt_err_t soft_rtc_control (rt_device_t dev , int cmd , void * args )
9885{
9986 time_t * t ;
@@ -114,7 +101,6 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
114101 {
115102 t = (time_t * ) args ;
116103 set_rtc_time (* t );
117- _source_device_control (RT_DEVICE_CTRL_RTC_SET_TIME , t );
118104 break ;
119105 }
120106#ifdef RT_USING_ALARM
@@ -143,7 +129,6 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
143129 rt_ktime_boottime_get_us (& _tv );
144130 set_rtc_time (tv -> tv_sec );
145131 init_tv .tv_usec = tv -> tv_usec - _tv .tv_usec ;
146- _source_device_control (RT_DEVICE_CTRL_RTC_SET_TIME , & (tv -> tv_sec ));
147132 break ;
148133 }
149134 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)
162147 rt_ktime_boottime_get_ns (& _ts );
163148 set_rtc_time (ts -> tv_sec );
164149 init_ts .tv_nsec = ts -> tv_nsec - _ts .tv_nsec ;
165- _source_device_control (RT_DEVICE_CTRL_RTC_SET_TIME , & (ts -> tv_sec ));
166150 break ;
167151 }
168152 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)
187171 rt_tick_t tick = rt_tick_get () - init_tick ;
188172 set_rtc_time (tv -> tv_sec );
189173 init_tv .tv_usec = tv -> tv_usec - ((tick % RT_TICK_PER_SECOND ) * (1000000 / RT_TICK_PER_SECOND ));
190- _source_device_control (RT_DEVICE_CTRL_RTC_SET_TIME , & (tv -> tv_sec ));
191174 break ;
192175 }
193176 case RT_DEVICE_CTRL_RTC_GET_TIMERES :
@@ -227,7 +210,7 @@ static int rt_soft_rtc_init(void)
227210 return 0 ;
228211 }
229212 /* make sure only one 'rtc' device */
230- #if defined(RT_USING_SOFT_RTC ) && defined(RT_USING_RTC )
213+ #if defined(RT_USING_SOFT_RTC ) && defined(BSP_USING_ONCHIP_RTC )
231214#warning "Please note: Currently only one RTC device is allowed in the system, and the name is "rtc"."
232215#endif
233216 RT_ASSERT (!rt_device_find ("rtc" ));
@@ -263,8 +246,6 @@ static int rt_soft_rtc_init(void)
263246
264247 rt_device_register (& soft_rtc_dev , "rtc" , RT_DEVICE_FLAG_RDWR );
265248
266- source_device = & soft_rtc_dev ;
267-
268249 init_ok = RT_TRUE ;
269250
270251 return 0 ;
@@ -277,13 +258,7 @@ rt_err_t rt_soft_rtc_sync(void)
277258{
278259 time_t time = 0 ;
279260
280- if (source_device == RT_NULL )
281- {
282- rt_kprintf ("error: rtc source not found, please set it!!!\n" );
283- return RT_ENOSYS ;
284- }
285-
286- _source_device_control (RT_DEVICE_CTRL_RTC_GET_TIME , & time );
261+ rt_device_control (& soft_rtc_dev , RT_DEVICE_CTRL_RTC_GET_TIME , & time );
287262 set_rtc_time (time );
288263 return RT_EOK ;
289264}
@@ -299,7 +274,6 @@ rt_err_t rt_soft_rtc_set_source(const char *name)
299274 RT_ASSERT (name != RT_NULL );
300275 RT_ASSERT (rt_device_find (name )); /* make sure source is exist*/
301276
302- source_device = rt_device_find (name );
303277 rt_work_init (& rtc_sync_work , rtc_sync_work_func , RT_NULL );
304278 rt_work_submit (& rtc_sync_work , rt_tick_from_millisecond (RTC_AUTO_SYNC_FIRST_DELAY * 1000 ));
305279
0 commit comments