FreeRTOS的调度器挂起和恢复

1. 调度器挂起 vTaskSuspendAll

void vTaskSuspendAll( void )
{
	/* A critical section is not required as the variable is of type
	BaseType_t.  Please read Richard Barry's reply in the following link to a
	post in the FreeRTOS support forum before reporting this as a bug! -
	http://goo.gl/wu4acr */
	/* 记录值++ */
	++uxSchedulerSuspended;
}

2.调度器恢复 xTaskResumeAll

BaseType_t xTaskResumeAll( void )
{
TCB_t *pxTCB;
BaseType_t xAlreadyYielded = pdFALSE;

	/* If uxSchedulerSuspended is zero then this function does not match a
	previous call to vTaskSuspendAll(). */
	configASSERT( uxSchedulerSuspended );

	/* It is possible that an ISR caused a task to be removed from an event
	list while the scheduler was suspended.  If this was the case then the
	removed task will have been added to the xPendingReadyList.  Once the
	scheduler has been resumed it is safe to move all the pending ready
	tasks from this list into their appropriate ready list. */
	/* 进入临界段 */
	taskENTER_CRITICAL();
	{
		/* 调度器记录值减一 */
		--uxSchedulerSuspended;

         /* 如果调度器需要恢复了 */
		if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )
		{
			  /* 判断当前任务数量大于0 */
			if( uxCurrentNumberOfTasks > ( UBaseType_t ) 0U )
			{
				/* Move any readied tasks from the pending list into the
				appropriate ready list. */
				/*将所有已准备好的任务从待处理列表移动到就绪链表中*/
				/* 从挂起的就绪列表中遍历 */
				while( listLIST_IS_EMPTY( &xPendingReadyList ) == pdFALSE )
				{
					 /* 获取任务控制块 */
					pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( ( &xPendingReadyList ) );
					/* 移除挂起就绪列表,移除事件列表 */
					( void ) uxListRemove( &( pxTCB->xEventListItem ) );
					( void ) uxListRemove( &( pxTCB->xGenericListItem ) );
					 /* 添加到就绪列表中 */
					prvAddTaskToReadyList( pxTCB );

					/* If the moved task has a priority higher than the current
					task then a yield must be performed. */
					  /* 如果优先级大于当前任务优先级,则进行任务切换 */
					if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )
					{
						xYieldPending = pdTRUE;
					}
					else
					{
						mtCOVERAGE_TEST_MARKER();
					}
				}

				/* If any ticks occurred while the scheduler was suspended then
				they should be processed now.  This ensures the tick count does
				not	slip, and that any delayed tasks are resumed at the correct
				time. */
				/* 如果记录值大于0 */
				if( uxPendedTicks > ( UBaseType_t ) 0U )
				{
					while( uxPendedTicks > ( UBaseType_t ) 0U )
					{
						 /* 进行systick调度处理,遍历阻塞列表,如果需要任务切换,返回true */
						if( xTaskIncrementTick() != pdFALSE )
						{
							xYieldPending = pdTRUE;
						}
						else
						{
							mtCOVERAGE_TEST_MARKER();
						}
						--uxPendedTicks;
					}
				}
				else
				{
					mtCOVERAGE_TEST_MARKER();
				}

				/* 如果需要进行任务切换 */
				if( xYieldPending == pdTRUE )
				{
					 /* 判断是否内核是抢占式 */
					#if( configUSE_PREEMPTION != 0 )
					{
						 /* 标记已经调度的状态 */
						xAlreadyYielded = pdTRUE;
					}
					#endif
					 /* 进行调度 */
					taskYIELD_IF_USING_PREEMPTION();
				}
				else
				{
					mtCOVERAGE_TEST_MARKER();
				}
			}
		}
		else
		{
			mtCOVERAGE_TEST_MARKER();
		}
	}
	taskEXIT_CRITICAL();

	return xAlreadyYielded;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值