MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_soft_rtc_init

Function rt_soft_rtc_init

components/drivers/rtc/dev_soft_rtc.c:203–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201#endif
202
203static int rt_soft_rtc_init(void)
204{
205 static rt_bool_t init_ok = RT_FALSE;
206 struct tm time_new = SOFT_RTC_TIME_DEFAULT;
207
208 if (init_ok)
209 {
210 return 0;
211 }
212 /* make sure only one 'rtc' device */
213#if defined(RT_USING_SOFT_RTC) && defined(BSP_USING_ONCHIP_RTC)
214#warning "Please note: Currently only one RTC device is allowed in the system, and the name is "rtc"."
215#endif
216 RT_ASSERT(!rt_device_find("rtc"));
217
218#ifdef RT_USING_ALARM
219 rt_timer_init(&alarm_time,
220 "alarm",
221 alarm_timeout,
222 &soft_rtc_dev,
223 0,
224 RT_TIMER_FLAG_SOFT_TIMER|RT_TIMER_FLAG_ONE_SHOT);
225#endif
226
227 init_tick = rt_tick_get();
228 init_time = timegm(&time_new);
229
230 soft_rtc_dev.type = RT_Device_Class_RTC;
231
232 /* register rtc device */
233#ifdef RT_USING_DEVICE_OPS
234 soft_rtc_dev.ops = &soft_rtc_ops;
235#else
236 soft_rtc_dev.init = RT_NULL;
237 soft_rtc_dev.open = RT_NULL;
238 soft_rtc_dev.close = RT_NULL;
239 soft_rtc_dev.read = RT_NULL;
240 soft_rtc_dev.write = RT_NULL;
241 soft_rtc_dev.control = soft_rtc_control;
242#endif
243
244 /* no private */
245 soft_rtc_dev.user_data = RT_NULL;
246
247 rt_device_register(&soft_rtc_dev, "rtc", RT_DEVICE_FLAG_RDWR);
248
249 init_ok = RT_TRUE;
250
251 return 0;
252}
253INIT_DEVICE_EXPORT(rt_soft_rtc_init);
254
255#ifdef RT_USING_SYSTEM_WORKQUEUE

Callers

nothing calls this directly

Calls 5

rt_device_findFunction · 0.85
rt_timer_initFunction · 0.85
rt_tick_getFunction · 0.85
timegmFunction · 0.85
rt_device_registerFunction · 0.85

Tested by

no test coverage detected