当前位置:网站首页>[practice] stm32mp157 development tutorial FreeRTOS system 6: FreeRTOS list and list items
[practice] stm32mp157 development tutorial FreeRTOS system 6: FreeRTOS list and list items
2022-06-21 09:13:00 【Huaqing vision it open laboratory】
1. Write it at the front :
This article is 《STM32MP157 Developing a tutorial FreeRTOS Operating system 》 One in a series , The development platform used by the author is Huaqing vision FS-MP1A Development board (STM32MP157 Development board ).stm32mp157 yes ARM Dual core ,2 individual A7 nucleus ,1 individual M4 nucleus ,A7 You can run on the core Linux operating system ,M4 You can run on the core FreeRTOS、RT-Thread And other real-time operating systems ,STM32MP157 Development board, so you can learn Embedded linux, You can also learn. stm32 Single chip microcomputer .
in the light of FS-MP1A Development board , except FreeRTOS Outside the operating system , There are also many other series of tutorials , Include Cortex-A7 Development of article 、Cortex-M4 Development of article 、 Expansion board driver transplantation 、Linux Application development 、Linux System transplantation 、Linux Driving development 、 Hardware design 、 Artificial intelligence machine vision 、Qt Application programming 、Qt Comprehensive project practice, etc . Welcome to your attention , more stm32mp157 Develop tutorials and videos , Technical exchange can be added Q Group 459754978, Thank you for attention .
FS-MP1A Development board Details : TaoBao - Amoy ! I like
2.FreeRTOS Lists and list items
2.1 Introduction to lists and list items
Study FreeRTOS, There must be lists and list items , Lists and list items are FreeRTOS A data structure , It is FreeRTOS Cornerstone .
Lists are used to track FreeRTOS The task , stay list.h The list structure is defined in the file List_t as follows
typedef struct xLIST
{
listFIRST_LIST_INTEGRITY_CHECK_VALUE
configLIST_VOLATILE UBaseType_t uxNumberOfItems;
ListItem_t * configLIST_VOLATILE pxIndex;
MiniListItem_t xListEnd;
listSECOND_LIST_INTEGRITY_CHECK_VALUE
} List_t;
The first and fifth lines are used to check the integrity of the list , You need to put the macro
configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES Set to 1.
uxNumberOfItems Used to record the number of items in a list .
pxIndex Used to record the index number of the current list item , For traversing the list .
xListEnd Represents the last list item in the list , Used to indicate the end of a list .
A list item is an item stored in a list , Its definition is 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_VOLATILE pvContainer;
listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE
};
typedef struct xLIST_ITEM ListItem_t;
The first and seventh lines are the same as the list , Are used to check the integrity of list items .
xItemValue Is the list item value .
pxNext Point to the next list item .
pxPrevious Point to the previous list item , And pxNext Match .
pvOwner Record who owns this list item , It's usually a task control block .
pvContainer Used to record which list items belong to .
There is also a mini list item , Its definition is as follows
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;
The first line is also used to check the integrity of the mini list items .
xItemValue Record list item values .
pxNext Point to the next list item .
pxPrevious Point to the previous list item .
The reason for this is to get a mini list item , Because in some cases , We don't need the full functionality of list items , You may only need a few of these member variables , Using list items at this time may cause a waste of memory .
2.2 List and list item functions
2.2.1 List and list item initialization
Newly created or defined lists need to be initialized , The initialization function for the list is vListInitialise(), The function prototype is as follows :
void vListInitialise ( List* const pxList)
Parameters :
pxList: List to initialize .
Return value : nothing
The initialization function for the list item is vListInitialiseItem(), The function prototype is as follows :
void vListInitialiseItem ( ListItem_t * const pxItem)
Parameters :
pxItem: List to initialize .
Return value : nothing
The specific code of the initialization function is not described here , If you are interested, you can go to list.c View in file .
2.2.2 List item insert
The insertion function of the list item is vListInsert(), The function prototype is as follows :
void vListInsert( List* const pxList, ListItem_t * const pxNewListItem)
Parameters :
pxList: List item list to insert .
pxNewListItem: List item to insert .
Return value : nothing
2.2.3 Insert... At the end of the list item
The function to insert a list item at the end of the list is vListInsertEnd(), The function prototype is as follows :
void vListInsertEnd( List * const pxList, ListItem_t * const pxNewListItem)
Parameters :
pxList: List item list to insert .
pxNewListItem: List item to insert .
Return value : nothing
2.2.4 List item delete
If there is insertion, there must be deletion , The delete function of the list item is uxListRemove(), The function prototype is as follows :
UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
Parameters :
pxItemToRemove: List item to delete .
Return value :
Returns the number of remaining list items in the list after deleting list items .
Deleting a list item only deletes the specified list item from the list , Does not free up memory for list items .
2.3 Operation experiment
2.3.1 Experimental design
This design creates a list and three list items , Collect the key status by interrupting , When KEY1 When pressed , Add three list items to the list in turn , When KEY2 When pressed , Delete the first 2 List items , When KEY3 When pressed , And then 2 A list item is inserted from the end .
May refer to 12.3.2 Chapter to import the existing project , Project storage path 【 Huaqing vision -FS-MP1A Development of information \02- Program source code \ARM Architecture and interface technology \FreeRTOS\7_MP1A-FreeRTOS-List】
The tasks and their functions are as follows :
StartTask02(): Initialize the list and list items and print , Then collect the key status , Carry out different processing according to different key results .
StartDefaultTask(): Give Way LED3 Cycle flashing , Prompt the system to operate normally .
2.3.2 Experimental process and analysis
First , Configure... According to the previous chapters CubeMX, Configure... According to the previous section “FREERTOS”, Generate code when finished . stay StartDefaultTask() And StartTask02() Add the following code to .
void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
LED_3_TOG();
osDelay(1000);
}
/* USER CODE END 5 */
}
void StartTask02(void *argument)
{
/* USER CODE BEGIN StartTask02 */
/* Infinite loop */
// Initializing lists and list items
vListInitialise(&TestList);
vListInitialiseItem(&ListItem1);
vListInitialiseItem(&ListItem2);
vListInitialiseItem(&ListItem3);
ListItem1.xItemValue=40; //ListItem1 The list item value is 40
ListItem2.xItemValue=60; //ListItem2 The list item value is 60
ListItem3.xItemValue=50; //ListItem3 The list item value is 50
// Print the addresses of lists and other list items
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);
for(;;)
{
if(key == EVENTBIT_1)
{
// To list TestList Add list item ListItem1, And print all of them through serial port
// Member variables in list items pxNext and pxPrevious Value , Look at the list through these two values
// The connection of items in the list .
vListInsert(&TestList,&ListItem1); // Insert list item ListItem1
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("/***********Connect the divider front and back 1************/\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");
// To list TestList Add list item ListItem2, And print all of them through serial port
// Member variables in list items pxNext and pxPrevious Value , Look at the list through these two values
// The connection of items in the list .
vListInsert(&TestList,&ListItem2); // Insert list item ListItem2
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("/***********Connect the divider front and back 2************/\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");
// To list TestList Add list item ListItem3, And print all of them through serial port
// Member variables in list items pxNext and pxPrevious Value , Look at the list through these two values
// The connection of items in the list .
vListInsert(&TestList,&ListItem3); // Insert list item ListItem3
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("/************Connect the divider front and back 3************/\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");
}
if(key == EVENTBIT_2)
{
// Delete ListItem2, And print all the member variables of list items through serial port pxNext and Previous Value , Use these two values to observe the connection of the list items in the list .
uxListRemove(&ListItem2); // Delete ListItem2
printf("/**************Delete list items 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("/***********Connect the divider front and back 2************/\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");
}
if(key == EVENTBIT_3)
{
// Add... At the end ListItem2, And print all the member variables of list items through serial port pxNext and Previous Value ,
// Use these two values to observe the connection of the list items in the list .
TestList.pxIndex=TestList.pxIndex->pxNext; //Index Move one item back , such pxIndex Can point to ListItem1.
vListInsertEnd(&TestList,&ListItem2); // Add a list item to the end of the list ListItem2
printf("/***********Add the list at the end of ListItem2***********/\r\n");
printf("project address \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("/************Connect the divider front and back 2*************/\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");
}
key = 0;
osDelay(100);
}
/* USER CODE END StartTask02 */
}
Write the key interrupt callback function as follows
void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)
{
switch(GPIO_Pin)
{
case GPIO_PIN_8:
if(HAL_GPIO_ReadPin(GPIOF,GPIO_PIN_8) == GPIO_PIN_SET) /* read KEY3 PF8 state */
key = EVENTBIT_3;
break;
case GPIO_PIN_7:
if(HAL_GPIO_ReadPin(GPIOF,GPIO_PIN_7) == GPIO_PIN_SET) /* read KEY2 PF7 state */
key = EVENTBIT_2;
break;
case GPIO_PIN_9:
if(HAL_GPIO_ReadPin(GPIOF,GPIO_PIN_9) == GPIO_PIN_SET) /* read KEY1 PF9 state */
key = EVENTBIT_1;
break;
}
}
After the burning program , Open the serial port , It can be found that the display is as follows

When pressed KEY1 Key time , Add a list item to the list , The serial port is shown as follows

When KEY2 When the key is pressed , Delete the first 2 List items , The remaining results are as follows

Now press KEY3 key , Will be the first 2 A list item is inserted from the end , The final results are as follows

Hardware platform : Huaqing vision FS-MP1A Development board (STM32MP157)
Download some development tutorials : Add QQ Group 459754978, There are in the group file .
Watch some video courses :
https://space.bilibili.com/670826565/channel/detail?cid=145472
Taobao purchase link :
https://item.taobao.com/item.htm?id=622457259672
Mobile Taobao sharing code : Copy the text of this line and open hand Amoy ₤T4FPXn3YYJ2₤
边栏推荐
- 【C】【时间操作】C语言中关于时间的操作
- 【实战】STM32 FreeRTOS移植系列教程4:FreeRTOS 软件定时器
- C#中的list操作入门
- Abstractqueuedsynchronizer (AQS) source code detailed analysis - semaphore source code analysis
- Unity的网络请求_短连接
- Mono fourni avec l'unit é 5 peut également supporter C # 6
- Unity Detailed explanation of meta file function
- STL教程2-MyArray框架实现
- Leetcode: print the common part of two ordered linked lists
- Detailed analysis of abstractqueuedsynchronizer (AQS) source code - Analysis of lock release and response interrupt locking processes
猜你喜欢

Zhihu wanzan: what kind of programmers are still wanted by the company after the age of 35? Breaking the "middle age crisis" of programmers

【实战】STM32MP157开发教程之FreeRTOS系统篇6:FreeRTOS 列表和列表项

Wechat applet

Audio immersive experience

leetcode:19. Delete the penultimate node of the linked list

ADO. Net - invalid size for size property, 0 - ado NET - The Size property has an invalid size of 0

Tidb3.0- 4.0 memory control / modification log saving days / maximum index length

【活动早知道】LiveVideoStack近期活动一览

Unity 5 自帶的Mono也可以支持C# 6

stm32mp1 Cortex M4开发篇13:扩展板按键外部中断
随机推荐
MySQL installation process under linux environment
Unity . Net framework
TiDB3.0- 4.0 内存控制/修改日志保存天数/最大索引长度
Quick sort_ sort
R language uses strptime function, format to format output parameters, and R environment options parameters to convert strings into time objects (the output time information includes time, minutes, se
Character function and string function
【实战】STM32 FreeRTOS移植系列教程5:FreeRTOS消息队列
finally block can not complete normally
Abstractqueuedsynchronizer (AQS) source code detailed analysis - semaphore source code analysis
JUnit5单元测试
It is said that this year gold three silver four has become gold one silver two.
Unity 5 自帶的Mono也可以支持C# 6
R language obtains help information of global, package and function: use the rsitesearch function to search the information of the specified package or function in the R community help manual and arch
Leetcode: print the common part of two ordered linked lists
apk 反编译 上的填坑之路
R language factor variable type: use factor function to convert string vector to factor vector, and use as The factor function converts a factor vector into a string vector and uses as The numeric fun
adb使用技巧和usb通信原理
C#中的list操作入门
GQL+Nodejs+MySQL数据库
stm32mp1 Cortex M4开发篇10:扩展板数码管控制