^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef _FSM_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _FSM_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Define this to get debugging messages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define FSM_DEBUG 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Define this to get debugging massages for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * timer handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define FSM_TIMER_DEBUG 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Define these to record a history of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * Events/Statechanges and print it if a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * action_function is not found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define FSM_DEBUG_HISTORY 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define FSM_HISTORY_SIZE 40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct fsm_instance_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * Definition of an action function, called by a FSM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) typedef void (*fsm_function_t)(struct fsm_instance_t *, int, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * Internal jump table for a FSM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) fsm_function_t *jumpmatrix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) int nr_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int nr_states;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) const char **event_names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) const char **state_names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) } fsm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #if FSM_DEBUG_HISTORY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * Element of State/Event history used for debugging.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) } fsm_history;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * Representation of a FSM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) typedef struct fsm_instance_t {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) fsm *f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) atomic_t state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) char name[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) void *userdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int userint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) wait_queue_head_t wait_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #if FSM_DEBUG_HISTORY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int history_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int history_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) fsm_history history[FSM_HISTORY_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) } fsm_instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * Description of a state-event combination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) int cond_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) int cond_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) fsm_function_t function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) } fsm_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * Description of a FSM Timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) fsm_instance *fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct timer_list tl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int expire_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) void *event_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) } fsm_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * Creates an FSM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * @param name Name of this instance for logging purposes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * @param state_names An array of names for all states for logging purposes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * @param event_names An array of names for all events for logging purposes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * @param nr_states Number of states for this instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * @param nr_events Number of events for this instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * @param tmpl An array of fsm_nodes, describing this FSM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * @param tmpl_len Length of the describing array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * @param order Parameter for allocation of the FSM data structs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) extern fsm_instance *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) init_fsm(char *name, const char **state_names,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) const char **event_names,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int nr_states, int nr_events, const fsm_node *tmpl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) int tmpl_len, gfp_t order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * Releases an FSM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * @param fi Pointer to an FSM, previously created with init_fsm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) extern void kfree_fsm(fsm_instance *fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #if FSM_DEBUG_HISTORY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) extern void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) fsm_print_history(fsm_instance *fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) extern void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) fsm_record_history(fsm_instance *fi, int state, int event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * Emits an event to a FSM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * If an action function is defined for the current state/event combination,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * this function is called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * @param fi Pointer to FSM which should receive the event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * @param event The event do be delivered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * @param arg A generic argument, handed to the action function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * @return 0 on success,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * 1 if current state or event is out of range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * !0 if state and event in range, but no action defined.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) fsm_event(fsm_instance *fi, int event, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) fsm_function_t r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) int state = atomic_read(&fi->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if ((state >= fi->f->nr_states) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) (event >= fi->f->nr_events) ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) printk(KERN_ERR "fsm(%s): Invalid state st(%ld/%ld) ev(%d/%ld)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) fi->name, (long)state,(long)fi->f->nr_states, event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) (long)fi->f->nr_events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #if FSM_DEBUG_HISTORY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) fsm_print_history(fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) r = fi->f->jumpmatrix[fi->f->nr_states * event + state];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #if FSM_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) printk(KERN_DEBUG "fsm(%s): state %s event %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) fi->name, fi->f->state_names[state],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) fi->f->event_names[event]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #if FSM_DEBUG_HISTORY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) fsm_record_history(fi, state, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) r(fi, event, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #if FSM_DEBUG || FSM_DEBUG_HISTORY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) printk(KERN_DEBUG "fsm(%s): no function for event %s in state %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) fi->name, fi->f->event_names[event],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) fi->f->state_names[state]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #if FSM_DEBUG_HISTORY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) fsm_print_history(fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return !0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * Modifies the state of an FSM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * This does <em>not</em> trigger an event or calls an action function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * @param fi Pointer to FSM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * @param state The new state for this FSM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) fsm_newstate(fsm_instance *fi, int newstate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) atomic_set(&fi->state,newstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #if FSM_DEBUG_HISTORY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) fsm_record_history(fi, newstate, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #if FSM_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) printk(KERN_DEBUG "fsm(%s): New state %s\n", fi->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) fi->f->state_names[newstate]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) wake_up(&fi->wait_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * Retrieves the state of an FSM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * @param fi Pointer to FSM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * @return The current state of the FSM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) fsm_getstate(fsm_instance *fi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return atomic_read(&fi->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * Retrieves the name of the state of an FSM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * @param fi Pointer to FSM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * @return The current state of the FSM in a human readable form.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) extern const char *fsm_getstate_str(fsm_instance *fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * Initializes a timer for an FSM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * This prepares an fsm_timer for usage with fsm_addtimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * @param fi Pointer to FSM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * @param timer The timer to be initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) extern void fsm_settimer(fsm_instance *fi, fsm_timer *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * Clears a pending timer of an FSM instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * @param timer The timer to clear.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) extern void fsm_deltimer(fsm_timer *timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * Adds and starts a timer to an FSM instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * @param timer The timer to be added. The field fi of that timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * must have been set to point to the instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * @param millisec Duration, after which the timer should expire.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * @param event Event, to trigger if timer expires.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * @param arg Generic argument, provided to expiry function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * @return 0 on success, -1 if timer is already active.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) extern int fsm_addtimer(fsm_timer *timer, int millisec, int event, void *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * Modifies a timer of an FSM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * @param timer The timer to modify.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * @param millisec Duration, after which the timer should expire.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * @param event Event, to trigger if timer expires.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * @param arg Generic argument, provided to expiry function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) extern void fsm_modtimer(fsm_timer *timer, int millisec, int event, void *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) #endif /* _FSM_H_ */