home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************
-
- FILE
- sigtime.c - timer test using xignal package
-
- SYNOPSIS
- #include "xignal.h"
-
- cl /Gs sigtime.c /link xignal
-
- REMARKS
- Prints the seconds for 10 seconds. DOS's time keeping function is
- temporarily suspended, but will be restored at the end of the test.
-
- This program uses the PC's system clock, ticking at approx. 18.2
- interrupts per second.
-
- Note that the program must be compiled with the /Gs flag to disable
- stack checking; otherwise a run time error may result because the
- interrupt service routine, tmr_isr() may run on a different stack.
-
- LAST UPDATE
- 12 September 1987
- name change from signal to xignal
-
- Copyright(c) 1987-1988 D.M. Auslander and C.H. Tham
-
- ***********************************************************************/
-
- /***********************************************************************
- I M P O R T S
- ***********************************************************************/
-
- #include <stdio.h>
-
- #include "envir.h"
- #include "xignal.h"
-
-
- /***********************************************************************
- P R I V A T E D A T A
- ***********************************************************************/
-
- static int tick = 0; /* count of interrupts */
- static int time = 0; /* time in seconds */
- static int flag = 0; /* flag each 1 second period */
-
-
- /***********************************************************************
- R O U T I N E S
- /***********************************************************************
-
- /*----------------------------------------------------------------------
- PROCEDURE
- TMR_ISR - timer service routine
-
- SYNOPSIS
- static void tmr_isr()
-
- REMARKS
- This routine is called by xignal's low level timer interrupt handler
- at every timer interrupt (approx. every 55 milliseconds). It counts
- off 18 ticks and sets a flag to indicate 1 second has elasped.
-
- LAST UPDATE
- 12 September 1987
- ----------------------------------------------------------------------*/
-
- static void tmr_isr()
- {
-
- if (++tick >= 18) /* approx. 18 interrupts per second */
- {
- tick = 0; /* reset */
- flag = 1; /* indicate 1 sec is up */
- }
- }
-
-
-
- /*----------------------------------------------------------------------
- PROCEDURE
- MAIN - main program
-
- REMARKS
- Calls xignal() to install tmr_isr() as the "high-level" timer
- interrupt service routine. Variable 'flag' is set whenever 1
- second has elasped. The original timer vector is restored before
- the program exits by a call to xignal() using the XIG_DFL argument.
-
- LAST UPDATE
- 17 September 1987
- ----------------------------------------------------------------------*/
-
- main()
- {
-
- xignal(XIGTMR, tmr_isr); /* set up tmr_isr */
-
- while (time < 10) /* not 10 seconds yet */
- {
- if (flag)
- {
- flag = 0; /* reset flag */
- printf("%2d\n", ++time); /* print seconds */
- }
- }
-
- xignal(XIGTMR, XIG_DFL); /* restore timer interrupts */
-
- }
-
-
-