freertos列表

typedef struct xLIST
{
listFIRST_LIST_INTEGRITY_CHECK_VALUE//檢查
UBaseType_t uxNumberOfItems;//item數量
ListItem_t * configLIST_VOLATILE pxIndex;//指向最後的item
MiniListItem_t xListEnd;//最大的item值,在列表的end
listSECOND_LIST_INTEGRITY_CHECK_VALUE
}List_t;

struct xLIST_ITEM
{
listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE//用於檢查
configLIST_VOLATILE TickType_t xItemValue;//item的值
struct xLIST_ITEM * configLIST_VOLATILE pxNext;//指向後一個item
struct xLIST_ITEM * configLIST_VOLATILE pxPrevious;//指向前一個item
void * pvOwner; //指向包含itm的目標,通常是TCB
void * configLIST_VOLATILE pvContainer; //指向item被放置的list
listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE
};
typedef struct xLIST_ITEM ListItem_t;
//mini item
struct xMINI_LIST_ITEM
{
listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. /
configLIST_VOLATILE TickType_t xItemValue;
struct xLIST_ITEM * configLIST_VOLATILE pxNext;
struct xLIST_ITEM * configLIST_VOLATILE pxPrevious;
};
//列表初始化
vListInitialise(List_t * const pxList)
{
pxList->pxIndex = (ListItem_t
)&(pxList->xListEnd);//item用來標記list的末端
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 );
}
//列表項初始化
void vListInitialiseItem(ListItem_t * const pxItem )
{
pxItem->pvContainer = NULL;//確保item不輸入任何list
listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
}

//列表插入
void vListInsert(List_t* const pxList,ListItem_t* const pxNewListItem)
{
ListItem_t *pxIterator;
const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;//插入的值
if( xValueOfInsertion == portMAX_DELAY )//如果插入的是最大值
{
pxIterator = pxList->xListEnd.pxPrevious;
}
else
{
for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. /
{
/
There is nothing to do here, just iterating to the wanted
insertion position. */
}
}
pxNewListItem->pxNext = pxIterator->pxNext;
pxNewListItem->pxNext->pxPrevious = pxNewListItem;
pxNewListItem->pxPrevious = pxIterator;
pxIterator->pxNext = pxNewListItem;

pxNewListItem->pvContainer = (void*)pxList;
(pxList->uxnumberOfItems)++;

}

//列表從末端插入
void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem )
{
ListItem_t * const pxIndex = pxList->pxIndex;
pxNewListItem->pxNext = pxIndex;
pxNewListItem->pxPrevious = pxIndex->pxPrevious;

/* Only used during decision coverage testing. */
mtCOVERAGE_TEST_DELAY();

pxIndex->pxPrevious->pxNext = pxNewListItem;
pxIndex->pxPrevious = pxNewListItem;

/* Remember which list the item is in. */
pxNewListItem->pvContainer = ( void * ) pxList;

( pxList->uxNumberOfItems )++;

}

//列表的刪除
UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
{
List_t * const pxList = ( List_t * ) pxItemToRemove->pvContainer;//list item知道哪個list
pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
mtCOVERAGE_TEST_DELAY();
//確保pxIndex指向有效的item
if( pxList->pxIndex == pxItemToRemove )
{
pxList->pxIndex = pxItemToRemove->pxPrevious;
}
else
{
mtCOVERAGE_TEST_MARKER();
}

pxItemToRemove->pvContainer = NULL;
( pxList->uxNumberOfItems )--;

return pxList->uxNumberOfItems;

}

遍歷列表,返回pxOwner
#define listGET_OWNER_OF_NEXT_ENTRY(pxTCB,pxList)\

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章