0

Is it good practice to call ftime() function in an Interrupt service routine(ISR) in C?

I have written an ISR that reads the buffer from I/O Device when particular interrupt(data ready) is generated.(only one interrupt is handled).

I want to track last time that particular interrupt is received.

Since ISRs have to be as small as possible,is it worth to add one more line to get time using ftime()?

Target OS is MS-DOS.

Thanks in advance.

ramu s
  • 57
  • 5
  • 1
    "*Since ISRs have to be as small as possible*" -- and probably yours already does to much. Can't you just set some flags and let the main code, outside the ISR, do everything else? –  Jun 24 '17 at 07:25
  • Dear @FelixPalmen,flag can be set but if we need to implement timeout,i thought we may need time of last data receive event.Please suggest if any better alternative available. – ramu s Jun 24 '17 at 07:34
  • What time span are you talking about for a timeout? – Weather Vane Jun 24 '17 at 07:35
  • Dear @WeatherVane,time span in milli seconds. – ramu s Jun 24 '17 at 07:41
  • Using `ftime` is overkill, seeing as you don't need time zone or daylight saving information. You might be interested in [this page](http://www.delorie.com/djgpp/doc/ug/interrupts/inthandlers1.html) wherein it advises: *Because MS-DOS is not reentrant, a hardware interrupt handler should never call any MS-DOS functions during the actual interrupt process.* – Weather Vane Jun 24 '17 at 07:51
  • Note too that the system clock in MS-DOS is not very accurate. Just because `ftime` provides millisecond timing data does not mean it has millisecond accuracy, I believe typically only about 55 millseconds resolution. – Weather Vane Jun 24 '17 at 07:59
  • On my relatively modern PC running Windows the resolution of `_ftime` is only about 16 millseconds. – Weather Vane Jun 24 '17 at 08:15
  • Probably the easiest is to use a hardware timer dedicated to the interrupt.. Reset it at interval start and read it at interval end. Alternatively, poll the free-running timer already used by the OS. – ThingyWotsit Jun 24 '17 at 08:16
  • Windows and DOS use differently the internal timers. And under DOS you have only roughly 18 interrupts per seconds ~55ms as @WeatherVane said. Anyway if you are using a modern CPU maybe you can use internal HighSpeed timers. – Frankie_C Jun 24 '17 at 09:26
  • @ramus I would go for [rdtsc](https://stackoverflow.com/a/21572772/2521214) read also the top voted answer there. It has resolution of a single CPU clock cycle. I think it is present from pentium so unless you are on 486 or older it should work. The [PIT](http://wiki.osdev.org/Programmable_Interval_Timer) timing interrupt is 18.2Hz but can be reprogrammed up to `1.193182 MHz / divider` where divider is 16 bit value – Spektre Sep 19 '17 at 19:42

0 Answers0