* @brief Get amount of time left for expiration on a per-process timer. * * See IEEE 1003.1 */
| 1113 | * See IEEE 1003.1 |
| 1114 | */ |
| 1115 | int 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 | } |
| 1155 | RTM_EXPORT(timer_gettime); |
| 1156 | |
| 1157 | /** |
no test coverage detected