root/drivers/isdn/teles/fsm.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. FsmNew
  2. FsmFree
  3. FsmEvent
  4. FsmChangeState
  5. FsmExpireTimer
  6. FsmInitTimer
  7. FsmDelTimer
  8. FsmAddTimer
  9. FsmTimerRunning
  10. jiftime

   1 #define __NO_VERSION__
   2 #include "teles.h"
   3 
   4 void
   5 FsmNew(struct Fsm *fsm,
     /* [previous][next][first][last][top][bottom][index][help] */
   6        struct FsmNode *fnlist, int fncount)
   7 {
   8         int             i;
   9 
  10         fsm->jumpmatrix = (int *) Smalloc(4L * fsm->state_count * fsm->event_count,
  11                                           GFP_KERNEL, "Fsm jumpmatrix");
  12         memset(fsm->jumpmatrix, 0, 4L * fsm->state_count * fsm->event_count);
  13 
  14         for (i = 0; i < fncount; i++)
  15                 fsm->jumpmatrix[fsm->state_count * fnlist[i].event +
  16                               fnlist[i].state] = (int) fnlist[i].routine;
  17 }
  18 
  19 void
  20 FsmFree(struct Fsm *fsm)
     /* [previous][next][first][last][top][bottom][index][help] */
  21 {
  22         Sfree((void *) fsm->jumpmatrix);
  23 }
  24 
  25 int
  26 FsmEvent(struct FsmInst *fi, int event, void *arg)
     /* [previous][next][first][last][top][bottom][index][help] */
  27 {
  28         void            (*r) (struct FsmInst *, int, void *);
  29         char            str[80];
  30 
  31         r = (void (*)) fi->fsm->jumpmatrix[fi->fsm->state_count * event + fi->state];
  32         if (r) {
  33                 if (fi->debug) {
  34                         sprintf(str, "State %s Event %s",
  35                                 fi->fsm->strState[fi->state],
  36                                 fi->fsm->strEvent[event]);
  37                         fi->printdebug(fi, str);
  38                 }
  39                 r(fi, event, arg);
  40                 return (0);
  41         } else {
  42                 if (fi->debug) {
  43                         sprintf(str, "State %s Event %s no routine",
  44                                 fi->fsm->strState[fi->state],
  45                                 fi->fsm->strEvent[event]);
  46                         fi->printdebug(fi, str);
  47                 }
  48                 return (!0);
  49         }
  50 }
  51 
  52 void
  53 FsmChangeState(struct FsmInst *fi, int newstate)
     /* [previous][next][first][last][top][bottom][index][help] */
  54 {
  55         char            str[80];
  56 
  57         fi->state = newstate;
  58         if (fi->debug) {
  59                 sprintf(str, "ChangeState %s",
  60                         fi->fsm->strState[newstate]);
  61                 fi->printdebug(fi, str);
  62         }
  63 }
  64 
  65 static void
  66 FsmExpireTimer(struct FsmTimer *ft)
     /* [previous][next][first][last][top][bottom][index][help] */
  67 {
  68         FsmEvent(ft->fi, ft->event, ft->arg);
  69 }
  70 
  71 void
  72 FsmInitTimer(struct FsmInst *fi, struct FsmTimer *ft)
     /* [previous][next][first][last][top][bottom][index][help] */
  73 {
  74         ft->fi = fi;
  75         ft->tl.function = (void *) FsmExpireTimer;
  76         ft->tl.data = (long) ft;
  77         init_timer(&ft->tl);
  78 }
  79 
  80 void
  81 FsmDelTimer(struct FsmTimer *ft, int where)
     /* [previous][next][first][last][top][bottom][index][help] */
  82 {
  83         long            flags;
  84 
  85 #if 0
  86         if (ft->fi->debug) {
  87                 sprintf(str, "FsmDelTimer %lx %d", ft, where);
  88                 ft->fi->printdebug(ft->fi, str);
  89         }
  90 #endif
  91 
  92         save_flags(flags);
  93         cli();
  94         if (ft->tl.next)
  95                 del_timer(&ft->tl);
  96         restore_flags(flags);
  97 }
  98 
  99 int
 100 FsmAddTimer(struct FsmTimer *ft,
     /* [previous][next][first][last][top][bottom][index][help] */
 101             int millisec, int event, void *arg, int where)
 102 {
 103 
 104 #if 0
 105         if (ft->fi->debug) {
 106                 sprintf(str, "FsmAddTimer %lx %d %d", ft, millisec, where);
 107                 ft->fi->printdebug(ft->fi, str);
 108         }
 109 #endif
 110 
 111         if (ft->tl.next) {
 112                 printk(KERN_WARNING "FsmAddTimer: timer already active!\n");
 113                 return -1;
 114         }
 115         init_timer(&ft->tl);
 116         ft->event = event;
 117         ft->arg = arg;
 118         ft->tl.expires = jiffies + (millisec * HZ) / 1000;
 119         add_timer(&ft->tl);
 120         return 0;
 121 }
 122 
 123 int
 124 FsmTimerRunning(struct FsmTimer *ft)
     /* [previous][next][first][last][top][bottom][index][help] */
 125 {
 126         return (ft->tl.next != NULL);
 127 }
 128 
 129 void
 130 jiftime(char *s, long mark)
     /* [previous][next][first][last][top][bottom][index][help] */
 131 {
 132         s += 8;
 133 
 134         *s-- = '\0';
 135         *s-- = mark % 10 + '0';
 136         mark /= 10;
 137         *s-- = mark % 10 + '0';
 138         mark /= 10;
 139         *s-- = '.';
 140         *s-- = mark % 10 + '0';
 141         mark /= 10;
 142         *s-- = mark % 6 + '0';
 143         mark /= 6;
 144         *s-- = ':';
 145         *s-- = mark % 10 + '0';
 146         mark /= 10;
 147         *s-- = mark % 10 + '0';
 148 }

/* [previous][next][first][last][top][bottom][index][help] */