Skip to content

Commit 9c91199

Browse files
jefftenneydan4thewinRichardBarry
authored
Add test for timer start delayed past expiration (FreeRTOS#557)
Co-authored-by: Dan Good <[email protected]> Co-authored-by: RichardBarry <[email protected]>
1 parent 2560a50 commit 9c91199

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

FreeRTOS/Demo/Common/Minimal/TimerDemo.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,8 @@ uint8_t ucTimer;
686686

687687
static void prvTest7_CheckBacklogBehaviour( void )
688688
{
689+
UBaseType_t uxOriginalPriority;
690+
689691
/* Use the first auto-reload timer to test stopping a timer from a
690692
backlogged callback. */
691693

@@ -734,6 +736,55 @@ static void prvTest7_CheckBacklogBehaviour( void )
734736
/* Clear the reload count for the timer used in this test. */
735737
ucAutoReloadTimerCounters[ 0 ] = ( uint8_t ) 0;
736738

739+
740+
/* Verify a one-shot timer is marked as inactive if the timer task processes
741+
the start or reset request after the expiration time has passed. */
742+
743+
/* The timer has not been started yet! */
744+
if( xTimerIsTimerActive( xOneShotTimer ) != pdFALSE )
745+
{
746+
xTestStatus = pdFAIL;
747+
configASSERT( xTestStatus );
748+
}
749+
750+
/* Use the timer period specific to backlogged timers because it reduces
751+
the impact on other tests that might be running when xTaskCatchUpTicks()
752+
creates the backlog, below. */
753+
xTimerChangePeriod( xOneShotTimer, tmrdemoBACKLOG_TIMER_PERIOD, tmrdemoDONT_BLOCK );
754+
755+
/* Temporarily give this task maximum priority so it can cause the timer
756+
task to delay its processing of the reset request below. */
757+
uxOriginalPriority = uxTaskPriorityGet( NULL );
758+
vTaskPrioritySet( NULL, ( configMAX_PRIORITIES - 1 ) );
759+
760+
/* Reset the timer. The timer service won't process this request right
761+
away as noted above. */
762+
xTimerReset( xOneShotTimer, tmrdemoDONT_BLOCK );
763+
764+
/* Cause the timer period to elapse without giving an opportunity for the
765+
timer service task to process the reset request. */
766+
xTaskCatchUpTicks( tmrdemoBACKLOG_TIMER_PERIOD );
767+
768+
/* Return this task to its original priority. The timer service task will
769+
process the reset request immediately. The timer task must handle the reset
770+
request as if it were processed at the time of the request even though in
771+
this test the processing occurs after the intended expiration time. */
772+
vTaskPrioritySet( NULL, uxOriginalPriority );
773+
774+
/* The timer should now be inactive. */
775+
if( xTimerIsTimerActive( xOneShotTimer ) != pdFALSE )
776+
{
777+
xTestStatus = pdFAIL;
778+
configASSERT( xTestStatus );
779+
}
780+
781+
/* Restore the standard timer period, and leave the timer inactive. */
782+
xTimerChangePeriod( xOneShotTimer, tmrdemoONE_SHOT_TIMER_PERIOD, tmrdemoDONT_BLOCK );
783+
xTimerStop( xOneShotTimer, tmrdemoDONT_BLOCK );
784+
785+
/* Clear the counter for the timer used in this test. */
786+
ucOneShotTimerCounter = ( uint8_t ) 0;
787+
737788
if( xTestStatus == pdPASS )
738789
{
739790
/* No errors have been reported so increment the loop counter so the check

0 commit comments

Comments
 (0)