Skip to content

Commit e67c63c

Browse files
committed
Fix linux timer for longer timeouts
The linux timer did not work for timeouts >= 1 second. The tv_nsec timespec member must be in the range 0 - 999 999 999. Change-Id: I0dda046adb345efcca52250071e939ce82baf975
1 parent 61f538e commit e67c63c

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/linux/osal.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,12 @@ void os_timer_set (os_timer_t * timer, uint32_t us)
545545
void os_timer_start (os_timer_t * timer)
546546
{
547547
struct itimerspec its;
548+
uint32_t sec = timer->us / (1000 * 1000);
549+
uint32_t us = timer->us - sec * 1000 * 1000;
548550

549551
/* Start timer */
550-
its.it_value.tv_sec = 0;
551-
its.it_value.tv_nsec = 1000 * timer->us;
552+
its.it_value.tv_sec = sec;
553+
its.it_value.tv_nsec = 1000 * us;
552554
its.it_interval.tv_sec = (timer->oneshot) ? 0 : its.it_value.tv_sec;
553555
its.it_interval.tv_nsec = (timer->oneshot) ? 0 : its.it_value.tv_nsec;
554556
timer_settime (timer->timerid, 0, &its, NULL);

0 commit comments

Comments
 (0)