FreeRTOS 源码注释(prvInitialiseTCBVariables)

#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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值