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
62#define static_task_instance(...) \
63 struct { \
64 uint_fast8_t fsm_state; \
65 __VA_ARGS__ \
66 } static VSF_MACRO_SAFE_NAME(local_cb), \
67 *this_ptr = &VSF_MACRO_SAFE_NAME(local_cb); \
68 vsf_evt_t evt = vsf_eda_get_cur_evt(); \
69 VSF_UNUSED_PARAM(evt); \
70 VSF_UNUSED_PARAM(this_ptr);
71
72#if __IS_COMPILER_IAR__
82# define features_used(...) __VA_ARGS__;
92# define mem_sharable(...) \
93 union {uint_fast8_t __zzzz_do_not_use; __VA_ARGS__;};
103# define mem_nonsharable(...) __VA_ARGS__;
104#else
111# define features_used(...) __VA_ARGS__
118# define mem_sharable(...) union {__VA_ARGS__};
125# define mem_nonsharable(...) __VA_ARGS__
126#endif
127
142#define vsf_yield() \
143 for ( vsf_evt_t result = VSF_EVT_INVALID; \
144 result == VSF_EVT_INVALID;) \
145 if ((result =__vsf_yield(), result == VSF_EVT_YIELD))
146
147/*----------------------------------------------------------------------------*
148 * Delay *
149 *----------------------------------------------------------------------------*/
150#if VSF_KERNEL_CFG_EDA_SUPPORT_TIMER == ENABLED
167# define vsf_delay(__tick) \
168 if (VSF_EVT_TIMER == __vsf_delay((vsf_systimer_tick_t)__tick))
187# define vsf_delay_ms(__ms) \
188 if (VSF_EVT_TIMER == __vsf_delay((vsf_systimer_tick_t)vsf_systimer_ms_to_tick(__ms)))
207# define vsf_delay_us(__us) \
208 if (VSF_EVT_TIMER == __vsf_delay((vsf_systimer_tick_t)vsf_systimer_us_to_tick(__us)))
209#endif
210
211
212
213#if VSF_KERNEL_CFG_SUPPORT_SYNC == ENABLED
214/*----------------------------------------------------------------------------*
215 * IPC Common *
216 *----------------------------------------------------------------------------*/
232# define on_timeout() \
233 if (VSF_EVT_TIMER == vsf_eda_get_cur_evt())
234
235/*----------------------------------------------------------------------------*
236 * Mutex *
237 *----------------------------------------------------------------------------*/
250# define vsf_mutex_init(__mutex_addr) vsf_eda_mutex_init(__mutex_addr)
263# define vsf_mutex_leave(__mutex_addr) vsf_eda_mutex_leave(__mutex_addr)
264
282# define vsf_mutex_enter(__mutex_addr) \
283 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
284 reason == VSF_SYNC_CANCEL;) \
285 if ((reason =__vsf_mutex_enter((__mutex_addr), \
286 (-1)), reason == VSF_SYNC_GET))
287
312# define vsf_mutex_try_enter_timeout(__mutex_addr, __timeout) \
313 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
314 reason == VSF_SYNC_CANCEL;) \
315 if ((reason =__vsf_mutex_enter((__mutex_addr), \
316 (__timeout)), \
317 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
318
343# define vsf_mutex_try_enter_timeout_ms(__mutex_addr, __timeout) \
344 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
345 reason == VSF_SYNC_CANCEL;) \
346 if ((reason =__vsf_mutex_enter((__mutex_addr), \
347 vsf_systimer_ms_to_tick(__timeout)), \
348 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
349
374# define vsf_mutex_try_enter_timeout_us(__mutex_addr, __timeout) \
375 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
376 reason == VSF_SYNC_CANCEL;) \
377 if ((reason =__vsf_mutex_enter((__mutex_addr), \
378 vsf_systimer_us_to_tick(__timeout)), \
379 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
380
381/*----------------------------------------------------------------------------*
382 * Critical Section *
383 *----------------------------------------------------------------------------*/
396# define vsf_crit_init(__crit_addr) vsf_eda_crit_init(__crit_addr)
409# define vsf_crit_leave(__crit_addr) vsf_eda_crit_leave(__crit_addr)
410
428# define vsf_crit_enter(__crit_addr) \
429 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
430 reason == VSF_SYNC_CANCEL;) \
431 if ((reason =__vsf_mutex_enter((__crit_addr), \
432 (-1)), reason == VSF_SYNC_GET))
433
459# define vsf_crit_try_enter_timeout(__crit_addr, __timeout) \
460 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
461 reason == VSF_SYNC_CANCEL;) \
462 if ((reason =__vsf_mutex_enter((__crit_addr), \
463 (__timeout)), \
464 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
465
491# define vsf_crit_try_enter_timeout_ms(__crit_addr, __timeout) \
492 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
493 reason == VSF_SYNC_CANCEL;) \
494 if ((reason =__vsf_mutex_enter((__crit_addr), \
495 vsf_systimer_ms_to_tick(__timeout)), \
496 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
497
523# define vsf_crit_try_enter_timeout_us(__crit_addr, __timeout) \
524 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
525 reason == VSF_SYNC_CANCEL;) \
526 if ((reason =__vsf_mutex_enter((__crit_addr), \
527 vsf_systimer_us_to_tick(__timeout)), \
528 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
529
530/*----------------------------------------------------------------------------*
531 * Semaphore *
532 *----------------------------------------------------------------------------*/
549# define vsf_sem_init(__psem, __cnt) \
550 vsf_eda_sync_init((__psem), (__cnt), VSF_SYNC_MAX | VSF_SYNC_AUTO_RST)
563# define vsf_sem_post(__psem) vsf_eda_sem_post((__psem))
564
582# define vsf_sem_pend(__psem) \
583 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
584 reason == VSF_SYNC_CANCEL;) \
585 if ((reason =__vsf_sem_pend((__psem), \
586 (-1)), reason == VSF_SYNC_GET))
587
611# define vsf_sem_pend_timeout(__psem, __timeout) \
612 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
613 reason == VSF_SYNC_CANCEL;) \
614 if ((reason =__vsf_sem_pend((__psem), \
615 (__timeout)), \
616 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
617
618
643# define vsf_sem_pend_timeout_ms(__psem, __timeout) \
644 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
645 reason == VSF_SYNC_CANCEL;) \
646 if ((reason =__vsf_sem_pend((__psem), \
647 vsf_systimer_ms_to_tick(__timeout)), \
648 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
649
674# define vsf_sem_pend_timeout_us(__psem, __timeout) \
675 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
676 reason == VSF_SYNC_CANCEL;) \
677 if ((reason =__vsf_sem_pend((__psem), \
678 vsf_systimer_us_to_tick(__timeout)), \
679 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
680
681/*----------------------------------------------------------------------------*
682 * Event *
683 *----------------------------------------------------------------------------*/
702# define vsf_trig_init(__ptrig, __set, __auto_rst) \
703 vsf_eda_trig_init(__ptrig, __set, __auto_rst)
718# define vsf_trig_set(__ptrig) vsf_eda_trig_set((__ptrig))
731# define vsf_trig_reset(__ptrig) vsf_eda_trig_reset((__ptrig))
732
750# define vsf_trig_wait(__ptrig) \
751 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
752 reason == VSF_SYNC_CANCEL;) \
753 if ((reason =__vsf_sem_pend((__ptrig), \
754 (-1)), reason == VSF_SYNC_GET))
755
781# define vsf_trig_wait_timeout(__ptrig, __timeout) \
782 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
783 reason == VSF_SYNC_CANCEL;) \
784 if ((reason =__vsf_sem_pend((__ptrig), \
785 (__timeout)), \
786 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
787
788
814# define vsf_trig_wait_timeout_ms(__ptrig, __timeout) \
815 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
816 reason == VSF_SYNC_CANCEL;) \
817 if ((reason =__vsf_sem_pend((__ptrig), \
818 vsf_systimer_ms_to_tick(__timeout)), \
819 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
820
846# define vsf_trig_wait_timeout_us(__ptrig, __timeout) \
847 for ( vsf_sync_reason_t reason = VSF_SYNC_CANCEL; \
848 reason == VSF_SYNC_CANCEL;) \
849 if ((reason =__vsf_sem_pend((__ptrig), \
850 vsf_systimer_us_to_tick(__timeout)), \
851 (reason == VSF_SYNC_GET || reason == VSF_SYNC_TIMEOUT)))
852
853#endif
854
855#if VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL == ENABLED
856
857/*----------------------------------------------------------------------------*
858 * sub call *
859 *----------------------------------------------------------------------------*/
860
879# define vsf_call_eda(__entry, __param_addr) \
880 __vsf_call_eda( (uintptr_t)(__entry), \
881 (__param_addr), \
882 0, 0, 0)
883
913# define vsf_call_fsm(__entry, __param_addr, ...) \
914 __vsf_call_task( (vsf_task_entry_t)(__entry), \
915 (uintptr_t)(__param_addr), \
916 (0, ##__VA_ARGS__))
917
951# define vsf_call_peda4( __peda_name, \
952 __entry, \
953 __private_local_size, \
954 __peda_param_addr, \
955 __buff) \
956 __vsf_call_eda((uintptr_t)__entry, \
957 (uintptr_t)(__peda_param_addr), \
958 ((sizeof(vsf_peda_local(__peda_name)) + 7) & ~0x07) + (__private_local_size),\
959 sizeof(vsf_peda_arg(__peda_name)), \
960 (uintptr_t)(__buff))
961
970# define vsf_call_peda3( __peda_name, \
971 __entry, \
972 __private_local_size, \
973 __peda_param_addr) \
974 __vsf_call_eda((uintptr_t)__entry, \
975 (uintptr_t)(__peda_param_addr), \
976 ((sizeof(vsf_peda_local(__peda_name)) + 7) & ~0x07) + (__private_local_size),\
977 sizeof(vsf_peda_arg(__peda_name)), \
978 0)
979
988# define vsf_call_peda2( __peda_name, \
989 __peda_param_addr, \
990 __buff) \
991 __vsf_call_eda((uintptr_t)vsf_peda_func(__peda_name), \
992 (uintptr_t)(__peda_param_addr), \
993 sizeof(vsf_peda_local(__peda_name)), \
994 sizeof(vsf_peda_arg(__peda_name)), \
995 (uintptr_t)(__buff))
996
1005# define vsf_call_peda1( __peda_name, \
1006 __peda_param_addr) \
1007 __vsf_call_eda((uintptr_t)vsf_peda_func(__peda_name), \
1008 (uintptr_t)(__peda_param_addr), \
1009 sizeof(vsf_peda_local(__peda_name)), \
1010 sizeof(vsf_peda_arg(__peda_name)), \
1011 0)
1012
1013# define vsf_call_peda(__peda_name, ...) \
1014 __PLOOC_EVAL(vsf_call_peda, __VA_ARGS__) (__peda_name, __VA_ARGS__)
1015
1016#endif
1017
1018/*============================ TYPES =========================================*/
1019/*============================ GLOBAL VARIABLES ==============================*/
1020/*============================ LOCAL VARIABLES ===============================*/
1021/*============================ PROTOTYPES ====================================*/
1022
1023#if VSF_KERNEL_CFG_EDA_SUPPORT_TIMER == ENABLED
1024VSF_CAL_SECTION(".text.vsf.kernel.__vsf_delay")
1042#endif
1043
1044#if VSF_KERNEL_CFG_SUPPORT_SYNC == ENABLED
1045VSF_CAL_SECTION(".text.vsf.kernel.__vsf_sem_pend")
1070extern
1072
1073VSF_CAL_SECTION(".text.vsf.kernel.vsf_mutex_enter")
1098extern
1100#endif
1101
1102#endif
1103
1104VSF_CAL_SECTION(".text.vsf.kernel.vsf_yield")
1119extern vsf_evt_t __vsf_yield(void);
1120
1121#if VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL == ENABLED
1122VSF_CAL_SECTION(".text.vsf.kernel.vsf_call_eda_ex")
1147extern vsf_err_t __vsf_call_eda(uintptr_t evthandler,
1148 uintptr_t param,
1149 size_t local_size,
1150 size_t local_buff_size,
1151 uintptr_t local_buff);
1152
1153# if VSF_KERNEL_CFG_EDA_SUPPORT_TASK == ENABLED && VSF_KERNEL_CFG_EDA_SUBCALL_HAS_RETURN_VALUE == ENABLED
1154VSF_CAL_SECTION(".text.vsf.kernel.__vsf_call_task")
1174 uintptr_t param,
1175 size_t local_size);
1176# endif
1177
1178#ifdef __cplusplus
1179}
1180#endif
1181
1182#endif
1183#endif
1184/* EOF */
#define VSF_CAL_SECTION(__SEC_STR)
Definition __compiler.h:189
vsf_err_t
Definition __type.h:42
Sync object with an owner (mutex base); supports priority inheritance; the owner must leave it itself...
Definition vsf_eda.h:2009
Base sync IPC object; sem/mutex/trig/crit are built on it.
Definition vsf_eda.h:1964
uint64_t vsf_systimer_tick_t
Definition cortex_a_generic.h:70
uint32_t uintptr_t
Definition stdint.h:38
int16_t vsf_evt_t
Kernel event type.
Definition vsf_eda.h:1658
VSF_KERNEL_TIMEOUT_TICK_T vsf_timeout_tick_t
Timeout type in system timer ticks: negative means wait forever, 0 means non-blocking try,...
Definition vsf_eda.h:1491
vsf_sync_reason_t
Result of a sync wait, returned by the *_get_reason() APIs and thread IPC.
Definition vsf_eda.h:2262
fsm_rt_t
Definition vsf_fsm.h:771
vsf_sync_reason_t __vsf_mutex_enter(vsf_mutex_t *mtx_ptr, vsf_timeout_tick_t time_out)
Low-level mutex-enter helper backing the vsf_mutex_enter() and vsf_crit_enter() statement macros.
Definition vsf_simple_task.c:150
#define vsf_mutex_enter(__mutex_addr)
Enter (lock) a mutex, waiting forever until it is obtained (cooperative, non-blocking for other tasks...
Definition vsf_simple.h:282
fsm_rt_t __vsf_call_task(vsf_task_entry_t entry, uintptr_t param, size_t local_size)
Low-level helper for calling a sub task with a return value.
Definition vsf_simple_task.c:241
vsf_evt_t __vsf_delay(vsf_systimer_tick_t tick)
Low-level delay helper backing the vsf_delay() statement macros.
Definition vsf_simple_task.c:50
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)
Low-level sub-task-call helper backing the vsf_call_eda() and vsf_call_peda() macros.
Definition vsf_simple_task.c:193
vsf_sync_reason_t __vsf_sem_pend(vsf_sem_t *sem_ptr, vsf_timeout_tick_t time_out)
Low-level semaphore-pend helper backing the vsf_sem_pend() and vsf_trig_wait() statement macros.
Definition vsf_simple_task.c:103
vsf_evt_t __vsf_yield(void)
Low-level yield helper backing the vsf_yield() statement macro.
Definition vsf_simple_task.c:159
fsm_rt_t(* vsf_task_entry_t)(uintptr_t target, vsf_evt_t evt)
Task entry function (the event handler of the task), returning fsm_rt_t when VSF_KERNEL_CFG_EDA_SUBCA...
Definition vsf_task.h:632
Generated from commit: vsfteam/vsf@a5104db