消息队列

仅作记录

QueueHandle_t q_handle;

q_handle = xQueueCreate(5, 1);

static void send_Task(void* pvParameters)
{
    uint8_t datat = 8;
    while(1)
    {
        BaseType_t  xReturn = xQueueSend( q_handle, &datat, 0);       
      if(pdPASS == xReturn)
        printf("发送成功!\n\r");

        vTaskDelay(10);
    }
}

static void receive_Task(void* pvParameters)
{
    uint8_t data1 = 0;
    const TickType_t xMaxBlockTime = pdMS_TO_TICKS(3000); /* 设置最大等待时间为300ms */
    while(1)
    {
        if(xQueueReceive(q_handle, (void*)&data1, (TickType_t)xMaxBlockTime) == pdPASS)
        {
            printf("接收成功data: %d\n\r",data1);            
        }        
    }
}

 

posted @ 2024-04-03 10:22  njit-sam  阅读(6)  评论(0编辑  收藏  举报