Click below“Information Technology Person”Follow to explore information technology together
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.
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:
- 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).
- The member uxNumberOfltems records the number of list items (excluding xListEnd).
- The member pxIndex points to a specific list item in the list, typically used for traversing all list items.
- The member variable xListEnd is a mini list item that appears at the end.
Illustration of the list structure:
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:
- The member variable xItemValue is the value of the list item, which is often used for sorting the list items in ascending order.
- The member variables pxNext and pxPrevious point to the next and previous list items in the list, respectively.
- The member variable pxOwner points to the object containing the list item (usually the task control block).
- The member variable pxContainer points to the list containing the list item.
Illustration of the list item structure:
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.
- The member variable xItemValue is the value of the list item, which is often used for sorting the list items in ascending order.
- The member variables pxNext and pxPrevious point to the next and previous list items in the list, respectively.
- 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:
9. Example of the Relationship between Lists and List Items
Answer:
Initial state of the list:
Inserting two list items into the list:
Current state of the list:
2. Introduction to List-Related API Functions (Master)
1. List API Functions
Answer:
2. List Initialization Function vListInitialise()
Answer:
Function Parameters:
Illustration of the list after initialization:
3. List Item Initialization Function vListInitialiseItem()
Answer:
Function Parameters:
Illustration of the list item after initialization:
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.
Function Parameters:
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.
Function Parameters:
6. Function to Remove List Items uxListRemove()
Answer: This function removes a list item from the list it belongs to.
Function Parameters:
Function Return Value:
「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"!