MCPcopy Create free account
hub / github.com/FreeRTOS/FreeRTOS-Kernel / xTaskCheckForTimeOut

Function xTaskCheckForTimeOut

tasks.c:4098–4160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4096/*-----------------------------------------------------------*/
4097
4098BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
4099 TickType_t * const pxTicksToWait )
4100{
4101 BaseType_t xReturn;
4102
4103 configASSERT( pxTimeOut );
4104 configASSERT( pxTicksToWait );
4105
4106 taskENTER_CRITICAL();
4107 {
4108 /* Minor optimisation. The tick count cannot change in this block. */
4109 const TickType_t xConstTickCount = xTickCount;
4110 const TickType_t xElapsedTime = xConstTickCount - pxTimeOut->xTimeOnEntering;
4111
4112 #if ( INCLUDE_xTaskAbortDelay == 1 )
4113 if( pxCurrentTCB->ucDelayAborted != ( uint8_t ) pdFALSE )
4114 {
4115 /* The delay was aborted, which is not the same as a time out,
4116 * but has the same result. */
4117 pxCurrentTCB->ucDelayAborted = pdFALSE;
4118 xReturn = pdTRUE;
4119 }
4120 else
4121 #endif
4122
4123 #if ( INCLUDE_vTaskSuspend == 1 )
4124 if( *pxTicksToWait == portMAX_DELAY )
4125 {
4126 /* If INCLUDE_vTaskSuspend is set to 1 and the block time
4127 * specified is the maximum block time then the task should block
4128 * indefinitely, and therefore never time out. */
4129 xReturn = pdFALSE;
4130 }
4131 else
4132 #endif
4133
4134 if( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( xConstTickCount >= pxTimeOut->xTimeOnEntering ) ) /*lint !e525 Indentation preferred as is to make code within pre-processor directives clearer. */
4135 {
4136 /* The tick count is greater than the time at which
4137 * vTaskSetTimeout() was called, but has also overflowed since
4138 * vTaskSetTimeOut() was called. It must have wrapped all the way
4139 * around and gone past again. This passed since vTaskSetTimeout()
4140 * was called. */
4141 xReturn = pdTRUE;
4142 *pxTicksToWait = ( TickType_t ) 0;
4143 }
4144 else if( xElapsedTime < *pxTicksToWait ) /*lint !e961 Explicit casting is only redundant with some compilers, whereas others require it to prevent integer conversion errors. */
4145 {
4146 /* Not a genuine timeout. Adjust parameters for time remaining. */
4147 *pxTicksToWait -= xElapsedTime;
4148 vTaskInternalSetTimeOutState( pxTimeOut );
4149 xReturn = pdFALSE;
4150 }
4151 else
4152 {
4153 *pxTicksToWait = ( TickType_t ) 0;
4154 xReturn = pdTRUE;
4155 }

Callers 6

xQueueGenericSendFunction · 0.85
xQueueReceiveFunction · 0.85
xQueueSemaphoreTakeFunction · 0.85
xQueuePeekFunction · 0.85
xStreamBufferSendFunction · 0.85
MPU_xTaskCheckForTimeOutFunction · 0.85

Calls 1

Tested by

no test coverage detected