FreeRTOS Course - Queue Management

14,069 views
13,621 views

Published on

Published in: Design, Technology, Business
2 Comments
9 Likes
Statistics
Notes
No Downloads
Views
Total views
14,069
On SlideShare
0
From Embeds
0
Number of Embeds
2,473
Actions
Shares
0
Downloads
0
Comments
2
Likes
9
Embeds 0
No embeds

No notes for slide
  • * 07/16/96 * ##
  • Queues macros are in queues.h while queues implementation is in queue.c. * 07/16/96 * ##
  • FreeRTOS Course - Queue Management

    1. 1. Introduction to FreeRTOS V6.0.5
    2. 2. About SwiftACT <ul><li>A Technology services startup company </li></ul><ul><ul><li>Under establishment </li></ul></ul><ul><li>Areas of specialties: </li></ul><ul><ul><li>Mobile telecommunication services development </li></ul></ul><ul><ul><li>Embedded systems development </li></ul></ul><ul><li>Types of services: </li></ul><ul><ul><li>Consultation </li></ul></ul><ul><ul><li>Managed services </li></ul></ul><ul><ul><li>Sourcing </li></ul></ul><ul><ul><li>Training </li></ul></ul>Introduction to FreeRTOS V6.0.5 Amr Ali Abdel-Naby@2010
    3. 3. About Me <ul><li>Graduated 2004 </li></ul><ul><ul><li>ECE, ASU: 5 yrs distinction </li></ul></ul><ul><li>6+ years in embedded systems development </li></ul><ul><ul><li>SDLC, Apps, MW, DD, Porting, ... </li></ul></ul><ul><li>4+ years in SW engineering </li></ul><ul><ul><li>PSP, CMMI, Systematic reuse, ... </li></ul></ul><ul><li>4+ years in SW testing </li></ul><ul><ul><li>IBM certified, ISTQB certified, ... </li></ul></ul>Introduction to FreeRTOS V6.0.5 Amr Ali Abdel-Naby@2010
    4. 4. Copyright <ul><li>Materials in this course is the property of Amr Ali Abdel-Naby. </li></ul><ul><li>Reproduction or transmission of the materials outside [Customer Name] in any manner without the copyright owner permission is a law violation. </li></ul><ul><li>[Customer Name] is free to use this material as is within its head quarters for noncommercial uses. </li></ul><ul><li>Snapshots or trademarks used are retained to their original owners. </li></ul>Introduction to FreeRTOS V6.0.5 Amr Ali Abdel-Naby@2010
    5. 5. Course Objectives <ul><li>After completing this course, you will: </li></ul><ul><ul><li>Understand what is FreeRTOS </li></ul></ul><ul><ul><li>Experience different FreeRTOS services and APIs </li></ul></ul><ul><ul><li>Understand the porting process of FreeRTOS </li></ul></ul>Introduction to FreeRTOS V6.0.5 Amr Ali Abdel-Naby@2010
    6. 6. Course Notes <ul><li>I assume you are familiar with RTOS concepts. </li></ul><ul><li>I assume you know C. </li></ul><ul><li>I assume you know 80x86 architecture and assembly. </li></ul><ul><li>Ask any time. </li></ul>Introduction to FreeRTOS V6.0.5 Amr Ali Abdel-Naby@2010
    7. 7. Course References <ul><li>http://www.freertos.org </li></ul>Introduction to FreeRTOS V6.0.5 Amr Ali Abdel-Naby@2010
    8. 8. Outline <ul><li>Introduction to FreeRTOS </li></ul><ul><li>Lab 0: Getting Started </li></ul><ul><li>Kernel Structure </li></ul><ul><li>Lab 1: Kernel Structure </li></ul><ul><li>Task Management </li></ul><ul><li>Lab 2: Task Management </li></ul><ul><li>Queue Management </li></ul><ul><li>Lab 3: Queue Management </li></ul><ul><li>Semaphore/Mutex Management </li></ul><ul><li>Lab 4: Semaphore/Mutex Management </li></ul><ul><li>Co-routine Management </li></ul><ul><li>Lab 5: Co-routine Management </li></ul><ul><li>Advanced Features </li></ul><ul><li>Lab 6: Advanced Features </li></ul><ul><li>Porting FreeRTOS </li></ul><ul><li>Lab 7: Porting FreeRTOS </li></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    9. 9. Outline <ul><li>Introduction to FreeRTOS </li></ul><ul><li>Lab 0: Getting Started </li></ul><ul><li>Kernel Structure </li></ul><ul><li>Lab 1: Kernel Structure </li></ul><ul><li>Task Management </li></ul><ul><li>Lab 2: Task Management </li></ul><ul><li>Queue Management </li></ul><ul><li>Lab 3: Queue Management </li></ul><ul><li>Semaphore/Mutex Management </li></ul><ul><li>Lab 4: Semaphore/Mutex Management </li></ul><ul><li>Co-routine Management </li></ul><ul><li>Lab 5: Co-routine Management </li></ul><ul><li>Advanced Features </li></ul><ul><li>Lab 6: Advanced Features </li></ul><ul><li>Porting FreeRTOS </li></ul><ul><li>Lab 7: Porting FreeRTOS </li></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    10. 10. Queues <ul><li>Task-safe FIFO buffers </li></ul><ul><li>Fixed size messages </li></ul><ul><ul><li>Defined during creation </li></ul></ul><ul><li>Messages placed by copy not reference. </li></ul><ul><li>You can copy message reference instead. </li></ul><ul><ul><li>Application programmer responsibility </li></ul></ul><ul><li>Queues are blocking but to a timeout. </li></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5 Message ISR Task Task
    11. 11. More About Queues <ul><li>Some of their APIs are macros that point to queues’ implementation APIs. </li></ul><ul><li>Same queues’ implementation APIs are used to implement semaphores/mutexes. </li></ul><ul><ul><li>Queues and semaphores/mutexes APIs are inter-operable. </li></ul></ul><ul><ul><ul><li>You should be careful if your are going to do this. </li></ul></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    12. 12. Queue Management APIs <ul><li>They fall under 4 categories: </li></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5 Creation xQueueCreate vQueueDelete Fully Featured xQueueSend xQueueSendToBack xQueueSendToFront xQueueReceive xQueuePeek uxQueueMessagesWaiting Light Weight xQueueSendFromISR xQueueSendToBackFromISR xQueueSendToFrontFromISR xQueueReceiveFromISR uxQueueMessagesWaitingFromISR xQueueIsQueueEmptyFromISR xQueueIsQueueFullFromISR Alternative xQueueAltSendToBack xQueueAltSendToFront xQueueAltReceive xQueueAltPeek
    13. 13. Creating a Queue, xQueueCreate <ul><li>xQueueHandle xQueueCreate(unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize) </li></ul><ul><ul><li>uxQueueLength: The maximum number of items that the queue can contain </li></ul></ul><ul><ul><li>uxItemSize: The number of bytes each message in the queue will require </li></ul></ul><ul><ul><ul><li>Each message posted on the queue must be the same size. </li></ul></ul></ul><ul><ul><li>Return value: </li></ul></ul><ul><ul><ul><li>Handle to the newly created queue on success </li></ul></ul></ul><ul><ul><ul><li>NULL on failure </li></ul></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    14. 14. Deleting a Queue, vQueueDelete <ul><li>void vQueueDelete(xQueueHandle xQueue) </li></ul><ul><ul><li>xQueue: A handle to the queue to be deleted </li></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    15. 15. Sending a Message, xQueueSend <ul><li>portBASE_TYPE xQueueSend( xQueueHandle xQueue, const void * pvItemToQueue, portTickType xTicksToWait) </li></ul><ul><ul><li>xQueue: The handle to the queue on which the message is to be posted. </li></ul></ul><ul><ul><li>pvItemToQueue: A pointer to the message that is to be placed on the queue </li></ul></ul><ul><ul><ul><li>Message size should match size defined during creation. </li></ul></ul></ul><ul><ul><li>xTicksToWait: The maximum amount of time the task should block waiting for space to become available on the queue </li></ul></ul><ul><ul><li>Return value: </li></ul></ul><ul><ul><ul><li>pdTRUE if the item was successfully posted </li></ul></ul></ul><ul><ul><ul><li>Otherwise errQUEUE_FULL </li></ul></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    16. 16. Sending a Message to Queue End, xQueueSendToBack <ul><li>portBASE_TYPE xQueueSendToBack(xQueueHandle xQueue, const void * pvItemToQueue, portTickType xTicksToWait) </li></ul><ul><ul><li>= xQueueSend </li></ul></ul><ul><ul><li>Newer version that will be used in future versions of FreeRTOS </li></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    17. 17. Sending a Message to Queue Front, xQueueSendToFront <ul><li>portBASE_TYPE xQueueSendToFront(xQueueHandle xQueue, const void * pvItemToQueue, portTickType xTicksToWait) </li></ul><ul><ul><li>= xQueueSend but with LIFO order </li></ul></ul><ul><ul><li>Newer version that will be used in future versions of FreeRTOS </li></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    18. 18. Destructive Receiving of a Message, xQueueReceive <ul><li>portBASE_TYPE xQueueReceive(xQueueHandle xQueue, void * pvBuffer, portTickType xTicksToWait) </li></ul><ul><ul><li>pxQueue: The handle to the queue from which the message is to be received </li></ul></ul><ul><ul><li>pvBuffer: Pointer to the buffer into which the received message will be copied </li></ul></ul><ul><ul><ul><li>Size defined during creation will be used </li></ul></ul></ul><ul><ul><ul><li>Its size should be adequate. </li></ul></ul></ul><ul><ul><li>xTicksToWait: The maximum amount of time the task should block waiting for a message to become available on the queue </li></ul></ul><ul><ul><li>Return value: </li></ul></ul><ul><ul><ul><li>pdTRUE if the item was successfully posted </li></ul></ul></ul><ul><ul><ul><li>Otherwise pdFALSE </li></ul></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    19. 19. Non-Destructive Receiving, xQueuePeek <ul><li>portBASE_TYPE xQueuePeek(xQueueHandle xQueue, void * pvBuffer, portTickType xTicksToWait) </li></ul><ul><ul><li>= xQueueReceive but non-destructive </li></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    20. 20. Getting Number of Messages in a Queue, uxQueueMessagesWaiting <ul><li>unsigned portBASE_TYPE uxQueueMessagesWaiting(const xQueueHandle xQueue) </li></ul><ul><ul><li>xQueue: A handle to the queue being queried </li></ul></ul><ul><ul><li>Return value: The number of messages available in the queue </li></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    21. 21. Sending a Message from ISR, xQueueSendFromISR <ul><li>portBASE_TYPE xQueueSendFromISR(xQueueHandle pxQueue, const void * pvItemToQueue, portBASE_TYPE * pxHigherPriorityTaskWoken) </li></ul><ul><ul><li>= xQueueSend but used within ISRs </li></ul></ul><ul><ul><li>pxHigherPriorityTaskWoken: Is set to pdTRUE if sending caused a higher priority task to unblock </li></ul></ul><ul><ul><ul><li>A context switch is needed after ISR exits. </li></ul></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    22. 22. Sending a Message to Queue End from ISR, xQueueSendToBackFromISR <ul><li>portBASE_TYPE xQueueSendToBackFromISR(xQueueHandle pxQueue, const void * pvItemToQueue, portBASE_TYPE *pxHigherPriorityTaskWoken) </li></ul><ul><ul><li>= xQueueSendFromISR </li></ul></ul><ul><ul><li>Newer version that will be used in future versions of FreeRTOS </li></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    23. 23. Sending a Message to Queue Front from ISR, xQueueSendToFrontFrom ISR <ul><li>portBASE_TYPE xQueueSendToFrontFromISR(xQueueHandle pxQueue, const void *pvItemToQueue, portBASE_TYPE * pxHigherPriorityTaskWoken) </li></ul><ul><ul><li>= xQueueSendFromISR but with LIFO order </li></ul></ul><ul><ul><li>Newer version that will be used in future versions of FreeRTOS </li></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    24. 24. Destructive Receiving of a Message From ISR, xQueueReceiveFromISR <ul><li>portBASE_TYPE xQueueReceiveFromISR(xQueueHandle pxQueue, void * pvBuffer, portBASE_TYPE * pxTaskWoken) </li></ul><ul><ul><li>= xQueueReceive but used within ISRs </li></ul></ul><ul><ul><li>pxTaskWoken : Is set to pdTRUE if receiving caused a higher priority task to unblock </li></ul></ul><ul><ul><ul><li>A context switch is needed after ISR exits. </li></ul></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    25. 25. Getting Number of Messages in a Queue from ISR, uxQueueMessagesWaitingFromISR <ul><li>unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue ) </li></ul><ul><ul><li>= uxQueueMessagesWaiting but used within ISRs </li></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    26. 26. Checking Queue Emptiness from ISR, xQueueIsQueueEmptyFromISR <ul><li>signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue) </li></ul><ul><ul><li>pxQueue: A handle to the queue being queried </li></ul></ul><ul><ul><li>Return value: </li></ul></ul><ul><ul><ul><li>!0 if empty </li></ul></ul></ul><ul><ul><ul><li>0 if not empty </li></ul></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    27. 27. Checking Queue Fullness from ISR, xQueueIsQueueFullFromISR <ul><li>signed portBASE_TYPE xQueueIsQueueFullFromISR(const xQueueHandle pxQueue) </li></ul><ul><ul><li>pxQueue: A handle to the queue being queried </li></ul></ul><ul><ul><li>Return value: </li></ul></ul><ul><ul><ul><li>!0 if full </li></ul></ul></ul><ul><ul><ul><li>0 if not full </li></ul></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    28. 28. Alternative Sending a Message to Queue End, xQueueSendToBack <ul><li>portBASE_TYPE xQueueAltSendToBack(xQueueHandle xQueue, const void * pvItemToQueue, portTickType xTicksToWait) </li></ul><ul><ul><li>= xQueueSendToBack but with alternative implementation </li></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    29. 29. Alternative Sending a Message to Queue Front, xQueueAltSendToFront <ul><li>portBASE_TYPE xQueueAltSendToFront(xQueueHandle xQueue, const void * pvItemToQueue, portTickType xTicksToWait) </li></ul><ul><ul><li>= xQueueSendToFront but with alternative implementation </li></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    30. 30. AlternativeDestructive Receiving of a Message, xQueueAltReceive <ul><li>portBASE_TYPE xQueueAltReceive(xQueueHandle xQueue, void * pvBuffer, portTickType xTicksToWait) </li></ul><ul><ul><li>= xQueueAltReceive but with alternative implementation </li></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    31. 31. Alternative Non-Destructive Receiving, xQueueAltPeek <ul><li>portBASE_TYPE xQueueAltPeek(xQueueHandle xQueue, void * pvBuffer, portTickType xTicksToWait) </li></ul><ul><ul><li>xQueueAltPeek but with alternative implementation </li></ul></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    32. 32. Outline <ul><li>Introduction to FreeRTOS </li></ul><ul><li>Lab 0: Getting Started </li></ul><ul><li>Kernel Structure </li></ul><ul><li>Lab 1: Kernel Structure </li></ul><ul><li>Task Management </li></ul><ul><li>Lab 2: Task Management </li></ul><ul><li>Queue Management </li></ul><ul><li>Lab 3: Queue Management </li></ul><ul><li>Semaphore/Mutex Management </li></ul><ul><li>Lab 4: Semaphore/Mutex Management </li></ul><ul><li>Co-routine Management </li></ul><ul><li>Lab 5: Co-routine Management </li></ul><ul><li>Advanced Features </li></ul><ul><li>Lab 6: Advanced Features </li></ul><ul><li>Porting FreeRTOS </li></ul><ul><li>Lab 7: Porting FreeRTOS </li></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5
    33. 33. Lab3: Queue Management <ul><li>Please follow the instructions in the lab handout </li></ul>Amr Ali Abdel-Naby@2010 Introduction to FreeRTOS V6.0.5

    ×