简体   繁体   English

在freertos API中使用队列

[英]Using Queues in freertos API

In freertos documentation they say that There are two ways in which queue behavior could have been implemented: 他们在freertos文档中说,可以通过两种方式来实现队列行为:

Queue by copy : Queuing by copy means the data sent to the queue is copied byte for byte into the queue. 按复制队列:按复制排队意味着将发送到队列的数据逐字节复制到队列中。

Queue by reference : Queuing by reference means the queue only holds pointers to the data sent to the queue, not the data itself. 按引用排队:按引用排队意味着队列仅保存指向发送到队列的数据的指针,而不是数据本身。

My question is in the code bellow when i send the struct "CommandData" from task1 to task2 and then change the DataArray field in the struct in the receiving task.does this affect the same field in the sending task. 当我从任务1向任务2发送结构“ CommandData”,然后在接收任务中更改结构中的DataArray字段时,我的问题在下面的代码中。这是否会影响发送任务中的同一字段。

In other word in this case is it Queuing by copy or Queuing by reference? 换句话说,在这种情况下是按副本排队还是按引用排队?

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)
     .....
    }

thank you 谢谢

The description from freeRTOS is pretty clear: freeRTOS的描述非常清楚:
Function protoype: 功能原型:

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. pvItemToQueue :指向要放在队列中的项目的指针。 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 . 创建队列时已定义了队列将要容纳的项目的大小, 因此,这许多字节将从pvItemToQueue复制到队列存储区域

NB: Be careful giving 0U as xTicksToWait parameter. 注意:小心将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. xTicksToWait :如果任务已满,则该任务应阻止等待队列上的可用空间的最长时间。 The call will return immediately if this is set to 0 . 如果将其设置为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. 时间以滴答周期定义,因此如果需要,应使用常数portTICK_PERIOD_MS转换为实时。

You have confused yourself by using struct that contains pointers. 您已经通过使用包含指针的结构使自己感到困惑。 Yes, the struct is passed by copy, but the copy holds the pointers, not the actual data. 是的,该结构是通过副本传递的,但是副本包含指针,而不是实际数据。

Since length is a pointer, if the receiver modifies length it will not result change in the sender's context, but if it modifies *length (the actual data length is pointing at) than the sender's *length will indeed be effected. 由于length是指针,因此,如果接收者修改了长度,则不会导致发送者上下文的变化,但是,如果修改了* length(指向实际数据长度),则发送者的* length确实会受到影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM