A queue is a first-in, first-out (FIFO) system that is used to store and pass information between tasks in an RTOS. Data copied to a queue will appear at the front of the queue, and any data added after that will line up behind it. When a task reads from a queue, the value at the front is removed, and all other tasks shift forward by one slot.
The solution to the challenge in the video can be found here: https://www.digikey.com/en/maker/projects/introduction-to-rtos-solution-to-part-5-freertos-queue-example/72d2b361f7b94e0691d947c7c29a03c9
Code for this video series (including demonstrations, challenges, and solutions) can be found here: https://github.com/ShawnHymel/introduction-to-rtos
When a queue is a kernel object within an operating system, read and write operations should be atomic (as they are with FreeRTOS). Atomic operations means that other threads cannot interrupt the operation while it is executing and overwrite or read partial data from shared variables or buffers.
As a result, we can use queues to pass information between tasks in an operating system without fear of losing the data or having it be corrupted by other threads.
In this video, we begin by showing how threads can interrupt each other to overwrite data or read partial data in shared resources (such as a global variable or shared memory). We then examine queues and show how they can protect shared resources. They are an essential form of inter-task communication to pass messages between tasks.
Additionally, we provide an example of using queues in FreeRTOS on an ESP32 using the Arduino framework. A challenge is issued at the end to use queues in your own program.
Product Links:
https://www.digikey.com/en/products/detail/adafruit-industries-llc/3405/7244967
Related Videos:
Introduction to RTOS Part 1 - What is a Real-Time Operating System (RTOS)? -
https://youtu.be/F321087yYy4
Introduction to RTOS Part 2 - Getting Started with FreeRTOS -
https://youtu.be/JIr7Xm_riRs
Introduction to RTOS Part 3 - Task Scheduling -
https://youtu.be/95yUbClyf3E
Introduction to RTOS Part 4 - Memory Management -
https://youtu.be/Qske3yZRW5I
Introduction to RTOS Part 5 - Queue -
https://youtu.be/pHJ3lxOoWeI
Introduction to RTOS Part 6 - Mutex -
https://youtu.be/I55auRpbiTs
Introduction to RTOS Part 7 -
https://youtu.be/5JcMtbA9QEE
Introduction to RTOS Part 8 -
https://youtu.be/b1f1Iex0Tso
Introduction to RTOS Part 9 -
https://youtu.be/qsflCf6ahXU
Introduction to RTOS Part 10 -
https://youtu.be/hRsWi4HIENc
Introduction to RTOS Part 11 -
https://youtu.be/C2xKhxROmhA
Introduction to RTOS Part 12 -
https://youtu.be/LPSHUcH5aQc
Related Project Links:
https://www.digikey.com/en/maker/projects/introduction-to-rtos-solution-to-part-5-freertos-queue-example/72d2b361f7b94e0691d947c7c29a03c9
Related Articles:
https://www.digikey.com/en/maker/videos/shawn-hymel/getting-started-with-stm32-and-nucleo-part-3-how-to-run-multiple-threads-with-cmsis-rtos-interface
Learn more:
Maker.io - https://www.digikey.com/en/maker
Digi-Key’s Blog – TheCircuit https://www.digikey.com/en/blog
Connect with Digi-Key on Facebook https://www.facebook.com/digikey.electronics/
And follow us on Twitter https://twitter.com/digikey