Skip to content

Commit a25667a

Browse files
committed
[rtc] add comments
1 parent 94a9332 commit a25667a

File tree

3 files changed

+39
-36
lines changed

3 files changed

+39
-36
lines changed

bsp/stm32/libraries/HAL_Drivers/drv_rtc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ static rt_err_t stm32_rtc_set_secs(void *args)
265265
static const struct rt_rtc_ops stm32_rtc_ops =
266266
{
267267
stm32_rtc_init,
268-
stm32_rtc_get_secs, /* get_secs */
269-
stm32_rtc_set_secs, /* set secs */
268+
stm32_rtc_get_secs,
269+
stm32_rtc_set_secs,
270270
RT_NULL,
271271
RT_NULL,
272272
RT_NULL,

components/drivers/include/drivers/rtc.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2012-10-10 aozima first version.
9-
* 2021-06-11 iysheng implement RTC v2.0
9+
* 2021-06-11 iysheng implement RTC framework V2.0
10+
* 2021-07-30 Meco Man move rtc_core.h to rtc.h
1011
*/
1112

1213
#ifndef __RTC_H__
@@ -38,7 +39,7 @@ typedef struct rt_rtc_device
3839
const struct rt_rtc_ops *ops;
3940
} rt_rtc_dev_t;
4041

41-
rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc,
42+
rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc,
4243
const char *name,
4344
rt_uint32_t flag,
4445
void *data);

components/drivers/rtc/rtc.c

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
* 2012-04-16 aozima add scheduler lock for set_date and set_time.
1111
* 2018-02-16 armink add auto sync time by NTP
1212
* 2021-05-09 Meco Man remove NTP
13-
* 2021-06-11 iysheng implement RTC v2.0
13+
* 2021-06-11 iysheng implement RTC framework V2.0
14+
* 2021-07-30 Meco Man move rtc_core.c to rtc.c
1415
*/
1516

1617
#include <time.h>
@@ -21,13 +22,10 @@
2122

2223
#ifdef RT_USING_RTC
2324

24-
#define TRY_DO_RTC_FUNC(rt_rtc_dev, func_name, args) \
25-
rt_rtc_dev->ops->func_name ? rt_rtc_dev->ops->func_name(args) : -RT_EINVAL;
26-
2725
/*
2826
* This function initializes rtc_core
2927
*/
30-
static rt_err_t rt_rtc_core_init(struct rt_device *dev)
28+
static rt_err_t rt_rtc_init(struct rt_device *dev)
3129
{
3230
rt_rtc_dev_t *rtc_core;
3331

@@ -38,71 +36,75 @@ static rt_err_t rt_rtc_core_init(struct rt_device *dev)
3836
return (rtc_core->ops->init());
3937
}
4038

41-
return (-RT_ENOSYS);
39+
return -RT_ENOSYS;
4240
}
4341

44-
static rt_err_t rt_rtc_core_open(struct rt_device *dev, rt_uint16_t oflag)
42+
static rt_err_t rt_rtc_open(struct rt_device *dev, rt_uint16_t oflag)
4543
{
46-
return (RT_EOK);
44+
return RT_EOK;
4745
}
4846

49-
static rt_err_t rt_rtc_core_close(struct rt_device *dev)
47+
static rt_err_t rt_rtc_close(struct rt_device *dev)
5048
{
5149
/* Add close member function in rt_rtc_ops when need,
5250
* then call that function here.
5351
* */
54-
return (RT_EOK);
52+
return RT_EOK;
5553
}
5654

57-
static rt_err_t rt_rtc_core_control(struct rt_device *dev,
58-
int cmd,
59-
void *args)
55+
static rt_err_t rt_rtc_control(struct rt_device *dev, int cmd, void *args)
6056
{
61-
rt_rtc_dev_t *rtc_core;
57+
#define TRY_DO_RTC_FUNC(rt_rtc_dev, func_name, args) \
58+
rt_rtc_dev->ops->func_name ? rt_rtc_dev->ops->func_name(args) : -RT_EINVAL;
59+
60+
rt_rtc_dev_t *rtc_device;
6261
rt_err_t ret = -RT_EINVAL;
6362

6463
RT_ASSERT(dev != RT_NULL);
65-
rtc_core = (rt_rtc_dev_t *)dev;
64+
rtc_device = (rt_rtc_dev_t *)dev;
6665

6766
switch (cmd)
6867
{
6968
case RT_DEVICE_CTRL_RTC_GET_TIME:
70-
ret = TRY_DO_RTC_FUNC(rtc_core, get_secs, args);
69+
ret = TRY_DO_RTC_FUNC(rtc_device, get_secs, args);
7170
break;
7271
case RT_DEVICE_CTRL_RTC_SET_TIME:
73-
ret = TRY_DO_RTC_FUNC(rtc_core, set_secs, args);
72+
ret = TRY_DO_RTC_FUNC(rtc_device, set_secs, args);
7473
break;
7574
case RT_DEVICE_CTRL_RTC_GET_TIME_US:
76-
ret = TRY_DO_RTC_FUNC(rtc_core, get_usecs, args);
75+
ret = TRY_DO_RTC_FUNC(rtc_device, get_usecs, args);
7776
break;
7877
case RT_DEVICE_CTRL_RTC_SET_TIME_US:
79-
ret = TRY_DO_RTC_FUNC(rtc_core, set_usecs, args);
78+
ret = TRY_DO_RTC_FUNC(rtc_device, set_usecs, args);
8079
break;
8180
case RT_DEVICE_CTRL_RTC_GET_ALARM:
82-
ret = TRY_DO_RTC_FUNC(rtc_core, get_alarm, args);
81+
ret = TRY_DO_RTC_FUNC(rtc_device, get_alarm, args);
8382
break;
8483
case RT_DEVICE_CTRL_RTC_SET_ALARM:
85-
ret = TRY_DO_RTC_FUNC(rtc_core, set_alarm, args);
84+
ret = TRY_DO_RTC_FUNC(rtc_device, set_alarm, args);
8685
break;
8786
default:
8887
break;
8988
}
9089

9190
return ret;
91+
92+
#undef TRY_DO_RTC_FUNC
9293
}
94+
9395
#ifdef RT_USING_DEVICE_OPS
9496
const static struct rt_device_ops rtc_core_ops =
9597
{
96-
rt_rtc_core_init,
97-
rt_rtc_core_open,
98-
rt_rtc_core_close,
98+
rt_rtc_init,
99+
rt_rtc_open,
100+
rt_rtc_close,
99101
RT_NULL,
100102
RT_NULL,
101-
rt_rtc_core_control,
103+
rt_rtc_control,
102104
};
103-
#endif
105+
#endif /* RT_USING_DEVICE_OPS */
104106

105-
rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc,
107+
rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc,
106108
const char *name,
107109
rt_uint32_t flag,
108110
void *data)
@@ -119,13 +121,13 @@ rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc,
119121
#ifdef RT_USING_DEVICE_OPS
120122
device->ops = &rtc_core_ops;
121123
#else
122-
device->init = rt_rtc_core_init;
123-
device->open = rt_rtc_core_open;
124-
device->close = rt_rtc_core_close;
124+
device->init = rt_rtc_init;
125+
device->open = rt_rtc_open;
126+
device->close = rt_rtc_close;
125127
device->read = RT_NULL;
126128
device->write = RT_NULL;
127-
device->control = rt_rtc_core_control;
128-
#endif
129+
device->control = rt_rtc_control;
130+
#endif /* RT_USING_DEVICE_OPS */
129131
device->user_data = data;
130132

131133
/* register a character device */

0 commit comments

Comments
 (0)