Home | Projects | Notes > Real-Time Operating Systems (RTOS) > Exercise: Queues and Timers (09_Queues_and_Timers)

Exercise: Queues and Timers (09_Queues_and_Timers)

 

Problem Statement

5 FreeRTOS tasks to implement and the Application Flow

 

exercise-09-queues-and-timers-application-flow-1

 

 

exercise-09-queues-and-timers-application-flow-2

 

 

exercise-09-queues-and-timers-application-flow-3

 

Receiving Data from User

Guideline

  1. Create a new project

  2. Create main.c, task_hanlder.c, led_effect.c, and rtc.c

  3. In the main function, create:

    • 5 tasks (use the same priority for all tasks 2)

    • 2 queues

 

Project Setup

 

Implementation

See the source code: https://github.com/kyungjae-lee/freertos-projects/tree/main/Workspace/09_Queues_and_Timers.

 

Review Questions

  1. What can be used for inter task communication?

    Semaphore, Queues, Pipes, Message Queues, etc.

  2. Let's say a queue is full, and a task1 of priority 5 was blocked on a queue while its attempt to write on that queue, now lets say task2 of priority 3 removes a data item from that queue. Do you think the moment task 2 removes a data item, it will be preempted by task 1?

    Yes, Task2 will be preempted by Task1 the moment it removes the data item from the queue. (It does not wait till the next kernel tick.)

  3. Can the Queue APIs be called from ISR in FreeRTOS?

    Yes, but its ISR versions must be used

  4. Are the Queue APIs ending with "FromISR" allowed to do task yielding?

    No

  5. Can a task block on a queue indefinitely?

    Yes, use "portMAX_DELAY" for the delay parameter of the queue read/write APIs

  6. Can a task choose not to block on a queue?

    Yes, use "0" for the delay parameter of the queue read/write APIs

  7. Describe what will happen when the following code gets executed (Assume : 32bit Processor):

    xQueueCreate( 5, sizeof(uint32_t) )

    20 bytes + sizeof(QCB) will be consumed in the heap space of the RAM.

  8. Can we use Queue for synchronization between tasks or between task and an interrupt?

    Yes

 

 

References

Nayak, K. (2022). Mastering RTOS: Hands on FreeRTOS and STM32Fx with Debugging [Video file]. Retrieved from https://www.udemy.com/course/mastering-rtos-hands-on-with-freertos-arduino-and-stm32fx/