STM32F103 porting FreeRTOS series twelve: insertion and deletion experiments of list items (code attached at the end of the article)

This experiment is based on stm32f103rct6 and punctual atom source code

12.1 Experimental program design

1. Purpose of the experiment: Learn to use the FreeRTOS list and the corresponding operation functions of the list items, and observe whether the operation results of these operation functions are consistent with our theoretical analysis.

2. Experiment design Three tasks are designed in this experiment: start_task, task1_task and list_task. The task functions of these three tasks are as follows:

start_task: used to create other 2 tasks.

task1_task: application task 1, control LED0 flashing, used to prompt the system is running.

task2_task: List and list item operation task, call the API functions related to the list and list items, and output the corresponding information through the serial port to observe the running process of these API functions. The experiment needs to use the KEY_UP button (PA0) to control the operation of the task.

In fact, the difference between the code and the atom is not big, just change the corresponding .c and .h files. For example, key.c, led.c, etc., you should be able to handle them casually when you see them here.

Here is a brief record of the experimental results.

 first and second steps

	//第一步:初始化列表和列表项
	vListInitialise(&TestList);
	vListInitialiseItem(&ListItem1);
	vListInitialiseItem(&ListItem2);
	vListInitialiseItem(&ListItem3);
	
	ListItem1.xItemValue=40;			//ListItem1列表项值为40
	ListItem2.xItemValue=60;			//ListItem2列表项值为60
	ListItem3.xItemValue=50;			//ListItem3列表项值为50
	
	//第二步:打印列表和其他列表项的地址
	printf("/*******************列表和列表项地址*******************/\r\n");
	printf("项目                              地址				    \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("/************************结束**************************/\r\n");
	printf("按下KEY_UP键继续!\r\n\r\n\r\n");

The first and second steps are used to initialize the list and list items, and output the address of the list and list items through the serial port. This step is run by default after the development board is reset. The information of the serial port debugging assistant is as follows:

Since the first six bits of the addresses of these lists and list items are all 0X200000, only the lowest 2 bits are different, so we use the lowest 2 bits to represent the addresses of these lists and list items . Notice! The addresses of lists and list items are different on different hardware platforms or compiled software, please refer to your own actual experimental results! Simply analyze Figure 7.7.2.1 to get the following information:

1. The address of the list TestList is bc.

2. The addresses of list items ListItem1, ListItem2 and ListItem3 are d0, e4 and f8 respectively.

3. The xListEnd address of the list TestList is bc. 4. The pxIndex of the list TestList points to the address bc, and this address is exactly the mini-list item xListEnd, indicating that pxIndex points to xListEnd, which is consistent with the result obtained when we analyze the list initialization function vListInitialise().

third step

	while(KEY_Scan(0)!=WKUP_PRES) delay_ms(10);					//等待KEY_UP键按下
	
	//第三步:向列表TestList添加列表项ListItem1,并通过串口打印所有
	//列表项中成员变量pxNext和pxPrevious的值,通过这两个值观察列表
	//项在列表中的连接情况。
	vListInsert(&TestList,&ListItem1);		//插入列表项ListItem1
	printf("/******************添加列表项ListItem1*****************/\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("/*******************前后向连接分割线********************/\r\n");
	printf("TestList->xListEnd->pxPrevious    %#x					\r\n",(int)(TestList.xListEnd.pxPrevious));
	printf("ListItem1->pxPrevious             %#x					\r\n",(int)(ListItem1.pxPrevious));
	printf("/************************结束**************************/\r\n");
	printf("按下KEY_UP键继续!\r\n\r\n\r\n");
	while(KEY_Scan(0)!=WKUP_PRES) delay_ms(10);					//等待KEY_UP键按下

 1. The pxNext of xListEnd points to the address d0, and d0 is the address of ListItem1, which means that the pxNext of xListEnd points to ListItem1. (ring)

2. The pxNext of ListItem1 points to the address c4, and c4 is the address of xListEnd, which means that the pxNext of ListItem1 points to xListEnd.

3. The pxPrevious of xListEnd points to the address d0, and d0 is the address of ListItem1, which means that the pxPrevious of xListEnd points to ListItem2.

4. The pxPrevious of ListItem1 points to the address c4, and c4 is the address of xListEnd, indicating that the pxPrevious of ListItem1 points to xListEnd.

the fourth step

 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 of the list item is similar, and the analysis will not be done in the following steps

 the fifth step

 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.

Steps Six and Seven

These two steps are to observe the running process of functions uxListRemove() and vListInsertEnd()

I will only analyze the seventh step here

 This sentence will change the position pointed to by TestList.pxIndex. By default, it points to the end of the list. Here we point this to list one.

So rank by

132 becomes 213, because this insert function is to insert one bit before the position pointed to by TestList.pxIndex.

 1. The pxNext of xListEnd points to ListItem2.

2. The pxNext of ListItem1 points to ListItem3.

3. The pxNext of ListItem3 points to xListEnd.

4. The pxNext of ListItem2 points to ListItem1.

You can do your own analysis based on the information output by the serial port debugging assistant.

Link: https://pan.baidu.com/s/1ZHX16Nuim6pWLH-y2XM7zQ?pwd=rtos 
Extraction code: rtos

 

Guess you like

Origin blog.csdn.net/qq_51519091/article/details/131604382