#define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner )( pxListItem )->pvOwner = ( void * ) ( pxOwner )
#define listSET_LIST_ITEM_VALUE( pxListItem, xValue )( pxListItem )->xItemValue = ( xValue )
/* 初始化 TCB 结构,被 xTaskGenericCreate 调用*/
static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed char * const pcName, unsigned portBASE_TYPE uxPriority, const xMemoryRegion * const xRegions, unsigned short usStackDepth )
{
#if configMAX_TASK_NAME_LEN > 1
{
/* 这里用 strncpy,不要用 strcpy,strcpy 不安全(如果被拷贝的字符串不以 0 结尾就不会停止) */
strncpy( ( char * ) pxTCB->pcTaskName, ( const char * ) pcName, ( unsigned short ) configMAX_TASK_NAME_LEN );
}
#endif
pxTCB->pcTaskName[ ( unsigned short ) configMAX_TASK_NAME_LEN - ( unsigned short ) 1 ] = ( signed char ) '\0';
if( uxPriority >= configMAX_PRIORITIES )
{
uxPriority = configMAX_PRIORITIES - ( unsigned portBASE_TYPE ) 1U;
}
pxTCB->uxPriority = uxPriority;
#if ( configUSE_MUTEXES == 1 )
{
pxTCB->uxBasePriority = uxPriority;
}
#endif
vListInitialiseItem( &( pxTCB->xGenericListItem ) ); /* 初始化 xGenericListItem,所谓初始化,就是使其不在任何一个链表中 */
vListInitialiseItem( &( pxTCB->xEventListItem ) ); /* 初始化 xEventListItem,所谓初始化,就是使其不在任何一个链表中 */
listSET_LIST_ITEM_OWNER( &( pxTCB->xGenericListItem ), pxTCB );/* 通过 xGenericListItem 我们可以找到对应的 TCB. */
/* 设置 xEventListItem. */
listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxPriority );
listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );
#if ( portCRITICAL_NESTING_IN_TCB == 1 )
{
pxTCB->uxCriticalNesting = ( unsigned portBASE_TYPE ) 0;
}
#endif
#if ( configUSE_APPLICATION_TASK_TAG == 1 )
{
pxTCB->pxTaskTag = NULL;
}
#endif
#if ( configGENERATE_RUN_TIME_STATS == 1 )
{
pxTCB->ulRunTimeCounter = 0UL;
}
#endif
#if ( portUSING_MPU_WRAPPERS == 1 )
{
vPortStoreTaskMPUSettings( &( pxTCB->xMPUSettings ), xRegions, pxTCB->pxStack, usStackDepth );
}
#else
{
( void ) xRegions;
( void ) usStackDepth;
}
#endif
}
void vListInitialiseItem( xListItem *pxItem )
{
/* Make sure the list item is not recorded as being on a list. */
pxItem->pvContainer = NULL;
}