Skip to content

Commit 1d02f42

Browse files
committed
优化
1 parent 82bc898 commit 1d02f42

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

components/drivers/rtc/dev_soft_rtc.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -186,30 +186,32 @@ static void get_rtc_time(struct timespec *ts)
186186
static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
187187
{
188188
time_t *t;
189+
struct timeval *tv;
190+
struct timespec *ts;
191+
struct timespec ts_temp;
189192
rt_base_t level;
190-
struct tm time_temp;
191193

192194
RT_ASSERT(dev != RT_NULL);
195+
193196
if (!args)
194197
return -RT_EINVAL;
195198

196-
rt_memset(&time_temp, 0, sizeof(struct tm));
199+
rt_memset(&ts_temp, 0, sizeof(ts_temp));
197200

198201
switch (cmd)
199202
{
200203
case RT_DEVICE_CTRL_RTC_GET_TIME:
201204
{
202205
t = (time_t *)args;
203-
struct timespec ts;
204-
get_rtc_time(&ts);
205-
*t = ts.tv_sec;
206+
get_rtc_time(&ts_temp);
207+
*t = ts_temp.tv_sec;
206208
break;
207209
}
208210
case RT_DEVICE_CTRL_RTC_SET_TIME:
209211
{
210212
t = (time_t *)args;
211-
struct timespec ts = { *t, 0 };
212-
set_rtc_time(&ts);
213+
ts_temp.tv_sec = *t;
214+
set_rtc_time(&ts_temp);
213215
break;
214216
}
215217
#ifdef RT_USING_ALARM
@@ -223,35 +225,35 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
223225
#endif
224226
case RT_DEVICE_CTRL_RTC_GET_TIMEVAL:
225227
{
226-
struct timeval *tv = (struct timeval *)args;
227-
struct timespec ts;
228-
get_rtc_time(&ts);
229-
tv->tv_sec = ts.tv_sec;
230-
tv->tv_usec = ts.tv_nsec / 1000;
228+
tv = (struct timeval *)args;
229+
get_rtc_time(&ts_temp);
230+
tv->tv_sec = ts_temp.tv_sec;
231+
tv->tv_usec = ts_temp.tv_nsec / 1000;
231232
break;
232233
}
233234
case RT_DEVICE_CTRL_RTC_SET_TIMEVAL:
234235
{
235-
struct timeval *tv = (struct timeval *)args;
236-
struct timespec ts = { tv->tv_sec, tv->tv_usec * 1000 };
237-
set_rtc_time(&ts);
236+
tv = (struct timeval *)args;
237+
ts_temp.tv_sec = tv->tv_sec;
238+
ts_temp.tv_nsec = tv->tv_usec * 1000;
239+
set_rtc_time(&ts_temp);
238240
break;
239241
}
240242
case RT_DEVICE_CTRL_RTC_GET_TIMESPEC:
241243
{
242-
struct timespec *ts = (struct timespec *)args;
244+
ts = (struct timespec *)args;
243245
get_rtc_time(ts);
244246
break;
245247
}
246248
case RT_DEVICE_CTRL_RTC_SET_TIMESPEC:
247249
{
248-
struct timespec *ts = (struct timespec *)args;
250+
ts = (struct timespec *)args;
249251
set_rtc_time(ts);
250252
break;
251253
}
252254
case RT_DEVICE_CTRL_RTC_GET_TIMERES:
253255
{
254-
struct timespec *ts = (struct timespec *)args;
256+
ts = (struct timespec *)args;
255257
level = rt_spin_lock_irqsave(&_spinlock);
256258
ts->tv_sec = 0;
257259
#ifdef RT_USING_KTIME

0 commit comments

Comments
 (0)