home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s300 / 1.ddi / CHAP2 / SIGTIME.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-02  |  3.3 KB  |  114 lines

  1. /***********************************************************************
  2.  
  3. FILE
  4.     sigtime.c  -  timer test using xignal package
  5.  
  6. SYNOPSIS
  7.     #include "xignal.h"
  8.  
  9.     cl /Gs sigtime.c /link xignal
  10.  
  11. REMARKS
  12.     Prints the seconds for 10 seconds.  DOS's time keeping function is
  13.     temporarily suspended, but will be restored at the end of the test.
  14.  
  15.     This program uses the PC's system clock, ticking at approx. 18.2
  16.     interrupts per second.
  17.  
  18.     Note that the program must be compiled with the /Gs flag to disable
  19.     stack checking; otherwise a run time error may result because the
  20.     interrupt service routine, tmr_isr() may run on a different stack.
  21.  
  22. LAST UPDATE
  23.     12 September 1987
  24.         name change from signal to xignal
  25.  
  26.     Copyright(c) 1987-1988  D.M. Auslander and C.H. Tham
  27.  
  28. ***********************************************************************/
  29.  
  30. /***********************************************************************
  31.                             I M P O R T S
  32. ***********************************************************************/
  33.  
  34. #include <stdio.h>
  35.  
  36. #include "envir.h"
  37. #include "xignal.h"
  38.  
  39.  
  40. /***********************************************************************
  41.                        P R I V A T E    D A T A
  42. ***********************************************************************/
  43.  
  44. static int tick = 0;            /* count of interrupts */
  45. static int time = 0;            /* time in seconds */
  46. static int flag = 0;            /* flag each 1 second period */
  47.  
  48.  
  49. /***********************************************************************
  50.                            R O U T I N E S
  51. /***********************************************************************
  52.  
  53. /*----------------------------------------------------------------------
  54. PROCEDURE
  55.     TMR_ISR  -  timer service routine
  56.  
  57. SYNOPSIS
  58.     static void tmr_isr()
  59.  
  60. REMARKS
  61.     This routine is called by xignal's low level timer interrupt handler
  62.     at every timer interrupt (approx. every 55 milliseconds).  It counts
  63.     off 18 ticks and sets a flag to indicate 1 second has elasped.
  64.  
  65. LAST UPDATE
  66.     12 September 1987
  67. ----------------------------------------------------------------------*/
  68.  
  69. static void tmr_isr()
  70. {
  71.  
  72.     if (++tick >= 18)           /* approx. 18 interrupts per second */
  73.     {
  74.         tick = 0;               /* reset */
  75.         flag = 1;               /* indicate 1 sec is up */
  76.     }
  77. }
  78.  
  79.  
  80.  
  81. /*----------------------------------------------------------------------
  82. PROCEDURE
  83.     MAIN  -  main program
  84.  
  85. REMARKS
  86.     Calls xignal() to install tmr_isr() as the "high-level" timer
  87.     interrupt service routine.  Variable 'flag' is set whenever 1
  88.     second has elasped.  The original timer vector is restored before
  89.     the program exits by a call to xignal() using the XIG_DFL argument.
  90.  
  91. LAST UPDATE
  92.     17 September 1987
  93. ----------------------------------------------------------------------*/
  94.  
  95. main()
  96. {
  97.  
  98.     xignal(XIGTMR, tmr_isr);        /* set up tmr_isr */
  99.  
  100.     while (time < 10)               /* not 10 seconds yet */
  101.     {
  102.         if (flag)
  103.         {
  104.             flag = 0;                   /* reset flag */
  105.             printf("%2d\n", ++time);    /* print seconds */
  106.         }
  107.     }
  108.  
  109.     xignal(XIGTMR, XIG_DFL);        /* restore timer interrupts */
  110.  
  111. }
  112.  
  113.  
  114.