Bird
Raised Fist0
FreeRTOSprogramming~30 mins

Queue set for monitoring multiple queues in FreeRTOS - Mini Project: Build & Apply

Choose your learning style10 modes available
Queue set for monitoring multiple queues
📖 Scenario: You are building a simple FreeRTOS application where multiple queues send messages. You want to monitor these queues efficiently using a queue set. This helps your program wait for messages from any queue without checking each one separately.
🎯 Goal: Create two queues and a queue set that monitors both. Then, write code to receive messages from whichever queue has data ready.
📋 What You'll Learn
Create two queues named queue1 and queue2 with length 5 and item size of sizeof(int).
Create a queue set named queueSet that can hold both queues.
Add queue1 and queue2 to queueSet.
Use xQueueSelectFromSet to wait for messages from either queue.
Receive the message from the queue that has data and store it in receivedValue.
💡 Why This Matters
🌍 Real World
Queue sets help embedded developers efficiently wait for messages from multiple sources without wasting CPU time checking each queue separately.
💼 Career
Understanding queue sets is important for embedded systems engineers working with FreeRTOS to build responsive and efficient multitasking applications.
Progress0 / 4 steps
1
Create two queues
Create two queues named queue1 and queue2 using xQueueCreate. Both queues should have a length of 5 and item size of sizeof(int).
FreeRTOS
Hint

Use xQueueCreate(5, sizeof(int)) to create each queue.

2
Create a queue set and add queues
Create a queue set named queueSet using xQueueCreateSet with enough space for both queues. Then add queue1 and queue2 to queueSet using xQueueAddToSet.
FreeRTOS
Hint

Use xQueueCreateSet(10) because the total length is 5 + 5. Then add each queue with xQueueAddToSet.

3
Wait for messages using queue set
Use xQueueSelectFromSet on queueSet with a block time of portMAX_DELAY to wait indefinitely for messages. Store the returned queue handle in activatedQueue. Then receive the message from activatedQueue into an integer variable receivedValue using xQueueReceive.
FreeRTOS
Hint

Use xQueueSelectFromSet(queueSet, portMAX_DELAY) to wait. Then call xQueueReceive on the activated queue.

4
Print the received value
Print the integer receivedValue using printf to display the received message.
FreeRTOS
Hint

Use printf("Received value: %d\n", receivedValue); to show the value.

Practice

(1/5)
1. What is the main purpose of a Queue Set in FreeRTOS?
easy
A. To monitor multiple queues with a single wait call
B. To increase the size of a single queue
C. To create a queue that stores different data types
D. To prioritize tasks based on queue length

Solution

  1. Step 1: Recall the purpose of a Queue Set

    A Queue Set allows monitoring multiple queues or semaphores with one blocking call.
  2. Step 2: Match options to the Queue Set purpose

    Only "To monitor multiple queues with a single wait call" correctly describes this purpose; others describe unrelated features.
  3. Final Answer:

    To monitor multiple queues with a single wait call -> Option A
  4. Quick Check:

    Queue Set = single wait for many queues [OK]
Hint: Queue Set = watch many queues with one wait [OK]
Common Mistakes:
  • Thinking Queue Set increases queue size
  • Confusing Queue Set with task priority
  • Believing Queue Set stores mixed data types
2. Which of the following is the correct way to create a queue set for monitoring two queues in FreeRTOS?
easy
A. xQueueSetCreate( queue1Length + queue2Length, itemSize )
B. xQueueSetCreate( queue1Length * queue2Length, itemSize )
C. xQueueSetCreate( queue1Length + queue2Length, sizeof(void*) )
D. xQueueSetCreate( queue1Length + queue2Length, 0 )

Solution

  1. Step 1: Review parameters of xQueueSetCreate

    The first parameter is the total number of items the set can hold, usually sum of queue lengths. The second is the size of a pointer (sizeof(void*)) because queue sets hold references to queues.
  2. Step 2: Evaluate each option

    xQueueSetCreate( queue1Length + queue2Length, sizeof(void*) ) correctly uses sum of lengths and pointer size. Others are incorrect: itemSize, multiplication, or zero size.
  3. Final Answer:

    xQueueSetCreate( queue1Length + queue2Length, sizeof(void*) ) -> Option C
  4. Quick Check:

    Queue set size = sum lengths, item size = pointer size [OK]
Hint: Queue set size = sum of queues, item size = pointer size [OK]
Common Mistakes:
  • Using item size instead of pointer size
  • Multiplying queue lengths instead of adding
  • Setting item size to zero
3. Given the code snippet:
QueueHandle_t queue1 = xQueueCreate(5, sizeof(int));
QueueHandle_t queue2 = xQueueCreate(3, sizeof(int));
QueueSetHandle_t queueSet = xQueueSetCreate(8, sizeof(void*));
xQueueAddToSet(queue1, queueSet);
xQueueAddToSet(queue2, queueSet);
QueueSetMemberHandle_t activatedQueue = xQueueSelectFromSet(queueSet, portMAX_DELAY);

What does activatedQueue represent after xQueueSelectFromSet returns?
medium
A. A pointer to the data item received
B. A handle to the queue that has data available
C. The total number of items in all queues
D. NULL if no queues have data

Solution

  1. Step 1: Analyze xQueueSelectFromSet behavior

    This function blocks until any queue in the set has data, then returns a handle to that queue.
  2. Step 2: Determine what activatedQueue holds

    It holds the queue handle that has data ready to be read, not the data itself or count.
  3. Final Answer:

    A handle to the queue that has data available -> Option B
  4. Quick Check:

    xQueueSelectFromSet returns queue handle with data [OK]
Hint: xQueueSelectFromSet returns queue handle with data ready [OK]
Common Mistakes:
  • Thinking it returns data pointer
  • Confusing with total item count
  • Expecting NULL when data is available
4. What is wrong with this code snippet for using a queue set?
QueueSetHandle_t set = xQueueSetCreate(5, sizeof(void*));
QueueHandle_t q1 = xQueueCreate(3, sizeof(int));
xQueueAddToSet(q1, set);
QueueSetMemberHandle_t member = xQueueSelectFromSet(set, portMAX_DELAY);
int value;
xQueueReceive(set, &value, 0);
medium
A. xQueueCreate uses wrong item size
B. Queue set size is too small for the queue length
C. xQueueAddToSet is missing for q1
D. xQueueReceive is called with a queue set handle instead of a queue handle

Solution

  1. Step 1: Examine the xQueueReceive call

    The code calls xQueueReceive(set, &value, 0), passing the queue set handle 'set'.
  2. Step 2: Recall the return value of xQueueSelectFromSet

    It returns 'member', a handle to the queue with data available.
  3. Step 3: Identify the mistake

    xQueueReceive must use the queue handle 'member', not the queue set handle 'set'.
  4. Final Answer:

    xQueueReceive is called with a queue set handle instead of a queue handle -> Option D
  5. Quick Check:

    xQueueReceive uses queue handle from set, not set itself [OK]
Hint: xQueueSelectFromSet returns queue handle for xQueueReceive [OK]
Common Mistakes:
  • Confusing queue set handle with queue handle
  • Assuming queue set size must match queue length
  • Missing xQueueAddToSet call
5. You want to monitor three queues with lengths 4, 5, and 6 using a queue set. Which of the following is the best practice to create and use the queue set correctly?
hard
A. Create queue set with size 15, add all queues, then call xQueueSelectFromSet to wait
B. Create queue set with size 6, add all queues, then call xQueueSelectFromSet to wait
C. Create queue set with size 4, add only the largest queue, then call xQueueSelectFromSet
D. Create queue set with size 15, add queues after calling xQueueSelectFromSet

Solution

  1. Step 1: Calculate total queue set size

    The queue set size must be at least the sum of all queue lengths: 4 + 5 + 6 = 15.
  2. Step 2: Add all queues before waiting

    All queues must be added to the set before calling xQueueSelectFromSet to monitor them properly.
  3. Step 3: Evaluate options

    Create queue set with size 15, add all queues, then call xQueueSelectFromSet to wait follows best practice: correct size, all queues added, then wait. Others fail on size, timing, or completeness.
  4. Final Answer:

    Create queue set with size 15, add all queues, then call xQueueSelectFromSet to wait -> Option A
  5. Quick Check:

    Queue set size = sum lengths, add all queues first [OK]
Hint: Queue set size = sum of queues; add all before waiting [OK]
Common Mistakes:
  • Using queue set size smaller than total queue lengths
  • Adding queues after waiting
  • Adding only some queues to the set
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard