]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/Common/Minimal/TimerDemo.c
Ensure both one-shot and auto-reload are written consistently with a hyphen in comments.
[freertos] / FreeRTOS / Demo / Common / Minimal / TimerDemo.c
index 122ae4f2407f8d1cf5159c18fef64f0ef9a9bcf7..29478819a141747086bcda190d780a01faffdc02 100644 (file)
@@ -1,67 +1,29 @@
 /*\r
-    FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd. \r
-    All rights reserved\r
-\r
-    VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
-\r
-    ***************************************************************************\r
-     *                                                                       *\r
-     *    FreeRTOS provides completely free yet professionally developed,    *\r
-     *    robust, strictly quality controlled, supported, and cross          *\r
-     *    platform software that has become a de facto standard.             *\r
-     *                                                                       *\r
-     *    Help yourself get started quickly and support the FreeRTOS         *\r
-     *    project by purchasing a FreeRTOS tutorial book, reference          *\r
-     *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
-     *                                                                       *\r
-     *    Thank you!                                                         *\r
-     *                                                                       *\r
-    ***************************************************************************\r
-\r
-    This file is part of the FreeRTOS distribution.\r
-\r
-    FreeRTOS is free software; you can redistribute it and/or modify it under\r
-    the terms of the GNU General Public License (version 2) as published by the\r
-    Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
-\r
-    >>! NOTE: The modification to the GPL is included to allow you to distribute\r
-    >>! a combined work that includes FreeRTOS without being obliged to provide\r
-    >>! the source code for proprietary components outside of the FreeRTOS\r
-    >>! kernel.\r
-\r
-    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
-    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
-    FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
-    link: http://www.freertos.org/a00114.html\r
-\r
-    1 tab == 4 spaces!\r
-\r
-    ***************************************************************************\r
-     *                                                                       *\r
-     *    Having a problem?  Start by reading the FAQ "My application does   *\r
-     *    not run, what could be wrong?"                                     *\r
-     *                                                                       *\r
-     *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
-     *                                                                       *\r
-    ***************************************************************************\r
-\r
-    http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
-    license and Real Time Engineers Ltd. contact details.\r
-\r
-    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
-    including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
-    compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
-\r
-    http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
-    Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
-    licenses offer ticketed support, indemnification and middleware.\r
-\r
-    http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
-    engineered and independently SIL3 certified version for use in safety and\r
-    mission critical applications that require provable dependability.\r
-\r
-    1 tab == 4 spaces!\r
-*/\r
+ * FreeRTOS Kernel V10.2.1\r
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+ * this software and associated documentation files (the "Software"), to deal in\r
+ * the Software without restriction, including without limitation the rights to\r
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
+ * the Software, and to permit persons to whom the Software is furnished to do so,\r
+ * subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in all\r
+ * copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * http://www.FreeRTOS.org\r
+ * http://aws.amazon.com/freertos\r
+ *\r
+ * 1 tab == 4 spaces!\r
+ */\r
 \r
 \r
 /*\r
        #error configTIMER_TASK_PRIORITY must be set to at least 1 for this test/demo to function correctly.\r
 #endif\r
 \r
-#define tmrdemoDONT_BLOCK                              ( ( portTickType ) 0 )\r
-#define tmrdemoONE_SHOT_TIMER_PERIOD   ( xBasePeriod * ( portTickType ) 3 )\r
-#define trmdemoNUM_TIMER_RESETS                        ( ( unsigned char ) 10 )\r
+#define tmrdemoDONT_BLOCK                              ( ( TickType_t ) 0 )\r
+#define tmrdemoONE_SHOT_TIMER_PERIOD   ( xBasePeriod * ( TickType_t ) 3 )\r
+#define tmrdemoNUM_TIMER_RESETS                        ( ( uint8_t ) 10 )\r
+\r
+#ifndef tmrTIMER_TEST_TASK_STACK_SIZE\r
+       #define tmrTIMER_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE\r
+#endif\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
@@ -97,14 +63,14 @@ prvAutoReloadTimerCallback() callback function, and use the ID of the
 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 prvOneShotTimerCallback( xTimerHandle pxExpiredTimer );\r
+static void prvAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer );\r
+static void prvOneShotTimerCallback( TimerHandle_t pxExpiredTimer );\r
 static void prvTimerTestTask( void *pvParameters );\r
-static void prvISRAutoReloadTimerCallback( xTimerHandle pxExpiredTimer );\r
-static void prvISROneShotTimerCallback( xTimerHandle pxExpiredTimer );\r
+static void prvISRAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer );\r
+static void prvISROneShotTimerCallback( TimerHandle_t 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
+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 prvTest2_CheckTaskAndTimersInitialState( void );\r
@@ -118,43 +84,43 @@ static void prvResetStartConditionsForNextIteration( void );
 \r
 /* Flag that will be latched to pdFAIL should any unexpected behaviour be\r
 detected in any of the demo tests. */\r
-static volatile portBASE_TYPE xTestStatus = pdPASS;\r
+static volatile BaseType_t xTestStatus = pdPASS;\r
 \r
 /* Counter that is incremented on each cycle of a test.  This is used to\r
 detect a stalled task - a test that is no longer running. */\r
-static volatile unsigned long ulLoopCounter = 0;\r
+static volatile uint32_t ulLoopCounter = 0;\r
 \r
-/* A set of auto reload timers - each of which use the same callback function.\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
+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 TimerHandle_t xAutoReloadTimers[ configTIMER_QUEUE_LENGTH + 1 ] = { 0 };\r
+static uint8_t ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH + 1 ] = { 0 };\r
 \r
-/* The one shot timer is configured to use a callback function that increments\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
+static TimerHandle_t xOneShotTimer = NULL;\r
+static uint8_t ucOneShotTimerCounter = ( uint8_t ) 0;\r
 \r
 /* The ISR reload 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
+static TimerHandle_t xISRAutoReloadTimer = NULL;\r
+static uint8_t ucISRAutoReloadTimerCounter = ( uint8_t ) 0;\r
 \r
-/* The ISR one shot timer is controlled from the tick hook to exercise the timer\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
+static TimerHandle_t xISROneShotTimer = NULL;\r
+static uint8_t ucISROneShotTimerCounter = ( uint8_t ) 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
+static TickType_t xBasePeriod = 0;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
-void vStartTimerDemoTask( portTickType xBasePeriodIn )\r
+void vStartTimerDemoTask( TickType_t xBasePeriodIn )\r
 {\r
        /* Start with the timer and counter arrays clear - this is only necessary\r
        where the compiler does not clear them automatically on start up. */\r
@@ -175,7 +141,7 @@ void vStartTimerDemoTask( portTickType xBasePeriodIn )
        task, which will then preempt this task). */\r
        if( xTestStatus != pdFAIL )\r
        {\r
-               xTaskCreate( prvTimerTestTask, ( signed portCHAR * ) "Tmr Tst", configMINIMAL_STACK_SIZE, NULL, configTIMER_TASK_PRIORITY - 1, NULL );\r
+               xTaskCreate( prvTimerTestTask, "Tmr Tst", tmrTIMER_TEST_TASK_STACK_SIZE, NULL, configTIMER_TASK_PRIORITY - 1, NULL );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -184,12 +150,13 @@ static void prvTimerTestTask( void *pvParameters )
 {\r
        ( void ) pvParameters;\r
 \r
-       /* Create a one-shot timer for use later on in this test. */\r
-       xOneShotTimer = xTimerCreate(   ( const signed char * ) "Oneshot Timer",/* Text name to facilitate debugging.  The kernel does not use this itself. */\r
-                                                                       tmrdemoONE_SHOT_TIMER_PERIOD,                   /* The period for the timer. */\r
-                                                                       pdFALSE,                                                                /* Don't auto-reload - hence a one shot timer. */\r
-                                                                       ( void * ) 0,                                                   /* The timer identifier.  In this case this is not used as the timer has its own callback. */\r
-                                                                       prvOneShotTimerCallback );                              /* The callback to be called when the timer expires. */\r
+       /* Create a one-shot timer for use later on in this test.  For test purposes it\r
+       is created as an auto-reload timer then converted to a one-shot timer. */\r
+       xOneShotTimer = xTimerCreate(   "Oneshot Timer",                                /* Text name to facilitate debugging.  The kernel does not use this itself. */\r
+                                                                       tmrdemoONE_SHOT_TIMER_PERIOD,   /* The period for the timer. */\r
+                                                                       pdFALSE,                                                /* Autorealod is false, so created as a one-shot timer. */\r
+                                                                       ( void * ) 0,                                   /* The timer identifier.  Initialise to 0, then increment each time it is called. */\r
+                                                                       prvOneShotTimerCallback );              /* The callback to be called when the timer expires. */\r
 \r
        if( xOneShotTimer == NULL )\r
        {\r
@@ -197,6 +164,20 @@ static void prvTimerTestTask( void *pvParameters )
                configASSERT( xTestStatus );\r
        }\r
 \r
+       /* Purely for test coverage purposes - change and query the reload mode to\r
+       auto-reload then back to one-shot. */\r
+\r
+       /* Change timer to auto-reload. */\r
+       vTimerSetReloadMode( xOneShotTimer, pdTRUE );\r
+\r
+       /* Timer should now be auto-reload. */\r
+       configASSERT( uxTimerGetReloadMode( xOneShotTimer ) == pdTRUE );\r
+\r
+       /* Change timer to one-shot, which is what is needed for this test. */\r
+       vTimerSetReloadMode( xOneShotTimer, pdFALSE );\r
+\r
+       /* Check change to one-shot was successful. */\r
+       configASSERT( uxTimerGetReloadMode( xOneShotTimer ) == pdFALSE );\r
 \r
        /* Ensure all the timers are in their expected initial state.  This\r
        depends on the timer service task having a higher priority than this task. */\r
@@ -204,14 +185,14 @@ static void prvTimerTestTask( void *pvParameters )
 \r
        for( ;; )\r
        {\r
-               /* Check the auto reload timers expire at the expected/correct rates. */\r
+               /* Check the auto-reload timers expire at the expected/correct rates. */\r
                prvTest3_CheckAutoReloadExpireRates();\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
                prvTest4_CheckAutoReloadTimersCanBeStopped();\r
-                               \r
-               /* Check the one shot timer only calls its callback once after it has been\r
+\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
@@ -226,28 +207,28 @@ static void prvTimerTestTask( void *pvParameters )
 \r
 /* This is called to check that the created task is still running and has not\r
 detected any errors. */\r
-portBASE_TYPE xAreTimerDemoTasksStillRunning( portTickType xCycleFrequency )\r
+BaseType_t xAreTimerDemoTasksStillRunning( TickType_t xCycleFrequency )\r
 {\r
-static unsigned long ulLastLoopCounter = 0UL;\r
-portTickType xMaxBlockTimeUsedByTheseTests, xLoopCounterIncrementTimeMax;\r
-static portTickType xIterationsWithoutCounterIncrement = ( portTickType ) 0, xLastCycleFrequency;\r
+static uint32_t ulLastLoopCounter = 0UL;\r
+TickType_t xMaxBlockTimeUsedByTheseTests, xLoopCounterIncrementTimeMax;\r
+static TickType_t xIterationsWithoutCounterIncrement = ( TickType_t ) 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 Iterations again. */\r
-               xIterationsWithoutCounterIncrement = ( portTickType ) 0;\r
+               xIterationsWithoutCounterIncrement = ( TickType_t ) 0;\r
                xLastCycleFrequency = xCycleFrequency;\r
-       }               \r
+       }\r
 \r
        /* Calculate the maximum number of times that it is permissible 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
+       xMaxBlockTimeUsedByTheseTests = ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;\r
+       xLoopCounterIncrementTimeMax = ( xMaxBlockTimeUsedByTheseTests / xCycleFrequency ) + 1;\r
 \r
-       /* If the demo task is still running then we expect the loopcounter to\r
+       /* If the demo task is still running then the loop counter is expected to\r
        have incremented every xLoopCounterIncrementTimeMax calls. */\r
        if( ulLastLoopCounter == ulLoopCounter )\r
        {\r
@@ -256,14 +237,13 @@ static portTickType xIterationsWithoutCounterIncrement = ( portTickType ) 0, xLa
                {\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
-               xIterationsWithoutCounterIncrement = ( portTickType ) 0;\r
+               xIterationsWithoutCounterIncrement = ( TickType_t ) 0;\r
        }\r
 \r
        ulLastLoopCounter = ulLoopCounter;\r
@@ -277,18 +257,18 @@ static portTickType xIterationsWithoutCounterIncrement = ( portTickType ) 0, xLa
 \r
 static void prvTest1_CreateTimersWithoutSchedulerRunning( void )\r
 {\r
-unsigned portBASE_TYPE xTimer;\r
+TickType_t xTimer;\r
 \r
        for( xTimer = 0; xTimer < configTIMER_QUEUE_LENGTH; xTimer++ )\r
        {\r
-               /* As the timer queue is not yet full, it should be possible to both create\r
-               and start a timer.  These timers are being started before the scheduler has\r
-               been started, so their block times should get set to zero within the timer\r
-               API itself. */\r
-               xAutoReloadTimers[ xTimer ] = xTimerCreate( ( const signed char * )"FR Timer",  /* Text name to facilitate debugging.  The kernel does not use this itself. */\r
-                                                                                                       ( ( xTimer + ( portTickType ) 1 ) * xBasePeriod ),/* The period for the timer.  The plus 1 ensures a period of zero is not specified. */\r
+               /* As the timer queue is not yet full, it should be possible to both\r
+               create and start a timer.  These timers are being started before the\r
+               scheduler has been started, so their block times should get set to zero\r
+               within the timer API itself. */\r
+               xAutoReloadTimers[ xTimer ] = xTimerCreate( "FR Timer",                                                 /* Text name to facilitate debugging.  The kernel does not use this itself. */\r
+                                                                                                       ( ( xTimer + ( TickType_t ) 1 ) * xBasePeriod ),/* The period for the timer.  The plus 1 ensures a period of zero is not specified. */\r
                                                                                                        pdTRUE,                                                         /* Auto-reload is set to true. */\r
-                                                                                                       ( void * ) xTimer,                                      /* An identifier for the timer as all the auto reload timers use the same callback. */\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
 \r
                if( xAutoReloadTimers[ xTimer ] == NULL )\r
@@ -298,6 +278,8 @@ unsigned portBASE_TYPE xTimer;
                }\r
                else\r
                {\r
+                       configASSERT( strcmp( pcTimerGetName( xAutoReloadTimers[ xTimer ] ), "FR Timer" ) == 0 );\r
+\r
                        /* The scheduler has not yet started, so the block period of\r
                        portMAX_DELAY should just get set to zero in xTimerStart().  Also,\r
                        the timer queue is not yet full so xTimerStart() should return\r
@@ -313,11 +295,11 @@ unsigned portBASE_TYPE xTimer;
        /* The timers queue should now be full, so it should be possible to create\r
        another timer, but not possible to start it (the timer queue will not get\r
        drained until the scheduler has been started. */\r
-       xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] = xTimerCreate( ( const signed char * ) "FR Timer",       /* Text name to facilitate debugging.  The kernel does not use this itself. */\r
-                                                                                                       ( configTIMER_QUEUE_LENGTH * xBasePeriod ),                     /* The period for the timer. */\r
-                                                                                                       pdTRUE,                                                                                         /* Auto-reload 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 executed when the timer expires. */\r
+       xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] = xTimerCreate( "FR Timer",                                       /* Text name to facilitate debugging.  The kernel does not use this itself. */\r
+                                                                                                       ( configTIMER_QUEUE_LENGTH * xBasePeriod ),     /* The period for the timer. */\r
+                                                                                                       pdTRUE,                                                                         /* Auto-reload 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 executed when the timer expires. */\r
 \r
        if( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] == NULL )\r
        {\r
@@ -334,21 +316,21 @@ unsigned portBASE_TYPE xTimer;
                        configASSERT( xTestStatus );\r
                }\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( ( const signed char * ) "ISR AR",   /* The text name given to the timer. */\r
+       xISRAutoReloadTimer = xTimerCreate( "ISR AR",                                                   /* The text name given to the timer. */\r
                                                                                0xffff,                                                         /* The timer is not given a period yet - this will be done from the tick hook, but a period of 0 is invalid. */\r
-                                                                               pdTRUE,                                                         /* This is an auto reload timer. */\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(        ( const signed char * ) "ISR OS",       /* The text name given to the timer. */\r
+       xISROneShotTimer = xTimerCreate(        "ISR OS",                                                       /* The text name given to the timer. */\r
                                                                                0xffff,                                                         /* The timer is not given a period yet - this will be done from the tick hook, but a period of 0 is invalid. */\r
-                                                                               pdFALSE,                                                        /* This is a one shot timer. */\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
+\r
        if( ( xISRAutoReloadTimer == NULL ) || ( xISROneShotTimer == NULL ) )\r
        {\r
                xTestStatus = pdFAIL;\r
@@ -359,16 +341,16 @@ unsigned portBASE_TYPE xTimer;
 \r
 static void prvTest2_CheckTaskAndTimersInitialState( void )\r
 {\r
-unsigned char ucTimer;\r
+uint8_t ucTimer;\r
 \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
+       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
        created). */\r
-       for( ucTimer = 0; ucTimer < ( unsigned char ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
+       for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
        {\r
                if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )\r
                {\r
@@ -387,28 +369,32 @@ unsigned char ucTimer;
 \r
 static void    prvTest3_CheckAutoReloadExpireRates( void )\r
 {\r
-unsigned char ucMaxAllowableValue, ucMinAllowableValue, ucTimer;\r
-portTickType xBlockPeriod, xTimerPeriod, xExpectedNumber;\r
+uint8_t ucMaxAllowableValue, ucMinAllowableValue, ucTimer;\r
+TickType_t xBlockPeriod, xTimerPeriod, xExpectedNumber;\r
+UBaseType_t uxOriginalPriority;\r
 \r
-       /* Check the auto reload timers expire at the expected rates. */\r
+       /* Check the auto-reload timers expire at the expected rates.  Do this at a\r
+       high priority for maximum accuracy.  This is ok as most of the time is spent\r
+       in the Blocked state. */\r
+       uxOriginalPriority = uxTaskPriorityGet( NULL );\r
+       vTaskPrioritySet( NULL, ( configMAX_PRIORITIES - 1 ) );\r
 \r
-       \r
        /* Delaying for configTIMER_QUEUE_LENGTH * xBasePeriod ticks should allow\r
-       all the auto reload timers to expire at least once. */\r
-       xBlockPeriod = ( ( portTickType ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;\r
+       all the auto-reload timers to expire at least once. */\r
+       xBlockPeriod = ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;\r
        vTaskDelay( xBlockPeriod );\r
 \r
-       /* Check that all the auto reload timers have called their callback     \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
+       for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
        {\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
+               xTimerPeriod = ( ( ( TickType_t ) ucTimer + ( TickType_t ) 1 ) * xBasePeriod );\r
                xExpectedNumber = xBlockPeriod / xTimerPeriod;\r
-               \r
-               ucMaxAllowableValue = ( ( unsigned char ) xExpectedNumber ) ;\r
-               ucMinAllowableValue = ( ( unsigned char ) xExpectedNumber - ( unsigned char ) 1 );\r
+\r
+               ucMaxAllowableValue = ( ( uint8_t ) xExpectedNumber ) ;\r
+               ucMinAllowableValue = ( uint8_t ) ( ( uint8_t ) xExpectedNumber - ( uint8_t ) 1 ); /* Weird casting to try and please all compilers. */\r
 \r
                if( ( ucAutoReloadTimerCounters[ ucTimer ] < ucMinAllowableValue ) ||\r
                        ( ucAutoReloadTimerCounters[ ucTimer ] > ucMaxAllowableValue )\r
@@ -419,6 +405,9 @@ portTickType xBlockPeriod, xTimerPeriod, xExpectedNumber;
                }\r
        }\r
 \r
+       /* Return to the original priority. */\r
+       vTaskPrioritySet( NULL, uxOriginalPriority );\r
+\r
        if( xTestStatus == pdPASS )\r
        {\r
                /* No errors have been reported so increment the loop counter so the\r
@@ -429,14 +418,14 @@ portTickType xBlockPeriod, xTimerPeriod, xExpectedNumber;
 /*-----------------------------------------------------------*/\r
 \r
 static void prvTest4_CheckAutoReloadTimersCanBeStopped( void )\r
-{              \r
-unsigned char ucTimer;\r
+{\r
+uint8_t 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
-       for( ucTimer = 0; ucTimer < ( unsigned char ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
+       for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
        {\r
                /* The timer has not been stopped yet! */\r
                if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )\r
@@ -464,7 +453,7 @@ unsigned char ucTimer;
                be active.  The critical section is used to ensure the timer does\r
                not call its callback between the next line running and the array\r
                being cleared back to zero, as that would mask an error condition. */\r
-               if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH ] != ( unsigned char ) 0 )\r
+               if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH ] != ( uint8_t ) 0 )\r
                {\r
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
@@ -477,10 +466,10 @@ unsigned char ucTimer;
 \r
        /* The timers are now all inactive, so this time, after delaying, none\r
        of the callback counters should have incremented. */\r
-       vTaskDelay( ( ( portTickType ) configTIMER_QUEUE_LENGTH ) * xBasePeriod );\r
-       for( ucTimer = 0; ucTimer < ( unsigned char ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
+       vTaskDelay( ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod );\r
+       for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
        {\r
-               if( ucAutoReloadTimerCounters[ ucTimer ] != ( unsigned char ) 0 )\r
+               if( ucAutoReloadTimerCounters[ ucTimer ] != ( uint8_t ) 0 )\r
                {\r
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
@@ -498,23 +487,23 @@ unsigned char ucTimer;
 \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
+       /* 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
+       if( ucOneShotTimerCounter != ( uint8_t ) 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
+       /* Start the one-shot timer and check that it reports its state correctly. */\r
        xTimerStart( xOneShotTimer, tmrdemoDONT_BLOCK );\r
        if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )\r
        {\r
@@ -522,10 +511,10 @@ static void prvTest5_CheckBasicOneShotTimerBehaviour( void )
                configASSERT( xTestStatus );\r
        }\r
 \r
-       /* Delay for three times as long as the one shot timer period, then check\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
+       vTaskDelay( tmrdemoONE_SHOT_TIMER_PERIOD * ( TickType_t ) 3 );\r
 \r
        if( xTimerIsTimerActive( xOneShotTimer ) != pdFALSE )\r
        {\r
@@ -533,15 +522,15 @@ static void prvTest5_CheckBasicOneShotTimerBehaviour( void )
                configASSERT( xTestStatus );\r
        }\r
 \r
-       if( ucOneShotTimerCounter != ( unsigned char ) 1 )\r
+       if( ucOneShotTimerCounter != ( uint8_t ) 1 )\r
        {\r
                xTestStatus = pdFAIL;\r
                configASSERT( xTestStatus );\r
        }\r
        else\r
        {\r
-               /* Reset the one shot timer callback count. */\r
-               ucOneShotTimerCounter = ( unsigned char ) 0;\r
+               /* Reset the one-shot timer callback count. */\r
+               ucOneShotTimerCounter = ( uint8_t ) 0;\r
        }\r
 \r
        if( xTestStatus == pdPASS )\r
@@ -555,11 +544,11 @@ static void prvTest5_CheckBasicOneShotTimerBehaviour( void )
 \r
 static void prvTest6_CheckAutoReloadResetBehaviour( void )\r
 {\r
-unsigned char ucTimer;\r
+uint8_t ucTimer;\r
 \r
        /* Check timer reset behaviour. */\r
 \r
-       /* Restart the one shot timer and check it reports its status correctly. */\r
+       /* Restart the one-shot timer and check it reports its status correctly. */\r
        xTimerStart( xOneShotTimer, tmrdemoDONT_BLOCK );\r
        if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )\r
        {\r
@@ -567,7 +556,7 @@ unsigned char ucTimer;
                configASSERT( xTestStatus );\r
        }\r
 \r
-       /* Restart one of the auto reload timers and check that it reports its\r
+       /* Restart one of the auto-reload timers and check that it reports its\r
        status correctly. */\r
        xTimerStart( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ], tmrdemoDONT_BLOCK );\r
        if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )\r
@@ -576,9 +565,9 @@ unsigned char ucTimer;
                configASSERT( xTestStatus );\r
        }\r
 \r
-       for( ucTimer = 0; ucTimer < trmdemoNUM_TIMER_RESETS; ucTimer++ )\r
+       for( ucTimer = 0; ucTimer < tmrdemoNUM_TIMER_RESETS; ucTimer++ )\r
        {\r
-               /* Delay for half as long as the one shot timer period, then reset it.\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
@@ -591,7 +580,7 @@ unsigned char ucTimer;
                        configASSERT( xTestStatus );\r
                }\r
 \r
-               if( ucOneShotTimerCounter != ( unsigned char ) 0 )\r
+               if( ucOneShotTimerCounter != ( uint8_t ) 0 )\r
                {\r
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
@@ -603,7 +592,7 @@ unsigned char ucTimer;
                        configASSERT( xTestStatus );\r
                }\r
 \r
-               if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] != ( unsigned char ) 0 )\r
+               if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] != ( uint8_t ) 0 )\r
                {\r
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
@@ -622,11 +611,11 @@ unsigned char ucTimer;
        }\r
 \r
        /* Finally delay long enough for both running timers to expire. */\r
-       vTaskDelay( ( ( portTickType ) configTIMER_QUEUE_LENGTH ) * xBasePeriod );\r
+       vTaskDelay( ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod );\r
 \r
        /* The timers were not reset during the above delay period so should now\r
        both have called their callback functions. */\r
-       if( ucOneShotTimerCounter != ( unsigned char ) 1 )\r
+       if( ucOneShotTimerCounter != ( uint8_t ) 1 )\r
        {\r
                xTestStatus = pdFAIL;\r
                configASSERT( xTestStatus );\r
@@ -638,7 +627,7 @@ unsigned char ucTimer;
                configASSERT( xTestStatus );\r
        }\r
 \r
-       /* The one shot timer should no longer be active, while the auto reload\r
+       /* The one-shot timer should no longer be active, while the auto-reload\r
        timer should still be active. */\r
        if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )\r
        {\r
@@ -652,7 +641,7 @@ unsigned char ucTimer;
                configASSERT( xTestStatus );\r
        }\r
 \r
-       /* Stop the auto reload timer again. */\r
+       /* Stop the auto-reload timer again. */\r
        xTimerStop( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ], tmrdemoDONT_BLOCK );\r
 \r
        if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) != pdFALSE )\r
@@ -663,8 +652,8 @@ unsigned char ucTimer;
 \r
        /* Clear the timer callback counts, ready for another iteration of these\r
        tests. */\r
-       ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] = ( unsigned char ) 0;\r
-       ucOneShotTimerCounter = ( unsigned char ) 0;\r
+       ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] = ( uint8_t ) 0;\r
+       ucOneShotTimerCounter = ( uint8_t ) 0;\r
 \r
        if( xTestStatus == pdPASS )\r
        {\r
@@ -677,12 +666,12 @@ unsigned char ucTimer;
 \r
 static void prvResetStartConditionsForNextIteration( void )\r
 {\r
-unsigned char ucTimer;\r
+uint8_t ucTimer;\r
 \r
        /* Start the timers again to start all the tests over again. */\r
 \r
        /* Start the timers again. */\r
-       for( ucTimer = 0; ucTimer < ( unsigned char ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
+       for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
        {\r
                /* The timer has not been started yet! */\r
                if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) != pdFALSE )\r
@@ -715,55 +704,77 @@ unsigned char ucTimer;
 \r
 void vTimerPeriodicISRTests( void )\r
 {\r
-static portTickType uxTick = ( portTickType ) -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
-signed portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
-portTickType xMargin;\r
+static TickType_t uxTick = ( TickType_t ) -1;\r
+\r
+#if( configTIMER_TASK_PRIORITY != ( configMAX_PRIORITIES - 1 ) )\r
+       /* The timer service task is not the highest priority task, so it cannot\r
+       be assumed that timings will be exact.  Timers should never call their\r
+       callback before their expiry time, but a margin is permissible for calling\r
+       their callback after their expiry time.  If exact timing is required then\r
+       configTIMER_TASK_PRIORITY must be set to ensure the timer service task\r
+       is the highest priority task in the system.\r
+\r
+       This function is called from the tick hook.  The tick hook is called\r
+       even when the scheduler is suspended.  Therefore it is possible that the\r
+       uxTick count maintained in this function is temporarily ahead of the tick\r
+       count maintained by the kernel.  When this is the case a message posted from\r
+       this function will assume a time stamp in advance of the real time stamp,\r
+       which can result in a timer being processed before this function expects it\r
+       to.  For example, if the kernel's tick count was 100, and uxTick was 102,\r
+       then this function will not expect the timer to have expired until the\r
+       kernel's tick count is (102 + xBasePeriod), whereas in reality the timer\r
+       will expire when the kernel's tick count is (100 + xBasePeriod).  For this\r
+       reason xMargin is used as an allowable margin for premature timer expiries\r
+       as well as late timer expiries. */\r
+       #ifdef _WINDOWS_\r
+               /* Windows is not real real time. */\r
+               const TickType_t xMargin = 20;\r
+       #else\r
+               const TickType_t xMargin = 6;\r
+       #endif /* _WINDOWS_ */\r
+#else\r
+       #ifdef _WINDOWS_\r
+               /* Windows is not real real time. */\r
+               const TickType_t xMargin = 20;\r
+       #else\r
+               const TickType_t xMargin = 4;\r
+       #endif /* _WINDOWS_ */\r
+#endif\r
 \r
-       if( configTIMER_TASK_PRIORITY != ( configMAX_PRIORITIES - 1 ) )\r
-       {\r
-               /* The timer service task is not the highest priority task, so it cannot\r
-               be assumed that timings will be exact.  Timers should never call their\r
-               callback before their expiry time, but a margin is permissible for calling\r
-               their callback after their expiry time.  If exact timing is required then\r
-               configTIMER_TASK_PRIORITY must be set to ensure the timer service task\r
-               is the highest priority task in the system. */\r
-               xMargin = 5;\r
-       }\r
-       else\r
-       {\r
-               xMargin = 1;\r
-       }\r
 \r
-       /* This test is called from the tick ISR even when the scheduler is suspended.\r
-       Therefore, it is possible for the xTickCount to be temporarily less than the\r
-       uxTicks count maintained in this function.  That can result in calculated\r
-       unblock times being too short, as this function is not called as missed ticks\r
-       (ticks that occur while the scheduler is suspended) are unwound to re-instate\r
-       the real tick value.  Therefore, if this happens, just abandon the test\r
-       and start again. */\r
-       if( xTaskGetSchedulerState() != taskSCHEDULER_RUNNING )\r
-       {\r
-               uxTick = ( portTickType ) -1;\r
-       }\r
-       else\r
-       {\r
-               uxTick++;\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
+               /* The timers will have been created, but not started.  Start them now\r
+               by setting their period. */\r
                ucISRAutoReloadTimerCounter = 0;\r
                ucISROneShotTimerCounter = 0;\r
-               xTimerChangePeriodFromISR( xISRAutoReloadTimer, xBasePeriod, &xHigherPriorityTaskWoken );\r
-               xTimerChangePeriodFromISR( xISROneShotTimer, xBasePeriod, &xHigherPriorityTaskWoken );\r
+\r
+               /* It is possible that the timer task has not yet made room in the\r
+               timer queue.  If the timers cannot be started then reset uxTick so\r
+               another attempt is made later. */\r
+               uxTick = ( TickType_t ) -1;\r
+\r
+               /* Try starting first timer. */\r
+               if( xTimerChangePeriodFromISR( xISRAutoReloadTimer, xBasePeriod, NULL ) == pdPASS )\r
+               {\r
+                       /* First timer was started, try starting the second timer. */\r
+                       if( xTimerChangePeriodFromISR( xISROneShotTimer, xBasePeriod, NULL ) == pdPASS )\r
+                       {\r
+                               /* Both timers were started, so set the uxTick back to its\r
+                               proper value. */\r
+                               uxTick = 0;\r
+                       }\r
+                       else\r
+                       {\r
+                               /* Second timer could not be started, so stop the first one\r
+                               again. */\r
+                               xTimerStopFromISR( xISRAutoReloadTimer, NULL );\r
+                       }\r
+               }\r
        }\r
-       else if( uxTick == xBasePeriod )\r
+       else if( uxTick == ( xBasePeriod - xMargin ) )\r
        {\r
                /* Neither timer should have expired yet. */\r
                if( ( ucISRAutoReloadTimerCounter != 0 ) || ( ucISROneShotTimerCounter != 0 ) )\r
@@ -774,45 +785,45 @@ portTickType xMargin;
        }\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
+               /* 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
+       else if( uxTick == ( ( 2 * xBasePeriod ) - xMargin ) )\r
        {\r
-               /* The auto reload timer will still be active, but the one shot timer\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
                should have expired again since the last test. */\r
                if( ( ucISRAutoReloadTimerCounter != 1 ) || ( ucISROneShotTimerCounter != 1 ) )\r
                {\r
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
-               }               \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
+               /* 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
+\r
                if( ucISROneShotTimerCounter != 1 )\r
                {\r
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
                }\r
        }\r
-       else if( uxTick == ( ( 2 * xBasePeriod ) + ( xBasePeriod >> ( portTickType ) 2U ) ) )\r
+       else if( uxTick == ( ( 2 * xBasePeriod ) + ( xBasePeriod >> ( TickType_t ) 2U ) ) )\r
        {\r
-               /* The auto reload timer will still be active, but the one shot timer\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
@@ -820,42 +831,42 @@ portTickType xMargin;
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
                }\r
-               \r
+\r
                if( ucISROneShotTimerCounter != 1 )\r
                {\r
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
                }\r
-       }       \r
+       }\r
        else if( uxTick == ( 3 * xBasePeriod ) )\r
        {\r
-               /* Start the one shot timer again. */\r
-               xTimerStartFromISR( xISROneShotTimer, &xHigherPriorityTaskWoken );\r
+               /* Start the one-shot timer again. */\r
+               xTimerStartFromISR( xISROneShotTimer, NULL );\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
+               /* 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
+\r
                if( ucISROneShotTimerCounter != 1 )\r
                {\r
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
                }\r
-               \r
-               /* Now stop the auto reload timer.  The one shot timer was started\r
+\r
+               /* Now stop the auto-reload timer.  The one-shot timer was started\r
                a few ticks ago. */\r
-               xTimerStopFromISR( xISRAutoReloadTimer, &xHigherPriorityTaskWoken );\r
-       }       \r
-       else if( uxTick == ( 4 * xBasePeriod ) )\r
+               xTimerStopFromISR( xISRAutoReloadTimer, NULL );\r
+       }\r
+       else if( uxTick == ( 4 * ( xBasePeriod - xMargin ) ) )\r
        {\r
-               /* The auto reload timer is now stopped, and the one shot timer is\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
@@ -863,33 +874,33 @@ portTickType xMargin;
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
                }\r
-               \r
+\r
                if( ucISROneShotTimerCounter != 1 )\r
                {\r
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
                }\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
+               /* 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
+\r
                if( ucISROneShotTimerCounter != 2 )\r
                {\r
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
                }\r
-       }       \r
-       else if( uxTick == ( ( 8 * xBasePeriod ) + xMargin ) )\r
+       }\r
+       else if( uxTick == ( 8 * xBasePeriod ) )\r
        {\r
-               /* The auto reload timer is now stopped, and the one shot timer has\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
@@ -897,86 +908,86 @@ portTickType xMargin;
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
                }\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
+               /* Now reset the one-shot timer. */\r
+               xTimerResetFromISR( xISROneShotTimer, NULL );\r
+       }\r
+       else if( uxTick == ( ( 9 * xBasePeriod ) - xMargin ) )\r
        {\r
-               /* Only the one shot timer should be running, but it should not have\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
+               incremented, then reset the one-shot timer again. */\r
                if( ucISRAutoReloadTimerCounter != 3 )\r
                {\r
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
                }\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
+               xTimerResetFromISR( xISROneShotTimer, NULL );\r
+       }\r
+       else if( uxTick == ( ( 10 * xBasePeriod ) - ( 2 * xMargin ) ) )\r
        {\r
-               /* Only the one shot timer should be running, but it should not have\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
+               incremented, then reset the one-shot timer again. */\r
                if( ucISRAutoReloadTimerCounter != 3 )\r
                {\r
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
                }\r
-               \r
+\r
                if( ucISROneShotTimerCounter != 2 )\r
                {\r
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
                }\r
-               \r
-               xTimerResetFromISR( xISROneShotTimer, &xHigherPriorityTaskWoken );\r
+\r
+               xTimerResetFromISR( xISROneShotTimer, NULL );\r
        }\r
-       else if( uxTick == ( 11 * xBasePeriod ) )\r
+       else if( uxTick == ( ( 11 * xBasePeriod ) - ( 3 * xMargin ) ) )\r
        {\r
-               /* Only the one shot timer should be running, but it should not have\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
+               incremented, then reset the one-shot timer once again. */\r
                if( ucISRAutoReloadTimerCounter != 3 )\r
                {\r
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
                }\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
+               xTimerResetFromISR( xISROneShotTimer, NULL );\r
+       }\r
+       else if( uxTick == ( ( 12 * xBasePeriod ) - ( 2 * xMargin ) ) )\r
        {\r
-               /* Only the one shot timer should have been running and this time it\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 reload 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
+               The auto-reload 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
+\r
                if( ucISROneShotTimerCounter != 3 )\r
                {\r
                        xTestStatus = pdFAIL;\r
@@ -993,28 +1004,28 @@ portTickType xMargin;
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
                }\r
-               \r
+\r
                if( ucISROneShotTimerCounter != 3 )\r
                {\r
                        xTestStatus = pdFAIL;\r
                        configASSERT( xTestStatus );\r
                }\r
-               \r
-               uxTick = ( portTickType ) -1;\r
-       }       \r
+\r
+               uxTick = ( TickType_t ) -1;\r
+       }\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 /*** Timer callback functions are defined below here. ***/\r
 \r
-static void prvAutoReloadTimerCallback( xTimerHandle pxExpiredTimer )\r
+static void prvAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer )\r
 {\r
-unsigned long ulTimerID;\r
+size_t uxTimerID;\r
 \r
-       ulTimerID = ( unsigned long ) pvTimerGetTimerID( pxExpiredTimer );\r
-       if( ulTimerID <= ( configTIMER_QUEUE_LENGTH + 1 ) )\r
+       uxTimerID = ( size_t ) pvTimerGetTimerID( pxExpiredTimer );\r
+       if( uxTimerID <= ( configTIMER_QUEUE_LENGTH + 1 ) )\r
        {\r
-               ( ucAutoReloadTimerCounters[ ulTimerID ] )++;\r
+               ( ucAutoReloadTimerCounters[ uxTimerID ] )++;\r
        }\r
        else\r
        {\r
@@ -1025,17 +1036,30 @@ unsigned long ulTimerID;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvOneShotTimerCallback( xTimerHandle pxExpiredTimer )\r
+static void prvOneShotTimerCallback( TimerHandle_t pxExpiredTimer )\r
 {\r
-       /* The parameter is not used in this case as only one timer uses this\r
-       callback function. */\r
-       ( void ) pxExpiredTimer;\r
+/* A count is kept of the number of times this callback function is executed.\r
+The count is stored as the timer's ID.  This is only done to test the\r
+vTimerSetTimerID() function. */\r
+static size_t uxCallCount = 0;\r
+size_t uxLastCallCount;\r
+\r
+       /* Obtain the timer's ID, which should be a count of the number of times\r
+       this callback function has been executed. */\r
+       uxLastCallCount = ( size_t ) pvTimerGetTimerID( pxExpiredTimer );\r
+       configASSERT( uxLastCallCount == uxCallCount );\r
+\r
+       /* Increment the call count, then save it back as the timer's ID.  This is\r
+       only done to test the vTimerSetTimerID() API function. */\r
+       uxLastCallCount++;\r
+       vTimerSetTimerID( pxExpiredTimer, ( void * ) uxLastCallCount );\r
+       uxCallCount++;\r
 \r
        ucOneShotTimerCounter++;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvISRAutoReloadTimerCallback( xTimerHandle pxExpiredTimer )\r
+static void prvISRAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer )\r
 {\r
        /* The parameter is not used in this case as only one timer uses this\r
        callback function. */\r
@@ -1045,7 +1069,7 @@ static void prvISRAutoReloadTimerCallback( xTimerHandle pxExpiredTimer )
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvISROneShotTimerCallback( xTimerHandle pxExpiredTimer )\r
+static void prvISROneShotTimerCallback( TimerHandle_t pxExpiredTimer )\r
 {\r
        /* The parameter is not used in this case as only one timer uses this\r
        callback function. */\r