Skip to content

Commit 94a9332

Browse files
committed
[rtc] 移除rtc_core.c/.h 将内容转移到rtc.c/.h
1 parent 9e47b95 commit 94a9332

File tree

6 files changed

+156
-215
lines changed

6 files changed

+156
-215
lines changed

bsp/efm32/drv_rtc.c

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -128,49 +128,6 @@ void rt_hw_rtc_isr(rt_device_t device)
128128
RTC->IFC = _RTC_IFC_MASK;
129129
}
130130

131-
/***************************************************************************//**
132-
* @brief
133-
* Register RTC device
134-
*
135-
* @details
136-
*
137-
* @note
138-
*
139-
* @param[in] device
140-
* Pointer to device descriptor
141-
*
142-
* @param[in] name
143-
* Device name
144-
*
145-
* @param[in] flag
146-
* Configuration flags
147-
*
148-
* @return
149-
* Error code
150-
******************************************************************************/
151-
rt_err_t rt_hw_rtc_register(
152-
rt_device_t device,
153-
const char *name,
154-
rt_uint32_t flag)
155-
{
156-
RT_ASSERT(device != RT_NULL);
157-
158-
device->type = RT_Device_Class_RTC;
159-
device->rx_indicate = RT_NULL;
160-
device->tx_complete = RT_NULL;
161-
device->init = RT_NULL;
162-
device->open = rt_rtc_open;
163-
device->close = RT_NULL;
164-
device->read = rt_rtc_read;
165-
device->write = RT_NULL;
166-
device->control = rt_rtc_control;
167-
device->user_data = RT_NULL; /* no private */
168-
169-
/* register a character device */
170-
return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR | flag);
171-
}
172-
173-
174131
/***************************************************************************//**
175132
* @brief
176133
* Initialize all RTC module related hardware and register RTC device to kernel
@@ -224,7 +181,18 @@ void rt_hw_rtc_init(void)
224181
}
225182

226183
/* register rtc device */
227-
rt_hw_rtc_register(&rtc, RT_RTC_NAME, EFM32_NO_DATA);
184+
rtc.type = RT_Device_Class_RTC;
185+
rtc.rx_indicate = RT_NULL;
186+
rtc.tx_complete = RT_NULL;
187+
rtc.init = RT_NULL;
188+
rtc.open = rt_rtc_open;
189+
rtc.close = RT_NULL;
190+
rtc.read = rt_rtc_read;
191+
rtc.write = RT_NULL;
192+
rtc.control = rt_rtc_control;
193+
rtc.user_data = RT_NULL; /* no private */
194+
195+
rt_device_register(&rtc, RT_RTC_NAME, RT_DEVICE_FLAG_RDWR | EFM32_NO_DATA);
228196
}
229197

230198
#endif

components/drivers/include/drivers/rtc.h

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,42 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2012-10-10 aozima first version.
9+
* 2021-06-11 iysheng implement RTC v2.0
910
*/
1011

1112
#ifndef __RTC_H__
1213
#define __RTC_H__
1314

14-
#include <rtconfig.h>
15-
#include <drivers/rtc_core.h>
15+
#include <rtdef.h>
16+
17+
#define RT_DEVICE_CTRL_RTC_GET_TIME 0x10 /**< get second time */
18+
#define RT_DEVICE_CTRL_RTC_SET_TIME 0x11 /**< set second time */
19+
#define RT_DEVICE_CTRL_RTC_GET_TIME_US 0x12 /**< get microsecond time */
20+
#define RT_DEVICE_CTRL_RTC_SET_TIME_US 0x13 /**< set microsecond time */
21+
#define RT_DEVICE_CTRL_RTC_GET_ALARM 0x14 /**< get alarm */
22+
#define RT_DEVICE_CTRL_RTC_SET_ALARM 0x15 /**< set alarm */
23+
24+
struct rt_rtc_ops
25+
{
26+
rt_err_t (*init)(void);
27+
rt_err_t (*get_secs)(void *arg);
28+
rt_err_t (*set_secs)(void *arg);
29+
rt_err_t (*get_alarm)(void *arg);
30+
rt_err_t (*set_alarm)(void *arg);
31+
rt_err_t (*get_usecs)(void *arg);
32+
rt_err_t (*set_usecs)(void *arg);
33+
};
34+
35+
typedef struct rt_rtc_device
36+
{
37+
struct rt_device parent;
38+
const struct rt_rtc_ops *ops;
39+
} rt_rtc_dev_t;
40+
41+
rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc,
42+
const char *name,
43+
rt_uint32_t flag,
44+
void *data);
1645

1746
rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day);
1847
rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second);

components/drivers/include/drivers/rtc_core.h

Lines changed: 0 additions & 45 deletions
This file was deleted.

components/drivers/rtc/SConscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CPPPATH = [cwd + '/../include']
77
group = []
88

99
if GetDepend(['RT_USING_RTC']):
10-
src = src + ['rtc.c', 'rtc_core.c']
10+
src = src + ['rtc.c']
1111
if GetDepend(['RT_USING_ALARM']):
1212
src = src + ['alarm.c']
1313
if GetDepend(['RT_USING_SOFT_RTC']):

components/drivers/rtc/rtc.c

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
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
1314
*/
1415

1516
#include <time.h>
@@ -20,6 +21,117 @@
2021

2122
#ifdef RT_USING_RTC
2223

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+
27+
/*
28+
* This function initializes rtc_core
29+
*/
30+
static rt_err_t rt_rtc_core_init(struct rt_device *dev)
31+
{
32+
rt_rtc_dev_t *rtc_core;
33+
34+
RT_ASSERT(dev != RT_NULL);
35+
rtc_core = (rt_rtc_dev_t *)dev;
36+
if (rtc_core->ops->init)
37+
{
38+
return (rtc_core->ops->init());
39+
}
40+
41+
return (-RT_ENOSYS);
42+
}
43+
44+
static rt_err_t rt_rtc_core_open(struct rt_device *dev, rt_uint16_t oflag)
45+
{
46+
return (RT_EOK);
47+
}
48+
49+
static rt_err_t rt_rtc_core_close(struct rt_device *dev)
50+
{
51+
/* Add close member function in rt_rtc_ops when need,
52+
* then call that function here.
53+
* */
54+
return (RT_EOK);
55+
}
56+
57+
static rt_err_t rt_rtc_core_control(struct rt_device *dev,
58+
int cmd,
59+
void *args)
60+
{
61+
rt_rtc_dev_t *rtc_core;
62+
rt_err_t ret = -RT_EINVAL;
63+
64+
RT_ASSERT(dev != RT_NULL);
65+
rtc_core = (rt_rtc_dev_t *)dev;
66+
67+
switch (cmd)
68+
{
69+
case RT_DEVICE_CTRL_RTC_GET_TIME:
70+
ret = TRY_DO_RTC_FUNC(rtc_core, get_secs, args);
71+
break;
72+
case RT_DEVICE_CTRL_RTC_SET_TIME:
73+
ret = TRY_DO_RTC_FUNC(rtc_core, set_secs, args);
74+
break;
75+
case RT_DEVICE_CTRL_RTC_GET_TIME_US:
76+
ret = TRY_DO_RTC_FUNC(rtc_core, get_usecs, args);
77+
break;
78+
case RT_DEVICE_CTRL_RTC_SET_TIME_US:
79+
ret = TRY_DO_RTC_FUNC(rtc_core, set_usecs, args);
80+
break;
81+
case RT_DEVICE_CTRL_RTC_GET_ALARM:
82+
ret = TRY_DO_RTC_FUNC(rtc_core, get_alarm, args);
83+
break;
84+
case RT_DEVICE_CTRL_RTC_SET_ALARM:
85+
ret = TRY_DO_RTC_FUNC(rtc_core, set_alarm, args);
86+
break;
87+
default:
88+
break;
89+
}
90+
91+
return ret;
92+
}
93+
#ifdef RT_USING_DEVICE_OPS
94+
const static struct rt_device_ops rtc_core_ops =
95+
{
96+
rt_rtc_core_init,
97+
rt_rtc_core_open,
98+
rt_rtc_core_close,
99+
RT_NULL,
100+
RT_NULL,
101+
rt_rtc_core_control,
102+
};
103+
#endif
104+
105+
rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc,
106+
const char *name,
107+
rt_uint32_t flag,
108+
void *data)
109+
{
110+
struct rt_device *device;
111+
RT_ASSERT(rtc != RT_NULL);
112+
113+
device = &(rtc->parent);
114+
115+
device->type = RT_Device_Class_RTC;
116+
device->rx_indicate = RT_NULL;
117+
device->tx_complete = RT_NULL;
118+
119+
#ifdef RT_USING_DEVICE_OPS
120+
device->ops = &rtc_core_ops;
121+
#else
122+
device->init = rt_rtc_core_init;
123+
device->open = rt_rtc_core_open;
124+
device->close = rt_rtc_core_close;
125+
device->read = RT_NULL;
126+
device->write = RT_NULL;
127+
device->control = rt_rtc_core_control;
128+
#endif
129+
device->user_data = data;
130+
131+
/* register a character device */
132+
return rt_device_register(device, name, flag);
133+
}
134+
23135
/**
24136
* Set system date(time not modify, local timezone).
25137
*

0 commit comments

Comments
 (0)