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