Lists and List Items in FreeRTOS

Click belowInformation Technology PersonFollow to explore information technology togetherLists and List Items in FreeRTOS

Lists and List Items in FreeRTOS

1. Introduction to Lists and List Items (Familiarize)

1. What is a List

Answer: A list is a data structure in FreeRTOS that conceptually resembles a linked list, used to track tasks in FreeRTOS.

2. What is a List Item

Answer: A list item is an entry stored within a list.

3. Relationship between Lists and List Items

Answer: A list is equivalent to a linked list, while a list item is akin to a node; the list in FreeRTOS is a doubly linked circular list.

Lists and List Items in FreeRTOS

4. Differences between Lists (Linked Lists) and Arrays

Answer:

  • Characteristics of Lists: The addresses of list items are non-contiguous and are linked together artificially. The number of list items can change based on additions or deletions at any time.
  • Characteristics of Arrays: The addresses of array members are contiguous, and once the number of members is determined, it cannot be changed later.

5. Why Use Lists in an OS

Answer: In an OS, the number of tasks is uncertain, and their states can change, making the list (linked list) data structure very suitable.

6. Introduction to List Structure

Answer: All list-related items are in the files list.c and list.h. Below is the list structure:Lists and List Items in FreeRTOS

  1. In the structure, there are two macros (listFIRST_LIST_INTEGRITY_CHECK_VALUE and listSECOND_LIST_INTEGRITY_CHECK_VALUE), which are known constants. FreeRTOS checks the values of these constants to determine if the list data has been corrupted during program execution; this feature is generally used for testing and is disabled by default (we usually do not need to worry about it).
  2. The member uxNumberOfltems records the number of list items (excluding xListEnd).
  3. The member pxIndex points to a specific list item in the list, typically used for traversing all list items.
  4. The member variable xListEnd is a mini list item that appears at the end.

Illustration of the list structure:

Lists and List Items in FreeRTOS

7. Introduction to List Item Structure

Answer: A list item is where data is stored in the list. The relevant structure definitions for list items are in the list.h file:

Lists and List Items in FreeRTOS

  1. The member variable xItemValue is the value of the list item, which is often used for sorting the list items in ascending order.
  2. The member variables pxNext and pxPrevious point to the next and previous list items in the list, respectively.
  3. The member variable pxOwner points to the object containing the list item (usually the task control block).
  4. The member variable pxContainer points to the list containing the list item.

Illustration of the list item structure:

Lists and List Items in FreeRTOS

8. Mini List Items

Answer: A mini list item is also a list item, but it is only used to mark the end of the list and to mount other list items inserted into the list.

Lists and List Items in FreeRTOS

  1. The member variable xItemValue is the value of the list item, which is often used for sorting the list items in ascending order.
  2. The member variables pxNext and pxPrevious point to the next and previous list items in the list, respectively.
  3. Mini list items are only used to mark the end of the list and to mount other list items inserted into the list, so they do not need the member variables pxOwner and pxContainer to save memory overhead.

Illustration of a mini list item:

Lists and List Items in FreeRTOS

9. Example of the Relationship between Lists and List Items

Answer:

Initial state of the list:

Lists and List Items in FreeRTOS

Inserting two list items into the list:

Lists and List Items in FreeRTOS

Current state of the list:

Lists and List Items in FreeRTOS

2. Introduction to List-Related API Functions (Master)

1. List API Functions

Answer:

Lists and List Items in FreeRTOS

2. List Initialization Function vListInitialise()

Answer:

Lists and List Items in FreeRTOS

Function Parameters:

Lists and List Items in FreeRTOS

Illustration of the list after initialization:

Lists and List Items in FreeRTOS

3. List Item Initialization Function vListInitialiseItem()

Answer:

Lists and List Items in FreeRTOS

Function Parameters:

Lists and List Items in FreeRTOS

Illustration of the list item after initialization:

Lists and List Items in FreeRTOS

4. Function to Insert List Items vListInsert()

Answer: This function is used to insert a list item into the list in ascending order based on the item value.

Lists and List Items in FreeRTOS

Function Parameters:

Lists and List Items in FreeRTOS

Summary: The function vListInsert() arranges the inserted list item in ascending order based on its value.

5. Function to Insert List Items at the End vListInsertEnd()

Answer: This function inserts a list item before the item pointed to by the pxIndex pointer, which is an unordered insertion method.

Lists and List Items in FreeRTOS

Function Parameters:

Lists and List Items in FreeRTOS

6. Function to Remove List Items uxListRemove()

Answer: This function removes a list item from the list it belongs to.

Lists and List Items in FreeRTOS

Function Parameters:

Lists and List Items in FreeRTOS

Function Return Value:

Lists and List Items in FreeRTOSLists and List Items in FreeRTOS

「Share Knowledge」

If you find this article helpful, please share it with more people in need; just click share to spread knowledge!

Follow me 【Information Technology Person】
Explore information technology together

If you like it, give Information Technology Person a "like", "share", or "recommend"!

Leave a Comment