[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Timer resolution et al : Implementation of Read_timer()
- Date: Fri, 12 Mar 2004 20:46:53 +0100
- From: gregmatu at poczta.onet.pl (Gregory Matus)
- Subject: Timer resolution et al : Implementation of Read_timer()
Hello all,
Thursday, March 11, 2004, sashti wrote:
> 8254 offers facility to read the current value of
> counter at any time. In the clock driver, the global
> variable,
> rtems_unsigned32 Clock_driver_ticks
> is used for counting each clock tick. This and the
> current snapshot of counter0 can together be used to
> measure with 1 microsecond accuracy. Will it be
> correct to do so?
I think that it is possible (and even simple) to implement new_read_timer
function as part of clock driver. I imagine it as follows:
struct tt { uint ticks;
uint usecs };
microseconds_per_isr should be static and global in ckinit.c;
new_read_timer (struct tt *arg) is
disable_interrupts;
latch_timer0;
temp_timer0_ticks = read and store (latched) msb,lsb values from
timer0's counter (like in read_timer), it ;
temp_clock_ticks = Clock_driver_ticks;
clock_isr_passed = Clock_isrs_per_tick - Clock_isrs;
enable_interrupts;
arg->ticks = temp_clock_ticks;
arg->usecs = clock_isr_passed * mikroseconds_per_isr
+ TICK_TO_MICROSECOND(temp_timer0_ticks);
end new_read_timer;
There is no need for timer_init but new_read_timer should be
called instead of the former. The difference between the first and
last call gives us passed time. User should take care when the value
from second call is less then from first it means that
clock_driver_ticks wraped around (typicaly after 2^32*10msec = 497days)
What do you think about the idea? Is it right or do I missed anything?
> With Regards
> Srinivasan
--
Gregory