Menu

timer interruption

2008-01-27
2012-09-26
  • ivan perino

    ivan perino - 2008-01-27

    Hello Especiaistas.

    I am looking for implementing an ISR (interrupt service) every one or two seconds.
    I need a method that interrupts the normal runtime operation in any part of my code every some given time regardless the application be doing, as it were a RTS (Real time Clock) on embedeed system.

    Is there any way to implement such requirement?

    Thanks to every one of you.

    ivan perino

     
    • Anonymous

      Anonymous - 2008-01-27

      Have a look to the SetTimer() function

       
    • cpns

      cpns - 2008-01-27

      Because Windows is designed to support multiple independent processes running simultaneously, it does not allow user mode applications to have the unprivileged access required to implement an ISR. For good reason, timing is a system wide service used by many processes needed to make the system work as well as applications - you cannot simply hijack a timer interrupt for your own purposes as you might in an embedded system or a single-tasking OS such as MS-DOS.

      No all that said of course to don't need to. For a GUI application you can request timer WM_TIMER messages to be sent to your process via the SetTimer() function. You can probably just about make that work in a console app as well, but console apps are not usually event message driven like GUI apps, so the architecture does not really lend itself. If you took teh trouble to make it work, you might just as well write a GUI app.

      The simplest way of achieving asynchronous timing events in a console application is to use a separate thread that simply sleeps for the desired time interval, does its work and then returns to sleep.

      BTW in an embedded system the RTC normally refers to hardware used to provide time and date (normally battery backed). Most often this is independent from the system clock that provides time-event and interval timing facilities.

      If you really need to implement an ISR, then you will have to write a kernel mode driver, but bear in mind that Windows already hooks the timer interrupt and you are likely to compromise your systems stability and performance by hooking your own code. Also the driver model differs between Windows versions. It is not a very practical approach, I mention it merely for completeness, you'd be a fool to try it when what you are trying to do is easily achieved in other ways.

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.