VSF Documented
vsf_pt.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_PT_H__
19#define __VSF_PT_H__
20
21/*============================ INCLUDES ======================================*/
23
24#if VSF_KERNEL_CFG_EDA_SUPPORT_PT == ENABLED && VSF_USE_KERNEL == ENABLED
25#include "../vsf_eda.h"
26#include "./__vsf_task_common.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/*============================ MACROS ========================================*/
33/*============================ MACROFIED FUNCTIONS ===========================*/
34
35
36#if VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL == ENABLED
37# define __implement_vsf_pt(__name) \
38 __implement_vsf_pt_common(__name, uintptr_t local) \
39 { \
40 __vsf_pt_common(__name) *vsf_pthis = \
41 *(__vsf_pt_common(__name) **) \
42 ((uintptr_t)local - sizeof(uintptr_t));
43
44# define __implement_vsf_pt_ex(__name, __func_name) \
45 __implement_vsf_pt_common( __func_name, uintptr_t local) \
46 { \
47 __vsf_pt_common(__name) *vsf_pthis = \
48 *(__vsf_pt_common(__name) **) \
49 ((uintptr_t)local - sizeof(uintptr_t));
50
51#else
52
53# define __implement_vsf_pt(__name) \
54 __implement_vsf_pt_common(__name, __name *obj_ptr) { \
55 __vsf_pt_common(__name) *vsf_pthis = &(obj_ptr->param);
56
57# define __implement_vsf_pt_ex(__name, __func_name) \
58 __implement_vsf_pt_common(__func_name, __name *obj_ptr) { \
59 __vsf_pt_common(__name) *vsf_pthis = &(obj_ptr->param);
60#endif
61
62#define __vsf_pt_state() (vsf_this.fsm_state)
63#define __vsf_pt_end() __vsf_pt_end_common()
64
65
66#define __vsf_pt_entry(__state, ...) \
67 __vsf_pt_entry_common(__state, __VA_ARGS__)
85#define vsf_pt_entry(...) \
86 __vsf_pt_entry(__vsf_pt_state(), __VA_ARGS__)
87
88#define __vsf_pt_begin(__state) __vsf_pt_begin_common(__state)
89
90
103#define vsf_pt_begin() VSF_UNUSED_PARAM(evt); \
104 __vsf_pt_begin(__vsf_pt_state())
105
114#define vsf_pt_end() __vsf_pt_end() }
115
130#define vsf_pt_wait_for_evt(__evt) __vsf_pt_wfe_common(__vsf_pt_state(), __evt)
131
140#define vsf_pt_wfe(__evt) vsf_pt_wait_for_evt(__evt)
141
151#define vsf_pt_yield() vsf_pt_entry(__vsf_eda_yield();)
152
153#if VSF_KERNEL_CFG_EDA_FAST_SUB_CALL == ENABLED
167# define vsf_pt_raw_next() __vsf_pt_raw_next_common(__vsf_pt_state())
168
183# define vsf_pt_raw_entry(...) __vsf_pt_raw_entry_common(__vsf_pt_state(), __VA_ARGS__)
184#endif
185
212#define vsf_pt_wait_until(...) \
213 vsf_pt_entry(); \
214 __VA_ARGS__ {} else { \
215 return ; \
216 }
217
218#if VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL == ENABLED
219# define __vsf_pt_call_sub(__name, __target, ...) \
220 __vsf_eda_call_eda( (uintptr_t)(__name), \
221 (uintptr_t)(__target), \
222 (0, ##__VA_ARGS__))
223
224# if VSF_KERNEL_CFG_EDA_FAST_SUB_CALL == ENABLED
245# define vsf_pt_call_sub(__name, __target) \
246 vsf_pt_raw_next(); \
247 vsf_err_t VSF_MACRO_SAFE_NAME(ret) = \
248 __vsf_pt_call_sub(__name, (__target)); \
249 VSF_KERNEL_ASSERT(VSF_ERR_NONE == VSF_MACRO_SAFE_NAME(ret)); \
250 return ; \
251 vsf_pt_raw_entry();
252# else
259# define vsf_pt_call_sub(__name, __target) \
260 vsf_pt_entry(); \
261 if (VSF_ERR_NONE != __vsf_pt_call_sub(__name, (__target))) { \
262 return ; \
263 } \
264 vsf_pt_entry(return;);
265#endif
266
267
284# define vsf_pt_call_pt(__name, __target) \
285 (__target)->fsm_state = 0; \
286 vsf_pt_call_sub(vsf_pt_func(__name), (__target))
287
288#endif
289
311#define vsf_eda_call_pt(__name, __target) \
312 __vsf_pt_call_sub(vsf_pt_func(__name), (__target))
313
314#if VSF_KERNEL_CFG_EDA_SUBCALL_HAS_RETURN_VALUE == ENABLED
315# define __vsf_pt_call_task(__name, __target, ...) \
316 __vsf_eda_call_task((vsf_task_entry_t)(__name), \
317 (uintptr_t)(__target), \
318 (0, ##__VA_ARGS__))
319
320
345# define vsf_pt_call_task(__name, __target, __ret_addr, ...) \
346 do { \
347 fsm_rt_t VSF_MCONNECT3(__vsf_pt_call_task,__LINE__,tReturn); \
348 vsf_pt_entry(); \
349 VSF_MCONNECT3(__vsf_pt_call_task,__LINE__,tReturn) = \
350 __vsf_pt_call_task(vsf_task_func(__name), (__target), (0, ##__VA_ARGS__));\
351 if (fsm_rt_on_going == \
352 VSF_MCONNECT3(__vsf_pt_call_task,__LINE__,tReturn)) { \
353 return ; \
354 } \
355 if (NULL != (__ret_addr)) { \
356 *(__ret_addr) = \
357 VSF_MCONNECT3(__vsf_pt_call_task,__LINE__,tReturn); \
358 } \
359 } while(0)
360#endif
361
362#if VSF_KERNEL_CFG_EDA_SUPPORT_TIMER == ENABLED
384# define vsf_pt_start vsf_teda_start
385#else
392# define vsf_pt_start vsf_eda_start
393#endif
394
395
396
414#define implement_vsf_pt(__name) __implement_vsf_pt(__name)
415
427#define implement_vsf_pt_ex(__name, __FUNC_NAME) \
428 __implement_vsf_pt_ex(__name, __FUNC_NAME)
429
438#define imp_vsf_pt(__name) implement_vsf_pt(__name)
439
450#define imp_vsf_pt_ex(__name, __FUNC_NAME) \
451 implement_vsf_pt_ex(__name, __FUNC_NAME)
452
461#define __vsf_pt_func(__name) __vsf_pt_func_common(__name)
462#define vsf_pt_func(__name) __vsf_pt_func(__name)
463
472#define __vsf_pt(__name) __vsf_pt_common(__name)
473#define vsf_pt(__name) __vsf_pt(__name)
474
475#define __def_vsf_pt(__name,...) \
476 __def_vsf_pt_common(__name, \
477 uint8_t fsm_state; \
478 __VA_ARGS__)
479
498#define def_vsf_pt(__name,...) __def_vsf_pt(__name,__VA_ARGS__)
499
508#define end_def_vsf_pt(...)
509
520#define define_vsf_pt(__name,...) def_vsf_pt(__name,__VA_ARGS__)
521
528#define end_define_vsf_pt(...)
529
530
531
532#if VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL == ENABLED
533# define __declare_vsf_pt(__name) \
534 __declare_vsf_pt_common(__name) \
535 __extern_vsf_pt_common(__name, uintptr_t local)
536#else
537# define __declare_vsf_pt(__name) \
538 __declare_vsf_pt_common(__name) \
539 __extern_vsf_pt_common(__name, __name *vsf_pthis)
540#endif
541
553#define declare_vsf_pt(__name) __declare_vsf_pt(__name)
554
563#define dcl_vsf_pt(__name) declare_vsf_pt(__name)
564
565#define __init_vsf_pt(__name, __pt, __pri, ...) \
566 do { \
567 vsf_eda_cfg_t VSF_MACRO_SAFE_NAME(cfg) = { \
568 .fn.evthandler = (vsf_pt_entry_t)__vsf_pt_func(__name), \
569 .priority = (__pri), \
570 .target = (uintptr_t)&((__pt)->param), \
571 __VA_ARGS__ \
572 }; \
573 (__pt)->param.fsm_state = 0; \
574 vsf_pt_start(&((__pt)->use_as__vsf_pt_t), \
575 &VSF_MACRO_SAFE_NAME(cfg)); \
576 } while(0)
577
578
579
580#if VSF_KERNEL_CFG_SUPPORT_THREAD == ENABLED \
581 && VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL == ENABLED
582
583# if VSF_KERNEL_CFG_EDA_FAST_SUB_CALL == ENABLED
603# define vsf_pt_call_thread(__name, __target) \
604 vsf_eda_call_thread_prepare(__name, __target); \
605 vsf_pt_raw_next(); \
606 vsf_err_t VSF_MACRO_SAFE_NAME(ret) = \
607 vsf_eda_call_thread(__target); \
608 VSF_KERNEL_ASSERT(VSF_ERR_NONE == VSF_MACRO_SAFE_NAME(ret)); \
609 return ; \
610 vsf_pt_raw_entry();
611# else
618# define vsf_pt_call_thread(__name, __target) \
619 vsf_eda_call_thread_prepare(__name, __target); \
620 vsf_pt_entry(); \
621 if (VSF_ERR_NONE != vsf_eda_call_thread(__target)) { \
622 return ; \
623 } \
624 vsf_pt_entry(return;);
625# endif
626#endif
627
649#define init_vsf_pt(__name, __pt, __pri, ...) \
650 __init_vsf_pt(__name, __pt, __pri, __VA_ARGS__)
651
652/*============================ TYPES =========================================*/
653
654#if VSF_KERNEL_CFG_EDA_SUPPORT_TIMER == ENABLED
664#else
673typedef vsf_eda_t vsf_pt_t;
674#endif
675
685
686/*============================ GLOBAL VARIABLES ==============================*/
687/*============================ PROTOTYPES ====================================*/
688
689#ifdef __cplusplus
690}
691#endif
692
693#endif
694#endif
The event-driven task (TCB); every VSF task is an eda at the bottom. Tasks share stacks and only occu...
Definition vsf_eda.h:1838
eda with timer support (can use vsf_teda_set_timer() etc.); derived classes (task/pt/thread) inherit ...
Definition vsf_eda.h:1916
void(* vsf_eda_evthandler_t)(vsf_eda_t *eda, vsf_evt_t evt)
eda event handler; invoked with the task (eda) and the event (evt)
Definition vsf_eda.h:1666
vsf_teda_t vsf_pt_t
Protothread type, alias of vsf_teda_t when VSF_KERNEL_CFG_EDA_SUPPORT_TIMER is ENABLED.
Definition vsf_pt.h:663
vsf_eda_evthandler_t vsf_pt_entry_t
Protothread entry function, with the eda event handler signature (alias of vsf_eda_evthandler_t)
Definition vsf_pt.h:684
Generated from commit: vsfteam/vsf@a5104db