Can you read osdata from inside and IRQ handler?

Hi,

I’m trying to read the os time (sec, nsec) from the osdata structure. I can
do this fine in the proxy.

Is it possible to do this inside the IRQ handler? I have setup global
volatile pointers to this area.

At the moment this is crashing the OS for me. Please help.

TIA

Augie

Augie Henriques <augiehenriques@hotmail.com> wrote:

Is it possible to do this inside the IRQ handler? I have setup global
volatile pointers to this area.

How are you “reading” the time? If you’re calling time() or ctime() etc
you’ll see in the documentation that they are not interrupt safe.

You can try accessing the realtime clock through raw assembler calls or
if you’re on Pentium III you might be able to access a special register
that just increments, do some math and calulate the time.

-Adam

At the top of the file I declare…

volatile GnTime systemTime;
struct _osinfo osdata;
volatile struct _timesel far *tptr;

Inside the IRQ handler I do…

// get qnx system time
do {
systemTime.sec = tptr->seconds;
systemTime.nsec = tpr->nsec;
} while ((systemTime.sec!=tptr->seconds)||(systemTime.nsec!=tptr->nsec));


In main, I initialize these

qnx_osinfo(0, &osdata);
tptr = MK_FP(osdata.timesel, 0);

// then start the interrupt handler

Is this a problem? How do you get the current time in sec and nsec inside
the IRQ handler? I can’t read it in the proxy, by then it will be off by a
small amount of time.

TIA

Augie

“Operating System for Tech Supp” <os@qnx.com> wrote in message
news:9ntb6r$1bh$1@nntp.qnx.com

Augie Henriques <> augiehenriques@hotmail.com> > wrote:

Is it possible to do this inside the IRQ handler? I have setup global
volatile pointers to this area.

How are you “reading” the time? If you’re calling time() or ctime() etc
you’ll see in the documentation that they are not interrupt safe.

You can try accessing the realtime clock through raw assembler calls or
if you’re on Pentium III you might be able to access a special register
that just increments, do some math and calulate the time.

-Adam

“Mario Charest” <mcharest@nowayzinformatic.com> wrote in message
news:9ntiif$8pg$1@inn.qnx.com

“Augie Henriques” <> augiehenriques@hotmail.com> > wrote in message
news:9ntdp2$5v5$> 1@inn.qnx.com> …
At the top of the file I declare…

volatile GnTime systemTime;
struct _osinfo osdata;
volatile struct _timesel far *tptr;

Inside the IRQ handler I do…

// get qnx system time
do {
systemTime.sec = tptr->seconds;
systemTime.nsec = tpr->nsec;
} while
((systemTime.sec!=tptr->seconds)||(systemTime.nsec!=tptr->nsec));


Are systemTime.sec and nsec floating point?
This should work. However it would be faster to read the

Faster to read what? I hear the word “faster” and I get a smile in my face.


In main, I initialize these

qnx_osinfo(0, &osdata);
tptr = MK_FP(osdata.timesel, 0);

// then start the interrupt handler

Is this a problem? How do you get the current time in sec and nsec
inside
the IRQ handler? I can’t read it in the proxy, by then it will be off
by
a
small amount of time.


Yes but that irrelavent ( to some degree) since this time is NOT
precise to the nanosec. To get maximum precisoin use the rdtc (?)
assembly instruction

Okay, How do you do this?

Initially, I was told to use the above method.

TIA

Augie

TIA

Augie

“Operating System for Tech Supp” <> os@qnx.com> > wrote in message
news:9ntb6r$1bh$> 1@nntp.qnx.com> …
Augie Henriques <> augiehenriques@hotmail.com> > wrote:

Is it possible to do this inside the IRQ handler? I have setup
global
volatile pointers to this area.

How are you “reading” the time? If you’re calling time() or ctime()
etc
you’ll see in the documentation that they are not interrupt safe.

You can try accessing the realtime clock through raw assembler calls
or
if you’re on Pentium III you might be able to access a special
register
that just increments, do some math and calulate the time.

-Adam
\

“Mario Charest” <mcharest@nowayzinformatic.com> wrote in message
news:9ntnhr$bcu$1@inn.qnx.com

“Augie Henriques” <> augiehenriques@hotmail.com> > wrote in message
news:9ntjcr$943$> 1@inn.qnx.com> …

“Mario Charest” <> mcharest@nowayzinformatic.com> > wrote in message
news:9ntiif$8pg$> 1@inn.qnx.com> …

“Augie Henriques” <> augiehenriques@hotmail.com> > wrote in message
news:9ntdp2$5v5$> 1@inn.qnx.com> …
At the top of the file I declare…

volatile GnTime systemTime;
struct _osinfo osdata;
volatile struct _timesel far *tptr;

Inside the IRQ handler I do…

// get qnx system time
do {
systemTime.sec = tptr->seconds;
systemTime.nsec = tpr->nsec;
} while
((systemTime.sec!=tptr->seconds)||(systemTime.nsec!=tptr->nsec));


Are systemTime.sec and nsec floating point?
This should work. However it would be faster to read the

Faster to read what? I hear the word “faster” and I get a smile in my
face.

Woops sorry about that, see below.




In main, I initialize these

qnx_osinfo(0, &osdata);
tptr = MK_FP(osdata.timesel, 0);

// then start the interrupt handler

Is this a problem? How do you get the current time in sec and nsec
inside
the IRQ handler? I can’t read it in the proxy, by then it will be
off
by
a
small amount of time.


Yes but that irrelavent ( to some degree) since this time is NOT
precise to the nanosec. To get maximum precisoin use the rdtc (?)
assembly instruction

Okay, How do you do this?


The problem with rdtc is that it only works on Pentium (486 don’t have
that instructions)

Download: > ftp://ftp.qnx.com/usr/free/qnx4/os/utils/examples/Micro_time.tgz

There is a file rtdc.c (from memory) that shows how to do it.

The number read is in CPU clock unit, you must apply a scaler to convert
it into seconds but that can be done outside of the interrupt. Reading
this is faster because the CPU doesn’t to go read memory. However
if you need a apply a scaler it will be slower overall. But you’ll
get a LOT more precision!

Sorry, I’m confused. I would like to read PC system time not something
specific to the CPU? Does the CPU also keep hardware clock?

TIA

Augie

Include this:

There is and example
Initially, I was told to use the above method.

TIA

Augie


TIA

Augie

“Operating System for Tech Supp” <> os@qnx.com> > wrote in message
news:9ntb6r$1bh$> 1@nntp.qnx.com> …
Augie Henriques <> augiehenriques@hotmail.com> > wrote:

Is it possible to do this inside the IRQ handler? I have setup
global
volatile pointers to this area.

How are you “reading” the time? If you’re calling time() or
ctime()
etc
you’ll see in the documentation that they are not interrupt safe.

You can try accessing the realtime clock through raw assembler
calls
or
if you’re on Pentium III you might be able to access a special
register
that just increments, do some math and calulate the time.

-Adam




\

Previously, Augie Henriques wrote in qdn.public.qnx4:

Sorry, I’m confused. I would like to read PC system time not something
specific to the CPU? Does the CPU also keep hardware clock?

Here’s a strategy that might pay off. Consider that the PC system time
only gets updated when timer interrupt fires. Attach a handler that
wakes up your process. In the process save the current time in a
variable. In your interrupt handler, read this time. There’s a small
window of inaccuracy if your interrupt comes right after the timer
interrupt.

Mitchell Schoenbrun --------- maschoen@pobox.com

“Augie Henriques” <augiehenriques@hotmail.com> wrote in message
news:9ntdp2$5v5$1@inn.qnx.com

At the top of the file I declare…

volatile GnTime systemTime;
struct _osinfo osdata;
volatile struct _timesel far *tptr;

Inside the IRQ handler I do…

// get qnx system time
do {
systemTime.sec = tptr->seconds;
systemTime.nsec = tpr->nsec;
} while
((systemTime.sec!=tptr->seconds)||(systemTime.nsec!=tptr->nsec));

Are systemTime.sec and nsec floating point?
This should work. However it would be faster to read the

In main, I initialize these

qnx_osinfo(0, &osdata);
tptr = MK_FP(osdata.timesel, 0);

// then start the interrupt handler

Is this a problem? How do you get the current time in sec and nsec inside
the IRQ handler? I can’t read it in the proxy, by then it will be off by
a
small amount of time.

Yes but that irrelavent ( to some degree) since this time is NOT
precise to the nanosec. To get maximum precisoin use the rdtc (?)
assembly instruction


TIA

Augie

“Operating System for Tech Supp” <> os@qnx.com> > wrote in message
news:9ntb6r$1bh$> 1@nntp.qnx.com> …
Augie Henriques <> augiehenriques@hotmail.com> > wrote:

Is it possible to do this inside the IRQ handler? I have setup global
volatile pointers to this area.

How are you “reading” the time? If you’re calling time() or ctime() etc
you’ll see in the documentation that they are not interrupt safe.

You can try accessing the realtime clock through raw assembler calls or
if you’re on Pentium III you might be able to access a special register
that just increments, do some math and calulate the time.

-Adam

“Augie Henriques” <augiehenriques@hotmail.com> wrote in message
news:9ntjcr$943$1@inn.qnx.com

“Mario Charest” <> mcharest@nowayzinformatic.com> > wrote in message
news:9ntiif$8pg$> 1@inn.qnx.com> …

“Augie Henriques” <> augiehenriques@hotmail.com> > wrote in message
news:9ntdp2$5v5$> 1@inn.qnx.com> …
At the top of the file I declare…

volatile GnTime systemTime;
struct _osinfo osdata;
volatile struct _timesel far *tptr;

Inside the IRQ handler I do…

// get qnx system time
do {
systemTime.sec = tptr->seconds;
systemTime.nsec = tpr->nsec;
} while
((systemTime.sec!=tptr->seconds)||(systemTime.nsec!=tptr->nsec));


Are systemTime.sec and nsec floating point?
This should work. However it would be faster to read the

Faster to read what? I hear the word “faster” and I get a smile in my
face.

Woops sorry about that, see below.

In main, I initialize these

qnx_osinfo(0, &osdata);
tptr = MK_FP(osdata.timesel, 0);

// then start the interrupt handler

Is this a problem? How do you get the current time in sec and nsec
inside
the IRQ handler? I can’t read it in the proxy, by then it will be off
by
a
small amount of time.


Yes but that irrelavent ( to some degree) since this time is NOT
precise to the nanosec. To get maximum precisoin use the rdtc (?)
assembly instruction

Okay, How do you do this?

The problem with rdtc is that it only works on Pentium (486 don’t have
that instructions)

Download: ftp://ftp.qnx.com/usr/free/qnx4/os/utils/examples/Micro_time.tgz

There is a file rtdc.c (from memory) that shows how to do it.

The number read is in CPU clock unit, you must apply a scaler to convert
it into seconds but that can be done outside of the interrupt. Reading
this is faster because the CPU doesn’t to go read memory. However
if you need a apply a scaler it will be slower overall. But you’ll
get a LOT more precision!


Include this:

There is and example

Initially, I was told to use the above method.

TIA

Augie


TIA

Augie

“Operating System for Tech Supp” <> os@qnx.com> > wrote in message
news:9ntb6r$1bh$> 1@nntp.qnx.com> …
Augie Henriques <> augiehenriques@hotmail.com> > wrote:

Is it possible to do this inside the IRQ handler? I have setup
global
volatile pointers to this area.

How are you “reading” the time? If you’re calling time() or ctime()
etc
you’ll see in the documentation that they are not interrupt safe.

You can try accessing the realtime clock through raw assembler calls
or
if you’re on Pentium III you might be able to access a special
register
that just increments, do some math and calulate the time.

-Adam


\

“Augie Henriques” <augiehenriques@hotmail.com> wrote in message
news:9ntpo3$cl9$1@inn.qnx.com

“Mario Charest” <> mcharest@nowayzinformatic.com> > wrote in message
news:9ntnhr$bcu$> 1@inn.qnx.com> …

“Augie Henriques” <> augiehenriques@hotmail.com> > wrote in message
news:9ntjcr$943$> 1@inn.qnx.com> …

“Mario Charest” <> mcharest@nowayzinformatic.com> > wrote in message
news:9ntiif$8pg$> 1@inn.qnx.com> …

“Augie Henriques” <> augiehenriques@hotmail.com> > wrote in message
news:9ntdp2$5v5$> 1@inn.qnx.com> …
At the top of the file I declare…

volatile GnTime systemTime;
struct _osinfo osdata;
volatile struct _timesel far *tptr;

Inside the IRQ handler I do…

// get qnx system time
do {
systemTime.sec = tptr->seconds;
systemTime.nsec = tpr->nsec;
} while
((systemTime.sec!=tptr->seconds)||(systemTime.nsec!=tptr->nsec));


Are systemTime.sec and nsec floating point?
This should work. However it would be faster to read the

Faster to read what? I hear the word “faster” and I get a smile in my
face.

Woops sorry about that, see below.




In main, I initialize these

qnx_osinfo(0, &osdata);
tptr = MK_FP(osdata.timesel, 0);

// then start the interrupt handler

Is this a problem? How do you get the current time in sec and
nsec
inside
the IRQ handler? I can’t read it in the proxy, by then it will be
off
by
a
small amount of time.


Yes but that irrelavent ( to some degree) since this time is NOT
precise to the nanosec. To get maximum precisoin use the rdtc (?)
assembly instruction

Okay, How do you do this?


The problem with rdtc is that it only works on Pentium (486 don’t have
that instructions)

Download:
ftp://ftp.qnx.com/usr/free/qnx4/os/utils/examples/Micro_time.tgz

There is a file rtdc.c (from memory) that shows how to do it.

The number read is in CPU clock unit, you must apply a scaler to convert
it into seconds but that can be done outside of the interrupt. Reading
this is faster because the CPU doesn’t to go read memory. However
if you need a apply a scaler it will be slower overall. But you’ll
get a LOT more precision!


Sorry, I’m confused.

I’m to blame :wink:

I would like to read PC system time not something
specific to the CPU? Does the CPU also keep hardware clock?

When to program starts you read BOTH system time and CPU counter.
You keep both these numbers that means later by rereading the CPU
counter you are able to figure out a new time value.

((current CPU clock) - (original CPU clock) * SCALER + System TIME) = new
time

This may be overly complicated for you case.

Maybe we should get back to the original problem,
your program shouldn’t crash. Do you get a kernel crash or
only a program crash?

  • Mario

TIA

Augie


Include this:

There is and example
Initially, I was told to use the above method.

TIA

Augie


TIA

Augie

“Operating System for Tech Supp” <> os@qnx.com> > wrote in message
news:9ntb6r$1bh$> 1@nntp.qnx.com> …
Augie Henriques <> augiehenriques@hotmail.com> > wrote:

Is it possible to do this inside the IRQ handler? I have
setup
global
volatile pointers to this area.

How are you “reading” the time? If you’re calling time() or
ctime()
etc
you’ll see in the documentation that they are not interrupt
safe.

You can try accessing the realtime clock through raw assembler
calls
or
if you’re on Pentium III you might be able to access a special
register
that just increments, do some math and calulate the time.

-Adam






\

“Mario Charest” <mcharest@nowayzinformatic.com> wrote in message
news:9o29fn$1k0$1@inn.qnx.com

“Augie Henriques” <> augiehenriques@hotmail.com> > wrote in message
news:9ntpo3$cl9$> 1@inn.qnx.com> …

“Mario Charest” <> mcharest@nowayzinformatic.com> > wrote in message
news:9ntnhr$bcu$> 1@inn.qnx.com> …

“Augie Henriques” <> augiehenriques@hotmail.com> > wrote in message
news:9ntjcr$943$> 1@inn.qnx.com> …

“Mario Charest” <> mcharest@nowayzinformatic.com> > wrote in message
news:9ntiif$8pg$> 1@inn.qnx.com> …

“Augie Henriques” <> augiehenriques@hotmail.com> > wrote in message
news:9ntdp2$5v5$> 1@inn.qnx.com> …
At the top of the file I declare…

volatile GnTime systemTime;
struct _osinfo osdata;
volatile struct _timesel far *tptr;

Inside the IRQ handler I do…

// get qnx system time
do {
systemTime.sec = tptr->seconds;
systemTime.nsec = tpr->nsec;
} while
((systemTime.sec!=tptr->seconds)||(systemTime.nsec!=tptr->nsec));


Are systemTime.sec and nsec floating point?
This should work. However it would be faster to read the

Faster to read what? I hear the word “faster” and I get a smile in
my
face.

Woops sorry about that, see below.




In main, I initialize these

qnx_osinfo(0, &osdata);
tptr = MK_FP(osdata.timesel, 0);

// then start the interrupt handler

Is this a problem? How do you get the current time in sec and
nsec
inside
the IRQ handler? I can’t read it in the proxy, by then it will
be
off
by
a
small amount of time.


Yes but that irrelavent ( to some degree) since this time is NOT
precise to the nanosec. To get maximum precisoin use the rdtc (?)
assembly instruction

Okay, How do you do this?


The problem with rdtc is that it only works on Pentium (486 don’t have
that instructions)

Download:
ftp://ftp.qnx.com/usr/free/qnx4/os/utils/examples/Micro_time.tgz

There is a file rtdc.c (from memory) that shows how to do it.

The number read is in CPU clock unit, you must apply a scaler to
convert
it into seconds but that can be done outside of the interrupt.
Reading
this is faster because the CPU doesn’t to go read memory. However
if you need a apply a scaler it will be slower overall. But you’ll
get a LOT more precision!


Sorry, I’m confused.

I’m to blame > :wink:

I would like to read PC system time not something
specific to the CPU? Does the CPU also keep hardware clock?


When to program starts you read BOTH system time and CPU counter.
You keep both these numbers that means later by rereading the CPU
counter you are able to figure out a new time value.

((current CPU clock) - (original CPU clock) * SCALER + System TIME) = new
time

This may be overly complicated for you case.

Maybe we should get back to the original problem,
your program shouldn’t crash. Do you get a kernel crash or
only a program crash?

It turns out that I can read the system clock from the interrupt handler as
mentioned above. I was also reading another time from an IRIG B card. This
is were I have a problem now. To get the IRIG B time I have to access dual
port ram.

Is this allowed from the interrupt handler?

TIA

Augie

  • Mario

TIA

Augie


Include this:

There is and example
Initially, I was told to use the above method.

TIA

Augie


TIA

Augie

“Operating System for Tech Supp” <> os@qnx.com> > wrote in message
news:9ntb6r$1bh$> 1@nntp.qnx.com> …
Augie Henriques <> augiehenriques@hotmail.com> > wrote:

Is it possible to do this inside the IRQ handler? I have
setup
global
volatile pointers to this area.

How are you “reading” the time? If you’re calling time() or
ctime()
etc
you’ll see in the documentation that they are not interrupt
safe.

You can try accessing the realtime clock through raw assembler
calls
or
if you’re on Pentium III you might be able to access a special
register
that just increments, do some math and calulate the time.

-Adam








\

Augie Henriques <augiehenriques@hotmail.com> wrote:

It turns out that I can read the system clock from the interrupt handler as
mentioned above. I was also reading another time from an IRIG B card. This
is were I have a problem now. To get the IRIG B time I have to access dual
port ram.

Is this allowed from the interrupt handler?

As long as you don’t actually map the memory into your process in the ISR,
it should be just a matter of using a pointer+offset. Ensure that when
you map in the memory in you process you specify the PROT_NOCACHE flag.

-Adam

Maybe we should get back to the original problem,
your program shouldn’t crash. Do you get a kernel crash or
only a program crash?

It turns out that I can read the system clock from the interrupt handler
as
mentioned above.

What was the problem?

I was also reading another time from an IRIG B card. This
is were I have a problem now. To get the IRIG B time I have to access
dual
port ram.

Is this allowed from the interrupt handler?

Shouldn’t make any difference, just make sure you’ve map
the memory from outside the ISR . Most PCI drivers do
access the cards memory from the ISR.

TIA

Augie

\

  • Mario

TIA

Augie


Include this:

There is and example
Initially, I was told to use the above method.

TIA

Augie


TIA

Augie

“Operating System for Tech Supp” <> os@qnx.com> > wrote in message
news:9ntb6r$1bh$> 1@nntp.qnx.com> …
Augie Henriques <> augiehenriques@hotmail.com> > wrote:

Is it possible to do this inside the IRQ handler? I have
setup
global
volatile pointers to this area.

How are you “reading” the time? If you’re calling time() or
ctime()
etc
you’ll see in the documentation that they are not interrupt
safe.

You can try accessing the realtime clock through raw
assembler
calls
or
if you’re on Pentium III you might be able to access a
special
register
that just increments, do some math and calulate the time.

-Adam










\

“Mario Charest” <mcharest@nowayzinformatic.com> wrote in message
news:9o77oe$a2i$1@inn.qnx.com

Maybe we should get back to the original problem,
your program shouldn’t crash. Do you get a kernel crash or
only a program crash?

It turns out that I can read the system clock from the interrupt handler
as
mentioned above.

What was the problem?

I forgot that the function which was reading the IRIG B card did floating
point to convert to seconds.

So, everything is okay now. Thanks for all the help.

Augie

I was also reading another time from an IRIG B card. This
is were I have a problem now. To get the IRIG B time I have to access
dual
port ram.

Is this allowed from the interrupt handler?

Shouldn’t make any difference, just make sure you’ve map
the memory from outside the ISR . Most PCI drivers do
access the cards memory from the ISR.


TIA

Augie

\

  • Mario

TIA

Augie


Include this:

There is and example
Initially, I was told to use the above method.

TIA

Augie


TIA

Augie

“Operating System for Tech Supp” <> os@qnx.com> > wrote in
message
news:9ntb6r$1bh$> 1@nntp.qnx.com> …
Augie Henriques <> augiehenriques@hotmail.com> > wrote:

Is it possible to do this inside the IRQ handler? I
have
setup
global
volatile pointers to this area.

How are you “reading” the time? If you’re calling time()
or
ctime()
etc
you’ll see in the documentation that they are not
interrupt
safe.

You can try accessing the realtime clock through raw
assembler
calls
or
if you’re on Pentium III you might be able to access a
special
register
that just increments, do some math and calulate the time.

-Adam












\