summaryrefslogtreecommitdiffhomepage
path: root/digital/io/src/fsm_templates/template_fsm.h
blob: 9ac988958c9120d628f9dce2e7ce000f31093a21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef %(prefix)s_fsm_h
#define %(prefix)s_fsm_h
/*
 * THIS IS AN AUTOMATICALLY GENERATED FILE, DO NOT EDIT!
 *
 * %(name)s
 *
%(*comments)s */

/* %(name)s states. */
enum %(prefix)s_state_t
{
%(states)s    %(PREFIX)s_STATE_NB
};

/* %(name)s events. */
enum %(prefix)s_event_t
{
%(events)s    %(PREFIX)s_EVENT_NB
};

/* This macro enables checks for branches used in the wrong state/event
 * combination. */
#ifdef HOST
# define _BRANCH(state, event, to) \
    ((%(PREFIX)s_STATE_ ## state) << 16 \
     | (%(PREFIX)s_EVENT_ ## event) << 8 \
     | (%(PREFIX)s_STATE_ ## to))
#else
# define _BRANCH(state, event, to) \
     ((%(PREFIX)s_STATE_ ## to))
#endif

/* %(name)s branches. */
enum %(prefix)s_branch_t
{
%(branches)s};

#undef _BRANCH

/* Value to return to follow the only branch. */
#define %(prefix)s_next(state, event) \
    %(PREFIX)s_BRANCH__ ## state ## __ ## event ## __

/* Value to return to follow a given branch. */
#define %(prefix)s_next_branch(state, event, branch) \
    %(PREFIX)s_BRANCH__ ## state ## __ ## event ## __ ## branch

/* %(name)s context. */
extern fsm_t %(prefix)s_fsm;

#endif /* %(prefix)s_fsm_h */