STM32F103移植FreeRTOS系列十:任务调度器的挂起和恢复

 如果临界区代码量很多,执行时间长会造成延时中断,这样子如果中断得不到响应的话,不符合实时操作系统。

使用实例

	void vTaskDelay( const TickType_t xTicksToDelay )
	{
	BaseType_t xAlreadyYielded = pdFALSE;

		/* A delay time of zero just forces a reschedule. */
		if( xTicksToDelay > ( TickType_t ) 0U )
		{
			configASSERT( uxSchedulerSuspended == 0 );
			vTaskSuspendAll();
			{
				traceTASK_DELAY();

				/* A task that is removed from the event list while the
				scheduler is suspended will not get placed in the ready
				list or removed from the blocked list until the scheduler
				is resumed.

				This task cannot be in an event list as it is the currently
				executing task. */
				prvAddCurrentTaskToDelayedList( xTicksToDelay, pdFALSE );
			}
			xAlreadyYielded = xTaskResumeAll();
		}
		else
		{
			mtCOVERAGE_TEST_MARKER();
		}

		/* Force a reschedule if xTaskResumeAll has not already done so, we may
		have put ourselves to sleep. */
		if( xAlreadyYielded == pdFALSE )
		{
			portYIELD_WITHIN_API();
		}
		else
		{
			mtCOVERAGE_TEST_MARKER();
		}
	}

下面讲解一下这两个API函数具体的底层实现

 我们知道,系统是通过pendsv中断来进行任务切换的,那么这个变量又是怎么和这个中断联系在一起的呢?

在delay.c中

在M3权威指南中

portNVIC_INT_CTRL_REG 被定义为一个指向寄存器地址的指针。通过将 portNVIC_PENDSVSET_BIT 的值(一个整数)赋给该指针,实际上将寄存器的值设置为 portNVIC_PENDSVSET_BIT 所表示的位模式。

回到delay.c

 go to进去

然后   

 此时相当于任务调度器被挂起,也是嵌套的一个功能

还有个挂起任务调度器的功能,要截图实在太多了,大家看完上面的再看视频应该就可以了。

 这里等于0说的是变量uxSchedulerSupended等于0

猜你喜欢

转载自blog.csdn.net/qq_51519091/article/details/131576118