/* * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2025-10-20 Administrator the first version */ /* DATA_comm.c */ #include #include "data_comm.h" rt_mq_t proc_mq; void proc_thread_entry(void *parameter) { struct proc_request *req; while (1) { // 接收请求指针 if (rt_mq_recv(proc_mq, &req, sizeof(req), RT_WAITING_FOREVER) == RT_EOK) { if (!req) continue; rt_kprintf("Processing: %.*s\n", req->input_len, req->input); // 示例处理:回显 req->output_len = rt_snprintf(req->output, sizeof(req->output), "Echo: %.*s", req->input_len, req->input); // 通知 UART 线程可以发送了 if (req->sem) { rt_sem_release(req->sem); } } } } int data_comm_init(void) { proc_mq = rt_mq_create("proc_mq", sizeof(struct proc_request*), 5, RT_IPC_FLAG_FIFO); if (proc_mq == RT_NULL) { rt_kprintf("Failed to create message queue!\n"); return -1; } rt_thread_t tid = rt_thread_create("proc", proc_thread_entry, RT_NULL, 2048, 20, 10); if (tid != RT_NULL) { rt_thread_startup(tid); } return 0; } //INIT_COMPONENT_EXPORT(data_comm_init);