[Bug 1748] LEON nanoseconds skipping back when called during timer tick

bugzilla-daemon at rtems.org bugzilla-daemon at rtems.org
Thu Mar 3 16:04:58 UTC 2011


https://www.rtems.org/bugzilla/show_bug.cgi?id=1748

--- Comment #4 from Rolf Schroedter <rolf.schroedter at dlr.de> 2011-03-03 10:04:58 CST ---
My feeling is that your patch might not work in one cases.
Namely, if the read the counter =0, and only then the counter overruns.
The you would return 1000+1000 usecs, while 1000 usec would be correct.

I think, you must reread the COUNTER register, if an interrupt is pending,
because you don't know whether you have read it *before* or *after* the COUNTER
overrun !

Or express in pseudo-code:

// Disable interrupts.
// Read the counter:
disable_interrupts();
clicks = COUNTER_REG;

// Check whether an interrupt is pending after the read.
if interrupt_pending()
{
    // If yes: we re-read the counter and add the missing tick.
    // Note the counter counts backwards.
    clicks = COUNTER_REG;
    usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks);
}
else {
    // If not: okay, we can use the counter, it was definitely correct.
    // Note the counter counts backwards.
    usecs = (rtems_configuration_get_microseconds_per_tick() - clicks);    
}

// enable interrupts and return nanoseconds
enable_interrupts();
return nanosecs = usecs*1000;

-- 
Configure bugmail: https://www.rtems.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.



More information about the bugs mailing list