home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1 / HamRadio.cdr / misc / tcpipsrc / timer.h < prev    next >
C/C++ Source or Header  |  1990-12-09  |  2KB  |  60 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 doubly-linked list
  11.  * pointed to by "Timers". The list is sorted in ascending order of
  12.  * expiration, with the next timer to expire at the head. Each timer's
  13.  * count field contains only the additional INCREMENT over all preceeding
  14.  * timers; this allows the hardware timer interrupt to decrement only the
  15.  * first timer on the chain until it hits zero.
  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. These operations have to be careful about adjusting the count
  20.  * field of the next entry in the list.
  21.  */
  22. struct timer {
  23.     struct timer *next;    /* Doubly-linked-list pointers */
  24.     struct timer *prev;
  25.     int32 start;        /* Period of counter (load value) */
  26.     int32 count;        /* Ticks to go until expiration */
  27.     void (*func) __ARGS((void *));    /* Function to call at expiration */
  28.     void *arg;        /* Arg to pass function */
  29.     char state;        /* Timer state */
  30. #define    TIMER_STOP    0
  31. #define    TIMER_RUN    1
  32. #define    TIMER_EXPIRE    2
  33. };
  34. #define    NULLTIMER    (struct timer *)0
  35. #define    MAX_TIME    (int32)4294967295    /* Max long integer */
  36. #ifndef    MSPTICK
  37. #define    MSPTICK        55        /* Milliseconds per tick */
  38. #endif
  39. /* Useful user macros that hide the timer structure internals */
  40. #define    dur_timer(t)    ((t)->start*MSPTICK)
  41. #define    run_timer(t)    ((t)->state == TIMER_RUN)
  42.  
  43. extern int32 Clock;    /* Count of ticks since start up */
  44. extern int Tick;
  45.  
  46. /* In timer.c: */
  47. void alarm __ARGS((int32 ms));
  48. int pause __ARGS((int32 ms));
  49. int32 read_timer __ARGS((struct timer *t));
  50. void set_timer __ARGS((struct timer *t,int32 x));
  51. void start_timer __ARGS((struct timer *t));
  52. void stop_timer __ARGS((struct timer *t));
  53. char *tformat __ARGS((int32 t));
  54.  
  55. /* In hardware.c: */
  56. int32 msclock __ARGS((void));
  57. int32 secclock __ARGS((void));
  58.  
  59. #endif    /* _TIMER_H */
  60.