home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / s920603.zip / TIMER.H < prev    next >
C/C++ Source or Header  |  1991-04-19  |  2KB  |  58 lines

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