XFusion API v1.3.0
载入中...
搜索中...
未找到
xf_main.c
浏览该文件的文档.
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_queue_t queue = NULL;
36
37/* ==================== [Macros] ============================================ */
38
39/* ==================== [Global Functions] ================================== */
40
41void xf_main(void)
42{
43 xf_osal_thread_attr_t attr1 = {
44 .name = "task1",
45 .priority = XF_OSAL_PRIORITY_NORMOL,
46 .stack_size = 1024 * 2,
47 };
48 xf_osal_thread_attr_t attr2 = {
49 .name = "task2",
51 .stack_size = 1024 * 2,
52 };
53
54 xf_osal_queue_attr_t queue_attr = {
55 .name = "queue",
56 };
57
58 queue = xf_osal_queue_create(5, sizeof(int32_t), &queue_attr);
59 if (queue == NULL) {
60 XF_LOGE(TAG, "xf queue create error");
61 return;
62 }
63
64 xf_err_t err;
66 if (err != XF_OK) {
67 XF_LOGW(TAG, "xf queue reset error:%d", err);
68 }
69
70 xf_osal_queue_t queue1 = xf_osal_queue_create(5, sizeof(int32_t), &queue_attr);
71 if (queue1 == NULL) {
72 XF_LOGE(TAG, "xf queue create error");
73 return;
74 }
75
76 err = xf_osal_queue_delete(queue1);
77 if (err != XF_OK) {
78 XF_LOGE(TAG, "xf queue delete error");
79 return;
80 }
81
83 if (thread1 == NULL) {
84 XF_LOGE(TAG, "xf thread1 create error");
85 return;
86 }
87
89 if (thread2 == NULL) {
90 XF_LOGE(TAG, "xf thread2 create error");
91 return;
92 }
93}
94
95/* ==================== [Static Functions] ================================== */
96
97static void task1(void *argument)
98{
99 int32_t rxData;
100 while (1) {
101 if (xf_osal_queue_get(queue, &rxData, 0, XF_OSAL_WAIT_FOREVER) == XF_OK) {
102 XF_LOGI(TAG, "xf queue recv %d", rxData);
103 }
104 xf_osal_delay_ms(1000);
105 }
106}
107
108static void task2(void *argument)
109{
110 int32_t txData = 0;
111 while (1) {
112 txData++;
113 XF_LOGI(TAG, "xf queue send %d", txData);
114 if (xf_osal_queue_put(queue, &txData, 0, XF_OSAL_WAIT_FOREVER) != XF_OK) {
115 XF_LOGI(TAG, "xf queue send error");
116 }
117 xf_osal_delay_ms(1500);
118 }
119}
void xf_main(void)
Definition xf_main.c:28
xf_err_t xf_osal_queue_get(xf_osal_queue_t queue, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout)
从队列获取消息,如果队列为空,则超时。
xf_err_t xf_osal_queue_reset(xf_osal_queue_t queue)
将消息队列重置为初始空状态。
void * xf_osal_queue_t
消息队列句柄。
xf_err_t xf_osal_queue_delete(xf_osal_queue_t queue)
删除消息队列对象。
xf_osal_queue_t xf_osal_queue_create(uint32_t msg_count, uint32_t msg_size, const xf_osal_queue_attr_t *attr)
创建并初始化消息队列对象。
xf_err_t xf_osal_queue_put(xf_osal_queue_t queue, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout)
将消息放入队列,如果队列已满,则超时。
xf_osal_thread_t xf_osal_thread_create(xf_osal_thread_func_t func, void *argument, const xf_osal_thread_attr_t *attr)
创建一个线程并将其添加到活动线程中。
void * xf_osal_thread_t
线程句柄。
xf_err_t xf_osal_delay_ms(uint32_t ms)
(睡眠)等待超时,以 ms 为单位。
@ XF_OSAL_PRIORITY_NORMOL
@ XF_OSAL_PRIORITY_ABOVE_NORMAL
#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_osal_queue_t queue
Definition xf_main.c:35
消息队列的属性结构。
线程的属性结构。
static xf_task_t * task1
Definition xf_main.c:34
#define XF_LOGI(tag, format,...)
#define XF_LOGE(tag, format,...)
#define XF_LOGW(tag, format,...)