home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR3 / KA9Q212.ZIP / TIMER.H < prev    next >
C/C++ Source or Header  |  1993-07-16  |  2KB  |  64 lines

  1. /****************************************************************************
  2. *    timer.h                                                                    *
  3. *    $Id: timer.h 1.2 93/07/16 11:51:38 ROOT_DOS Exp $
  4. *    04 Jul 93    1.2        GT    Fix warnings.                                    *
  5. ****************************************************************************/
  6.  
  7. #ifndef    _TIMER_H
  8. #define    _TIMER_H
  9.  
  10. #ifndef    _GLOBAL_H
  11. #include "global.h"
  12. #endif
  13.  
  14. /* Software timers
  15.  * There is one of these structures for each simulated timer.
  16.  * Whenever the timer is running, it is on a linked list
  17.  * pointed to by "Timers". The list is sorted in ascending order of
  18.  * expiration, with the first timer to expire at the head. This
  19.  * allows the timer process to avoid having to scan the entire list
  20.  * on every clock tick; once it finds an unexpired timer, it can
  21.  * stop searching.
  22.  *
  23.  * Stopping a timer or letting it expire causes it to be removed
  24.  * from the list. Starting a timer puts it on the list at the right
  25.  * place.
  26.  */
  27. struct timer {
  28.     struct timer *next;    /* Linked-list pointer */
  29.     int32 duration;        /* Duration of timer, in ticks */
  30.     int32 expiration;    /* Clock time at expiration */
  31.     void (*func) __ARGS((void *));    /* Function to call at expiration */
  32.     void *arg;        /* Arg to pass function */
  33.     char state;        /* Timer state */
  34. #define    TIMER_STOP    0
  35. #define    TIMER_RUN    1
  36. #define    TIMER_EXPIRE    2
  37. };
  38. #define    NULLTIMER    (struct timer *)0
  39. #define    MAX_TIME    (int32)4294967295    /* Max long integer */
  40. #ifndef    MSPTICK
  41. #define    MSPTICK        55        /* Milliseconds per tick */
  42. #endif
  43. /* Useful user macros that hide the timer structure internals */
  44. #define    dur_timer(t)    ((t)->duration*MSPTICK)
  45. #define    run_timer(t)    ((t)->state == TIMER_RUN)
  46.  
  47. extern int Tick;
  48. extern void (*Cfunc[]) __ARGS((void));    /* List of clock tick functions */
  49.  
  50. /* In timer.c: */
  51. void alarm __ARGS((int32 ms));
  52. int pause __ARGS((int32 ms));
  53. int32 read_timer __ARGS((struct timer *t));
  54. void set_timer __ARGS((struct timer *t,int32 x));
  55. void start_timer __ARGS((struct timer *t));
  56. void stop_timer __ARGS((struct timer *timer));
  57. char *tformat __ARGS((int32 t));
  58.  
  59. /* In hardware.c: */
  60. int32 msclock __ARGS((void));
  61. int32 secclock __ARGS((void));
  62.  
  63. #endif    /* _TIMER_H */
  64.