18#ifndef __VSF_KERNEL_SHELL_SIMPLE_H__
19#define __VSF_KERNEL_SHELL_SIMPLE_H__
24#if VSF_KERNEL_USE_SIMPLE_SHELL == ENABLED
25#include "../../vsf_eda.h"
27#if VSF_KERNEL_CFG_EDA_SUPPORT_TASK == ENABLED
28# include "../../task/vsf_task.h"
42#define static_task_instance(...) \
44 uint_fast8_t fsm_state; \
46 } static VSF_MACRO_SAFE_NAME(local_cb), \
47 *this_ptr = &VSF_MACRO_SAFE_NAME(local_cb); \
48 vsf_evt_t evt = vsf_eda_get_cur_evt(); \
49 VSF_UNUSED_PARAM(evt); \
50 VSF_UNUSED_PARAM(this_ptr);
52#if __IS_COMPILER_IAR__
53# define features_used(...) __VA_ARGS__;
54# define mem_sharable(...) \
55 union {uint_fast8_t __zzzz_do_not_use; __VA_ARGS__;};
56# define mem_nonsharable(...) __VA_ARGS__;
58# define features_used(...) __VA_ARGS__
59# define mem_sharable(...) union {__VA_ARGS__};
60# define mem_nonsharable(...) __VA_ARGS__
64 for ( vsf_evt_t result = VSF_EVT_INVALID; \
65 result == VSF_EVT_INVALID;) \
66 if ((result =__vsf_yield(), result == VSF_EVT_YIELD))
71#if VSF_KERNEL_CFG_EDA_SUPPORT_TIMER == ENABLED
72# define vsf_delay(__tick) \
73 if (VSF_EVT_TIMER == __vsf_delay((uint_fast32_t)__tick))
74# define vsf_delay_ms(__ms) \
75 if (VSF_EVT_TIMER == __vsf_delay((uint_fast32_t)vsf_systimer_ms_to_tick(__ms)))
76# define vsf_delay_us(__us) \
77 if (VSF_EVT_TIMER == __vsf_delay((uint_fast32_t)vsf_systimer_us_to_tick(__us)))
82#if VSF_KERNEL_CFG_SUPPORT_SYNC == ENABLED
86# define on_timeout() \
87 if (VSF_SYNC_TIMEOUT == vsf_eda_get_cur_evt())
92# define vsf_mutex_init(__mutex_addr) vsf_eda_mutex_init(__mutex_addr)
93# define vsf_mutex_leave(__mutex_addr) vsf_eda_mutex_leave(__mutex_addr)
95# define vsf_mutex_enter(__mutex_addr) \
96 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
97 reason == VSF_SYNC_CANCEL;) \
98 if ((reason =__vsf_mutex_enter((__mutex_addr), \
99 (-1)), reason == VSF_SYNC_GET))
101# define vsf_mutex_try_enter_timeout(__mutex_addr, __timeout) \
102 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
103 reason == VSF_SYNC_CANCEL;) \
104 if ((reason =__vsf_mutex_enter((__mutex_addr), \
106 (reason == VSF_SYNC_GET || reason = VSF_SYNC_TIMEOUT)))
108# define vsf_mutex_try_enter_timeout_ms(__mutex_addr, __timeout) \
109 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
110 reason == VSF_SYNC_CANCEL;) \
111 if ((reason =__vsf_mutex_enter((__mutex_addr), \
112 vsf_systimer_ms_to_tick(__timeout)), \
113 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
115# define vsf_mutex_try_enter_timeout_us(__mutex_addr, __timeout) \
116 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
117 reason == VSF_SYNC_CANCEL;) \
118 if ((reason =__vsf_mutex_enter((__mutex_addr), \
119 vsf_systimer_us_to_tick(__timeout)), \
120 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
125# define vsf_crit_init(__crit_addr) vsf_eda_crit_init(__crit_addr)
126# define vsf_crit_leave(__crit_addr) vsf_eda_crit_leave(__crit_addr)
128# define vsf_crit_enter(__crit_addr) \
129 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
130 reason == VSF_SYNC_CANCEL;) \
131 if ((reason =__vsf_mutex_enter((__crit_addr), \
132 (-1)), reason == VSF_SYNC_GET))
134# define vsf_crit_try_enter_timeout(__crit_addr, __timeout) \
135 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
136 reason == VSF_SYNC_CANCEL;) \
137 if ((reason =__vsf_mutex_enter((__crit_addr), \
139 (reason == VSF_SYNC_GET || reason = VSF_SYNC_TIMEOUT)))
141# define vsf_crit_try_enter_timeout_ms(__crit_addr, __timeout) \
142 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
143 reason == VSF_SYNC_CANCEL;) \
144 if ((reason =__vsf_mutex_enter((__crit_addr), \
145 vsf_systimer_ms_to_tick(__timeout)), \
146 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
148# define vsf_crit_try_enter_timeout_us(__crit_addr, __timeout) \
149 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
150 reason == VSF_SYNC_CANCEL;) \
151 if ((reason =__vsf_mutex_enter((__crit_addr), \
152 vsf_systimer_us_to_tick(__timeout)), \
153 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
158# define vsf_sem_init(__psem, __cnt) \
159 vsf_eda_sync_init((__psem), (__cnt), VSF_SYNC_MAX | VSF_SYNC_AUTO_RST)
160# define vsf_sem_post(__psem) vsf_eda_sem_post((__psem))
162# define vsf_sem_pend(__psem) \
163 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
164 reason == VSF_SYNC_CANCEL;) \
165 if ((reason =__vsf_sem_pend((__psem), \
166 (-1)), reason == VSF_SYNC_GET))
168# define vsf_sem_pend_timeout(__psem, __timeout) \
169 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
170 reason == VSF_SYNC_CANCEL;) \
171 if ((reason =__vsf_sem_pend((__psem), \
173 (reason == VSF_SYNC_GET || reason = VSF_SYNC_TIMEOUT)))
176# define vsf_sem_pend_timeout_ms(__psem, __timeout) \
177 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
178 reason == VSF_SYNC_CANCEL;) \
179 if ((reason =__vsf_sem_pend((__psem), \
180 vsf_systimer_ms_to_tick(__timeout)), \
181 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
183# define vsf_sem_pend_timeout_us(__psem, __timeout) \
184 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
185 reason == VSF_SYNC_CANCEL;) \
186 if ((reason =__vsf_sem_pend((__psem), \
187 vsf_systimer_us_to_tick(__timeout)), \
188 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
193# define vsf_trig_init(__ptrig, __set, __auto_rst) \
194 vsf_eda_trig_init(__ptrig, __set, __auto_rst)
195# define vsf_trig_set(__ptrig) vsf_eda_trig_set((__ptrig))
196# define vsf_trig_reset(__ptrig) vsf_eda_trig_reset((__ptrig))
198# define vsf_trig_wait(__ptrig) \
199 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
200 reason == VSF_SYNC_CANCEL;) \
201 if ((reason =__vsf_sem_pend((__ptrig), \
202 (-1)), reason == VSF_SYNC_GET))
204# define vsf_trig_wait_timeout(__ptrig, __timeout) \
205 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
206 reason == VSF_SYNC_CANCEL;) \
207 if ((reason =__vsf_sem_pend((__ptrig), \
209 (reason == VSF_SYNC_GET || reason = VSF_SYNC_TIMEOUT)))
212# define vsf_trig_wait_timeout_ms(__ptrig, __timeout) \
213 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
214 reason == VSF_SYNC_CANCEL;) \
215 if ((reason =__vsf_sem_pend((__ptrig), \
216 vsf_systimer_ms_to_tick(__timeout)), \
217 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
219# define vsf_trig_wait_timeout_us(__ptrig, __timeout) \
220 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
221 reason == VSF_SYNC_CANCEL;) \
222 if ((reason =__vsf_sem_pend((__ptrig), \
223 vsf_systimer_us_to_tick(__timeout)), \
224 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
228#if VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL == ENABLED
234# define vsf_call_eda(__entry, __param_addr) \
235 __vsf_call_eda( (vsf_fsm_entry_t)(__entry), \
239# define vsf_call_fsm(__entry, __param_addr, ...) \
240 __vsf_call_fsm( (vsf_fsm_entry_t)(__entry), \
244# define vsf_call_peda4( __peda_name, \
246 __private_local_size, \
249 __vsf_call_eda((uintptr_t)__entry, \
250 (uintptr_t)(__peda_param_addr), \
251 ((sizeof(vsf_peda_local(__peda_name)) + 7) & ~0x07) + (__private_local_size),\
252 sizeof(vsf_peda_arg(__peda_name)), \
255# define vsf_call_peda3( __peda_name, \
257 __private_local_size, \
259 __vsf_call_eda((uintptr_t)__entry, \
260 (uintptr_t)(__peda_param_addr), \
261 ((sizeof(vsf_peda_local(__peda_name)) + 7) & ~0x07) + (__private_local_size),\
262 sizeof(vsf_peda_arg(__peda_name)), \
265# define vsf_call_peda2( __peda_name, \
268 __vsf_call_eda((uintptr_t)vsf_peda_func(__peda_name), \
269 (uintptr_t)(__peda_param_addr), \
270 sizeof(vsf_peda_local(__peda_name)), \
271 sizeof(vsf_peda_arg(__peda_name)), \
274# define vsf_call_peda1( __peda_name, \
276 __vsf_call_eda((uintptr_t)vsf_peda_func(__peda_name), \
277 (uintptr_t)(__peda_param_addr), \
278 sizeof(vsf_peda_local(__peda_name)), \
279 sizeof(vsf_peda_arg(__peda_name)), \
282# define vsf_call_peda(__peda_name, ...) \
283 __PLOOC_EVAL(vsf_call_peda, __VA_ARGS__) (__peda_name, __VA_ARGS__)
292#if VSF_KERNEL_CFG_EDA_SUPPORT_TIMER == ENABLED
297#if VSF_KERNEL_CFG_SUPPORT_SYNC == ENABLED
312#if VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL == ENABLED
317 size_t local_buff_size,
320# if VSF_KERNEL_CFG_EDA_SUPPORT_TASK == ENABLED && VSF_KERNEL_CFG_EDA_SUBCALL_HAS_RETURN_VALUE == ENABLED
#define VSF_CAL_SECTION(__SEC)
Definition __compiler.h:181
vsf_err_t
Definition __type.h:42
uint32_t uintptr_t
Definition stdint.h:38
unsigned int uint_fast32_t
Definition stdint.h:27
int int_fast32_t
Definition stdint.h:26
int16_t vsf_evt_t
Definition vsf_eda.h:654
vsf_sync_reason_t
Definition vsf_eda.h:1053
fsm_rt_t
Definition vsf_fsm.h:315
vsf_sync_reason_t __vsf_mutex_enter(vsf_mutex_t *mtx_ptr, int_fast32_t time_out)
Definition vsf_simple_task.c:150
vsf_evt_t __vsf_delay(uint_fast32_t ms)
Definition vsf_simple_task.c:50
#define vsf_mutex_enter(__mutex_addr)
Definition vsf_simple.h:95
fsm_rt_t __vsf_call_task(vsf_task_entry_t entry, uintptr_t param, size_t local_size)
Definition vsf_simple_task.c:241
vsf_sync_reason_t __vsf_sem_pend(vsf_sem_t *sem_ptr, int_fast32_t time_out)
Definition vsf_simple_task.c:103
vsf_err_t __vsf_call_eda(uintptr_t evthandler, uintptr_t param, size_t local_size, size_t local_buff_size, uintptr_t local_buff)
Definition vsf_simple_task.c:193
vsf_evt_t __vsf_yield(void)
Definition vsf_simple_task.c:159
fsm_rt_t(* vsf_task_entry_t)(uintptr_t target, vsf_evt_t evt)
Definition vsf_task.h:241