timer connection: fix division by null

When synchronizing with the remote time source, we have to take care that the
measured time difference cannot become null because its real value is smaller
than the measurement granularity. Since the granularity is one microsecond, we
simply go on polling timestamp and time until the microsecond has passed.
This busy waiting should be no problem for the system for two reasons. First,
it is limited to a relatively small amount of time and second, a busy lock
does not happen because the time source that is responsible for the limiting
factor is explicitely called on each poll.

Ref #2400
This commit is contained in:
Martin Stein 2017-08-23 13:51:25 +02:00 committed by Christian Helmuth
parent 2356128237
commit 22294d3b18
1 changed files with 7 additions and 4 deletions

View File

@ -38,13 +38,16 @@ void Timer::Connection::_update_real_time()
* reached, we take the results that has the lowest latency.
*/
for (unsigned remote_time_trials = 0;
remote_time_trials < MAX_REMOTE_TIME_TRIALS;
remote_time_trials++)
remote_time_trials < MAX_REMOTE_TIME_TRIALS; )
{
/* read out the two time values close in succession */
Timestamp volatile new_ts = _timestamp();
unsigned long volatile new_us = elapsed_us();
/* do not proceed until the time difference is at least 1 us */
if (new_us == _us) { continue; }
remote_time_trials++;
/*
* If interpolation is not ready, yet we cannot determine a latency
* and take the values as they are.
@ -144,9 +147,9 @@ void Timer::Connection::_update_real_time()
}
/*
* The cast to unsigned long does not cause a loss because of the
* limitations we applied to the timestamp difference.
* limitations we applied to the timestamp difference. We also took
* care that the time difference cannot become null.
*/
unsigned long const new_factor =
(unsigned long)((Timestamp)ts_diff_shifted / us_diff);