Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: fsm.h,v 1.3.2.2 2001/09/23 22:24:47 kai Exp $ |
| 2 | * |
| 3 | * Finite state machine |
| 4 | * |
| 5 | * Author Karsten Keil |
| 6 | * Copyright by Karsten Keil <keil@isdn4linux.de> |
| 7 | * by Kai Germaschewski <kai.germaschewski@gmx.de> |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * This software may be used and distributed according to the terms |
| 10 | * of the GNU General Public License, incorporated herein by reference. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #ifndef __FSM_H__ |
| 15 | #define __FSM_H__ |
| 16 | |
| 17 | #include <linux/timer.h> |
| 18 | |
| 19 | struct FsmInst; |
| 20 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 21 | typedef void (*FSMFNPTR)(struct FsmInst *, int, void *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | struct Fsm { |
| 24 | FSMFNPTR *jumpmatrix; |
| 25 | int state_count, event_count; |
| 26 | char **strEvent, **strState; |
| 27 | }; |
| 28 | |
| 29 | struct FsmInst { |
| 30 | struct Fsm *fsm; |
| 31 | int state; |
| 32 | int debug; |
| 33 | void *userdata; |
| 34 | int userint; |
| 35 | void (*printdebug) (struct FsmInst *, char *, ...); |
| 36 | }; |
| 37 | |
| 38 | struct FsmNode { |
| 39 | int state, event; |
| 40 | void (*routine) (struct FsmInst *, int, void *); |
| 41 | }; |
| 42 | |
| 43 | struct FsmTimer { |
| 44 | struct FsmInst *fi; |
| 45 | struct timer_list tl; |
| 46 | int event; |
| 47 | void *arg; |
| 48 | }; |
| 49 | |
| 50 | int FsmNew(struct Fsm *fsm, struct FsmNode *fnlist, int fncount); |
| 51 | void FsmFree(struct Fsm *fsm); |
| 52 | int FsmEvent(struct FsmInst *fi, int event, void *arg); |
| 53 | void FsmChangeState(struct FsmInst *fi, int newstate); |
| 54 | void FsmInitTimer(struct FsmInst *fi, struct FsmTimer *ft); |
| 55 | int FsmAddTimer(struct FsmTimer *ft, int millisec, int event, |
| 56 | void *arg, int where); |
| 57 | void FsmRestartTimer(struct FsmTimer *ft, int millisec, int event, |
| 58 | void *arg, int where); |
| 59 | void FsmDelTimer(struct FsmTimer *ft, int where); |
| 60 | |
| 61 | #endif |