void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement )
{
portTickType xTimeToWake;
portBASE_TYPE xAlreadyYielded, xShouldDelay = pdFALSE;
vTaskSuspendAll();
{
/* 计算下次唤醒的时刻. */
xTimeToWake = *pxPreviousWakeTime + xTimeIncrement;
if( xTickCount < *pxPreviousWakeTime ) /* 说明 xTickCount 溢出了 */
{
/* 这时只有 xTimeToWake 也溢出了,并且 xTimeToWake > xTickCount 才需要休眠 */
if( ( xTimeToWake < *pxPreviousWakeTime ) && ( xTimeToWake > xTickCount ) )
{
xShouldDelay = pdTRUE;
}
}
else
{
/* 下面两种情况才需要休眠 */
if( ( xTimeToWake < *pxPreviousWakeTime ) || ( xTimeToWake > xTickCount ) )
{
xShouldDelay = pdTRUE;
}
}
/* 为下一次 Delay 更新 pxPreviousWakeTime. */
*pxPreviousWakeTime = xTimeToWake;
if( xShouldDelay != pdFALSE ) /* 这时需要休眠 */
{
traceTASK_DELAY_UNTIL();
/* 从 Ready 链表中删除,加入 DelayedList */
vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );
prvAddCurrentTaskToDelayedList( xTimeToWake );
}
}
xAlreadyYielded = xTaskResumeAll(); /* 不知道作用,找时间仔细看看 */
/* Force a reschedule if xTaskResumeAll has not already done so, we may
have put ourselves to sleep. */
if( !xAlreadyYielded )
{
portYIELD_WITHIN_API();
}
}
FreeRTOS 源码注释(vTaskDelayUntil)
最新推荐文章于 2024-09-23 22:18:57 发布