当前位置:网站首页>FreeRTOS personal notes - lists and list items
FreeRTOS personal notes - lists and list items
2022-07-18 12:32:00 【Couvrir wild beast】
According to personal learning direction , Study FreeRTOS. Because brother wildfire FreeRTOS It's more implicit , I intend to be as detailed as possible in this column . As a personal note , For reference or reference only .
mixed material item :FreeRTOS Kernel Implementation and application development practice guide 、 Wildfire FreeRTOS Supporting video source code 、b Standing wildfire FreeRTOS video . It's better to match it !!!
Hint ,FreeRTOS For different processors , To the standard C The data type of is redefined . And the general naming is standardized , For variable names 、 Function names and macros are usually prefixed .
/* Data type redefinition */
#define portCHAR char
#define portFLOAT float
#define portDOUBLE double
#define portLONG long
#define portSHORT short
#define portSTACK_TYPE uint32_t
#define portBASE_TYPE long
typedef portSTACK_TYPE StackType_t;
typedef long BaseType_t;
typedef unsigned long UBaseType_t;For variable names , Prefixed : Data type abbreviation ( One or more ).
| Prefix prototype | Symbol |
| char | c |
| short | s |
| long | l |
| Structure , data structure , Task to handle , Queue handle, etc | x |
| Unsigned unsigned | u |
| The pointer | p |
For function names , Prefixed : return type 、 The file name 、 The functionality . Such as prv representative private( private ) The prefix of .
void vTaskPrioritySet() The representative return value is void, stay task.c File defines .
xQueueReceive() The representative return value is portBASE_TYPE, stay queue.c File defines .
vSemaphoreCreateBinary() representative The return value is void, stay semaphr.h File defines .
For macros , Prefixed : Which header file defines .
| Prefix | Macro definition file |
| port( Such as portMAX_DELAY) | portable.h |
| task( Such as taskENTER_CRITICAL()) | task.h |
| pd( Such as pdTRUE) | projdefs.h |
| config( Such as configUSE_PREEMPTION) | FreeRTOSConfig.h |
| err( Such as errQUEUE_FULL) | projdefs.h |
Pay attention to the
| macro | actual value |
| pdTRUE | 1 |
| pdFALSE | 0 |
| pdPASS | 1 |
| pdFALL | 0 |
Lists and list items
Mainly around nodes and linked lists . node = list , Linked list = List item .
Structure
Node structure
struct xLIST_ITEM
{
TickType_t xItemValue; /* The number , Every node has , Used for sorting linked lists ( General ascending order ) */
struct xLIST_ITEM * pxNext; /* Point to the next node in the linked list */
struct xLIST_ITEM * pxPrevious; /* Point to the previous node of the linked list */
void * pvOwner; /* Point to the kernel object that owns the node , Usually TCB( Task control block ) . Each node has a TCB, For task scheduling */
void * pvContainer; /* The node of the linked list points to , That is, record the current linked list */
};
typedef struct xLIST_ITEM ListItem_t; /* Node data type redefinition */mini Node structure , That is, the tail node structure
/* mini Node structure definition , As the end of the two-way linked list . Because the two-way linked list is end-to-end , The head is the tail , The tail is the head */
struct xMINI_LIST_ITEM
{
TickType_t xItemValue; /* The number , Every node has , Used for sorting linked lists ( General ascending order ) */
struct xLIST_ITEM * pxNext; /* Point to the next node in the linked list */
struct xLIST_ITEM * pxPrevious; /* Point to the previous node of the linked list */
};
typedef struct xMINI_LIST_ITEM MiniListItem_t; /* The minimum node data type is redefined */Root node of linked list , That is, the linked list structure
/* Linked list structure definition */
typedef struct xLIST
{
UBaseType_t uxNumberOfItems; /* Linked list node counter */
ListItem_t * pxIndex; /* Linked list node index pointer */
MiniListItem_t xListEnd; /* The last node in the list */
}List_t;In the above structure ,TickType_t stay portmacro.h The document defines .
#define configUSE_16_BIT_TICKS 0
#if( configUSE_16_BIT_TICKS == 1 )
typedef uint16_t TickType_t;
#define portMAX_DELAY ( TickType_t ) 0xffff
#else
typedef uint32_t TickType_t;
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL
#endifAfter graphical .

initialization
Node initialization
/* Node initialization */
void vListInitialiseItem( ListItem_t * const pxItem )
{
/* The linked list where the node is initialized is empty , Indicates that the node has not inserted any linked list */
pxItem->pvContainer = NULL;
}The root node of the linked list is initialized , That is, linked list initialization .( I won't repeat them one by one in the future )
/* The root node of the linked list is initialized */
void vListInitialise( List_t * const pxList )
{
/* Point the index pointer of the linked list to the last node */
pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd );
/* Set the auxiliary sorting value of the last node of the linked list to the maximum , Ensure that this node is the last node of the linked list */
pxList->xListEnd.xItemValue = portMAX_DELAY;
/* Will be the last node of pxNext and pxPrevious Pointers point to the node itself , Indicates that the list is empty */
pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd );
pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd );
/* The value of the initialization linked list node counter is 0, Indicates that the list is empty */
pxList->uxNumberOfItems = ( UBaseType_t ) 0U;
}After graphical .

List and list item operations
Insert the node at the end of the linked list
/* Insert the node into the end of the linked list */
void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem )
{
ListItem_t * const pxIndex = pxList->pxIndex; //pxIndex As END node
pxNewListItem->pxNext = pxIndex; // The first point
pxNewListItem->pxPrevious = pxIndex->pxPrevious; // Second point
pxIndex->pxPrevious->pxNext = pxNewListItem; // The third point
pxIndex->pxPrevious = pxNewListItem; // Fourth,
/* Record the linked list of this node */
pxNewListItem->pvContainer = ( void * ) pxList;
/* Linked list node counter ++, The length of the linked list ++ */
( pxList->uxNumberOfItems )++;
}
Insert the nodes into the linked list in ascending order
/* Insert the nodes into the linked list in ascending order */
void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem )
{
ListItem_t *pxIterator;
/* Get the sorting auxiliary value of the node */
const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
/* Find the location where the node is to be inserted */
if( xValueOfInsertion == portMAX_DELAY )
{
pxIterator = pxList->xListEnd.pxPrevious; //END node
}
else
{
for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd );
pxIterator->pxNext->xItemValue <= xValueOfInsertion;
pxIterator = pxIterator->pxNext )
{
/* There is nothing to do , Iterating constantly just to find the location where the node is to be inserted */
}
}
// here , Theoretically ,pxIterator As pxNewListItem Last node
pxNewListItem->pxNext = pxIterator->pxNext;
pxNewListItem->pxNext->pxPrevious = pxNewListItem;
pxNewListItem->pxPrevious = pxIterator;
pxIterator->pxNext = pxNewListItem;
// here ,pxNewListItem Insert the success
/* Record the linked list of this node */
pxNewListItem->pvContainer = ( void * ) pxList;
/* Linked list node counter ++, The length of the linked list ++*/
( pxList->uxNumberOfItems )++;
}The figure below , First the xItemValue = 2 The node of is omitted , Then insert it into the linked list as an insertion node for program verification .

Delete the node from the linked list
/* Delete the node from the linked list */
UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
{
/* Get the linked list where the node is located */
List_t * const pxList = ( List_t * ) pxItemToRemove->pvContainer;
pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
/* Make sure the index is left pointing to a valid item. */
if( pxList->pxIndex == pxItemToRemove )
{
pxList->pxIndex = pxItemToRemove->pxPrevious;
}
/* The linked list where the node is initialized is empty , Indicates that the node has not inserted any linked list , Release the node */
pxItemToRemove->pvContainer = NULL;
/* Linked list node counter --, The length of the linked list -- */
( pxList->uxNumberOfItems )--;
/* Return the number of remaining nodes in the linked list */
return pxList->uxNumberOfItems;
} 
The list and list items have come to an end
Finally, there are macro and small functions
/*
************************************************************************
* Macro definition
************************************************************************
*/
/* Initialize the owner of the node */
#define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner ) ( ( pxListItem )->pvOwner = ( void * ) ( pxOwner ) )
/* Get the node owner */
#define listGET_LIST_ITEM_OWNER( pxListItem ) ( ( pxListItem )->pvOwner )
/* Initialize the auxiliary value of node sorting */
#define listSET_LIST_ITEM_VALUE( pxListItem, xValue ) ( ( pxListItem )->xItemValue = ( xValue ) )
/* Get the auxiliary value of node sorting */
#define listGET_LIST_ITEM_VALUE( pxListItem ) ( ( pxListItem )->xItemValue )
/* Get the value of the node counter of the root node of the linked list */
#define listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext->xItemValue )
/* Get the entry node of the linked list */
#define listGET_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext )
/* Get the first node of the linked list */
#define listGET_NEXT( pxListItem ) ( ( pxListItem )->pxNext )
/* Get the last node of the linked list */
#define listGET_END_MARKER( pxList ) ( ( ListItem_t const * ) ( &( ( pxList )->xListEnd ) ) )
/* Judge whether the list is empty */
#define listLIST_IS_EMPTY( pxList ) ( ( BaseType_t ) ( ( pxList )->uxNumberOfItems == ( UBaseType_t ) 0 ) )
/* Get the number of nodes in the linked list */
#define listCURRENT_LIST_LENGTH( pxList ) ( ( pxList )->uxNumberOfItems )
/* Get the name of the linked list node OWNER, namely TCB */
#define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList ) \
{ \
List_t * const pxConstList = ( pxList ); \
/* The node index points to the first node in the linked list. Adjust the node index pointer , Point to next node ,
If the current linked list has N Nodes , When the first N When this function is called again ,pxInedex Then point to the second N Nodes */\
( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \
/* The current linked list is empty */ \
if( ( void * ) ( pxConstList )->pxIndex == ( void * ) &( ( pxConstList )->xListEnd ) ) \
{ \
( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \
} \
/* Get the OWNER, namely TCB */ \
( pxTCB ) = ( pxConstList )->pxIndex->pvOwner; \
}
#define listGET_OWNER_OF_HEAD_ENTRY( pxList ) ( (&( ( pxList )->xListEnd ))->pxNext->pvOwner )Enclosed main() Function use case
/* Define the root node of the linked list */
struct xLIST List_Test;
/* Define the node */
struct xLIST_ITEM List_Item1;
struct xLIST_ITEM List_Item2;
struct xLIST_ITEM List_Item3; /* The root node of the linked list is initialized */
vListInitialise( &List_Test );
/* node 1 initialization */
vListInitialiseItem( &List_Item1 );
List_Item1.xItemValue = 1;
/* node 2 initialization */
vListInitialiseItem( &List_Item2 );
List_Item2.xItemValue = 2;
/* node 3 initialization */
vListInitialiseItem( &List_Item3 );
List_Item3.xItemValue = 3;
/* Insert the node into the linked list , In ascending order */
vListInsert( &List_Test, &List_Item2 );
vListInsert( &List_Test, &List_Item1 );
vListInsert( &List_Test, &List_Item3 );
边栏推荐
- Gson解析生成json数据工具类
- HDOJ-2057(A + B Again)
- [pyGame game] no admittance for disabled hands. The latest sadistic game "stitching" - a game you have to play.
- 【MOCO基础】Attention, learn to solve routing problems(Wouter Kool, 2018)
- Openeuler knowledge: official Community
- [jailhouse article] bao: a modern lightweight embedded hypervisor (2020)
- Flink basic record supplement
- openEuler 知:常用网址
- 021.多态详解 续2
- 8 o'clock tonight! Lightdb PG distributed database technology innovation and practice "
猜你喜欢

Image denoising using nlmeas

FreeRTOS个人笔记-任务定义与任务切换

今晚8点! LightDB PG分布式数据库技术创新与实践”
![[Moco foundation] attention, learn to solve routing problems (Wouter Kool, 2018)](/img/69/c5d745ff9c3a60b998fd28d4b2aa47.png)
[Moco foundation] attention, learn to solve routing problems (Wouter Kool, 2018)

TMUX usage
![[wechat applet] slide effect realization](/img/c6/24550b2bf3f755be299a6f9d7117c3.gif)
[wechat applet] slide effect realization

8 o'clock tonight! Lightdb PG distributed database technology innovation and practice "

三個步驟,一天就搞定了MySQL,讓我順利拿下了天猫offer

Appium自动化测试基础 — webview操作(重点)
![[jailhouse article] bao: a lightweight static partitioning hypervisor for modern multi core embedded](/img/0b/c3a6241ae423f4af7fcef55fb5ab2f.png)
[jailhouse article] bao: a lightweight static partitioning hypervisor for modern multi core embedded
随机推荐
Flink basic record supplement
openEuler 知:日志查找技巧
Simulation static method in mockito
Redis_ Linux Installation
[pyGame game] no admittance for disabled hands. The latest sadistic game "stitching" - a game you have to play.
Blazor University (36) component library
JVM tuning practice (detailed version)
Openeuler knowledge: official Community
Installing MySQL on Linux
HDOJ-2057(A + B Again)
022.static与final关键字详解
MySQL original field to hump naming
【鸡汤】天下事有难易乎
Use of gin framework
Excel-vba quick start (VII. Get cell objects)
模拟实现C语言中常用函数
Redis 中两个字段排序
openEuler 知:管理策略
0714下午1,review,
[Vulnhub] Raven-1