Path: utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!wuarchive!emory!hubcap!gatech!prism!np4 From: np4@prism.gatech.EDU (POMPONIO,NICHOLAS A) Newsgroups: comp.sys.ibm.pc.misc Subject: Re: Fast Timer Interrupts, anyone? Message-ID: <15116@hydra.gatech.EDU> Date: 12 Oct 90 19:03:35 GMT References: <39119@ucbvax.BERKELEY.EDU> Organization: Georgia Institute of Technology Lines: 81 In article <39119@ucbvax.BERKELEY.EDU> scole@janus.Berkeley.EDU (Steven Cole) writes: >I'm wondering if anyone out there can help me... > >I'm looking for a code fragment that sets up timer interrupts >approximately every 125 usec on a vanilla PC. From what I understand, >this is possible by resetting the timer chip that causes INT 08, but >unfortunately I don't know just how to do this. (I.e., is this >register memory mapped or does it take some obscure I/O operation?) > >Thanks for any pointers, > I used the following snippit of code to speed the clock interrupts. (I hope that you are using a very fast PC, because an XT that I used previously could take up to 125 usec just to respond to the interrupt!) The code is in Microsoft C 5.1. I gathered bits and pieces from some working code, and hopefully the details you need are here. If not, let me know by e-mail. -------------------------------------------------------------------------- static void (interrupt * old_intr8)(); static void interrupt system_timer (); /* Timer (8253) values */ #define TIMER_CONTROL_PORT 0x43 #define TIMER_0_PORT 0x40 #define TIMER_LOAD0_CMD 0x36 #define DIVIDE_BY 2 /* Speed up clock int's by this factor */ #define TIMER_0_COUNT 0x10000 / DIVIDE_BY #define TIMER_0_DEFAULT 0u static void install_interrupts () { /* This routine installs the interrupt handler routine below and reprograms the timer channel 0 */ auto union { unsigned int word; unsigned char bytes [2]; } split; old_intr8 = _dos_getvect (0x08); split.word = TIMER_0_COUNT; _disable (); outp (TIMER_CONTROL_PORT, TIMER_LOAD0_CMD); outp (TIMER_0_PORT, split.bytes [0]); outp (TIMER_0_PORT, split.bytes [1]); _dos_setvect (0x08, system_timer); _enable (); } #pragma check_stack(off) void interrupt system_timer () { /* This routine is the interrupt handler. The check_stack pragmas are needed only if you plan to call another function from this handler. */ static int divide_by = DIVIDE_BY; if (--divide_by == 0) { divide_by = DIVIDE_BY; (* old_intr8)(); } else { outp (0x20, 0x20); /* non-specific end-of-interrupt reset */ _enable (); } /* Do something here */ } #pragma check_stack(on) -- POMPONIO,NICHOLAS A Georgia Institute of Technology, Atlanta Georgia, 30332 uucp: ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!np4 Internet: np4@prism.gatech.edu