gpt4 book ai didi

c - 在 freertos API 中使用队列

转载 作者:太空宇宙 更新时间:2023-11-04 07:54:47 24 4
gpt4 key购买 nike

在 freertos 文档中,他们说可以通过两种方式实现队列行为:

Queue by copy:复制排队意味着发送到队列的数据被逐字节复制到队列中。

按引用排队:按引用排队意味着队列只保存指向发送到队列的数据的指针,而不是数据本身。

我的问题是在下面的代码中,当我将结构“CommandData”从任务 1 发送到任务 2,然后更改接收中结构中的 DataArray 字段时任务。这是否会影响发送任务中的相同字段。

换句话说,在这种情况下是按复制排队还是按引用排队?

typedef struct
{
uint8_t * ArrayLength;
uint8_t * DataArray;
}
FunctionStruct;



bool Read(uint8_t * Length, uint8_t * AttributeData)
{
FunctionStruct CommandData;
....
__t_CommandData.ArrayLength = Length;
__t_CommandData.DataArray = AttributeData;
....
xQueueSendToBack(x_Queue, &CommandData, 0U)
.....
}

谢谢

最佳答案

来自 freeRTOS 的描述很清楚:
函数原型(prototype):

BaseType_t xQueueSendToBack(QueueHandle_t xQueue,
const void * pvItemToQueue,
TickType_t xTicksToWait);

pvItemToQueue: A pointer to the item that is to be placed on the queue. The size of the items the queue will hold was defined when the queue was created, so this many bytes will be copied from pvItemToQueue into the queue storage area.

注意:请小心将 0U 作为 xTicksToWait 参数。

xTicksToWait: The maximum amount of time the task should block waiting for space to become available on the queue, should it already be full. The call will return immediately if this is set to 0. The time is defined in tick periods so the constant portTICK_PERIOD_MS should be used to convert to real time if this is required.

关于c - 在 freertos API 中使用队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50914473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com