Skip to content

Commit 3260e22

Browse files
robamulundinc2
andauthored
vTaskDelayUntil improvement (#77)
* vTaskDelayUntil improvement * suggestions implemented * xTaskDelayUntil #define added * doc small fix * small formatting stuff * more small formatting stuff * Update lexicon.txt Co-authored-by: Carl Lundin <53273776+lundinc2@users.noreply.github.com> Co-authored-by: Carl Lundin <lundinc@amazon.com>
1 parent 3d4d171 commit 3260e22

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

include/task.h

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
781781
/**
782782
* task. h
783783
* <pre>
784-
* void vTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );
784+
* BaseType_t xTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );
785785
* </pre>
786786
*
787787
* INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
@@ -799,7 +799,7 @@ void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
799799
* each time it executes].
800800
*
801801
* Whereas vTaskDelay () specifies a wake time relative to the time at which the function
802-
* is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
802+
* is called, xTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
803803
* unblock.
804804
*
805805
* The constant portTICK_PERIOD_MS can be used to calculate real time from the tick
@@ -808,13 +808,16 @@ void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
808808
* @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
809809
* task was last unblocked. The variable must be initialised with the current time
810810
* prior to its first use (see the example below). Following this the variable is
811-
* automatically updated within vTaskDelayUntil ().
811+
* automatically updated within xTaskDelayUntil ().
812812
*
813813
* @param xTimeIncrement The cycle time period. The task will be unblocked at
814-
* time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the
814+
* time *pxPreviousWakeTime + xTimeIncrement. Calling xTaskDelayUntil with the
815815
* same xTimeIncrement parameter value will cause the task to execute with
816816
* a fixed interface period.
817817
*
818+
* @return Value which can be used to check whether the task was actually delayed.
819+
* Will be pdTRUE if the task way delayed and pdFALSE otherwise.
820+
*
818821
* Example usage:
819822
* <pre>
820823
* // Perform an action every 10 ticks.
@@ -823,22 +826,28 @@ void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
823826
* TickType_t xLastWakeTime;
824827
* const TickType_t xFrequency = 10;
825828
*
826-
* // Initialise the xLastWakeTime variable with the current time.
827-
* xLastWakeTime = xTaskGetTickCount ();
828-
* for( ;; )
829-
* {
830-
* // Wait for the next cycle.
831-
* vTaskDelayUntil( &xLastWakeTime, xFrequency );
829+
* // Initialise the xLastWakeTime variable with the current time.
830+
* xLastWakeTime = xTaskGetTickCount ();
831+
* for( ;; )
832+
* {
833+
* // Wait for the next cycle.
834+
* BaseType_t xWasDelayed = xTaskDelayUntil( &xLastWakeTime, xFrequency );
832835
*
833-
* // Perform action here.
834-
* }
836+
* // Perform action here. xWasDelayed value can be used to determine
837+
* // whether a deadline was missed if the code here took too long.
838+
* }
835839
* }
836840
* </pre>
837-
* \defgroup vTaskDelayUntil vTaskDelayUntil
841+
* \defgroup xTaskDelayUntil xTaskDelayUntil
838842
* \ingroup TaskCtrl
839843
*/
840-
void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime,
841-
const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
844+
BaseType_t xTaskDelayUntil( TickType_t * const pxPreviousWakeTime,
845+
const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
846+
#define vTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement ) \
847+
{ \
848+
xTaskDelayUntil ( pxPreviousWakeTime , xTimeIncrement ); \
849+
}
850+
842851

843852
/**
844853
* task. h

lexicon.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2976,6 +2976,7 @@ xtaskcreate
29762976
xtaskcreaterestricted
29772977
xtaskcreaterestrictedstatic
29782978
xtaskcreatestatic
2979+
xtaskdelayuntil
29792980
xtaskdetails
29802981
xtaskendscheduler
29812982
xtaskgetapplicationtasktag
@@ -3076,6 +3077,7 @@ xvalueofinsertion
30763077
xvtorconst
30773078
xwaitforallbits
30783079
xwantedsize
3080+
xwasdelayed
30793081
xwritevalue
30803082
xxr
30813083
xyieldpending

tasks.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
12461246

12471247
#if ( INCLUDE_vTaskDelayUntil == 1 )
12481248

1249-
void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime,
1249+
BaseType_t xTaskDelayUntil( TickType_t * const pxPreviousWakeTime,
12501250
const TickType_t xTimeIncrement )
12511251
{
12521252
TickType_t xTimeToWake;
@@ -1324,6 +1324,8 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
13241324
{
13251325
mtCOVERAGE_TEST_MARKER();
13261326
}
1327+
1328+
return xShouldDelay;
13271329
}
13281330

13291331
#endif /* INCLUDE_vTaskDelayUntil */

0 commit comments

Comments
 (0)