Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 2 additions & 28 deletions components/drivers/rtc/dev_soft_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有看懂 麻烦增加一些解释 这里为什么删除了这行

Copy link
Member Author

@kurisaW kurisaW Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原本是这样的,在软件rtc驱动中有个rt_soft_rtc_sync,但是其中的source_device句柄是没有进行初始化的,所以这里把这个句柄传递了下,但是后面看了看,dev_soft_rtc.c这个驱动文件中,还调用了硬件驱动的ops,这块感觉还是需要独立开的;
除此之外,rt_soft_rtc_sync是通过一个工作队列的机制去做的同步,原本的驱动之所以有source_device和soft_rtc_dev两个设备句柄,我感觉是为了这个rtc也能够同步硬件rtc设备,但是不应该放在这里一起去弄,本身也不合理;
我这里又重新提交了一份,现在看应该会清晰些,rtc的同步就暂时给软件rtc去使用,硬件的话不需要应该问题也不大,本身是硬件的机制,容错率更高。


init_ok = RT_TRUE;

return 0;
Expand All @@ -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;
}
Expand All @@ -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));

Expand Down
Loading