Read accumulated data in a queueSet

Hello)
I’m trying to use a queue set that has two queues, if queue 2 has multiple values accumulated, how do I read them?

if I just use a queue and data has accumulated there (for example, the task has been stopped), then when I get into the task, I can read everything that is there at once, but with a queueSet I could not do this.

With a QueueSet, you ask the QueueSet for where the next data is, and then go to THAT Queue and get the data.

If queue2 has multiple pieces of data in it, then the QueueSet will have multiple entries in it of data in queue2.

You need to closely follow the API instructions, or you can get the QueueSet out of sync with the Queues, and then “bad things” can happen.

I follow the API instructions)
But in the case of a queueSet, I only get the last element in the queue (if there are several values in the queue), the remaining values remain in the queue until it is completely full…

Can you show your code?

I have some kind of interface through which I can send and receive data, but it is not possible to do both at the same time.
That is, if I receive data, then I need to wait until the end of reception and only then send it.
i.e. if I receive data (I set the flag STATE_BUSY_RX)
When the data is received, I set the flag STATE_READY and if there is data in the queue to be sent, it can be sent
I thought QueueSet would be the best solution because while I’m receiving, I can add several data to send to the queue, and then when the interface is free, I can take data from the queue one by one (at short intervals) to send.

void TransceiverTask(void const * argument)
{
  /* USER CODE BEGIN TransceiverTask*/
	my_struct_rx bean_rx;
	my_struct_tx bean_tx;

	QueueSetHandle_t xQueueSet;
	QueueSetMemberHandle_t xActivatedMember;

	xQueueSet = xQueueCreateSet( 20 );

	 xQueueAddToSet( RX_QueueHandle, xQueueSet );
	 xQueueAddToSet( TX_QueueHandle, xQueueSet );

	/* Infinite loop */
	for (;;) {

		xActivatedMember = xQueueSelectFromSet( xQueueSet, 200);


		if((bus_state == STATE_READY) && (xActivatedMember == RX_QueueHandle)){
			xQueueReceive(RX_QueueHandle, &data_rx, 0);
		}


		if((bus_state == STATE_READY) && (xActivatedMember == TX_QueueHandle))
		{
			xQueueReceive(TX_QueueHandle, &data_tx, 0);

		}

	}

  /* USER CODE END TransceiverTask*/
}

from other tasks, data is placed in queues (for sending and/or receiving)
For example, in another task the data is in receive mode, the flag bus_state = BUSY_RX is set there.
At this time, data may arrive in the queue for sending, but since the STATE_READY flag is not set, I cannot send the data, I need to wait until the end of receiving data, receive the free line flag and then the accumulated data for sending must be sent (one after another with short period of time)

Your problem is that once you get the value from the QueueSet, you MUST get that data from that queue, and your bus_state == STATE_READY condition breaks that requirement.

Don’t take any items from the QueueSet until you are ready to take the items from the Queues.

My first though is you have a problem with your definitions, as it seems strange that a task is reading from both the RX and TX queues under the same conditions.

you mean all or nothing, if there is data in both queues then they all need to be taken at once?)

I assumed which queue the data came in first, that one will be processed first, and the second one will wait…

As I understand it, for my implementation, queueSet are not suitable and it is better to do it in different tasks

The QueueSet works by putting a marker into the QueueSet queue for each piece of data put into one of the queues in the set.

When you take that marker, you MUST take the data out of that Queue, or you break the QueueSet. If you don’t, the QueueSet doesn’t know that the data is still in that Queue.

You can get away with reading data instead from a different Queue, but then in the future, when it tells you to read that data from that Queue, you will need to read for the Queue you were told the first time, so that isn’t recommended unless you know what you are doing and document your “breaking” of the rules to not trip up the next person that needs to work on your code.

If you know which Queue you will need to read from, you don’t need the QueueSet. Its whole purpose is to allow you to wait for data from multiple sources that you don’t know which one will give you the next data.

Now I know more about the queue set, thanks!

I understand correctly, in order to use two queues in one task, you need to use a queueSet or (for example) a event group?

I tried to put two queues (A and B) in one task, but if I blocked the task for the portMAX_DELAY with queue A (before receiving any data in the queue), I cannot unblock the same task with queue B (when receiving data)?

NO. Queue are not “tied” to tasks.

You need a QueueSet if a task wants to wait for data an either (any) of the Queues in the Set.

If you know the Queue to take from next, you can just access the Queue. If you don’t, a QueueSet might help, or the task that puts data in the other Queue could signal the task with a call to xTaskAbortDelay().

Note, I generally try to avoid delays of portMAX_DELAY (unless I really have nothing to do until something comes, and it may be a long time), but try to figure a timeout value and handle the “error” condition.

QueueSets are the “Wait for multiple objects” in FreeRTOS, or you could use an EventGroup.

Rather than trying to tell us what you’re trying to do with a certain FreeRTOS structure, can you tell us what you’re trying to do? I think you’ll get an answer for what you’re actually trying to do.