I need to get interrupt time in ISR.
So my method is that :
First when program start ,get start_time(nsec) and ClockCycles1 count.
In ISR ,get ClockCycles2 count.
So the current_time(nsec) = start_time(nsec)
+1000000000L/SYSPAGE_ENTRY(qtime)->cycles_per_sec
*(ClockCycles2 -
ClockCycles1 )
the interrupt happened about every 5 second.when I get the
current_time,and convert it into string to print.
I find a problem: With the time go on (after several minutes),the
difference between current_time the program and the real clock system is
more and more.
So I simulate it in a normal program,the problem happened too.
the program is in accessories,named “timecha.c”
Is the problem with ClockCycles()or other else.I can’t understand.
The other thing is the calculation of cur_nsec. The operation
should be perform in float or double. Assuming 450Mhz
clock. 1000000000/450000000 = 2.2 which
can’t be represented in an integer formant so it gets truncated
to 2, not good
I need to get interrupt time in ISR.
So my method is that :
First when program start ,get start_time(nsec) and ClockCycles1
count.
In ISR ,get ClockCycles2 count.
So the current_time(nsec) = start_time(nsec)
+1000000000L/SYSPAGE_ENTRY(qtime)->cycles_per_sec
*(ClockCycles2 -
ClockCycles1 )
the interrupt happened about every 5 second.when I get the
current_time,and convert it into string to print.
I find a problem: With the time go on (after several minutes),the
difference between current_time the program and the real clock system is
more and more.
So I simulate it in a normal program,the problem happened too.
the program is in accessories,named “timecha.c”
Is the problem with ClockCycles()or other else.I can’t understand.
My Qnx system is 6.1.0A not 6.2,my cpu is PIII 500MHz.
The doc about ClockCycles is safe to be called in an interrupt.
And there is no crash in my interrupt program.
I have slove the problem.You are right,the calculation of cur_nsec
should be perform in float or double.
And I change my program “timcha.c”,to set a temp double argument to get the
cur_nsec.
Now,
The cur_time which the ClockCycles count is almost as same as
the real_time which clock_gettime count with the time go on.
The other thing is the calculation of cur_nsec. The operation
should be perform in float or double. Assuming 450Mhz
clock. 1000000000/450000000 = 2.2 which
can’t be represented in an integer formant so it gets truncated
to 2, not good >
Beware, according to the documenation ClockCycles is not safe
to be called from an interrupt
My Qnx system is 6.1.0A not 6.2,my cpu is PIII 500MHz.
The doc about ClockCycles is safe to be called in an interrupt.
And there is no crash in my interrupt program.
This was an error in the 6.1 doc
I have slove the problem.You are right,the calculation of cur_nsec
should be perform in float or double.
And I change my program “timcha.c”,to set a temp double argument to get
the
cur_nsec.
Now,
The cur_time which the ClockCycles count is almost as same as
the real_time which clock_gettime count with the time go on.
The other thing is the calculation of cur_nsec. The operation
should be perform in float or double. Assuming 450Mhz
clock. 1000000000/450000000 = 2.2 which
can’t be represented in an integer formant so it gets truncated
to 2, not good >
Beware, according to the documenation ClockCycles is not safe
to be called from an interrupt
My Qnx system is 6.1.0A not 6.2,my cpu is PIII 500MHz.
The doc about ClockCycles is safe to be called in an interrupt.
The doc is wrong… ClockCycles() is just USUALLY safe to call
in an interrupt handler. On some hardware (e.g. 486) it is not,
since that doesn’t have any native operation to do the work, so
the kernel has to emulate it… effectively making a kernel call
inside a interrupt handler, which is bad.
On hardware (e.g. Pentium with rdtsc opcode available or
PPC with a decrementor register) this will be safe to use
in an irq handler.
And there is no crash in my interrupt program.
The crash would be of the whole OS if you got this wrong, not
just in the interrupt program – but if it works, you’re ok on
your hardware.
Would you re-post your modified code? I am interested in this also and have
made the changes suggested but I must have missed something because my
results are not the same.
KenR
My Qnx system is 6.1.0A not 6.2,my cpu is PIII 500MHz.
The doc about ClockCycles is safe to be called in an interrupt.
And there is no crash in my interrupt program.
I have slove the problem.You are right,the calculation of cur_nsec
should be perform in float or double.
And I change my program “timcha.c”,to set a temp double argument to get
the
cur_nsec.
Now,
The cur_time which the ClockCycles count is almost as same as
the real_time which clock_gettime count with the time go on.
The other thing is the calculation of cur_nsec. The operation
should be perform in float or double. Assuming 450Mhz
clock. 1000000000/450000000 = 2.2 which
can’t be represented in an integer formant so it gets truncated
to 2, not good >
Beware, according to the documenation ClockCycles is not safe
to be called from an interrupt