xt-sdk 文档
v1.0.3
xt-sdk 嵌入式 SDK API 参考
Toggle main menu visibility
载入中...
搜索中...
未找到
xt_task.h
浏览该文件的文档.
1
12
13
#ifndef __XT_TASK_H__
14
#define __XT_TASK_H__
15
16
/* ==================== [Includes] ========================================== */
17
18
#include "
xtiny.h
"
19
#if (XT_TASK_ENABLE_OS)
20
#include "cmsis_os2.h"
21
#endif
22
#include "
xt_timer2.h
"
23
#include "
xt_event.h
"
24
25
#ifdef __cplusplus
26
extern
"C"
{
27
#endif
28
35
36
/* ==================== [Defines] =========================================== */
37
39
#define XT_TASK_INLIVAD_ID 0xff
40
42
#define XT_TASK_WAIT_FOREVER 0xffffffff
43
45
#define XT_TASK_LC_INIT_VALUE 0
46
53
#define xt_task_lc_init(s) s = XT_TASK_LC_INIT_VALUE;
54
62
#define xt_task_lc_resume(s) switch(s) { case XT_TASK_LC_INIT_VALUE:
63
73
#define _xt_task_lc_set(s) s = __LINE__; case __LINE__:
74
82
#define xt_task_lc_end(s) default:; break; }
83
84
/* ==================== [Typedefs] ========================================== */
85
90
typedef
void (*
xt_task_entry_t
)(
void
*user_data);
91
93
typedef
struct
xt_task
xt_task_t
;
94
98
struct
xt_task
{
99
xt_task_entry_t
entry
;
100
void
*
user_data
;
101
volatile
int
lc
;
102
xt_timer2_t
timer
;
103
xt_event_id_t
wait_event
;
104
uint8_t
task_id
;
105
uint8_t
parent_id
;
106
};
107
108
/* ==================== [Global Prototypes] ================================= */
109
114
122
xt_err_t
xt_task_setup
(
void
);
123
134
xt_task_t
*
xt_task_start
(
xt_task_entry_t
entry,
void
*user_data);
135
142
xt_task_t
*
xt_task_running
(
void
);
143
153
bool
xt_task_is_running
(
xt_task_t
*task);
154
161
void
xt_task_sys_reset
(
void
);
162
/* 任务生命周期与控制 */
164
165
/* ---- 内部 API(用户不应直接调用) ---- */
166
174
void
xt_task_timer_start
(uint32_t timeout_ms);
175
184
void
xt_task_event_subscribe
(
xt_event_id_t
event_id, uint32_t timeout_ms);
185
195
void
xt_task_event_handler
(
xt_event_id_t
event_id);
196
197
/* ==================== [Macros] ============================================ */
198
208
#define XT_TASK_BEGIN() \
209
_Pragma("GCC diagnostic push") \
210
_Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"") \
211
{ char XT_TASK_YIELD_FLAG = 1; (void)XT_TASK_YIELD_FLAG; xt_task_lc_resume(xt_task_running()->lc)
212
220
#define XT_TASK_END() \
221
xt_task_lc_end(); xt_task_lc_init(xt_task_running()->lc);} \
222
_Pragma("GCC diagnostic pop")
223
234
#define xt_task_delay(ms) \
235
do { \
236
xt_task_timer_start(ms); \
237
XT_TASK_YIELD_FLAG = 0; \
238
_xt_task_lc_set(xt_task_running()->lc); \
239
if (XT_TASK_YIELD_FLAG == 0) { \
240
return; \
241
} \
242
} while(0)
243
256
#define xt_task_wait_event(event_id, event_param) \
257
do { \
258
xt_task_event_subscribe(event_id, XT_TASK_WAIT_FOREVER); \
259
XT_TASK_YIELD_FLAG = 0; \
260
_xt_task_lc_set(xt_task_running()->lc); \
261
if (XT_TASK_YIELD_FLAG == 0) { \
262
return; \
263
} \
264
event_param = xt_event_get_current_event_param(); \
265
} while(0)
266
281
#define xt_task_wait_until(event_id, timeout) \
282
do { \
283
xt_task_event_subscribe(event_id, timeout); \
284
XT_TASK_YIELD_FLAG = 0; \
285
_xt_task_lc_set((xt_task_running()->lc)); \
286
if (XT_TASK_YIELD_FLAG == 0) { \
287
return; \
288
} \
289
} while(0)
290
305
#define xt_task_call_subtask(entry, user_data) \
306
do { \
307
xt_task_t *__sub = xt_task_start(entry, user_data); \
308
if (__sub == NULL) { \
309
break; \
310
} \
311
XT_TASK_YIELD_FLAG = 0; \
312
_xt_task_lc_set((xt_task_running()->lc)); \
313
if (XT_TASK_YIELD_FLAG == 0) { \
314
return; \
315
} \
316
} while(0)
317
/* xt_task */
319
320
#ifdef __cplusplus
321
}
/* extern "C" */
322
#endif
323
324
#endif
/* __XT_TASK_H__ */
xt_err_t
int32_t xt_err_t
错误码类型
定义
xt_error.h:38
xt_event_id_t
uint32_t xt_event_id_t
事件 ID 类型,32 位无符号
定义
xt_event.h:42
xt_task_entry_t
void(* xt_task_entry_t)(void *user_data)
协程任务入口函数类型
定义
xt_task.h:90
xt_task_event_handler
void xt_task_event_handler(xt_event_id_t event_id)
事件到达分发入口
xt_task_running
xt_task_t * xt_task_running(void)
获取当前正在运行的 task
xt_task_event_subscribe
void xt_task_event_subscribe(xt_event_id_t event_id, uint32_t timeout_ms)
为当前 task 订阅事件
xt_task_start
xt_task_t * xt_task_start(xt_task_entry_t entry, void *user_data)
启动一个协程任务
xt_task_is_running
bool xt_task_is_running(xt_task_t *task)
检查 task 是否在运行
xt_task_timer_start
void xt_task_timer_start(uint32_t timeout_ms)
启动当前 task 的定时器
xt_task_sys_reset
void xt_task_sys_reset(void)
重置 task 子系统(仅测试用)
xt_task_t
struct xt_task xt_task_t
协程任务句柄
定义
xt_task.h:93
xt_task_setup
xt_err_t xt_task_setup(void)
初始化 task 子系统
xt_timer2_t
struct xt_timer2 xt_timer2_t
定时器句柄(前向声明)
定义
xt_timer2.h:58
xt_task
任务控制块结构体
定义
xt_task.h:98
xt_task::entry
xt_task_entry_t entry
定义
xt_task.h:99
xt_task::task_id
uint8_t task_id
定义
xt_task.h:104
xt_task::timer
xt_timer2_t timer
定义
xt_task.h:102
xt_task::parent_id
uint8_t parent_id
定义
xt_task.h:105
xt_task::wait_event
xt_event_id_t wait_event
定义
xt_task.h:103
xt_task::user_data
void * user_data
定义
xt_task.h:100
xt_task::lc
volatile int lc
定义
xt_task.h:101
xt_event.h
事件发布订阅模块接口(去重匹配、dispatch 上下文栈、临界区保护)
xt_timer2.h
新版软件定时器接口(对象化、单链表、new/delete 生命周期)
xtiny.h
XTINY 总头文件
components
xt_task
xt_task.h
生成于
, 为 xt-sdk 文档使用
1.17.0