比如有一個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
}
我跑了一些,但是感覺這個接口封裝的很不直觀,很容易誤導用戶。