FreeRTOS中任务控制块中关于堆栈的三个变量pxTopOfStack、pxStack、pxEndOfStack的分析

本文分析了FreeRTOS中任务控制块中关于堆栈的三个关键变量pxTopOfStack、pxStack和pxEndOfStack。讨论了portSTACK_GROWTH宏对堆栈增长方向的影响,以及在不同增长模式下如何确定栈顶和栈底地址。pxStack是任务栈的起始地址,pxEndOfStack用于记录栈底地址,pxTopOfStack则在任务运行过程中会变化,用于防止栈溢出。
摘要由CSDN通过智能技术生成

这里写自定义目录标题

FreeRTOS中任务控制块中关于堆栈的定义

typedef struct tskTaskControlBlock
{
	volatile StackType_t	*pxTopOfStack;	/*< Points to the location of the last item placed on the tasks stack.  THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT. */
	//指向放置在任务堆栈上的最后一个项目的位置,对于向下增长的栈,这个总是指向最后一个入栈的项目。

	#if ( portUSING_MPU_WRAPPERS == 1 )
		xMPU_SETTINGS	xMPUSettings;		/*< The MPU settings are defined as part of the port layer.  THIS MUST BE THE SECOND MEMBER OF THE TCB STRUCT. */
	#endif

	ListItem_t			xStateListItem;	/*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */
	ListItem_t			xEventListItem;		/*< Used to reference a task from an event list. */
	UBaseType_t			uxPriority;			/*< The priority of the task.  0 is the lowest priority. */
	StackType_t			*pxStack;			/*< Points to the start of the stack. */
	//位置是固定的,随着任务的运行,堆栈可能溢出,堆栈往下增长的系统中,这个变量就可以判断堆栈是否溢出,对于堆栈往上增长的系统,想确定堆栈是否溢出,还需要pxEndOfStack这个变量。
	char				pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created.  Facilitates debugging only. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */

	#if ( portSTACK_GROWTH > 0 )
		StackType_t		*pxEndOfStack;		/*< Points to the end of the stack on architectures where the stack grows up from low memory. *///如果堆栈向上生长(portSTACK_GROWTH > 0),指针pxEndOfStack指向堆栈尾部,用于检验堆栈是否溢出。
	#endif
	...
}

xTaskCreate()函数中对栈的申请的过程

BaseType_t xTaskCreate(	TaskFunction_t pxTaskCode,				//函数指针,指向任务函数的入口
							
  • 7
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值