-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New API xTaskPeriodicDelay (#1349) #1368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2374,6 +2374,62 @@ | |
|
|
||
| #if ( INCLUDE_xTaskDelayUntil == 1 ) | ||
|
|
||
| TickType_t xTaskPeriodicDelay( TickType_t * const pxPreviousWakeTime, | ||
| const TickType_t xTimeIncrement ) | ||
| { | ||
| TickType_t xIncrements, xTicksIncrements, xTicksToWait; | ||
|
Check warning on line 2380 in tasks.c
|
||
|
|
||
| traceENTER_xTaskPeriodicDelay( pxPreviousWakeTime, xTimeIncrement ); | ||
|
|
||
| configASSERT( pxPreviousWakeTime ); | ||
| configASSERT( ( xTimeIncrement > 0U ) ); | ||
|
|
||
| vTaskSuspendAll(); | ||
| { | ||
| /* As long as everything is the same type, this plays well with overflows */ | ||
| const TickType_t xTicksElapsed = xTickCount - *pxPreviousWakeTime; | ||
|
|
||
| configASSERT( uxSchedulerSuspended == 1U ); | ||
|
|
||
| /* Number of increments to catch up: it could be 0 if | ||
| * not enough ticks have elapsed, 1 in the common case or | ||
| * more than 1 if the task has not been resumed in time */ | ||
| xIncrements = xTicksElapsed / xTimeIncrement; | ||
| xTicksIncrements = xIncrements * xTimeIncrement; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably need a check for overflow here. Don't want
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
so |
||
|
|
||
| /* Update to the last wake time */ | ||
| *pxPreviousWakeTime += xTicksIncrements; | ||
|
|
||
| /* Ticks to the next wake time */ | ||
| xTicksToWait = xTimeIncrement - ( xTicksElapsed - xTicksIncrements ); | ||
|
|
||
| if( xTicksToWait > 0 ) | ||
| { | ||
| prvAddCurrentTaskToDelayedList( xTicksToWait, pdFALSE ); | ||
| } | ||
| else | ||
| { | ||
| mtCOVERAGE_TEST_MARKER(); | ||
| } | ||
| } | ||
|
|
||
| /* Force a reschedule if xTaskResumeAll has not already done so, we may | ||
| * have put ourselves to sleep. */ | ||
| if( xTaskResumeAll() == pdFALSE ) | ||
| { | ||
| taskYIELD_WITHIN_API(); | ||
| } | ||
| else | ||
| { | ||
| mtCOVERAGE_TEST_MARKER(); | ||
| } | ||
|
|
||
| traceRETURN_xTaskPeriodicDelay( xIncrements ); | ||
|
|
||
| return xIncrements; | ||
| } | ||
|
|
||
|
|
||
| BaseType_t xTaskDelayUntil( TickType_t * const pxPreviousWakeTime, | ||
| const TickType_t xTimeIncrement ) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the unsigned based type since this is a simple count
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My problem is this code:
needs everything to be of the same type to work properly, so
xTicksElapsedmust beTickType_t. ThenxIncrements(that is, whatxTaskPeriodicDelayreturns) is calculated as:and if I declare it as
UBaseType_tI get the following error on my host:I can cast it to remove the error, but in that case I think the result can easily overflow if I suspend a task for too much time.