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.7k
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

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览