FreeRTOS - Lists and List Items

 

Catalog

Initialization of Lists and List Items

Insertion of List Items

Lists are a data structure in FreeRTOS. They are similar in concept to linked lists. Lists are used to track tasks in FreeRTOS. Everything related to lists is in the files list.c and list. H. In list.h, a structure called List_t is defined as follows:

typedef struct xLIST
{
    listFIRST_LIST_INTEGRITY_CHECK_VALUE;
    configLIST_VOLATILE UBaseType_t   uxNumberOfltems; 
    ListItem_t * configLIST_VOLATILE  pxIndex;
    MiniListItem_t                    xListEnd;
    listSECOND_LIST_INTEGRITY_CHECK_VALUE
} List_t;

                                               

 

List items are items stored in the list. FreeRTOS provides two kinds of list items: list items and mini-list items. Both are defined in the file list.h. Let's first look at the list items and define them as follows:

struct xLIST_ITEM
{
    listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE
    configLIST_VOLATILE TickType_t	xItemValue; 
    struct xLIST_ITEM * configLIST_VOLATILE	  pxNext; 
    struct xLIST_ITEM * configLIST_VOLATILE	pxPrevious;
    void *                      pvOwner;
    void * configLIST           pvContainer;
    listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE_VOLATILE
};
typedef struct  xLIST_ITEM	ListItem_t
struct xMINI_LIST_ITEM
{
    listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE
    configLIST_VOLATILE TickType_t	xItemValue;
    struct xLIST_ITEM * configLIST_VOLATILE	pxNext; 
    struct xLIST_ITEM * configLIST_VOLATILE	pxPrevious;
};
typedef struct xMINI_LIST_ITEM MiniListItem_t;

 

  • List and list item initialization

The initialization of a list is actually to initialize the member variables in the List_t structure. The initialization of a list is accomplished by making the function vListInitialise(), which is defined in list.c. The functions are as follows:

void vListInitialise( List_t * const pxList )
{
    pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd );	
    pxList->xListEnd.xItemValue = portMAX_DELAY;	
    pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd );	
    pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd );
    pxList->uxNumberOfItems = ( UBaseType_t ) 0U;	
    listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList );
    listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList );
}

Initialization of list items is accomplished by the function vListInitialiseItem(), which is as follows:

void vListInitialiseItem( ListItem_t * const pxItem )
{
    pxItem->pvContainer = NULL;    //Initialize pvContainer to NULL
    
    //Initialize variables for integrity checking if this function is turned on.
    listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );             
    listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
}

​​​​

  • List item insertion

The insertion of list items is accomplished by the function vListInsert(). The function prototype is as follows:

void vListInsert( List_t * const   pxList,ListItem_t * const   pxNewListItem )

To illustrate the insertion process, insert three list items into an empty list with values of 40, 60 and 50, respectively.

 

  • Insertion and deletion experiments

This experiment designed three tasks: start_task, task 1_task and list_task. The task functions of these three tasks are as follows:

start_task: Used to create two other tasks.

Task 1_task: Apply Task 1 to control LED 0 flicker to indicate that the system is running.

task2_task: List and list item operation tasks, call list and list item related API functions, and output corresponding information through serial port to observe the operation process of these API functions.

 

Settings of task priority, stack size, task handle, etc.

#define START_TASK_PRIO 1//Task Priority
#Define START_STK_SIZE 128 // Task Stack Size
TaskHandle_t StartTask_Handler;      //task handle
void start_task(void *pvParameters); //Task function	

#define TASK1_TASK_PRIO 2//Task Priority
#Define TASK1_STK_SIZE 128 // Task Stack Size
TaskHandle_t Task1Task_Handler;      //task handle
void task1_task(void *pvParameters); //Task function	


#define LIST_TASK_PRIO 3//Task Priority
#define LIST_STK_SIZE 128 // / Task Stack Size
TaskHandle_t ListTask_Handler;		 //task handle
void list_task(void *pvParameters);  //Task function

 

Definitions of lists and list items:

 

main function:

int main(void)
{
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);//Setting System Interrupt Priority Group 4         
    delay_init(168);	//Initialization Delay Function
    uart_init(115200);	//Initialize Serial Port
    LED_Init();	//Initialization of LED Port
    KEY_Init();	//Initialization key
    LCD_Init();	//Initialize LCD

    POINT_COLOR = RED; LCD_ShowString(30,10,200,16,16,"ATK STM32F103/407");
    LCD_ShowString(30,30,200,16,16,"FreeRTOS Examp 7-1");                 
    LCD_ShowString(30,50,200,16,16,"list and listItem");     
    LCD_ShowString(30,70,200,16,16,"ATOM@ALIENTEK");     
    LCD_ShowString(30,90,200,16,16,"2016/11/25");
    
    //Create Start Tasks		
    xTaskCreate((TaskFunction_t	)start_task,	//Task function
    (const char*	)"start_task",	//Task Name
    (uint16_t	)START_STK_SIZE,	//Task Stack Size
    (void*	)NULL,	//Parameters passed to task functions
    (UBaseType_t	)START_TASK_PRIO,	//Task Priority
    (TaskHandle_t*	)&StartTask_Handler);	//task handle
    vTaskStartScheduler();		//Open Task Scheduling
}

 

Verification:

  1. The list TestList address is b4.
  2. The addresses of ListItem1, ListItem2 and ListItem3 are c8, dc and f0, respectively.
  3. The xListEnd address of the list TestList is bc.
  4. The pxIndex of the List TestList points to the address bc, which is exactly the mini-list item xListEnd, indicating that pxIndex points to xListEnd, which is consistent with the result of our analysis of the list initialization function vListInitialise().

 

   

  1. The pxNext of xListEnd points to address c8, while C8 is the address of ListItem1, indicating that the pxNext of xListEnd points to ListItem1.
  2. The list item pxNext of ListItem1 points to address bc, while BC is the address of xListEnd, indicating that pxNext of ListItem1 points to xListEnd.
  3. The pxPrevious of xListEnd points to address c8, which is the address of ListItem1, indicating that pxPrevious of xListEnd points to ListItem2.
  4. ListItem1's pxPrevious points to address bc, which is the address of xListEnd, indicating that ListItem1's pxPrevious points to xListEnd.

 

       

  1. The pxNext of xListEnd points to ListItem1.
  2. The pxNext of ListItem1 points to ListItem2.
  3. The pxNext of ListItem2 points to xListEnd.
  4. The pxPrevious analysis process for list items is similar. In the following steps, the analysis is not done, but only the pxNext member variables.

 

     

  1. The pxNext of xListEnd points to ListItem1.
  2. The pxNext of ListItem1 points to ListItem3.
  3. The pxNext of ListItem3 points to ListItem2.
  4. The pxNext of ListItem2 points to xListEnd.

Posted by Jack_Slocum on Sun, 04 Aug 2019 02:15:59 -0700