XFusion API
v1.3.0
载入中...
搜索中...
未找到
examples/osal/notify/main/xf_main.c
xf_osal 线程通知示例。
1
17
/* ==================== [Includes] ========================================== */
18
19
#include "xf_hal.h"
20
#include "xf_osal.h"
21
22
/* ==================== [Defines] =========================================== */
23
24
#define TAG "main"
25
26
/* ==================== [Typedefs] ========================================== */
27
28
/* ==================== [Static Prototypes] ================================= */
29
30
static
void
task1
(
void
*argument);
31
static
void
task2
(
void
*argument);
32
33
/* ==================== [Static Variables] ================================== */
34
35
static
xf_osal_thread_t
thread1
= NULL;
36
static
xf_osal_thread_t
thread2
= NULL;
37
38
/* ==================== [Macros] ============================================ */
39
40
/* ==================== [Global Functions] ================================== */
41
42
void
xf_main
(
void
)
43
{
44
xf_osal_thread_attr_t
attr1 = {
45
.
name
=
"task1"
,
46
.priority =
XF_OSAL_PRIORITY_NORMOL
,
47
.stack_size = 1024 * 3,
48
};
49
xf_osal_thread_attr_t
attr2 = {
50
.
name
=
"task2"
,
51
.priority =
XF_OSAL_PRIORITY_ABOVE_NORMAL
,
52
.stack_size = 1024 * 3,
53
};
54
55
thread1
=
xf_osal_thread_create
(
task1
, NULL, &attr1);
56
if
(
thread1
== NULL) {
57
XF_LOGE
(
TAG
,
"xf check error: %d"
,
thread1
);
58
return
;
59
}
60
61
thread2
=
xf_osal_thread_create
(
task2
, NULL, &attr2);
62
if
(
thread2
== NULL) {
63
XF_LOGE
(
TAG
,
"xf check error: %d"
,
thread2
);
64
return
;
65
}
66
67
}
68
69
/* ==================== [Static Functions] ================================== */
70
static
void
task1
(
void
*argument)
71
{
72
xf_err_t
err =
XF_OK
;
73
err |=
xf_osal_delay_ms
(1000);
74
err |=
xf_osal_thread_notify_set
(
thread2
, 0x01);
75
XF_LOGI
(
TAG
,
"task1, err:%d"
, err);
76
while
(1) {
77
if
(
xf_osal_thread_notify_wait
(0x01,
XF_OSAL_WAIT_ALL
,
XF_OSAL_WAIT_FOREVER
) ==
XF_OK
) {
78
XF_LOGI
(
TAG
,
"task1 running"
);
79
xf_osal_delay_ms
(1000);
80
}
81
}
82
}
83
84
static
void
task2
(
void
*argument)
85
{
86
XF_LOGI
(
TAG
,
"task2"
);
87
while
(1) {
88
xf_err_t
err =
xf_osal_thread_notify_wait
(0x01,
XF_OSAL_NO_CLEAR
,
XF_OSAL_WAIT_FOREVER
);
89
if
(err ==
XF_OK
) {
90
uint32_t notify =
xf_osal_thread_notify_get
();
91
XF_LOGI
(
TAG
,
"task2 running, notify:%d"
, notify);
92
err =
xf_osal_thread_notify_clear
(0x01);
93
if
(err !=
XF_OK
) {
94
XF_LOGE
(
TAG
,
"task2 error, %d"
, err);
95
}
96
97
err =
xf_osal_thread_notify_set
(
thread1
, 0x01);
98
if
(err !=
XF_OK
) {
99
XF_LOGE
(
TAG
,
"task2 error, %d"
, err);
100
}
101
xf_osal_delay_ms
(1000);
102
}
else
{
103
XF_LOGE
(
TAG
,
"task2 error, %d"
, err);
104
}
105
106
}
107
}
xf_main
void xf_main(void)
Definition
xf_main.c:28
xf_osal_thread_create
xf_osal_thread_t xf_osal_thread_create(xf_osal_thread_func_t func, void *argument, const xf_osal_thread_attr_t *attr)
创建一个线程并将其添加到活动线程中。
xf_osal_thread_notify_get
uint32_t xf_osal_thread_notify_get(void)
获取当前正在运行的线程的当前线程标志。
xf_osal_thread_t
void * xf_osal_thread_t
线程句柄。
Definition
xf_osal_thread.h:159
xf_osal_delay_ms
xf_err_t xf_osal_delay_ms(uint32_t ms)
(睡眠)等待超时,以 ms 为单位。
xf_osal_thread_notify_clear
xf_err_t xf_osal_thread_notify_clear(uint32_t notify)
清除当前运行线程的指定线程标志。
xf_osal_thread_notify_wait
xf_err_t xf_osal_thread_notify_wait(uint32_t notify, uint32_t options, uint32_t timeout)
当前运行线程等待一个或多个线程标志变为有信号状态。
xf_osal_thread_notify_set
xf_err_t xf_osal_thread_notify_set(xf_osal_thread_t thread, uint32_t notify)
设置线程的指定线程标志。
XF_OSAL_PRIORITY_NORMOL
@ XF_OSAL_PRIORITY_NORMOL
Definition
xf_osal_thread.h:95
XF_OSAL_PRIORITY_ABOVE_NORMAL
@ XF_OSAL_PRIORITY_ABOVE_NORMAL
Definition
xf_osal_thread.h:103
XF_OSAL_NO_CLEAR
#define XF_OSAL_NO_CLEAR
Definition
xf_osal_def.h:37
XF_OSAL_WAIT_ALL
#define XF_OSAL_WAIT_ALL
Definition
xf_osal_def.h:36
XF_OSAL_WAIT_FOREVER
#define XF_OSAL_WAIT_FOREVER
Definition
xf_osal_def.h:30
xf_err_t
int32_t xf_err_t
整形错误类型。 错误码具体值见 xf_err_code_t.
Definition
xf_err.h:69
XF_OK
@ XF_OK
Definition
xf_err.h:43
task2
static void task2(void *argument)
Definition
xf_main.c:104
TAG
#define TAG
Definition
xf_main.c:24
thread1
static xf_osal_thread_t thread1
Definition
xf_main.c:35
thread2
static xf_osal_thread_t thread2
Definition
xf_main.c:36
_xf_osal_thread_attr_t
线程的属性结构。
Definition
xf_osal_thread.h:135
_xf_osal_thread_attr_t::name
const char * name
Definition
xf_osal_thread.h:136
task1
static xf_task_t * task1
Definition
xf_main.c:34
XF_LOGI
#define XF_LOGI(tag, format,...)
Definition
xf_log_uitls.h:44
XF_LOGE
#define XF_LOGE(tag, format,...)
Definition
xf_log_uitls.h:32
生成于 2025年 一月 21日 星期二 17:25:08 , 为 XFusion API使用
1.9.8