Bug with clock nanoseconds

Aitor.Viana.Sanchez at esa.int Aitor.Viana.Sanchez at esa.int
Tue Mar 31 12:06:09 UTC 2009


> I repeat.  It is the responsibility of the clock tick device driver
> to reliably and correctly report the number of nanoseconds since
> the last time rtems_clock_tick was called.  If that was slightly
> greater than 1 tick ago, then it needs to return a number of nanoseconds
> slightly greater than 1 tick.

I agree but...

I think bsp_clock_nanoseconds_since_last_tick() for LEON2 and ERC32 are 
well implemented. They return the precise amount of nanoseconds since last 
tick and I dont really see the proposed workaround (see bellow)

LEON2:

uint32_t bsp_clock_nanoseconds_since_last_tick(void) {
   uint32_t clicks;

   clicks = LEON_REG.Timer_Counter_1;

   /* Down counter */
   clicks = (uint32_t) (BSP_Configuration.microseconds_per_tick - clicks) 
*
1000;

   /* if an interrupt occurred while interrupts were disabled and the
nanoseconds is too little */
   /* means that a clock interrupt occurred BEFORE the nanoseconds were
read */
   if (LEON_Is_interrupt_pending(LEON_INTERRUPT_TIMER1) && clicks <
BSP_Configuration.microseconds_per_tick / 2)
       clicks += BSP_Configuration.microseconds_per_tick * 1000;

   return clicks;
}

This implementation does not make sense without the framework of the 
_TOD_Get_uptime() function where the problem is an interrupt between 
getting _TOD_Uptime and getting nanoseconds since last tick.

Moreover, CONFIGURE_MICROSECONDS_PER_TICK  defines the RTEMS time 
granularity so I dont see the point making this ad-hoc modification in 
bsp_clock_nanoseconds_since_last_tick() function to make _TOD_Get_Uptime() 
work properly when we can do it applying this simple patch

=== modified file 'cpukit/score/src/coretodgetuptime.c'
--- cpukit/score/src/coretodgetuptime.c 2009-03-31 07:56:38 +0000
+++ cpukit/score/src/coretodgetuptime.c 2009-03-31 11:58:51 +0000
@@ -46,8 +46,8 @@

   _ISR_Disable( level );
     *uptime = _TOD_Uptime;
-    if ( _Watchdog_Nanoseconds_since_tick_handler )
-      offset.tv_nsec = (*_Watchdog_Nanoseconds_since_tick_handler)();
+//    if ( _Watchdog_Nanoseconds_since_tick_handler )
+//      offset.tv_nsec = (*_Watchdog_Nanoseconds_since_tick_handler)();

   _ISR_Enable( level );

loosing no resolution.

BTW this patch is tested and working.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20090331/f4793660/attachment-0001.html>


More information about the users mailing list