Skip to content

Commit 5409cee

Browse files
committed
[bsp][bluetrum] Fixed RTC driver building errors
1 parent 1e72902 commit 5409cee

File tree

1 file changed

+24
-107
lines changed

1 file changed

+24
-107
lines changed

bsp/bluetrum/libraries/hal_drivers/drv_rtc.c

Lines changed: 24 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -144,151 +144,68 @@ void hal_rtc_init(void)
144144
}
145145
/************** HAL End *******************/
146146

147-
static time_t get_rtc_time_stamp(void)
147+
static rt_err_t ab32_rtc_get_secs(void *args)
148148
{
149-
time_t sec = 0;
150-
151-
sec = irtc_time_read(RTCCNT_CMD);
152-
LOG_D("get rtc time.");
149+
*(rt_uint32_t *)args = irtc_time_read(RTCCNT_CMD);
150+
LOG_D("RTC: get rtc_time %x\n", *(rt_uint32_t *)args);
153151

154-
return sec;
152+
return RT_EOK;
155153
}
156154

157-
static rt_err_t set_rtc_time_stamp(time_t time_stamp)
155+
static rt_err_t ab32_rtc_set_secs(void *args)
158156
{
159-
irtc_time_write(RTCCNT_CMD, time_stamp);
157+
irtc_time_write(RTCCNT_CMD, *(rt_uint32_t *)args);
160158

161159
return RT_EOK;
162160
}
163161

164-
static rt_err_t set_rtc_alarm_stamp(time_t alarm_stamp)
162+
static rt_err_t ab32_rtc_get_alarm(void *args)
165163
{
166-
irtc_time_write(RTCALM_CMD, alarm_stamp);
164+
*(rt_uint32_t *)args = irtc_time_read(RTCALM_CMD);
167165

168166
return RT_EOK;
169167
}
170168

171-
static time_t get_rtc_alarm_stamp(void)
169+
static rt_err_t ab32_rtc_set_alarm(void *args)
172170
{
173-
time_t sec = 0;
174-
175-
sec = irtc_time_read(RTCALM_CMD);
171+
irtc_time_write(RTCALM_CMD, *(rt_uint32_t *)args);
176172

177-
return sec;
173+
return RT_EOK;
178174
}
179175

180-
static void rt_rtc_init(void)
176+
static rt_err_t ab32_rtc_init(void)
181177
{
182178
hal_rtc_init();
183-
}
184-
185-
static rt_err_t ab32_rtc_control(rt_device_t dev, int cmd, void *args)
186-
{
187-
rt_err_t result = RT_EOK;
188-
RT_ASSERT(dev != RT_NULL);
189-
switch (cmd)
190-
{
191-
case RT_DEVICE_CTRL_RTC_GET_TIME:
192-
*(time_t *)args = get_rtc_time_stamp();
193-
LOG_D("RTC: get rtc_time %x", *(time_t *)args);
194-
break;
195-
196-
case RT_DEVICE_CTRL_RTC_SET_TIME:
197-
if (set_rtc_time_stamp(*(time_t *)args))
198-
{
199-
result = -RT_ERROR;
200-
}
201-
LOG_D("RTC: set rtc_time %x", *(time_t *)args);
202-
break;
203-
case RT_DEVICE_CTRL_RTC_SET_ALARM:
204-
if (set_rtc_alarm_stamp(*(time_t *)args))
205-
{
206-
result = -RT_ERROR;
207-
}
208-
LOG_D("RTC: set alarm_stamp %x", *(time_t *)args);
209-
break;
210-
case RT_DEVICE_CTRL_RTC_GET_ALARM:
211-
*(time_t *)args = get_rtc_alarm_stamp();
212-
LOG_D("RTC: get alarm_stamp %x", *(time_t *)args);
213-
break;
214-
}
215179

216-
return result;
180+
return RT_EOK;
217181
}
218182

219-
#ifdef RT_USING_DEVICE_OPS
220-
const static struct rt_device_ops rtc_ops =
183+
static const struct rt_rtc_ops ab32_rtc_ops =
221184
{
185+
ab32_rtc_init,
186+
ab32_rtc_get_secs,
187+
ab32_rtc_set_secs,
188+
ab32_rtc_get_alarm,
189+
ab32_rtc_set_alarm,
222190
RT_NULL,
223191
RT_NULL,
224-
RT_NULL,
225-
RT_NULL,
226-
RT_NULL,
227-
ab32_rtc_control
228192
};
229-
#endif
230-
231-
static rt_err_t rt_hw_rtc_register(rt_device_t device, const char *name, rt_uint32_t flag)
232-
{
233-
RT_ASSERT(device != RT_NULL);
234-
235-
rt_rtc_init();
236-
#ifdef RT_USING_DEVICE_OPS
237-
device->ops = &rtc_ops;
238-
#else
239-
device->init = RT_NULL;
240-
device->open = RT_NULL;
241-
device->close = RT_NULL;
242-
device->read = RT_NULL;
243-
device->write = RT_NULL;
244-
device->control = ab32_rtc_control;
245-
#endif
246-
device->type = RT_Device_Class_RTC;
247-
device->rx_indicate = RT_NULL;
248-
device->tx_complete = RT_NULL;
249-
device->user_data = RT_NULL;
250-
251-
/* register a character device */
252-
return rt_device_register(device, name, flag);
253-
}
254-
255-
#ifdef RT_USING_ALARM
256-
RT_SECTION(".irq.rtc")
257-
static void rtc_isr(int vector, void *param)
258-
{
259-
rt_interrupt_enter();
260-
261-
if (RTCCON & RTC_CON_ALM_PEND)
262-
{
263-
RTCCPND |= RTC_CPND_ALM;
264-
}
265-
266-
#ifdef RTC_USING_1S_INT
267-
if (RTCCON & RTC_CON_1S_PEND)
268-
{
269-
RTCCPND |= RTC_CPND_1S;
270-
}
271-
#endif
272193

273-
rt_interrupt_leave();
274-
}
275-
#endif
194+
static rt_rtc_dev_t ab32_rtc_dev;
276195

277-
int rt_hw_rtc_init(void)
196+
static int rt_hw_rtc_init(void)
278197
{
279198
rt_err_t result;
280199

281-
result = rt_hw_rtc_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR);
200+
ab32_rtc_dev.ops = &ab32_rtc_ops;
201+
result = rt_hw_rtc_register(&ab32_rtc_dev, "rtc", RT_DEVICE_FLAG_RDWR, RT_NULL);
282202
if (result != RT_EOK)
283203
{
284204
LOG_E("rtc register err code: %d", result);
285205
return result;
286206
}
287-
288-
#ifdef RT_USING_ALARM
289-
rt_hw_interrupt_install(IRQ_RTC_VECTOR, rtc_isr, RT_NULL, "rtc_isr");
290-
#endif
291207
LOG_D("rtc init success");
208+
292209
return RT_EOK;
293210
}
294211
INIT_DEVICE_EXPORT(rt_hw_rtc_init);

0 commit comments

Comments
 (0)