野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 174|回复: 1

[freertos] xtaskincrementtick 跳不出来

[复制链接]
发表于 2024-1-16 11:14:56 | 显示全部楼层 |阅读模式
  1. BaseType_t xTaskIncrementTick( void )
  2. {
  3. TCB_t * pxTCB;
  4. TickType_t xItemValue;
  5. BaseType_t xSwitchRequired = pdFALSE;

  6.         /* Called by the portable layer each time a tick interrupt occurs.
  7.         Increments the tick then checks to see if the new tick value will cause any
  8.         tasks to be unblocked. */
  9.         traceTASK_INCREMENT_TICK( xTickCount );
  10.         if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )
  11.         {
  12.                 /* Increment the RTOS tick, switching the delayed and overflowed
  13.                 delayed lists if it wraps to 0. */
  14.                 ++xTickCount;

  15.                 {
  16.                         /* Minor optimisation.  The tick count cannot change in this
  17.                         block. */
  18.                         const TickType_t xConstTickCount = xTickCount;

  19.                         if( xConstTickCount == ( TickType_t ) 0U )
  20.                         {
  21.                                 taskSWITCH_DELAYED_LISTS();
  22.                         }
  23.                         else
  24.                         {
  25.                                 mtCOVERAGE_TEST_MARKER();
  26.                         }

  27.                         /* See if this tick has made a timeout expire.  Tasks are stored in
  28.                         the        queue in the order of their wake time - meaning once one task
  29.                         has been found whose block time has not expired there is no need to
  30.                         look any further down the list. */
  31.                         if( xConstTickCount >= xNextTaskUnblockTime )
  32.                         {
  33.                                 for( ;; )
  34.                                 {
  35.                                         if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )
  36.                                         {
  37.                                                 /* The delayed list is empty.  Set xNextTaskUnblockTime
  38.                                                 to the maximum possible value so it is extremely
  39.                                                 unlikely that the
  40.                                                 if( xTickCount >= xNextTaskUnblockTime ) test will pass
  41.                                                 next time through. */
  42.                                                 xNextTaskUnblockTime = portMAX_DELAY;
  43.                                                 break;
  44.                                         }
  45.                                         else
  46.                                         {
  47.                                                 /* The delayed list is not empty, get the value of the
  48.                                                 item at the head of the delayed list.  This is the time
  49.                                                 at which the task at the head of the delayed list must
  50.                                                 be removed from the Blocked state. */
  51.                                                 pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );
  52.                                                 xItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) );

  53.                                                 if( xConstTickCount < xItemValue )
  54.                                                 {
  55.                                                         /* It is not time to unblock this item yet, but the
  56.                                                         item value is the time at which the task at the head
  57.                                                         of the blocked list must be removed from the Blocked
  58.                                                         state -        so record the item value in
  59.                                                         xNextTaskUnblockTime. */
  60.                                                         xNextTaskUnblockTime = xItemValue;
  61.                                                         break;
  62.                                                 }
  63.                                                 else
  64.                                                 {
  65.                                                         mtCOVERAGE_TEST_MARKER();
  66.                                                 }

  67.                                                 /* It is time to remove the item from the Blocked state. */
  68.                                                 ( void ) uxListRemove( &( pxTCB->xGenericListItem ) );

  69.                                                 /* Is the task waiting on an event also?  If so remove
  70.                                                 it from the event list. */
  71.                                                 if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )
  72.                                                 {
  73.                                                         ( void ) uxListRemove( &( pxTCB->xEventListItem ) );
  74.                                                 }
  75.                                                 else
  76.                                                 {
  77.                                                         mtCOVERAGE_TEST_MARKER();
  78.                                                 }

  79.                                                 /* Place the unblocked task into the appropriate ready
  80.                                                 list. */
  81.                                                 prvAddTaskToReadyList( pxTCB );

  82.                                                 /* A task being unblocked cannot cause an immediate
  83.                                                 context switch if preemption is turned off. */
  84.                                                 #if (  configUSE_PREEMPTION == 1 )
  85.                                                 {
  86.                                                         /* Preemption is on, but a context switch should
  87.                                                         only be performed if the unblocked task has a
  88.                                                         priority that is equal to or higher than the
  89.                                                         currently executing task. */
  90.                                                         if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )
  91.                                                         {
  92.                                                                 xSwitchRequired = pdTRUE;
  93.                                                         }
  94.                                                         else
  95.                                                         {
  96.                                                                 mtCOVERAGE_TEST_MARKER();
  97.                                                         }
  98.                                                 }
  99.                                                 #endif /* configUSE_PREEMPTION */
  100.                                         }
  101.                                 }
  102.                         }
  103.                 }

  104.                 /* Tasks of equal priority to the currently running task will share
  105.                 processing time (time slice) if preemption is on, and the application
  106.                 writer has not explicitly turned time slicing off. */
  107.                 #if ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) )
  108.                 {
  109.                         if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ pxCurrentTCB->uxPriority ] ) ) > ( UBaseType_t ) 1 )
  110.                         {
  111.                                 xSwitchRequired = pdTRUE;
  112.                         }
  113.                         else
  114.                         {
  115.                                 mtCOVERAGE_TEST_MARKER();
  116.                         }
  117.                 }
  118.                 #endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) ) */

  119.                 #if ( configUSE_TICK_HOOK == 1 )
  120.                 {
  121.                         /* Guard against the tick hook being called when the pended tick
  122.                         count is being unwound (when the scheduler is being unlocked). */
  123.                         if( uxPendedTicks == ( UBaseType_t ) 0U )
  124.                         {
  125.                                 vApplicationTickHook();
  126.                         }
  127.                         else
  128.                         {
  129.                                 mtCOVERAGE_TEST_MARKER();
  130.                         }
  131.                 }
  132.                 #endif /* configUSE_TICK_HOOK */
  133.         }
  134.         else
  135.         {
  136.                 ++uxPendedTicks;

  137.                 /* The tick hook gets called at regular intervals, even if the
  138.                 scheduler is locked. */
  139.                 #if ( configUSE_TICK_HOOK == 1 )
  140.                 {
  141.                         vApplicationTickHook();
  142.                 }
  143.                 #endif
  144.         }

  145.         #if ( configUSE_PREEMPTION == 1 )
  146.         {
  147.                 if( xYieldPending != pdFALSE )
  148.                 {
  149.                         xSwitchRequired = pdTRUE;
  150.                 }
  151.                 else
  152.                 {
  153.                         mtCOVERAGE_TEST_MARKER();
  154.                 }
  155.         }
  156.         #endif /* configUSE_PREEMPTION */

  157.         return xSwitchRequired;
  158. }
复制代码



野火论坛202401161113024478..png
回复

使用道具 举报

发表于 2024-1-22 17:44:53 | 显示全部楼层
问题太模糊
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-4-30 11:07 , Processed in 0.109683 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表