[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
endianness : Re: timer.c and ckinit.c Re: Timer resolution et al : Read_timer()
- Date: Sat, 13 Mar 2004 01:36:07 -0800 (PST)
- From: svasn_rtems at yahoo.com (sashti srinivasan)
- Subject: endianness : Re: timer.c and ckinit.c Re: Timer resolution et al : Read_timer()
--- Adrian Bocaniciu <a.bocaniciu at computer.org> wrote:
> today I have looked at the sources of RTEMS 4.6.0 so
> now I know what you
> were asking about.
> The file
> contains the RTEMS clock driver, that initializes
> correctly the 8254 PIT
> to generate an interrupt that will call
> "rtems_clock_tick()" every
> As you can see in the code, the frequency of 8254
> interrupts can be
> "Clock_isrs_per_tick" times higher than the
> frequency of the ticks, but
> that variable is initialized to "1", so normally the
> two frequencies
> will be the same.
> 8254 is initialized in mode 2 (TIMER_RATEGEN),
> in this mode if you
> initially load the timer with N, it will count in
> the sequence N, N-1,
> N-2, ... 3, 2, 1, N, N-1 ... which has the period N
> and generates
> interrupts at the transition from 1 to N, so the
> count of clock periods
> from last interrupt is N-(value read from timer 0).
> In my last message
> I wrote a mistake, timer 0 is indeed the one that
> generates the
> interrupts, so the code is correct.
> In conclusion, if you just want to measure precisely
> some time interval,
> it is enough to get the number of RTEMS ticks and to
> also read timer 0
> before and after whatever you want to measure.
> However the following
> precautions must be observed: you must first get the
> ticks, then read
> 8254, then get again the ticks and check if the
> ticks have been
> incremented, otherwise you may obtain inconsistent
> values. Also, when
> reading 8254, you must write first to it the timer
> latch command, to
> freeze the value that will be read. See the 8254
> datasheet at
> The file
> two sections, only one of each is compiled
> conditionally, depending if
> "pentium" is defined or not. The function "rdtsc"
> that you previously
> asked about is in the "pentium" section, so it is
> not used on older CPU's.
> When using 8254, for 386/486, Ttimer_val is
> incremented by each
> interrupt in the assembler file
> Because for non-Pentium CPU's the file "timer.c"
> reinitializes 8254
> differently than "ckinit.c" and with a different
> ISR, these two modules
> cannot be used simultaneously. I suggest that
> instead of using
> "timer.c" you should copy the procedure "Read_timer"
> from line 260 in
> file timer.c (the non-Pentium version) in a source
> file of your own,
> that you should link with your tests. Then you
> should replace in it
> "US_PER_ISR" with
> "BSP_Configuration.microseconds_per_tick" and
> "Ttimer_val" with "_Watchdog_Ticks_since_boot".
> Pay attention to the fact that "Read_timer", as
> written in "timer.c"
> works right ONLY if it is called with the interrupts
> Otherwise you should do as I have written above and
> _Watchdog_Ticks_since_boot both before and after
> reading 8254 and
> compare the values for equality and correct the
> values, if necessary
> (usually it is easier to read the time once more
> than to figure how to
> correct the values).
> Best regards !
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam