VSF Documented
vsf_simple.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#ifndef __VSF_KERNEL_SHELL_SIMPLE_H__
19#define __VSF_KERNEL_SHELL_SIMPLE_H__
20
21/*============================ INCLUDES ======================================*/
23
24#if VSF_KERNEL_USE_SIMPLE_SHELL == ENABLED
25#include "../../vsf_eda.h"
26#include "./vsf_simple_bmpevt.h"
27#if VSF_KERNEL_CFG_EDA_SUPPORT_TASK == ENABLED
28# include "../../task/vsf_task.h"
29#endif
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35/*============================ MACROS ========================================*/
36/*============================ MACROFIED FUNCTIONS ===========================*/
37
38/*----------------------------------------------------------------------------*
39 * Common *
40 *----------------------------------------------------------------------------*/
41
42#define static_task_instance(...) \
43 struct { \
44 uint_fast8_t fsm_state; \
45 __VA_ARGS__ \
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);
51
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__;
57#else
58# define features_used(...) __VA_ARGS__
59# define mem_sharable(...) union {__VA_ARGS__};
60# define mem_nonsharable(...) __VA_ARGS__
61#endif
62
63#define vsf_yield() \
64 for ( vsf_evt_t result = VSF_EVT_INVALID; \
65 result == VSF_EVT_INVALID;) \
66 if ((result =__vsf_yield(), result == VSF_EVT_YIELD))
67
68/*----------------------------------------------------------------------------*
69 * Delay *
70 *----------------------------------------------------------------------------*/
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)))
78#endif
79
80
81
82#if VSF_KERNEL_CFG_SUPPORT_SYNC == ENABLED
83/*----------------------------------------------------------------------------*
84 * IPC Common *
85 *----------------------------------------------------------------------------*/
86# define on_timeout() \
87 if (VSF_SYNC_TIMEOUT == vsf_eda_get_cur_evt())
88
89/*----------------------------------------------------------------------------*
90 * Mutex *
91 *----------------------------------------------------------------------------*/
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)
94
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))
100
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), \
105 (__timeout)), \
106 (reason == VSF_SYNC_GET || reason = VSF_SYNC_TIMEOUT)))
107
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)))
114
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)))
121
122/*----------------------------------------------------------------------------*
123 * Critical Section *
124 *----------------------------------------------------------------------------*/
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)
127
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))
133
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), \
138 (__timeout)), \
139 (reason == VSF_SYNC_GET || reason = VSF_SYNC_TIMEOUT)))
140
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)))
147
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)))
154
155/*----------------------------------------------------------------------------*
156 * Semaphore *
157 *----------------------------------------------------------------------------*/
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))
161
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))
167
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), \
172 (__timeout)), \
173 (reason == VSF_SYNC_GET || reason = VSF_SYNC_TIMEOUT)))
174
175
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)))
182
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)))
189
190/*----------------------------------------------------------------------------*
191 * Event *
192 *----------------------------------------------------------------------------*/
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))
197
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))
203
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), \
208 (__timeout)), \
209 (reason == VSF_SYNC_GET || reason = VSF_SYNC_TIMEOUT)))
210
211
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)))
218
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)))
225
226#endif
227
228#if VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL == ENABLED
229
230/*----------------------------------------------------------------------------*
231 * sub call *
232 *----------------------------------------------------------------------------*/
233
234# define vsf_call_eda(__entry, __param_addr) \
235 __vsf_call_eda( (vsf_fsm_entry_t)(__entry), \
236 (__param_addr), \
237 0, 0, 0)
238
239# define vsf_call_fsm(__entry, __param_addr, ...) \
240 __vsf_call_fsm( (vsf_fsm_entry_t)(__entry), \
241 (__param_addr), \
242 (0, ##__VA_ARGS__))
243
244# define vsf_call_peda4( __peda_name, \
245 __entry, \
246 __private_local_size, \
247 __peda_param_addr, \
248 __buff) \
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)), \
253 (uintptr_t)(__buff))
254
255# define vsf_call_peda3( __peda_name, \
256 __entry, \
257 __private_local_size, \
258 __peda_param_addr) \
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)), \
263 0)
264
265# define vsf_call_peda2( __peda_name, \
266 __peda_param_addr, \
267 __buff) \
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)), \
272 (uintptr_t)(__buff))
273
274# define vsf_call_peda1( __peda_name, \
275 __peda_param_addr) \
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)), \
280 0)
281
282# define vsf_call_peda(__peda_name, ...) \
283 __PLOOC_EVAL(vsf_call_peda, __VA_ARGS__) (__peda_name, __VA_ARGS__)
284
285#endif
286
287/*============================ TYPES =========================================*/
288/*============================ GLOBAL VARIABLES ==============================*/
289/*============================ LOCAL VARIABLES ===============================*/
290/*============================ PROTOTYPES ====================================*/
291
292#if VSF_KERNEL_CFG_EDA_SUPPORT_TIMER == ENABLED
293VSF_CAL_SECTION(".text.vsf.kernel.__vsf_delay")
295#endif
296
297#if VSF_KERNEL_CFG_SUPPORT_SYNC == ENABLED
298VSF_CAL_SECTION(".text.vsf.kernel.__vsf_sem_pend")
299extern
301
302VSF_CAL_SECTION(".text.vsf.kernel.vsf_mutex_enter")
303extern
305#endif
306
307#endif
308
309VSF_CAL_SECTION(".text.vsf.kernel.vsf_yield")
310extern vsf_evt_t __vsf_yield(void);
311
312#if VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL == ENABLED
313VSF_CAL_SECTION(".text.vsf.kernel.vsf_call_eda_ex")
314extern vsf_err_t __vsf_call_eda(uintptr_t evthandler,
315 uintptr_t param,
316 size_t local_size,
317 size_t local_buff_size,
318 uintptr_t local_buff);
319
320# if VSF_KERNEL_CFG_EDA_SUPPORT_TASK == ENABLED && VSF_KERNEL_CFG_EDA_SUBCALL_HAS_RETURN_VALUE == ENABLED
321VSF_CAL_SECTION(".text.vsf.kernel.__vsf_call_task")
323 uintptr_t param,
324 size_t local_size);
325# endif
326
327#ifdef __cplusplus
328}
329#endif
330
331#endif
332#endif
333/* EOF */
#define VSF_CAL_SECTION(__SEC)
Definition __compiler.h:181
vsf_err_t
Definition __type.h:42
Definition vsf_eda.h:892
Definition vsf_eda.h:864
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