VSF Documented
vsf_fsm.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18/****************************************************************************
19* Copyright 2017 Gorgon Meducer (Email:embedded_zhuoran@hotmail.com) *
20* *
21* Licensed under the Apache License, Version 2.0 (the "License"); *
22* you may not use this file except in compliance with the License. *
23* You may obtain a copy of the License at *
24* *
25* http://www.apache.org/licenses/LICENSE-2.0 *
26* *
27* Unless required by applicable law or agreed to in writing, software *
28* distributed under the License is distributed on an "AS IS" BASIS, *
29* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
30* See the License for the specific language governing permissions and *
31* limitations under the License. *
32* *
33****************************************************************************/
34
35#ifndef __SIMPLE_FSM_H__
36#define __SIMPLE_FSM_H__
37
38/*============================ INCLUDES ======================================*/
40
42/*============================ MACROS ========================================*/
43
44#if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) && !defined(__cplusplus)
45# undef VSF_KERNEL_CFG_EDA_SUPPORT_SIMPLE_FSM
46# define VSF_KERNEL_CFG_EDA_SUPPORT_SIMPLE_FSM DISABLED
47#endif
48
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
53
54#ifdef __cplusplus
55extern "C" {
56#endif
57
58
59#ifndef vsf_this
60# define vsf_this (*vsf_pthis)
61#endif
62
63
64#if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) && !defined(__cplusplus)
65# error simple_fsm require at least ANSI-C99 support
66#endif
67
68/*============================ MACROFIED FUNCTIONS ===========================*/
81#define def_states(...) \
82 enum { \
83 START = 0, \
84 __VA_ARGS__ \
85 };
86
87#ifndef def_params
96# define def_params(...) __VA_ARGS__
97#endif
98
109#define vsf_args(...) ,__VA_ARGS__
110
119#define vsf_fsm(__name) vsf_task(__name)
120
121#define __def_fsm(__fsm_type, ...) \
122 def_vsf_task(__fsm_type, \
123 __VA_ARGS__);
124
142#define def_fsm(__name, ...) \
143 __def_fsm(__name, __VA_ARGS__)
144
155#define def_simple_fsm(__name, ...) \
156 __declare_fsm(__name); \
157 __def_fsm(__name, __VA_ARGS__)
158
167#define end_def_simple_fsm(...)
168
169/*
170#define __extern_simple_fsm(__fsm_type, ...) \
171 declare_class(__fsm_type) \
172 extern_class(__fsm_type) \
173 uint_fast8_t fsm_state; \
174 __VA_ARGS__ \
175 end_extern_class(__fsm_type)
176
177#define extern_simple_fsm(__name, ...) \
178 __extern_simple_fsm(fsm(__name), __VA_ARGS__)
179*/
180
181#define __declare_fsm(__name) \
182 declare_vsf_task(__name)
183
194#define declare_vsf_fsm(__name) __declare_fsm(__name)
195
205#define __extern_fsm_initialiser(__name, ...) \
206 vsf_fsm(__name) *__name##_init(vsf_fsm(__name) *fsm_ptr __VA_ARGS__); \
207 typedef vsf_fsm(__name) *__name##_init_fn(vsf_fsm(__name) *fsm_ptr __VA_ARGS__);
208
228#define extern_vsf_fsm_initialiser(__name, ...) \
229 __extern_fsm_initialiser(__name, __VA_ARGS__)
230
231
241#define __extern_fsm_implementation_ex(__name,__type) \
242 fsm_rt_t __name(fsm(__type) *vsf_pthis, vsf_evt_t evt); \
243 typedef fsm_rt_t __name##_fn( vsf_fsm(__type) *vsf_pthis, vsf_evt_t evt );
244
264#define declare_vsf_fsm_implementation_ex(__name, __type) \
265 __extern_fsm_implementation_ex(__name, __type)
266
277#define extern_vsf_fsm_implementation_ex(__name,__type) \
278 __extern_fsm_implementation_ex(__name, __type)
279
289#define extern_vsf_fsm_implementation(__name) \
290 __extern_fsm_implementation_ex(__name, __name)
291
300#define declare_vsf_fsm_implementation(__name) \
301 __extern_fsm_implementation_ex(__name, __name)
303
320#define call_vsf_fsm(__name, __fsm ) \
321 vsf_task_call_task(__name, __fsm)
322
323#define ____state(__state, ...) \
324 case __state: \
325 __state_entry_##__state:{ \
326 __VA_ARGS__; \
327 };
328
341#define vsf_state(__state, ...) break; ____state(__state, __VA_ARGS__)
342
351#define on_start(...) {__VA_ARGS__;}
352
353
360#define reset_vsf_fsm() do { vsf_this.fsm_state = 0; } while(0);
361
368#define vsf_fsm_cpl() do {reset_vsf_fsm(); return fsm_rt_cpl;} while(0);
369
379#define vsf_fsm_report(__ERROR) do {reset_vsf_fsm(); return (fsm_rt_t)(__ERROR); } while(0);
380
389#define vsf_fsm_wait_for_obj() return fsm_rt_wait_for_obj;
390
399#define vsf_fsm_on_going() return fsm_rt_on_going;
400
402//#define fsm_continue() break
403
404
419#define update_state_to(__state) \
420 { vsf_this.fsm_state = (__state); goto __state_entry_##__state;}
421
432#define transfer_to(__state) \
433 { vsf_this.fsm_state = (__state); vsf_fsm_on_going() }
434
435
436#define __fsm_initialiser(__name, ...) \
437 vsf_fsm(__name) *__name##_init(vsf_fsm(__name) *vsf_pthis __VA_ARGS__) \
438 { \
439 VSF_KERNEL_ASSERT (NULL != vsf_pthis); \
440 vsf_this.fsm_state = 0;
441
460#define vsf_fsm_initialiser(__name, ...) \
461 __fsm_initialiser(__name, __VA_ARGS__)
462
463
474#define abort_vsf_fsm_init() return NULL;
475
485#define vsf_fsm_init_body(...) \
486 __VA_ARGS__ \
487 return &vsf_this; \
488 }
489
490
505#define init_vsf_fsm(__name, __fsm, ...) \
506 __name##_init(__fsm __VA_ARGS__)
507
520#define init_simple_fsm(__name, __fsm, ...) \
521 init_vsf_fsm(__name, __fsm, __VA_ARGS__)
522
542#define start_vsf_fsm(__name, __fsm, __pri, ...) \
543 init_vsf_task(__name, (__fsm), (__pri), __VA_ARGS__)
544
559#define start_simple_fsm(__name, __fsm, __pri, ...) \
560 start_vsf_fsm(__name, (__fsm), (__pri), __VA_ARGS__)
561
562#define __implement_fsm_ex(__name, __type) \
563 implement_vsf_task(__name) \
564 { \
565 vsf_task_begin(); \
566 if (NULL == vsf_pthis) { \
567 return fsm_rt_err; \
568 }
569
570#define __body(...) \
571 switch (vsf_this.fsm_state) { \
572 case 0: \
573 vsf_this.fsm_state++; \
574 __VA_ARGS__ \
575 break; \
576 default: \
577 return fsm_rt_err; \
578 } \
579 \
580 vsf_task_end(); \
581 }
582
597#define vsf_fsm_body(...) __body(__VA_ARGS__)
598
613#define vsf_fsm_begin() \
614 switch (vsf_this.fsm_state) { \
615 case 0: \
616 vsf_this.fsm_state++;
617
628#define vsf_fsm_end() \
629 break; \
630 default: \
631 return fsm_rt_err; \
632 } \
633 }vsf_task_end()
634
635
674#define implement_fsm_ex(__name, __type) \
675 __implement_fsm_ex(__name, __type)
676
677#define __implement_fsm(__name) \
678 implement_fsm_ex(__name, __name)
679
698#define implement_vsf_fsm(__name, ...) __implement_fsm(__name)
699
700#define __privilege_state(__state, ...) \
701 break;do { \
702 do { \
703 ____state(__state, __VA_ARGS__) \
704 } while(0); /* add extra while(0) to catch the fsm_continue()*/ \
705 if (vsf_this.fsm_state != (__state)) { \
706 break; \
707 } \
708 } while(1);
709
723#define privilege_state(__state, ...) \
724 __privilege_state(__state, __VA_ARGS__)
725
726
735#define privilege_group(...) { __VA_ARGS__;}
736
752#define privilege_body(...) \
753 do { \
754 switch (vsf_this.fsm_state) { \
755 case 0: \
756 vsf_this.fsm_state++; \
757 __VA_ARGS__ \
758 } \
759 while(1); \
760 \
761 return fsm_rt_on_going; \
762 }
763
764
765/*============================ TYPES =========================================*/
766
767#ifndef __FSM_RT_TYPE__
768#define __FSM_RT_TYPE__
779
780#endif
781
782/*============================ GLOBAL VARIABLES ==============================*/
783/*============================ LOCAL VARIABLES ===============================*/
784/*============================ PROTOTYPES ====================================*/
785
786#ifdef __cplusplus
787}
788#endif
789
790#endif
791#endif
fsm_rt_t
Definition vsf_fsm.h:771
@ fsm_rt_asyn
fsm asynchronose complete, you can check it later.
Definition vsf_fsm.h:776
@ fsm_rt_err
fsm error, error code can be get from other interface
Definition vsf_fsm.h:772
@ fsm_rt_wait_for_obj
fsm wait for object
Definition vsf_fsm.h:775
@ fsm_rt_cpl
fsm complete
Definition vsf_fsm.h:773
@ fsm_rt_on_going
fsm on-going
Definition vsf_fsm.h:774
Generated from commit: vsfteam/vsf@d7c7a8f