tls_os_queue_send和tls_os_queue_receive應怎麼使用?

發布於 2022-09-06 20:52:44

比如有一個mytype_t的數據要發送,根據tls_os_queue_send的參數說明,如下:
mytype_t data;
tls_os_status_t res = tls_os_queue_send(queue_handle, &data, sizeof(mytype_t));
但實際上接收端並沒有收到正確的數據,請問如何理解這2個函數的參數?

tls_os_queue_send函數:
/**

  • @brief This function sends a message to a queue

*

  • @param[in] *queue pointer to the event control block

                              associated with the desired queue
  • @param[in] *msg pointer to the message to send.
  • @param[in] msg_size message size

*

  • @retval 0 success
  • @retval other failed

*

  • @note None

*/
tls_os_status_t tls_os_queue_send(tls_os_queue_t *queue,

    void *msg,
    u32 msg_size);

查看更多

關注者
0
被浏覽
1.8k
ZYQ
ZYQ 2022-09-06
我已不再支持W80X任何相關問題的回複,請大家不要私信,有問題找 isme 謝謝

建議你直接先跑一下SDK中的demo 測試程序,裡面有大量的該接口的使用例程,可以參考

2 個回答
isme
isme 認證專家 2022-09-07
冰鎮大西瓜
/***************************************************************************** 
* 
* File Name : main.c
* 
* Description: main 
* 
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd. 
* All rights reserved. 
* 
* Author : dave
* 
* Date : 2014-6-14
*****************************************************************************/ 
#include "wm_include.h"

#define USER_TASK_QUEUE_SIZE             1
#define USER_TASK_QUEUE_TEST             0x01
static tls_os_queue_t *user_task_queue = NULL;

static OS_STK TaskStk1[512];
static OS_STK TaskStk2[512];



static void user_task1(void)
{

    while(1)
    {
        printf("---> send msg\r\n");
        // 發送隊裡消息
        tls_os_queue_send(user_task_queue, (void *)USER_TASK_QUEUE_TEST, 0);
        tls_os_time_delay(HZ);
    }
}

static void user_task2(void)
{
    void *msg;
    tls_os_status_t ret;

    for ( ; ; )
    {
        // 接收隊裡消息
        ret= tls_os_queue_receive(user_task_queue, (void **)&msg, 0, 0);
        if (ret == TLS_OS_SUCCESS)
        {
            switch((u32)msg)
            {
            case USER_TASK_QUEUE_TEST: // 收到指定的消息
                printf("---> received msg\r\n");
                break;

            default:
                break;
            }
        }
    }
}

void UserMain(void)
{
    printf("\n user task \n");
    // 創建task1用於發送隊列消息
    tls_os_task_create(NULL, "task1",
                        ( void (*))user_task1,
                        NULL,
                        (void *)TaskStk1,          /* task's stack start address */
                        sizeof(TaskStk1), /* task's stack size, unit:byte */
                        31,
                        0);
    // 創建task2用於接收隊裡消息
    tls_os_task_create(NULL, "task2",
                        ( void (*))user_task2,
                        NULL,
                        (void *)TaskStk2,          /* task's stack start address */
                        sizeof(TaskStk2), /* task's stack size, unit:byte */
                        32,
                        0);
    // 創建消息隊列
    tls_os_queue_create(&user_task_queue, USER_TASK_QUEUE_SIZE);

#if DEMO_CONSOLE
    CreateDemoTask();
#endif
//用戶自己的task
}

image.png

撰寫答案

請登錄後再發布答案,點擊登錄

發布
問題

分享
好友

手機
浏覽

掃碼手機浏覽