* @brief Sets expiration time of per-process timer. * * See IEEE 1003.1 */
| 1160 | * See IEEE 1003.1 |
| 1161 | */ |
| 1162 | int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, |
| 1163 | struct itimerspec *ovalue) |
| 1164 | { |
| 1165 | struct timespec ts = {0}; |
| 1166 | rt_err_t err = RT_EOK; |
| 1167 | |
| 1168 | struct timer_obj *timer; |
| 1169 | timer = _g_timerid[(rt_ubase_t)timerid]; |
| 1170 | if (timer == NULL || |
| 1171 | value->it_interval.tv_nsec < 0 || |
| 1172 | value->it_interval.tv_nsec >= NANOSECOND_PER_SECOND || |
| 1173 | value->it_interval.tv_sec < 0 || |
| 1174 | value->it_value.tv_nsec < 0 || |
| 1175 | value->it_value.tv_nsec >= NANOSECOND_PER_SECOND || |
| 1176 | value->it_value.tv_sec < 0) |
| 1177 | { |
| 1178 | rt_set_errno(EINVAL); |
| 1179 | return -1; |
| 1180 | } |
| 1181 | |
| 1182 | /* Save time to expire and old reload value. */ |
| 1183 | if (ovalue != NULL) |
| 1184 | { |
| 1185 | timer_gettime(timerid, ovalue); |
| 1186 | } |
| 1187 | |
| 1188 | /* Stop the timer if the value is 0 */ |
| 1189 | if ((value->it_value.tv_sec == 0) && (value->it_value.tv_nsec == 0)) |
| 1190 | { |
| 1191 | if (timer->status == ACTIVE) |
| 1192 | { |
| 1193 | rt_ktime_hrtimer_stop(&timer->hrtimer); |
| 1194 | } |
| 1195 | |
| 1196 | timer->status = NOT_ACTIVE; |
| 1197 | return 0; |
| 1198 | } |
| 1199 | |
| 1200 | switch (timer->clockid) |
| 1201 | { |
| 1202 | #ifdef RT_USING_RTC |
| 1203 | case CLOCK_REALTIME: |
| 1204 | case CLOCK_REALTIME_ALARM: |
| 1205 | if (flags & TIMER_ABSTIME) |
| 1206 | err = _control_rtc(RT_DEVICE_CTRL_RTC_GET_TIMESPEC, &ts); |
| 1207 | break; |
| 1208 | #endif /* RT_USING_RTC */ |
| 1209 | case CLOCK_MONOTONIC: |
| 1210 | case CLOCK_BOOTTIME: |
| 1211 | case CLOCK_BOOTTIME_ALARM: |
| 1212 | case CLOCK_PROCESS_CPUTIME_ID: |
| 1213 | case CLOCK_THREAD_CPUTIME_ID: |
| 1214 | if (flags & TIMER_ABSTIME) |
| 1215 | err = rt_ktime_boottime_get_ns(&ts); |
| 1216 | break; |
| 1217 | default: |
| 1218 | rt_set_errno(EINVAL); |
| 1219 | return -1; |
no test coverage detected