Current Time in an interrupt handler?

How does one obtain the current time while in an interrupt handler?

  • Richard

Brown, Richard <brownr@aecl.ca> wrote:

How does one obtain the current time while in an interrupt handler?

How accurate do you need it? Why do you need it in an ISR?

One “trick” would be to simply snapshot it periodically into a global
variable… :slight_smile:

-RK


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.

Our policy is to timestamp data at the time of reception. So if we have data
being gathered via an ISR we would like to timestamp that data as close to
the actual time it was obtained. If we wait until outside the ISR then we
could potentially be preempted and the accuracy of the timestamping would be
lost.

Reading the safety notes on clock_gettime I see that its not interrupt safe.
Could one wrap this function around calls to disable/enable interrupts to
make it interrupt safe? What exactly does interrupt safe mean for this
function? I tried to find the code for this function but I didn’t see it
posed in CVS.

“Robert Krten” <nospam90@parse.com> wrote in message
news:a4j0o2$283$1@inn.qnx.com

Brown, Richard <> brownr@aecl.ca> > wrote:
How does one obtain the current time while in an interrupt handler?

How accurate do you need it? Why do you need it in an ISR?

One “trick” would be to simply snapshot it periodically into a global
variable… > :slight_smile:

-RK


\

Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at > www.parse.com> .
Email my initials at parse dot com.

“Brown, Richard” <brownr@aecl.ca> wrote in message
news:a4j4fs$59b$1@inn.qnx.com

Our policy is to timestamp data at the time of reception. So if we have
data
being gathered via an ISR we would like to timestamp that data as close to
the actual time it was obtained. If we wait until outside the ISR then we
could potentially be preempted and the accuracy of the timestamping would
be
lost.

Reading the safety notes on clock_gettime I see that its not interrupt
safe.
Could one wrap this function around calls to disable/enable interrupts to
make it interrupt safe? What exactly does interrupt safe mean for this
function?

I means it cannot be called from within an interrupt. Even if it could
clock_gettime is limited the resolution of ticksize (1ms), not very precise
to time stamp stuff in a ISR.

I tried to find the code for this function but I didn’t see it
posed in CVS.

You could use ClockCycles() if processor is Pentium or above.
That 's VERY precise, down to the CPU clock frequency.

or

SYSPAGE_ENTRY(qtime)->nsec (resolution is the ticksize)

“Robert Krten” <> nospam90@parse.com> > wrote in message
news:a4j0o2$283$> 1@inn.qnx.com> …
Brown, Richard <> brownr@aecl.ca> > wrote:
How does one obtain the current time while in an interrupt handler?

How accurate do you need it? Why do you need it in an ISR?

One “trick” would be to simply snapshot it periodically into a global
variable… > :slight_smile:

-RK


\

Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at > www.parse.com> .
Email my initials at parse dot com.

Accidentally,I find this topic.
I am interested with this topic ,because my program needs “Current Time in
an interrupt handler”.
So I want to continue discussing.
Up to now,I haven’t find a appropriate method to get current time in an
interrupt handler,

I see what
“Mario Charest” <goto@nothingness.com>
wrote in message news:a4j5nj$5v4$1@inn.qnx.com

You could use ClockCycles() if processor is Pentium or above.
That 's VERY precise, down to the CPU clock frequency.
or
SYSPAGE_ENTRY(qtime)->nsec (resolution is the ticksize)

I have seen the doc about ClockCycles().As if it is not Current “time”,but
current value of a free-running 64-bit cycle counter.
To the SYSPAGE_ENTRY(qtime)->nsec (resolution is the ticksize),I don’t know
what the concept " ticksize".

In a word ,whether I need some convert the ClockCycles() or
SYSPAGE_ENTRY(qtime)->nsec to get current time.
The time accurate I wish is at least 1ms .How could I do?

Thanks

Hongzhi Zhang

Brown, Richard <brownr@aecl.ca> wrote:

How does one obtain the current time while in an interrupt handler?

The syspage entry for qtime has the current system time in it. Take
a look at struct qtime_entry in <sys/sypage.h>. I’m not sure which
values are added together to get the current time – likely it is
nsec + nsec_tod_adjust, but I’m not positive. A bit of experimentation
should allow you to figure this out.

The syspage should be accessible from an irq handler, since it is
in the address space of your process.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.