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

Function timer_gettime

components/libc/compilers/common/ctime.c:1115–1154  ·  view source on GitHub ↗

* @brief Get amount of time left for expiration on a per-process timer. * * See IEEE 1003.1 */

Source from the content-addressed store, hash-verified

1113 * See IEEE 1003.1
1114 */
1115int timer_gettime(timer_t timerid, struct itimerspec *its)
1116{
1117 struct timer_obj *timer;
1118 rt_uint32_t seconds, nanoseconds;
1119
1120 timer = _g_timerid[(rt_ubase_t)timerid];
1121
1122 if (timer == NULL)
1123 {
1124 rt_set_errno(EINVAL);
1125 return -1;
1126 }
1127
1128 if (its == NULL)
1129 {
1130 rt_set_errno(EFAULT);
1131 return -1;
1132 }
1133
1134 if (timer->status == ACTIVE)
1135 {
1136 unsigned long remain_cnt;
1137 rt_ktime_hrtimer_control(&timer->hrtimer, RT_TIMER_CTRL_GET_REMAIN_TIME, &remain_cnt);
1138 nanoseconds = ((remain_cnt - rt_ktime_cputimer_getcnt()) * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL;
1139 seconds = nanoseconds / NANOSECOND_PER_SECOND;
1140 nanoseconds = nanoseconds % NANOSECOND_PER_SECOND;
1141 its->it_value.tv_sec = (rt_int32_t)seconds;
1142 its->it_value.tv_nsec = (rt_int32_t)nanoseconds;
1143 }
1144 else
1145 {
1146 /* Timer is disarmed */
1147 its->it_value.tv_sec = 0;
1148 its->it_value.tv_nsec = 0;
1149 }
1150
1151 /* The interval last set by timer_settime() */
1152 its->it_interval = timer->interval;
1153 return 0;
1154}
1155RTM_EXPORT(timer_gettime);
1156
1157/**

Callers 2

sys_timer_gettimeFunction · 0.85
timer_settimeFunction · 0.85

Calls 4

rt_set_errnoFunction · 0.85
rt_ktime_hrtimer_controlFunction · 0.85
rt_ktime_cputimer_getcntFunction · 0.50
rt_ktime_cputimer_getresFunction · 0.50

Tested by

no test coverage detected