VSF Documented
vsf_task.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_TASK_H__
19#define __VSF_KERNEL_TASK_H__
20
21/*============================ INCLUDES ======================================*/
22
24
25#if VSF_USE_KERNEL == ENABLED && VSF_KERNEL_CFG_EDA_SUPPORT_TASK == ENABLED
26
27#include "service/vsf_service.h"
28#include "../vsf_eda.h"
29#include "./vsf_pt.h"
30#include "./vsf_fsm.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/*============================ MACROS ========================================*/
37/*============================ MACROFIED FUNCTIONS ===========================*/
38
39#define __vsf_task_func(__name) vsf_task_func_##__name
48#define vsf_task_func(__name) __vsf_task_func(__name)
49
50#define __vsf_task(__name) task_cb_##__name
59#define vsf_task(__name) __vsf_task(__name)
60
61#if VSF_KERNEL_CFG_EDA_SUBCALL_HAS_RETURN_VALUE == ENABLED
62# define __implement_vsf_task(__name) \
63 fsm_rt_t vsf_task_func(__name)( uintptr_t local, \
64 vsf_evt_t evt) \
65 { \
66 vsf_task(__name) *vsf_pthis = \
67 *(vsf_task(__name) **) \
68 ((uintptr_t)local - sizeof(uintptr_t));
69
80# define vsf_task_begin()
81
94# define vsf_task_end() \
95 } return fsm_rt_on_going;
96
103# define vsf_task_state (vsf_this.fsm_state)
104
105#else
106# define __implement_vsf_task(__name) \
107 void vsf_task_func(__name)(__name *obj_ptr, vsf_evt_t evt) \
108 { \
109 vsf_task(__name) *vsf_pthis = &(obj_ptr->param);
110
117# define vsf_task_begin()
118
125# define vsf_task_end() } __vsf_eda_yield();
126
133# define vsf_task_state (vsf_this.fsm_state)
134#endif
135
155#define implement_vsf_task(__name) __implement_vsf_task(__name)
156
165#define imp_vsf_task(__name) implement_vsf_task(__name)
166
167#if VSF_KERNEL_CFG_EDA_SUPPORT_TIMER == ENABLED
188# define vsf_task_start vsf_teda_start
189#else
196# define vsf_task_start vsf_eda_start
197#endif
198
199#if VSF_KERNEL_CFG_EDA_SUBCALL_HAS_RETURN_VALUE == ENABLED
200# define __def_vsf_task(__name,...) \
201 struct task_cb_##__name { \
202 uint8_t fsm_state; \
203 __VA_ARGS__ \
204 }; \
205 struct __name { \
206 implement(vsf_task_t); \
207 implement_ex(task_cb_##__name, param); \
208 }; \
209 extern fsm_rt_t vsf_task_func_##__name( uintptr_t local, \
210 vsf_evt_t evt);
211
212#else
213# define __def_vsf_task(__name,...) \
214 typedef struct task_cb_##__name { \
215 uint8_t fsm_state; \
216 __VA_ARGS__ \
217 } task_cb_##__name; \
218 typedef struct __name { \
219 implement(vsf_task_t); \
220 implement_ex(task_cb_##__name, param); \
221 } __name; \
222 extern void vsf_task_func_##__name(struct __name *vsf_pthis, vsf_evt_t evt);
223#endif
224
242#define def_vsf_task(__name,...) __def_vsf_task(__name,__VA_ARGS__)
243
254#define define_vsf_task(__name,...) def_vsf_task(__name,__VA_ARGS__)
255
264#define end_def_vsf_task(...)
265
272#define end_define_vsf_task(...)
273
274#define __declare_vsf_task(__name) \
275 typedef struct __name __name; \
276 typedef struct task_cb_##__name task_cb_##__name;
277
288#define declare_vsf_task(__name) __declare_vsf_task(__name)
289
298#define dcl_vsf_task(__name) declare_vsf_task(__name)
299
311#define prepare_vsf_task(__name, __task) \
312 do {(__task)->fsm_state = 0; } while(0)
313
324#define prp_vsf_task(__name, __task) prepare_vsf_task(__name, __task)
325
326#if VSF_KERNEL_CFG_EDA_SUBCALL_HAS_RETURN_VALUE == ENABLED
327# define __init_vsf_task(__name, __task, __pri, ...) \
328 do { \
329 vsf_eda_cfg_t VSF_MACRO_SAFE_NAME(cfg) = { \
330 .fn.func = (uintptr_t)vsf_task_func(__name), \
331 .priority = (__pri), \
332 .target = (uintptr_t)&((__task)->param), \
333 .feature.is_subcall_has_return_value = true, \
334 __VA_ARGS__ \
335 }; \
336 prepare_vsf_task(__name, &((__task)->param)); \
337 vsf_task_start(&((__task)->use_as__vsf_task_t), \
338 &VSF_MACRO_SAFE_NAME(cfg)); \
339 } while(0)
340#else
341# define __init_vsf_task(__name, __task, __pri, ...) \
342 do { \
343 vsf_eda_cfg_t VSF_MACRO_SAFE_NAME(cfg) = { \
344 .fn.evthandler = (vsf_task_entry_t)vsf_task_func(__name), \
345 .priority = (__pri), \
346 .target = NULL, \
347 __VA_ARGS__ \
348 }; \
349 prepare_vsf_task(__name, &((__task)->param)); \
350 vsf_task_start(&((__task)->use_as__vsf_task_t), \
351 &VSF_MACRO_SAFE_NAME(cfg)); \
352 } while(0)
353#endif
354
376#define init_vsf_task(__name, __task, __pri, ...) \
377 __init_vsf_task(__name, (__task), (__pri), __VA_ARGS__)
378
379
380#if VSF_KERNEL_CFG_EDA_SUBCALL_HAS_RETURN_VALUE == ENABLED
403#define vsf_task_call_task(__name, __target, ...) \
404 __vsf_eda_call_task((vsf_task_entry_t)vsf_task_func(__name), \
405 (uintptr_t)(__target), (0, ##__VA_ARGS__))
406#endif
407
408#if VSF_KERNEL_CFG_EDA_SUBCALL_HAS_RETURN_VALUE == ENABLED
426# define vsf_task_call_sub(__name, __target, ...) \
427 if (VSF_ERR_NONE != __vsf_eda_call_eda( \
428 (vsf_task_entry_t)(__name), \
429 (__target), \
430 (0, ##__VA_ARGS))) { \
431 return fsm_rt_on_going; \
432 }
433
446# define vsf_eda_call_task vsf_task_call_task
447
448#elif VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL == ENABLED
455# define vsf_task_call_sub(__name, __target, ...) \
456 if (VSF_ERR_NONE != __vsf_eda_call_eda( \
457 (vsf_task_entry_t)(__name), \
458 (__target), \
459 (0, ##__VA_ARGS))) { \
460 return ; \
461 }
462
469# define vsf_eda_call_task(__name, __target) \
470 vsf_eda_call_sub((vsf_task_entry_t)vsf_task_func(__name), (__target))
471#endif
472
473
474#if VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL == ENABLED
485#define vsf_task_call_pt(__name, __target) \
486 vsf_task_call_sub(vsf_pt_func(__name), __target)
487#endif
488
501#define on_vsf_task_init() \
502 if (VSF_EVT_INIT == evt)
503
515#define on_vsf_task_fini() \
516 if (VSF_EVT_FINI == evt)
517
532#define on_vsf_task_evt(__evt) \
533 if ((__evt) == evt)
534
535
553#if VSF_KERNEL_CFG_EDA_SUBCALL_HAS_RETURN_VALUE == ENABLED
573# define vsf_task_wait_until(...) \
574 __VA_ARGS__ {} else { \
575 return fsm_rt_wait_for_evt; \
576 }
577
578#else
585# define vsf_task_wait_until(...) \
586 __VA_ARGS__ {} else { \
587 return ; \
588 }
589#endif
590
591/*============================ TYPES =========================================*/
592
593# if VSF_KERNEL_CFG_EDA_SUPPORT_TIMER == ENABLED
604# else
614typedef vsf_eda_t vsf_task_t;
615# endif
616
617#if VSF_KERNEL_CFG_EDA_SUBCALL_HAS_RETURN_VALUE == ENABLED
633#else
645#endif
646
647/*============================ GLOBAL VARIABLES ==============================*/
648/*============================ LOCAL VARIABLES ===============================*/
649/*============================ PROTOTYPES ====================================*/
650
651#if VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL == ENABLED
652# if VSF_KERNEL_CFG_EDA_SUBCALL_HAS_RETURN_VALUE == ENABLED
674VSF_CAL_SECTION(".text.vsf.kernel.eda_task")
676 uintptr_t param,
677 size_t local_size);
678# endif // VSF_KERNEL_CFG_EDA_SUBCALL_HAS_RETURN_VALUE
679#endif // VSF_KERNEL_CFG_EDA_SUPPORT_SUB_CALL
680
681#ifdef __cplusplus
682}
683#endif
684
685#endif
686#endif
687/* EOF */
#define VSF_CAL_SECTION(__SEC_STR)
Definition __compiler.h:189
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
uint32_t uintptr_t
Definition stdint.h:38
int16_t vsf_evt_t
Kernel event type.
Definition vsf_eda.h:1658
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
fsm_rt_t
Definition vsf_fsm.h:771
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
vsf_teda_t vsf_task_t
Cooperative task type, alias of vsf_teda_t when VSF_KERNEL_CFG_EDA_SUPPORT_TIMER is ENABLED; the base...
Definition vsf_task.h:603
fsm_rt_t __vsf_eda_call_task(vsf_task_entry_t entry, uintptr_t param, size_t local_size)
Call a task as a sub-task and wait for its return value.
Definition vsf_task.c:49
Generated from commit: vsfteam/vsf@a5104db