FreeRTOS list and list items

FreeRTOS list and list items

Definition analysis

list

List is the data structure of FreeRTOS, similar to linked list. Lists are used to track data tasks for FreeRTOS.

List item

List item

List items are items in the list. FreeRTOS provides two kinds of list items: list items and mini list items.


Mini list item


correlation function

1. List initialization vlistinitialize (& testlist); / / {testlist: List}
2. List item initialization vlistinitializeitem (& listitem1); / / {listitem1: list item 1}
3. Insert list item into vlistinsert (& TestList, & listitem1); / / {insert list item 1ListItem1} into list TestList
 4. Insert vlistinsertend & TestList, & listitem2); / / {insert list item 2ListItem2} to the end of list TestList
 5. List item delete uxlistremove (& ListItem2); / {ListItem2: list item 2}
6. Traversal of ListGet > owner > of next > entry() / {user cannot use}

Experimental phenomena

Requirement

program

#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "timer.h"
#include "lcd.h"
#include "key.h"
#include "FreeRTOS.h"
#include "task.h"

//priority
#define START_TASK_PRIO		1
#define TASK1_TASK_PRIO		2
#define LIST_TASK_PRIO		3

//Stack size
#define START_STK_SIZE 		128  
#define TASK1_STK_SIZE 		128 
#define LIST_STK_SIZE 		128  


//task handle
TaskHandle_t StartTask_Handler;
TaskHandle_t Task1Task_Handler;
TaskHandle_t ListTask_Handler;



//Task function
void start_task(void *pvParameters);
void task1_task(void *pvParameters);
void list_task(void *pvParameters);



//Define a list and 3 list items
List_t TestList;		  //list
ListItem_t ListItem1;	//List item 1
ListItem_t ListItem2;	//List item 2
ListItem_t ListItem3;	//List item 3

int main(void)
{ 
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);//Group 4
	delay_init(168);					//Initialization delay function
	uart_init(115200);     				//Serial port initialization
	LED_Init();		        			//Lamp initialization
	KEY_Init();							//Key initialization

	
	//Start creating task
    xTaskCreate((TaskFunction_t )start_task,            //Task function
                (const char*    )"start_task",          //Task name
                (uint16_t       )START_STK_SIZE,        //Task stack size
                (void*          )NULL,                  //Pass parameters to task
                (UBaseType_t    )START_TASK_PRIO,       //Task priority
                (TaskHandle_t*  )&StartTask_Handler);   //task handle             
    vTaskStartScheduler();          //Turn on scheduler
}

//Start task function
void start_task(void *pvParameters)
{
    taskENTER_CRITICAL();           //Enter critical area
    //Create task 1
    xTaskCreate((TaskFunction_t )task1_task,             
                (const char*    )"task1_task",           
                (uint16_t       )TASK1_STK_SIZE,        
                (void*          )NULL,                  
                (UBaseType_t    )TASK1_TASK_PRIO,        
                (TaskHandle_t*  )&Task1Task_Handler);   
    //Create list task
    xTaskCreate((TaskFunction_t )list_task,     
                (const char*    )"list_task",   
                (uint16_t       )LIST_STK_SIZE,
                (void*          )NULL,
                (UBaseType_t    )LIST_TASK_PRIO,
                (TaskHandle_t*  )&ListTask_Handler); 
    vTaskDelete(StartTask_Handler); //Delete start task
    taskEXIT_CRITICAL();            //Exit critical area
}

//Task 1 task1
void task1_task(void *pvParameters)
{
	while(1)
	{
		LED0=!LED0;
        vTaskDelay(500);                           //delayed
	}
}

//List list task
void list_task(void *pvParameters)
{
	//Step 1: initialize list and list items
	vListInitialise(&TestList);
	vListInitialiseItem(&ListItem1);
	vListInitialiseItem(&ListItem2);
	vListInitialiseItem(&ListItem3);
	
	ListItem1.xItemValue=40;			//ListItem1 list item? 40
	ListItem2.xItemValue=60;			//ListItem2 list item? 60
	ListItem3.xItemValue=50;			//ListItem3 list item? 50
	
	//Step 2: Print list and other list item addresses
	printf("/*******************Print list and other list item addresses*******************/\r\n");
	printf("project                              address				    \r\n");
	printf("TestList                          %#x					\r\n",(int)&TestList);
	printf("TestList->pxIndex                 %#x					\r\n",(int)TestList.pxIndex);
	printf("TestList->xListEnd                %#x					\r\n",(int)(&TestList.xListEnd));
	printf("ListItem1                         %#x					\r\n",(int)&ListItem1);
	printf("ListItem2                         %#x					\r\n",(int)&ListItem2);
	printf("ListItem3                         %#x					\r\n",(int)&ListItem3);
	printf("/************************End**************************/\r\n");
	printf("Press down KEY_UP Continue\r\n\r\n\r\n");
	while(KEY_Scan(0)!=WKUP_PRES) delay_ms(10);					//Wait for key up to be pressed
	

	//Step 3: add ListItem1 list item to TestList
	vListInsert(&TestList,&ListItem1);		//Add ListItem1 list item
	printf("/******************Add ListItem1 list item*****************/\r\n");
	printf("ÏîÄ¿                              µØÖ·				    \r\n");
	printf("TestList->xListEnd->pxNext        %#x					\r\n",(int)(TestList.xListEnd.pxNext));
	printf("ListItem1->pxNext                 %#x					\r\n",(int)(ListItem1.pxNext));
	printf("/*******************Bisection line********************/\r\n");
	printf("TestList->xListEnd->pxPrevious    %#x					\r\n",(int)(TestList.xListEnd.pxPrevious));
	printf("ListItem1->pxPrevious             %#x					\r\n",(int)(ListItem1.pxPrevious));
	printf("/************************End**************************/\r\n");
	printf("Press down KEY_UP Continue\r\n\r\n\r\n");
	while(KEY_Scan(0)!=WKUP_PRES) delay_ms(10);					//Wait for key up to be pressed
	

	//Step 4: add ListItem2 list item to TestList
	vListInsert(&TestList,&ListItem2);	//Add ListItem2 list item
	printf("/******************Add ListItem2 list item*****************/\r\n");
	printf("project                              address   			    \r\n");
	printf("TestList->xListEnd->pxNext        %#x					\r\n",(int)(TestList.xListEnd.pxNext));
	printf("ListItem1->pxNext                 %#x					\r\n",(int)(ListItem1.pxNext));
	printf("ListItem2->pxNext                 %#x					\r\n",(int)(ListItem2.pxNext));
	printf("/*******************Bisection line********************/\r\n");
	printf("TestList->xListEnd->pxPrevious    %#x					\r\n",(int)(TestList.xListEnd.pxPrevious));
	printf("ListItem1->pxPrevious             %#x					\r\n",(int)(ListItem1.pxPrevious));
	printf("ListItem2->pxPrevious             %#x					\r\n",(int)(ListItem2.pxPrevious));
    printf("/************************End**************************/\r\n");
	printf("Press down KEY_UP Continue\r\n\r\n\r\n");
	while(KEY_Scan(0)!=WKUP_PRES) delay_ms(10);					//Wait for key up to be pressed
	

	//Step 5: add ListItem3 list item to TestList
	vListInsert(&TestList,&ListItem3);	//Add ListItem3 list item
	printf("/******************Add ListItem3 list item****************/\r\n");
	printf("project                              address  					\r\n");
	printf("TestList->xListEnd->pxNext        %#x					\r\n",(int)(TestList.xListEnd.pxNext));
	printf("ListItem1->pxNext                 %#x					\r\n",(int)(ListItem1.pxNext));
	printf("ListItem3->pxNext                 %#x					\r\n",(int)(ListItem3.pxNext));
	printf("ListItem2->pxNext                 %#x					\r\n",(int)(ListItem2.pxNext));
	printf("/*******************Bisection line********************/\r\n");
	printf("TestList->xListEnd->pxPrevious    %#x					\r\n",(int)(TestList.xListEnd.pxPrevious));
	printf("ListItem1->pxPrevious             %#x					\r\n",(int)(ListItem1.pxPrevious));
	printf("ListItem3->pxPrevious             %#x					\r\n",(int)(ListItem3.pxPrevious));
	printf("ListItem2->pxPrevious             %#x					\r\n",(int)(ListItem2.pxPrevious));
	 printf("/************************End**************************/\r\n");
	printf("Press down KEY_UP Continue\r\n\r\n\r\n");
	while(KEY_Scan(0)!=WKUP_PRES) delay_ms(10);					//Wait for key up to be pressed
	
    //Step 6: delete ListItem2
	uxListRemove(&ListItem2);						//ɾ³ýListItem2
	printf("/******************Delete ListItem2*****************/\r\n");
	printf("project                            address                           \r\n");
	printf("TestList->xListEnd->pxNext        %#x					\r\n",(int)(TestList.xListEnd.pxNext));
	printf("ListItem1->pxNext                 %#x					\r\n",(int)(ListItem1.pxNext));
	printf("ListItem3->pxNext                 %#x					\r\n",(int)(ListItem3.pxNext));
	printf("/********************Bisection line*******************/\r\n");
	printf("TestList->xListEnd->pxPrevious    %#x					\r\n",(int)(TestList.xListEnd.pxPrevious));
	printf("ListItem1->pxPrevious             %#x					\r\n",(int)(ListItem1.pxPrevious));
	printf("ListItem3->pxPrevious             %#x					\r\n",(int)(ListItem3.pxPrevious));
	printf("/************************End**************************/\r\n");
	printf("Press down KEY_UP Continue\r\n\r\n\r\n");
	while(KEY_Scan(0)!=WKUP_PRES) delay_ms(10);					//Wait for key up to be pressed
	
	
	//Step 7: add list item ListItem2 at the end
	TestList.pxIndex=TestList.pxIndex->pxNext;			//Add list item ListItem2 at the end
	vListInsertEnd(&TestList,&ListItem2);				//Add list item ListItem2 at the end
	printf("/***************Add list item ListItem2 at the end***************/\r\n");
	printf("ÏîÄ¿                              µØÖ·				    \r\n");
	printf("TestList->pxIndex                 %#x					\r\n",(int)TestList.pxIndex);
	printf("TestList->xListEnd->pxNext        %#x					\r\n",(int)(TestList.xListEnd.pxNext));
	printf("ListItem2->pxNext                 %#x					\r\n",(int)(ListItem2.pxNext));
	printf("ListItem1->pxNext                 %#x					\r\n",(int)(ListItem1.pxNext));
	printf("ListItem3->pxNext                 %#x					\r\n",(int)(ListItem3.pxNext));
	printf("/*****************Bisection line*******************/\r\n");
	printf("TestList->xListEnd->pxPrevious    %#x					\r\n",(int)(TestList.xListEnd.pxPrevious));
	printf("ListItem2->pxPrevious             %#x					\r\n",(int)(ListItem2.pxPrevious));
	printf("ListItem1->pxPrevious             %#x					\r\n",(int)(ListItem1.pxPrevious));
	printf("ListItem3->pxPrevious             %#x					\r\n",(int)(ListItem3.pxPrevious));
	printf("/************************End**************************/\r\n\r\n\r\n");
	while(1)
	{
		LED1=!LED1;
        vTaskDelay(1000);                           
	}
}


Published 11 original articles, won praise 2, visited 83
Private letter follow

Posted on Tue, 04 Feb 2020 10:22:58 -0500 by Bou