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

Function soft_rtc_control

components/drivers/rtc/dev_soft_rtc.c:84–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
85{
86 time_t *t;
87 struct tm time_temp;
88
89 RT_ASSERT(dev != RT_NULL);
90 rt_memset(&time_temp, 0, sizeof(struct tm));
91
92 switch (cmd)
93 {
94 case RT_DEVICE_CTRL_RTC_GET_TIME:
95 {
96 t = (time_t *) args;
97 *t = init_time + (rt_tick_get() - init_tick) / RT_TICK_PER_SECOND;
98 break;
99 }
100 case RT_DEVICE_CTRL_RTC_SET_TIME:
101 {
102 t = (time_t *) args;
103 set_rtc_time(*t);
104 break;
105 }
106#ifdef RT_USING_ALARM
107 case RT_DEVICE_CTRL_RTC_GET_ALARM:
108 *((struct rt_rtc_wkalarm *)args) = wkalarm;
109 break;
110 case RT_DEVICE_CTRL_RTC_SET_ALARM:
111 wkalarm = *((struct rt_rtc_wkalarm *)args);
112 soft_rtc_alarm_update(&wkalarm);
113 break;
114#endif
115#ifdef RT_USING_KTIME
116 case RT_DEVICE_CTRL_RTC_GET_TIMEVAL:
117 {
118 struct timeval _tv;
119 struct timeval *tv = (struct timeval *)args;
120 rt_ktime_boottime_get_us(&_tv);
121 tv->tv_sec = init_time + _tv.tv_sec;
122 tv->tv_usec = init_tv.tv_usec + _tv.tv_usec;
123 break;
124 }
125 case RT_DEVICE_CTRL_RTC_SET_TIMEVAL:
126 {
127 struct timeval _tv;
128 struct timeval *tv = (struct timeval *)args;
129 rt_ktime_boottime_get_us(&_tv);
130 set_rtc_time(tv->tv_sec);
131 init_tv.tv_usec = tv->tv_usec - _tv.tv_usec;
132 break;
133 }
134 case RT_DEVICE_CTRL_RTC_GET_TIMESPEC:
135 {
136 struct timespec _ts;
137 struct timespec *ts = (struct timespec *)args;
138 rt_ktime_boottime_get_ns(&_ts);
139 ts->tv_sec = init_time + _ts.tv_sec;
140 ts->tv_nsec = init_ts.tv_nsec + _ts.tv_nsec;
141 break;

Callers

nothing calls this directly

Calls 7

rt_memsetFunction · 0.85
rt_tick_getFunction · 0.85
set_rtc_timeFunction · 0.85
rt_ktime_boottime_get_usFunction · 0.85
rt_ktime_boottime_get_nsFunction · 0.85
soft_rtc_alarm_updateFunction · 0.70
rt_ktime_cputimer_getresFunction · 0.50

Tested by

no test coverage detected