OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [isdn/] [hisax/] [fsm.c] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/* $Id: fsm.c,v 1.1 2005-12-20 10:17:01 jcastillo Exp $
2
 
3
 * Author       Karsten Keil (keil@temic-ech.spacenet.de)
4
 *              based on the teles driver from Jan den Ouden
5
 *
6
 * Thanks to    Jan den Ouden
7
 *              Fritz Elfert
8
 *
9
 * $Log: not supported by cvs2svn $
10
 * Revision 1.1.1.1  2001/09/10 07:44:18  simons
11
 * Initial import
12
 *
13
 * Revision 1.1.1.1  2001/07/02 17:58:32  simons
14
 * Initial revision
15
 *
16
 * Revision 1.4.2.5  1998/11/03 00:06:23  keil
17
 * certification related changes
18
 * fixed logging for smaller stack use
19
 *
20
 * Revision 1.4.2.4  1998/05/27 18:05:21  keil
21
 * HiSax 3.0
22
 *
23
 * Revision 1.4.2.3  1998/03/07 23:15:20  tsbogend
24
 * made HiSax working on Linux/Alpha
25
 *
26
 * Revision 1.4.2.2  1997/11/15 18:54:29  keil
27
 * cosmetics
28
 *
29
 * Revision 1.4.2.1  1997/10/17 22:13:49  keil
30
 * update to last hisax version
31
 *
32
 * Revision 1.6  1997/07/27 21:42:25  keil
33
 * proof Fsm routines
34
 *
35
 * Revision 1.5  1997/06/26 11:10:05  keil
36
 * Restart timer function added
37
 *
38
 * Revision 1.4  1997/04/06 22:56:42  keil
39
 * Some cosmetic changes
40
 *
41
 * Revision 1.3  1997/02/16 01:04:08  fritz
42
 * Bugfix: Changed timer handling caused hang with 2.1.X
43
 *
44
 * Revision 1.2  1997/01/09 20:57:27  keil
45
 * cleanup & FSM_TIMER_DEBUG
46
 *
47
 * Revision 1.1  1996/10/13 20:04:52  keil
48
 * Initial revision
49
 *
50
 *
51
 */
52
#define __NO_VERSION__
53
#include "hisax.h"
54
 
55
#define FSM_TIMER_DEBUG 0
56
 
57
HISAX_INITFUNC(void
58
FsmNew(struct Fsm *fsm,
59
       struct FsmNode *fnlist, int fncount))
60
{
61
        int i;
62
 
63
        fsm->jumpmatrix = (FSMFNPTR *)
64
                kmalloc(sizeof (FSMFNPTR) * fsm->state_count * fsm->event_count, GFP_KERNEL);
65
        memset(fsm->jumpmatrix, 0, sizeof (FSMFNPTR) * fsm->state_count * fsm->event_count);
66
 
67
        for (i = 0; i < fncount; i++)
68
                if ((fnlist[i].state>=fsm->state_count) || (fnlist[i].event>=fsm->event_count)) {
69
                        printk(KERN_ERR "FsmNew Error line %d st(%ld/%ld) ev(%ld/%ld)\n",
70
                                i,(long)fnlist[i].state,(long)fsm->state_count,
71
                                (long)fnlist[i].event,(long)fsm->event_count);
72
                } else
73
                        fsm->jumpmatrix[fsm->state_count * fnlist[i].event +
74
                                fnlist[i].state] = (FSMFNPTR) fnlist[i].routine;
75
}
76
 
77
void
78
FsmFree(struct Fsm *fsm)
79
{
80
        kfree((void *) fsm->jumpmatrix);
81
}
82
 
83
int
84
FsmEvent(struct FsmInst *fi, int event, void *arg)
85
{
86
        FSMFNPTR r;
87
 
88
        if ((fi->state>=fi->fsm->state_count) || (event >= fi->fsm->event_count)) {
89
                printk(KERN_ERR "FsmEvent Error st(%ld/%ld) ev(%d/%ld)\n",
90
                        (long)fi->state,(long)fi->fsm->state_count,event,(long)fi->fsm->event_count);
91
                return(1);
92
        }
93
        r = fi->fsm->jumpmatrix[fi->fsm->state_count * event + fi->state];
94
        if (r) {
95
                if (fi->debug)
96
                        fi->printdebug(fi, "State %s Event %s",
97
                                fi->fsm->strState[fi->state],
98
                                fi->fsm->strEvent[event]);
99
                r(fi, event, arg);
100
                return (0);
101
        } else {
102
                if (fi->debug)
103
                        fi->printdebug(fi, "State %s Event %s no routine",
104
                                fi->fsm->strState[fi->state],
105
                                fi->fsm->strEvent[event]);
106
                return (!0);
107
        }
108
}
109
 
110
void
111
FsmChangeState(struct FsmInst *fi, int newstate)
112
{
113
        fi->state = newstate;
114
        if (fi->debug)
115
                fi->printdebug(fi, "ChangeState %s",
116
                        fi->fsm->strState[newstate]);
117
}
118
 
119
static void
120
FsmExpireTimer(struct FsmTimer *ft)
121
{
122
#if FSM_TIMER_DEBUG
123
        if (ft->fi->debug)
124
                ft->fi->printdebug(ft->fi, "FsmExpireTimer %lx", (long) ft);
125
#endif
126
        FsmEvent(ft->fi, ft->event, ft->arg);
127
}
128
 
129
void
130
FsmInitTimer(struct FsmInst *fi, struct FsmTimer *ft)
131
{
132
        ft->fi = fi;
133
        ft->tl.function = (void *) FsmExpireTimer;
134
        ft->tl.data = (long) ft;
135
#if FSM_TIMER_DEBUG
136
        if (ft->fi->debug)
137
                ft->fi->printdebug(ft->fi, "FsmInitTimer %lx", (long) ft);
138
#endif
139
        init_timer(&ft->tl);
140
}
141
 
142
void
143
FsmDelTimer(struct FsmTimer *ft, int where)
144
{
145
#if FSM_TIMER_DEBUG
146
        if (ft->fi->debug)
147
                ft->fi->printdebug(ft->fi, "FsmDelTimer %lx %d", (long) ft, where);
148
#endif
149
        del_timer(&ft->tl);
150
}
151
 
152
int
153
FsmAddTimer(struct FsmTimer *ft,
154
            int millisec, int event, void *arg, int where)
155
{
156
 
157
#if FSM_TIMER_DEBUG
158
        if (ft->fi->debug)
159
                ft->fi->printdebug(ft->fi, "FsmAddTimer %lx %d %d",
160
                        (long) ft, millisec, where);
161
#endif
162
 
163
        if (ft->tl.next || ft->tl.prev) {
164
                printk(KERN_WARNING "FsmAddTimer: timer already active!\n");
165
                ft->fi->printdebug(ft->fi, "FsmAddTimer already active!");
166
                return -1;
167
        }
168
        init_timer(&ft->tl);
169
        ft->event = event;
170
        ft->arg = arg;
171
        ft->tl.expires = jiffies + (millisec * HZ) / 1000;
172
        add_timer(&ft->tl);
173
        return 0;
174
}
175
 
176
void
177
FsmRestartTimer(struct FsmTimer *ft,
178
            int millisec, int event, void *arg, int where)
179
{
180
 
181
#if FSM_TIMER_DEBUG
182
        if (ft->fi->debug)
183
                ft->fi->printdebug(ft->fi, "FsmRestartTimer %lx %d %d",
184
                        (long) ft, millisec, where);
185
#endif
186
 
187
        if (ft->tl.next || ft->tl.prev)
188
                del_timer(&ft->tl);
189
        init_timer(&ft->tl);
190
        ft->event = event;
191
        ft->arg = arg;
192
        ft->tl.expires = jiffies + (millisec * HZ) / 1000;
193
        add_timer(&ft->tl);
194
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.