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
30static void task1(void *argument);
31static void task2(void *argument);
32
33/* ==================== [Static Variables] ================================== */
34
35static xf_osal_thread_t thread1 = NULL;
36static xf_osal_thread_t thread2 = NULL;
37
38/* ==================== [Macros] ============================================ */
39
40/* ==================== [Global Functions] ================================== */
41
42void 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",
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] ================================== */
70static void task1(void *argument)
71{
72 xf_err_t err = XF_OK;
73 err |= xf_osal_delay_ms(1000);
75 XF_LOGI(TAG, "task1, err:%d", err);
76 while (1) {
78 XF_LOGI(TAG, "task1 running");
79 xf_osal_delay_ms(1000);
80 }
81 }
82}
83
84static void task2(void *argument)
85{
86 XF_LOGI(TAG, "task2");
87 while (1) {
89 if (err == XF_OK) {
90 uint32_t notify = xf_osal_thread_notify_get();
91 XF_LOGI(TAG, "task2 running, notify:%d", notify);
93 if (err != XF_OK) {
94 XF_LOGE(TAG, "task2 error, %d", err);
95 }
96
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}
void xf_main(void)
Definition xf_main.c:28
xf_osal_thread_t xf_osal_thread_create(xf_osal_thread_func_t func, void *argument, const xf_osal_thread_attr_t *attr)
创建一个线程并将其添加到活动线程中。
uint32_t xf_osal_thread_notify_get(void)
获取当前正在运行的线程的当前线程标志。
void * xf_osal_thread_t
线程句柄。
xf_err_t xf_osal_delay_ms(uint32_t ms)
(睡眠)等待超时,以 ms 为单位。
xf_err_t xf_osal_thread_notify_clear(uint32_t notify)
清除当前运行线程的指定线程标志。
xf_err_t xf_osal_thread_notify_wait(uint32_t notify, uint32_t options, uint32_t timeout)
当前运行线程等待一个或多个线程标志变为有信号状态。
xf_err_t xf_osal_thread_notify_set(xf_osal_thread_t thread, uint32_t notify)
设置线程的指定线程标志。
@ XF_OSAL_PRIORITY_NORMOL
@ XF_OSAL_PRIORITY_ABOVE_NORMAL
#define XF_OSAL_NO_CLEAR
Definition xf_osal_def.h:37
#define XF_OSAL_WAIT_ALL
Definition xf_osal_def.h:36
#define XF_OSAL_WAIT_FOREVER
Definition xf_osal_def.h:30
int32_t xf_err_t
整形错误类型。 错误码具体值见 xf_err_code_t.
Definition xf_err.h:69
@ XF_OK
Definition xf_err.h:43
static void task2(void *argument)
Definition xf_main.c:104
#define TAG
Definition xf_main.c:24
static xf_osal_thread_t thread1
Definition xf_main.c:35
static xf_osal_thread_t thread2
Definition xf_main.c:36
线程的属性结构。
static xf_task_t * task1
Definition xf_main.c:34
#define XF_LOGI(tag, format,...)
#define XF_LOGE(tag, format,...)