比如有一个 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 函数:
/**
*
@param[in] *queue pointer to the event control block
associated with the desired queue
*
*
*/
tls_os_status_t tls_os_queue_send (tls_os_queue_t *queue,
void *msg,
u32 msg_size) ;
/*****************************************************************************
*
* 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
}
我跑了一些, 但是感觉这个接口封装的很不直观, 很容易误导用户.