\r
/*-----------------------------------------------------------*/\r
\r
+/* The callback functions used by the timers. These each increment a counter\r
+to indicate which timer has expired. The autoreload timers that are used by\r
+the test task (as opposed to being used from an ISR) all share the same\r
+prvAutoReloadTimerCallback() callback function, and use the ID of the\r
+pxExpiredTimer parameter passed into that function to know which counter to\r
+increment. The other timers all have their own unique callback function and\r
+simply increment their counters without using the callback function parameter. */\r
static void prvAutoReloadTimerCallback( xTimerHandle pxExpiredTimer );\r
-static void prvTimerControlTask( void *pvParameters );\r
-\r
+static void prvOneShotTimerCallback( xTimerHandle pxExpiredTimer );\r
+static void prvTimerTestTask( void *pvParameters );\r
+static void prvISRAutoReloadTimerCallback( xTimerHandle pxExpiredTimer );\r
+static void prvISROneShotTimerCallback( xTimerHandle pxExpiredTimer );\r
+\r
+/* The test functions used by the timer test task. These manipulate the auto\r
+reload and one shot timers in various ways, then delay, then inspect the timers\r
+to ensure they have behaved as expected. */\r
static void prvTest1_CreateTimersWithoutSchedulerRunning( void );\r
-static void prvTest3_CheckAutoReloadExpireRates( void );\r
static void prvTest2_CheckTaskAndTimersInitialState( void );\r
+static void prvTest3_CheckAutoReloadExpireRates( void );\r
static void prvTest4_CheckAutoReloadTimersCanBeStopped( void );\r
static void prvTest5_CheckBasicOneShotTimerBehaviour( void );\r
static void prvTest6_CheckAutoReloadResetBehaviour( void );\r
detect a stalled task - a test that is no longer running. */\r
static volatile unsigned portLONG ulLoopCounter = 0;\r
\r
+/* A set of auto reload timers - each of which use the same callback function.\r
+The callback function uses the timer ID to index into, and then increment, a\r
+counter in the ucAutoReloadTimerCounters[] array. The auto reload timers\r
+referenced from xAutoReloadTimers[] are used by the prvTimerTestTask task. */\r
static xTimerHandle xAutoReloadTimers[ configTIMER_QUEUE_LENGTH + 1 ] = { 0 };\r
static unsigned char ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH + 1 ] = { 0 };\r
-static unsigned char ucOneShotTimerCounter = ( unsigned char ) 0;\r
\r
+/* The one shot timer is configured to use a callback function that increments\r
+ucOneShotTimerCounter each time it gets called. */\r
static xTimerHandle xOneShotTimer = NULL;\r
+static unsigned char ucOneShotTimerCounter = ( unsigned char ) 0;\r
+\r
+/* The ISR realod timer is controlled from the tick hook to exercise the timer\r
+API functions that can be used from an ISR. It is configured to increment\r
+ucISRReloadTimerCounter each time its callback function is executed. */\r
+static xTimerHandle xISRAutoReloadTimer = NULL;\r
+static unsigned char ucISRAutoReloadTimerCounter = ( unsigned char ) 0;\r
+\r
+/* The ISR one shot timer is controlled from the tick hook to exercise the timer\r
+API functions that can be used from an ISR. It is configured to increment\r
+ucISRReloadTimerCounter each time its callback function is executed. */\r
+static xTimerHandle xISROneShotTimer = NULL;\r
+static unsigned char ucISROneShotTimerCounter = ( unsigned char ) 0;\r
\r
+/* The period of all the timers are a multiple of the base period. The base\r
+period is configured by the parameter to vStartTimerDemoTask(). */\r
static portTickType xBasePeriod = 0;\r
\r
/*-----------------------------------------------------------*/\r
task, which will then preempt this task). */\r
if( xTestStatus != pdFAIL )\r
{\r
- xTaskCreate( prvTimerControlTask, ( signed portCHAR * ) "Tmr Ctl", configMINIMAL_STACK_SIZE, NULL, configTIMER_TASK_PRIORITY - 1, NULL );\r
+ xTaskCreate( prvTimerTestTask, ( signed portCHAR * ) "Tmr Tst", configMINIMAL_STACK_SIZE, NULL, configTIMER_TASK_PRIORITY - 1, NULL );\r
}\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static void prvAutoReloadTimerCallback( xTimerHandle pxExpiredTimer )\r
-{\r
-portBASE_TYPE xTimerID;\r
-\r
- xTimerID = ( portBASE_TYPE ) pvTimerGetTimerID( pxExpiredTimer );\r
- if( xTimerID <= ( configTIMER_QUEUE_LENGTH + 1 ) )\r
- {\r
- ( ucAutoReloadTimerCounters[ xTimerID ] )++;\r
- }\r
- else\r
- {\r
- /* The timer ID appears to be unexpected (invalid). */\r
- xTestStatus = pdFAIL;\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvOneShotTimerCallback( xTimerHandle pxExpiredTimer )\r
-{\r
- /* The parameter is not used in this case as only one timer uses this\r
- callback function. */\r
- ( void ) pxExpiredTimer;\r
-\r
- ucOneShotTimerCounter++;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvTimerControlTask( void *pvParameters )\r
+static void prvTimerTestTask( void *pvParameters )\r
{\r
( void ) pvParameters;\r
\r
if( xOneShotTimer == NULL )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
\r
report their state. */\r
prvTest4_CheckAutoReloadTimersCanBeStopped();\r
\r
- /* Check the one shot timer only calls its callback once after it has been \r
+ /* Check the one shot timer only calls its callback once after it has been\r
started, and that it reports its state correctly. */\r
prvTest5_CheckBasicOneShotTimerBehaviour();\r
\r
\r
/* This is called to check that the created task is still running and has not\r
detected any errors. */\r
-portBASE_TYPE xAreTimerDemoTasksStillRunning( void )\r
+portBASE_TYPE xAreTimerDemoTasksStillRunning( portTickType xCycleFrequency )\r
{\r
-static unsigned portLONG ulLastLoopCounter = 0;\r
+static unsigned portLONG ulLastLoopCounter = 0UL;\r
+portTickType xMaxBlockTimeUsedByTheseTests, xLoopCounterIncrementTimeMax;\r
+static portTickType xItterationsWithoutCounterIncrement = ( portTickType ) 0, xLastCycleFrequency;\r
+\r
+ if( xLastCycleFrequency != xCycleFrequency )\r
+ {\r
+ /* The cycle frequency has probably become much faster due to an error\r
+ elsewhere. Start counting itterations again. */\r
+ xItterationsWithoutCounterIncrement = ( portTickType ) 0;\r
+ xLastCycleFrequency = xCycleFrequency;\r
+ } \r
+\r
+ /* Calculate the maximum number of times that it is permittable for this\r
+ function to be called without ulLoopCounter being incremented. This is\r
+ necessary because the tests in this file block for extended periods, and the\r
+ block period might be longer than the time between calls to this function. */\r
+ xMaxBlockTimeUsedByTheseTests = ( ( portTickType ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;\r
+ xLoopCounterIncrementTimeMax = xMaxBlockTimeUsedByTheseTests / xCycleFrequency;\r
\r
/* If the demo task is still running then we expect the loopcounter to\r
- have incremented since this function was last called. */\r
+ have incremented every xLoopCounterIncrementTimeMax calls. */\r
if( ulLastLoopCounter == ulLoopCounter )\r
{\r
- xTestStatus = pdFAIL;\r
+ xItterationsWithoutCounterIncrement++;\r
+ if( xItterationsWithoutCounterIncrement > xLoopCounterIncrementTimeMax )\r
+ {\r
+ /* The tests appear to be no longer running (stalled). */\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* ulLoopCounter changed, so the count of times this function was called\r
+ without a change can be reset to zero. */\r
+ xItterationsWithoutCounterIncrement = ( portTickType ) 0;\r
}\r
\r
ulLastLoopCounter = ulLoopCounter;\r
if( xAutoReloadTimers[ xTimer ] == NULL )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
else\r
{\r
if( xTimerStart( xAutoReloadTimers[ xTimer ], portMAX_DELAY ) != pdPASS )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
}\r
}\r
( configTIMER_QUEUE_LENGTH * xBasePeriod ), /* The period for the timer. */\r
pdTRUE, /* Autoreload is set to true. */\r
( void * ) xTimer, /* An identifier for the timer as all the auto reload timers use the same callback. */\r
- prvAutoReloadTimerCallback ); /* The callback to be called when the timer expires. */\r
+ prvAutoReloadTimerCallback ); /* The callback executed when the timer expires. */\r
\r
if( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] == NULL )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
else\r
{\r
/* This time it would not be expected that the timer could be\r
started at this point. */\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
}\r
+ \r
+ /* Create the timers that are used from the tick interrupt to test the timer\r
+ API functions that can be called from an ISR. */\r
+ xISRAutoReloadTimer = xTimerCreate( "ISR AR", /* The text name given to the timer. */\r
+ 0, /* The timer is not given a period yet - this will be done from the tick hook. */\r
+ pdTRUE, /* This is an auto reload timer. */\r
+ ( void * ) NULL, /* The identifier is not required. */\r
+ prvISRAutoReloadTimerCallback );/* The callback that is executed when the timer expires. */\r
+\r
+ xISROneShotTimer = xTimerCreate( "ISR OS", /* The text name given to the timer. */\r
+ 0, /* The timer is not given a period yet - this will be done from the tick hook. */\r
+ pdFALSE, /* This is a one shot timer. */\r
+ ( void * ) NULL, /* The identifier is not required. */\r
+ prvISROneShotTimerCallback ); /* The callback that is executed when the timer expires. */\r
+ \r
+ if( ( xISRAutoReloadTimer == NULL ) || ( xISROneShotTimer == NULL ) )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
}\r
/*-----------------------------------------------------------*/\r
\r
{\r
unsigned char ucTimer;\r
\r
- /* Ensure all the timers are in their expected initial state. This depends \r
+ /* Ensure all the timers are in their expected initial state. This depends\r
on the timer service task having a higher priority than this task.\r
\r
auto reload timers 0 to ( configTIMER_QUEUE_LENGTH - 1 ) should now be active,\r
- and auto reload timer configTIMER_QUEUE_LENGTH should not yet be active (it \r
- could not be started prior to the scheduler being started when it was \r
+ and auto reload timer configTIMER_QUEUE_LENGTH should not yet be active (it\r
+ could not be started prior to the scheduler being started when it was\r
created). */\r
for( ucTimer = 0; ucTimer < ( unsigned char ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
{\r
if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
}\r
\r
if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] ) != pdFALSE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
}\r
/*-----------------------------------------------------------*/\r
static void prvTest3_CheckAutoReloadExpireRates( void )\r
{\r
unsigned char ucMaxAllowableValue, ucMinAllowableValue, ucTimer;\r
-portTickType xNextWakeTime;\r
+portTickType xBlockPeriod, xTimerPeriod, xExpectedNumber;\r
\r
/* Check the auto reload timers expire at the expcted rates. */\r
\r
- /* Initialise the next wake time value before the call to vTaskDelayUntil() \r
- as this is not really a periodic task. */\r
- xNextWakeTime = xTaskGetTickCount();\r
-\r
- /* Delaying for configTIMER_QUEUE_LENGTH * xBasePeriod ticks should allow \r
+ \r
+ /* Delaying for configTIMER_QUEUE_LENGTH * xBasePeriod ticks should allow\r
all the auto reload timers to expire at least once. */\r
- vTaskDelayUntil( &xNextWakeTime, ( ( portTickType ) configTIMER_QUEUE_LENGTH ) * xBasePeriod );\r
+ xBlockPeriod = ( ( portTickType ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;\r
+ vTaskDelay( xBlockPeriod );\r
\r
/* Check that all the auto reload timers have called their callback \r
function the expected number of times. */\r
for( ucTimer = 0; ucTimer < ( unsigned char ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
{\r
- /* The timer in array position 0 should elapse every xBasePeriod ticks, \r
- the timer in array position 1 should elapse every ( 2 * xBasePeriod ) \r
- ticks, etc. This task blocked for configTIMER_QUEUE_LENGTH * xBasePeriod, \r
- so the timer in array position 0 should have elapsed \r
- configTIMER_QUEUE_LENGTH times, the timer in array possition 1 should \r
- have elapsed ( configTIMER_QUEUE_LENGTH - 1 ) times, etc. */\r
- ucMaxAllowableValue = ( ( ( unsigned char ) configTIMER_QUEUE_LENGTH ) - ucTimer );\r
- ucMinAllowableValue = ( ( ( unsigned char ) configTIMER_QUEUE_LENGTH ) - ucTimer ) - 1;\r
+ /* The expected number of expiries is equal to the block period divided\r
+ by the timer period. */\r
+ xTimerPeriod = ( ( ( portTickType ) ucTimer + ( portTickType ) 1 ) * xBasePeriod );\r
+ xExpectedNumber = xBlockPeriod / xTimerPeriod;\r
+ \r
+ ucMaxAllowableValue = ( ( unsigned char ) xExpectedNumber ) ;\r
+ ucMinAllowableValue = ( ( unsigned char ) xExpectedNumber - ( unsigned char ) 1 );\r
\r
if( ( ucAutoReloadTimerCounters[ ucTimer ] < ucMinAllowableValue ) ||\r
( ucAutoReloadTimerCounters[ ucTimer ] > ucMaxAllowableValue )\r
)\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
}\r
\r
if( xTestStatus == pdPASS )\r
{\r
- /* No errors have been reported so increment the loop counter so the \r
+ /* No errors have been reported so increment the loop counter so the\r
check task knows this task is still running. */\r
ulLoopCounter++;\r
}\r
{ \r
unsigned char ucTimer;\r
\r
- /* Check the auto reload timers can be stopped correctly, and correctly \r
+ /* Check the auto reload timers can be stopped correctly, and correctly\r
report their state. */\r
\r
/* Stop all the active timers. */\r
if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
/* Now stop the timer. This will appear to happen immediately to\r
if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) != pdFALSE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
}\r
\r
if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH ] != ( unsigned char ) 0 )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
/* Clear the timer callback count. */\r
if( ucAutoReloadTimerCounters[ ucTimer ] != ( unsigned char ) 0 )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
}\r
\r
\r
static void prvTest5_CheckBasicOneShotTimerBehaviour( void )\r
{\r
- /* Check the one shot timer only calls its callback once after it has been \r
+ /* Check the one shot timer only calls its callback once after it has been\r
started, and that it reports its state correctly. */\r
\r
/* The one shot timer should not be active yet. */\r
if( xTimerIsTimerActive( xOneShotTimer ) != pdFALSE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
if( ucOneShotTimerCounter != ( unsigned char ) 0 )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
/* Start the one shot timer and check that it reports its state correctly. */\r
if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
- /* Delay for three times as long as the one shot timer period, then check \r
- to ensure it has only called its callback once, and is now not in the \r
+ /* Delay for three times as long as the one shot timer period, then check\r
+ to ensure it has only called its callback once, and is now not in the\r
active state. */\r
vTaskDelay( tmrdemoONE_SHOT_TIMER_PERIOD * ( portTickType ) 3 );\r
\r
if( xTimerIsTimerActive( xOneShotTimer ) != pdFALSE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
if( ucOneShotTimerCounter != ( unsigned char ) 1 )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
else\r
{\r
\r
if( xTestStatus == pdPASS )\r
{\r
- /* No errors have been reported so increment the loop counter so the \r
+ /* No errors have been reported so increment the loop counter so the\r
check task knows this task is still running. */\r
ulLoopCounter++;\r
}\r
if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
/* Restart one of the auto reload timers and check that it reports its\r
if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
for( ucTimer = 0; ucTimer < trmdemoNUM_TIMER_RESETS; ucTimer++ )\r
{\r
- /* Delay for half as long as the one shot timer period, then reset it. \r
- It should never expire while this is done, so its callback count should \r
+ /* Delay for half as long as the one shot timer period, then reset it.\r
+ It should never expire while this is done, so its callback count should\r
never increment. */\r
vTaskDelay( tmrdemoONE_SHOT_TIMER_PERIOD / 2 );\r
\r
if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
if( ucOneShotTimerCounter != ( unsigned char ) 0 )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] != ( unsigned char ) 0 )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
/* Reset both running timers. */\r
\r
if( xTestStatus == pdPASS )\r
{\r
- /* No errors have been reported so increment the loop counter so \r
+ /* No errors have been reported so increment the loop counter so\r
the check task knows this task is still running. */\r
ulLoopCounter++;\r
}\r
if( ucOneShotTimerCounter != ( unsigned char ) 1 )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] == 0 )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
/* The one shot timer should no longer be active, while the auto reload\r
if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
if( xTimerIsTimerActive( xOneShotTimer ) == pdTRUE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
/* Stop the auto reload timer again. */\r
if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) != pdFALSE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
/* Clear the timer callback counts, ready for another iteration of these\r
\r
if( xTestStatus == pdPASS )\r
{\r
- /* No errors have been reported so increment the loop counter so the check \r
+ /* No errors have been reported so increment the loop counter so the check\r
task knows this task is still running. */\r
ulLoopCounter++;\r
}\r
if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) != pdFALSE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
\r
/* Now start the timer. This will appear to happen immediately to\r
- this task because this task is running at a priority below the timer \r
+ this task because this task is running at a priority below the timer\r
service task. */\r
xTimerStart( xAutoReloadTimers[ ucTimer ], tmrdemoDONT_BLOCK );\r
\r
if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )\r
{\r
xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
}\r
}\r
\r
if( xTestStatus == pdPASS )\r
{\r
- /* No errors have been reported so increment the loop counter so the \r
+ /* No errors have been reported so increment the loop counter so the\r
check task knows this task is still running. */\r
ulLoopCounter++;\r
}\r
}\r
/*-----------------------------------------------------------*/\r
\r
+void vTimerPeriodicISRTests( void )\r
+{\r
+static unsigned portBASE_TYPE uxTick = ( unsigned portBASE_TYPE ) -1;\r
+\r
+/* The xHigherPriorityTaskWoken parameter is not used in this case as this\r
+function is called from the tick hook anyway. However the API required it\r
+to be present. */\r
+portBASE_TYPE xHigherPriorityTaskWoken = pdTRUE;\r
+const portBASE_TYPE xMargin = 3;\r
+\r
+ uxTick++;\r
+\r
+ if( uxTick == 0 )\r
+ {\r
+ /* The timers will have been created, but not started. Start them\r
+ now by setting their period. */\r
+ ucISRAutoReloadTimerCounter = 0;\r
+ ucISROneShotTimerCounter = 0;\r
+ xTimerChangePeriodFromISR( xISRAutoReloadTimer, xBasePeriod, &xHigherPriorityTaskWoken );\r
+ xTimerChangePeriodFromISR( xISROneShotTimer, xBasePeriod, &xHigherPriorityTaskWoken );\r
+ }\r
+ else if( uxTick == xBasePeriod )\r
+ {\r
+ /* Neither timer should have expired yet. */\r
+ if( ( ucISRAutoReloadTimerCounter != 0 ) || ( ucISROneShotTimerCounter != 0 ) )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ }\r
+ else if( uxTick == ( xBasePeriod + xMargin ) )\r
+ {\r
+ /* Both timers should now have expired once. The auto reload timer will\r
+ still be active, but the one shot timer should now have stopped. */\r
+ if( ( ucISRAutoReloadTimerCounter != 1 ) || ( ucISROneShotTimerCounter != 1 ) )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ } \r
+ }\r
+ else if( uxTick == ( 2 * xBasePeriod ) )\r
+ {\r
+ /* The auto reload timer will still be active, but the one shot timer\r
+ should now have stopped - however, at this time neither of the timers\r
+ shoud have expired again since the last test. */\r
+ if( ( ucISRAutoReloadTimerCounter != 1 ) || ( ucISROneShotTimerCounter != 1 ) )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ } \r
+ }\r
+ else if( uxTick == ( ( 2 * xBasePeriod ) + xMargin ) )\r
+ {\r
+ /* The auto reload timer will still be active, but the one shot timer\r
+ should now have stopped. At this time the auto reload timer should have\r
+ expired again, but the one shot timer count should not have changed. */\r
+ if( ucISRAutoReloadTimerCounter != 2 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ if( ucISROneShotTimerCounter != 1 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ }\r
+ else if( uxTick == ( ( 2 * xBasePeriod ) + ( xBasePeriod >> ( portTickType ) 2U ) ) )\r
+ {\r
+ /* The auto reload timer will still be active, but the one shot timer\r
+ should now have stopped. Again though, at this time, neither timer call\r
+ back should have been called since the last test. */\r
+ if( ucISRAutoReloadTimerCounter != 2 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ if( ucISROneShotTimerCounter != 1 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ } \r
+ } \r
+ else if( uxTick == ( 3 * xBasePeriod ) )\r
+ {\r
+ /* Start the one shot timer again. */\r
+ xTimerStartFromISR( xISROneShotTimer, &xHigherPriorityTaskWoken );\r
+ }\r
+ else if( uxTick == ( ( 3 * xBasePeriod ) + xMargin ) )\r
+ {\r
+ /* The auto reload timer and one shot timer will be active. At\r
+ this time the auto reload timer should have expired again, but the one\r
+ shot timer count should not have changed yet. */\r
+ if( ucISRAutoReloadTimerCounter != 3 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ if( ucISROneShotTimerCounter != 1 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ /* Now stop the auto realod timer. The one shot timer was started\r
+ a few ticks ago. */\r
+ xTimerStopFromISR( xISRAutoReloadTimer, &xHigherPriorityTaskWoken );\r
+ } \r
+ else if( uxTick == ( 4 * xBasePeriod ) )\r
+ {\r
+ /* The auto reload timer is now stopped, and the one shot timer is\r
+ active, but at this time neither timer should have expired since the\r
+ last test. */\r
+ if( ucISRAutoReloadTimerCounter != 3 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ if( ucISROneShotTimerCounter != 1 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ } \r
+ else if( uxTick == ( ( 4 * xBasePeriod ) + xMargin ) )\r
+ {\r
+ /* The auto reload timer is now stopped, and the one shot timer is\r
+ active. The one shot timer should have expired again, but the auto\r
+ reload timer should not have executed its callback. */\r
+ if( ucISRAutoReloadTimerCounter != 3 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ if( ucISROneShotTimerCounter != 2 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ } \r
+ else if( uxTick == ( ( 8 * xBasePeriod ) + xMargin ) )\r
+ {\r
+ /* The auto reload timer is now stopped, and the one shot timer has\r
+ already expired and then stopped itself. Both callback counters should\r
+ not have incremented since the last test. */\r
+ if( ucISRAutoReloadTimerCounter != 3 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ if( ucISROneShotTimerCounter != 2 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ /* Now reset the one shot timer. */\r
+ xTimerResetFromISR( xISROneShotTimer, &xHigherPriorityTaskWoken );\r
+ } \r
+ else if( uxTick == ( 9 * xBasePeriod ) )\r
+ {\r
+ /* Only the one shot timer should be running, but it should not have\r
+ expired since the last test. Check the callback counters have not\r
+ incremented, then reset the one shot timer again. */\r
+ if( ucISRAutoReloadTimerCounter != 3 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ if( ucISROneShotTimerCounter != 2 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ xTimerResetFromISR( xISROneShotTimer, &xHigherPriorityTaskWoken );\r
+ } \r
+ else if( uxTick == ( 10 * xBasePeriod ) )\r
+ {\r
+ /* Only the one shot timer should be running, but it should not have\r
+ expired since the last test. Check the callback counters have not\r
+ incremented, then reset the one shot timer again. */\r
+ if( ucISRAutoReloadTimerCounter != 3 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ if( ucISROneShotTimerCounter != 2 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ xTimerResetFromISR( xISROneShotTimer, &xHigherPriorityTaskWoken );\r
+ }\r
+ else if( uxTick == ( 11 * xBasePeriod ) )\r
+ {\r
+ /* Only the one shot timer should be running, but it should not have\r
+ expired since the last test. Check the callback counters have not\r
+ incremented, then reset the one shot timer once again. */\r
+ if( ucISRAutoReloadTimerCounter != 3 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ if( ucISROneShotTimerCounter != 2 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ xTimerResetFromISR( xISROneShotTimer, &xHigherPriorityTaskWoken );\r
+ } \r
+ else if( uxTick == ( ( 12 * xBasePeriod ) + xMargin ) )\r
+ {\r
+ /* Only the one shot timer should have been running and this time it\r
+ should have expired. Check its callback count has been incremented.\r
+ The auto realod timer is still not running so should still have the same\r
+ count value. This time the one shot timer is not reset so should not\r
+ restart from its expiry period again. */\r
+ if( ucISRAutoReloadTimerCounter != 3 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ if( ucISROneShotTimerCounter != 3 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ }\r
+ else if( uxTick == ( 15 * xBasePeriod ) )\r
+ {\r
+ /* Neither timer should be running now. Check neither callback count\r
+ has incremented, then go back to the start to run these tests all\r
+ over again. */\r
+ if( ucISRAutoReloadTimerCounter != 3 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ if( ucISROneShotTimerCounter != 3 )\r
+ {\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+ \r
+ uxTick = ( unsigned portBASE_TYPE ) -1;\r
+ } \r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+/*** Timer callback functions are defined below here. ***/\r
+\r
+static void prvAutoReloadTimerCallback( xTimerHandle pxExpiredTimer )\r
+{\r
+portBASE_TYPE xTimerID;\r
+\r
+ xTimerID = ( portBASE_TYPE ) pvTimerGetTimerID( pxExpiredTimer );\r
+ if( xTimerID <= ( configTIMER_QUEUE_LENGTH + 1 ) )\r
+ {\r
+ ( ucAutoReloadTimerCounters[ xTimerID ] )++;\r
+ }\r
+ else\r
+ {\r
+ /* The timer ID appears to be unexpected (invalid). */\r
+ xTestStatus = pdFAIL;\r
+ configASSERT( xTestStatus );\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvOneShotTimerCallback( xTimerHandle pxExpiredTimer )\r
+{\r
+ /* The parameter is not used in this case as only one timer uses this\r
+ callback function. */\r
+ ( void ) pxExpiredTimer;\r
+\r
+ ucOneShotTimerCounter++;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvISRAutoReloadTimerCallback( xTimerHandle pxExpiredTimer )\r
+{\r
+ /* The parameter is not used in this case as only one timer uses this\r
+ callback function. */\r
+ ( void ) pxExpiredTimer;\r
+\r
+ ucISRAutoReloadTimerCounter++;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvISROneShotTimerCallback( xTimerHandle pxExpiredTimer )\r
+{\r
+ /* The parameter is not used in this case as only one timer uses this\r
+ callback function. */\r
+ ( void ) pxExpiredTimer;\r
+\r
+ ucISROneShotTimerCounter++;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+\r
+\r
+\r