35#ifndef __SIMPLE_FSM_H__
36#define __SIMPLE_FSM_H__
44#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
45# undef VSF_KERNEL_CFG_EDA_SUPPORT_SIMPLE_FSM
46# define VSF_KERNEL_CFG_EDA_SUPPORT_SIMPLE_FSM DISABLED
49#if VSF_KERNEL_CFG_EDA_SUBCALL_HAS_RETURN_VALUE == ENABLED \
50 && VSF_USE_KERNEL == ENABLED \
51 && VSF_KERNEL_CFG_EDA_SUPPORT_SIMPLE_FSM == ENABLED \
52 && VSF_KERNEL_CFG_EDA_SUPPORT_TASK == ENABLED
60# define vsf_this (*vsf_pthis)
64#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
65# error simple_fsm require at least ANSI-C99 support
69#define def_states(...) \
76# define def_params(...) __VA_ARGS__
79#define vsf_args(...) ,__VA_ARGS__
81#define vsf_fsm(__name) vsf_task(__name)
83#define __def_fsm(__fsm_type, ...) \
84 def_vsf_task(__fsm_type, \
87#define def_fsm(__name, ...) \
88 __def_fsm(__name, __VA_ARGS__)
90#define def_simple_fsm(__name, ...) \
91 __declare_fsm(__name); \
92 __def_fsm(__name, __VA_ARGS__)
94#define end_def_simple_fsm(...)
108#define __declare_fsm(__name) \
109 declare_vsf_task(__name)
111#define declare_vsf_fsm(__name) __declare_fsm(__name)
122#define __extern_fsm_initialiser(__name, ...) \
123 vsf_fsm(__name) *__name##_init(vsf_fsm(__name) *fsm_ptr __VA_ARGS__); \
124 typedef vsf_fsm(__name) *__name##_init_fn(vsf_fsm(__name) *fsm_ptr __VA_ARGS__);
126#define extern_vsf_fsm_initialiser(__name, ...) \
127 __extern_fsm_initialiser(__name, __VA_ARGS__)
139#define __extern_fsm_implementation_ex(__name,__type) \
140 fsm_rt_t __name(fsm(__type) *vsf_pthis, vsf_evt_t evt); \
141 typedef fsm_rt_t __name##_fn( vsf_fsm(__type) *vsf_pthis, vsf_evt_t evt );
143#define declare_vsf_fsm_implementation_ex(__name, __type) \
144 __extern_fsm_implementation_ex(__name, __type)
146#define extern_vsf_fsm_implementation_ex(__name,__type) \
147 __extern_fsm_implementation_ex(__name, __type)
149#define extern_vsf_fsm_implementation(__name) \
150 __extern_fsm_implementation_ex(__name, __name)
152#define declare_vsf_fsm_implementation(__name) \
153 __extern_fsm_implementation_ex(__name, __name)
156#define call_vsf_fsm(__name, __fsm ) \
157 vsf_task_call_task(__name, __fsm)
159#define ____state(__state, ...) \
161 __state_entry_##__state:{ \
165#define vsf_state(__state, ...) break; ____state(__state, __VA_ARGS__)
167#define on_start(...) {__VA_ARGS__;}
170#define reset_vsf_fsm() do { vsf_this.fsm_state = 0; } while(0);
171#define vsf_fsm_cpl() do {reset_vsf_fsm(); return fsm_rt_cpl;} while(0);
172#define vsf_fsm_report(__ERROR) do {reset_vsf_fsm(); return (fsm_rt_t)(__ERROR); } while(0);
173#define vsf_fsm_wait_for_obj() return fsm_rt_wait_for_obj;
174#define vsf_fsm_on_going() return fsm_rt_on_going;
180#define update_state_to(__state) \
181 { vsf_this.fsm_state = (__state); goto __state_entry_##__state;}
183#define transfer_to(__state) \
184 { vsf_this.fsm_state = (__state); vsf_fsm_on_going() }
187#define __fsm_initialiser(__name, ...) \
188 vsf_fsm(__name) *__name##_init(vsf_fsm(__name) *vsf_pthis __VA_ARGS__) \
190 VSF_KERNEL_ASSERT (NULL != vsf_pthis); \
191 vsf_this.fsm_state = 0;
193#define vsf_fsm_initialiser(__name, ...) \
194 __fsm_initialiser(__name, __VA_ARGS__)
197#define abort_vsf_fsm_init() return NULL;
199#define vsf_fsm_init_body(...) \
205#define init_vsf_fsm(__name, __fsm, ...) \
206 __name##_init(__fsm __VA_ARGS__)
208#define init_simple_fsm(__name, __fsm, ...) \
209 init_vsf_fsm(__fsm __VA_ARGS__)
211#define start_vsf_fsm(__name, __fsm, __pri, ...) \
212 init_vsf_task(__name, (__fsm), (__pri), __VA_ARGS__)
214#define start_simple_fsm(__name, __fsm, __pri, ...) \
215 start_vsf_fsm(__name, (__fsm), (__pri), __VA_ARGS__)
217#define __implement_fsm_ex(__name, __type) \
218 implement_vsf_task(__name) \
221 if (NULL == vsf_pthis) { \
226 switch (vsf_this.fsm_state) { \
228 vsf_this.fsm_state++; \
238#define vsf_fsm_body(...) __body(__VA_ARGS__)
240#define vsf_fsm_begin() \
241 switch (vsf_this.fsm_state) { \
243 vsf_this.fsm_state++;
245#define vsf_fsm_end() \
272#define implement_fsm_ex(__name, __type) \
273 __implement_fsm_ex(__name, __type)
275#define __implement_fsm(__name) \
276 implement_fsm_ex(__name, __name)
278#define implement_vsf_fsm(__name, ...) __implement_fsm(__name)
280#define __privilege_state(__state, ...) \
283 ____state(__state, __VA_ARGS__) \
285 if (vsf_this.fsm_state != (__state)) { \
290#define privilege_state(__state, ...) \
291 __privilege_state(__state, __VA_ARGS__)
294#define privilege_group(...) { __VA_ARGS__;}
296#define privilege_body(...) \
298 switch (vsf_this.fsm_state) { \
300 vsf_this.fsm_state++; \
305 return fsm_rt_on_going; \
311#ifndef __FSM_RT_TYPE__
312#define __FSM_RT_TYPE__
fsm_rt_t
Definition vsf_fsm.h:315
@ fsm_rt_asyn
fsm asynchronose complete, you can check it later.
Definition vsf_fsm.h:320
@ fsm_rt_err
fsm error, error code can be get from other interface
Definition vsf_fsm.h:316
@ fsm_rt_wait_for_obj
fsm wait for object
Definition vsf_fsm.h:319
@ fsm_rt_cpl
fsm complete
Definition vsf_fsm.h:317
@ fsm_rt_on_going
fsm on-going
Definition vsf_fsm.h:318