RTOS:
static EventGroupHandle_t g_curtain_event_group = NULL;
if (g_curtain_event_group == NULL)
{
g_curtain_event_group = xEventGroupCreate();
}
应用:
#define CURTAIN_RUN_EVT (BIT0)
#define CURTAIN_CALIB_INIT_EVT (BIT1)
#define CURTAIN_CALIB_START_EVT (BIT2)
#define CURTAIN_REPORT_EVT (BIT3)
EventBits_t evBits = 0;
evBits = xEventGroupWaitBits(g_curtain_event_group, CURTAIN_CALIB_INIT_EVT | CURTAIN_CALIB_START_EVT | CURTAIN_RUN_EVT | CURTAIN_REPORT_EVT, false, false, 0);
if (evBits & CURTAIN_REPORT_EVT)
{
//xxx
}
RTT:
#include <rtthread.h>
rt_uint32_t test_stack[10];
rt_mq_t messageQueue;
void thread1t(void *param)
{
int i = -1;
while(1)
{
rt_mq_recv(messageQueue,&i,4,RT_WAITING_FOREVER);
rt_kprintf("Recv data:%d\n",i);
rt_thread_mdelay(1000);
}
}
void thread2t(void *param)
{
rt_uint32_t i = 0;
while(1)
{
rt_mq_send_wait(messageQueue,&i,4,RT_WAITING_FOREVER);
i++;
}
}
int main(void)
{
messageQueue = rt_mq_create("mqFirst", 4, 10, RT_IPC_FLAG_FIFO);
rt_thread_t thread1 = rt_thread_create("thread", thread1t, NULL, 1000, 1, 10);
if (thread1 != RT_NULL)
{
if (rt_thread_startup(thread1) == RT_EOK)
{
rt_kprintf("Thread1 started successfully.\n");
}
else
{
rt_kprintf("Failed to start Thread1.\n");
}
}
else
{
rt_kprintf("Failed to create Thread1.\n");
}
rt_thread_t thread2 = rt_thread_create("thread2", thread2t, NULL, 1000, 1, 10);
if (thread2 != RT_NULL)
{
if (rt_thread_startup(thread2) == RT_EOK)
{
rt_kprintf("thread2 started successfully.\n");
}
else
{
rt_kprintf("Failed to start thread2.\n");
}
}
else
{
rt_kprintf("Failed to create thread2.\n");
}
return 0;
}
RTOS和RTT消息发送接收
于 2024-04-19 18:11:40 首次发布