]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Common/Minimal/TimerDemo.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / Common / Minimal / TimerDemo.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 \r
30 /*\r
31  * Tests the behaviour of timers.  Some timers are created before the scheduler\r
32  * is started, and some after.\r
33  */\r
34 \r
35 /* Standard includes. */\r
36 #include <string.h>\r
37 \r
38 /* Scheduler include files. */\r
39 #include "FreeRTOS.h"\r
40 #include "task.h"\r
41 #include "timers.h"\r
42 \r
43 /* Demo program include files. */\r
44 #include "TimerDemo.h"\r
45 \r
46 #if ( configTIMER_TASK_PRIORITY < 1 )\r
47         #error configTIMER_TASK_PRIORITY must be set to at least 1 for this test/demo to function correctly.\r
48 #endif\r
49 \r
50 #define tmrdemoDONT_BLOCK                               ( ( TickType_t ) 0 )\r
51 #define tmrdemoONE_SHOT_TIMER_PERIOD    ( xBasePeriod * ( TickType_t ) 3 )\r
52 #define trmdemoNUM_TIMER_RESETS                 ( ( uint8_t ) 10 )\r
53 \r
54 /*-----------------------------------------------------------*/\r
55 \r
56 /* The callback functions used by the timers.  These each increment a counter\r
57 to indicate which timer has expired.  The auto-reload timers that are used by\r
58 the test task (as opposed to being used from an ISR) all share the same\r
59 prvAutoReloadTimerCallback() callback function, and use the ID of the\r
60 pxExpiredTimer parameter passed into that function to know which counter to\r
61 increment.  The other timers all have their own unique callback function and\r
62 simply increment their counters without using the callback function parameter. */\r
63 static void prvAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer );\r
64 static void prvOneShotTimerCallback( TimerHandle_t pxExpiredTimer );\r
65 static void prvTimerTestTask( void *pvParameters );\r
66 static void prvISRAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer );\r
67 static void prvISROneShotTimerCallback( TimerHandle_t pxExpiredTimer );\r
68 \r
69 /* The test functions used by the timer test task.  These manipulate the auto\r
70 reload and one shot timers in various ways, then delay, then inspect the timers\r
71 to ensure they have behaved as expected. */\r
72 static void prvTest1_CreateTimersWithoutSchedulerRunning( void );\r
73 static void prvTest2_CheckTaskAndTimersInitialState( void );\r
74 static void     prvTest3_CheckAutoReloadExpireRates( void );\r
75 static void prvTest4_CheckAutoReloadTimersCanBeStopped( void );\r
76 static void prvTest5_CheckBasicOneShotTimerBehaviour( void );\r
77 static void prvTest6_CheckAutoReloadResetBehaviour( void );\r
78 static void prvResetStartConditionsForNextIteration( void );\r
79 \r
80 /*-----------------------------------------------------------*/\r
81 \r
82 /* Flag that will be latched to pdFAIL should any unexpected behaviour be\r
83 detected in any of the demo tests. */\r
84 static volatile BaseType_t xTestStatus = pdPASS;\r
85 \r
86 /* Counter that is incremented on each cycle of a test.  This is used to\r
87 detect a stalled task - a test that is no longer running. */\r
88 static volatile uint32_t ulLoopCounter = 0;\r
89 \r
90 /* A set of auto reload timers - each of which use the same callback function.\r
91 The callback function uses the timer ID to index into, and then increment, a\r
92 counter in the ucAutoReloadTimerCounters[] array.  The auto reload timers\r
93 referenced from xAutoReloadTimers[] are used by the prvTimerTestTask task. */\r
94 static TimerHandle_t xAutoReloadTimers[ configTIMER_QUEUE_LENGTH + 1 ] = { 0 };\r
95 static uint8_t ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH + 1 ] = { 0 };\r
96 \r
97 /* The one shot timer is configured to use a callback function that increments\r
98 ucOneShotTimerCounter each time it gets called. */\r
99 static TimerHandle_t xOneShotTimer = NULL;\r
100 static uint8_t ucOneShotTimerCounter = ( uint8_t ) 0;\r
101 \r
102 /* The ISR reload timer is controlled from the tick hook to exercise the timer\r
103 API functions that can be used from an ISR.  It is configured to increment\r
104 ucISRReloadTimerCounter each time its callback function is executed. */\r
105 static TimerHandle_t xISRAutoReloadTimer = NULL;\r
106 static uint8_t ucISRAutoReloadTimerCounter = ( uint8_t ) 0;\r
107 \r
108 /* The ISR one shot timer is controlled from the tick hook to exercise the timer\r
109 API functions that can be used from an ISR.  It is configured to increment\r
110 ucISRReloadTimerCounter each time its callback function is executed. */\r
111 static TimerHandle_t xISROneShotTimer = NULL;\r
112 static uint8_t ucISROneShotTimerCounter = ( uint8_t ) 0;\r
113 \r
114 /* The period of all the timers are a multiple of the base period.  The base\r
115 period is configured by the parameter to vStartTimerDemoTask(). */\r
116 static TickType_t xBasePeriod = 0;\r
117 \r
118 /*-----------------------------------------------------------*/\r
119 \r
120 void vStartTimerDemoTask( TickType_t xBasePeriodIn )\r
121 {\r
122         /* Start with the timer and counter arrays clear - this is only necessary\r
123         where the compiler does not clear them automatically on start up. */\r
124         memset( ucAutoReloadTimerCounters, 0x00, sizeof( ucAutoReloadTimerCounters ) );\r
125         memset( xAutoReloadTimers, 0x00, sizeof( xAutoReloadTimers ) );\r
126 \r
127         /* Store the period from which all the timer periods will be generated from\r
128         (multiples of). */\r
129         xBasePeriod = xBasePeriodIn;\r
130 \r
131         /* Create a set of timers for use by this demo/test. */\r
132         prvTest1_CreateTimersWithoutSchedulerRunning();\r
133 \r
134         /* Create the task that will control and monitor the timers.  This is\r
135         created at a lower priority than the timer service task to ensure, as\r
136         far as it is concerned, commands on timers are actioned immediately\r
137         (sending a command to the timer service task will unblock the timer service\r
138         task, which will then preempt this task). */\r
139         if( xTestStatus != pdFAIL )\r
140         {\r
141                 xTaskCreate( prvTimerTestTask, "Tmr Tst", configMINIMAL_STACK_SIZE, NULL, configTIMER_TASK_PRIORITY - 1, NULL );\r
142         }\r
143 }\r
144 /*-----------------------------------------------------------*/\r
145 \r
146 static void prvTimerTestTask( void *pvParameters )\r
147 {\r
148         ( void ) pvParameters;\r
149 \r
150         /* Create a one-shot timer for use later on in this test. */\r
151         xOneShotTimer = xTimerCreate(   "Oneshot Timer",                                /* Text name to facilitate debugging.  The kernel does not use this itself. */\r
152                                                                         tmrdemoONE_SHOT_TIMER_PERIOD,   /* The period for the timer. */\r
153                                                                         pdFALSE,                                                /* Don't auto-reload - hence a one shot timer. */\r
154                                                                         ( void * ) 0,                                   /* The timer identifier.  Initialise to 0, then increment each time it is called. */\r
155                                                                         prvOneShotTimerCallback );              /* The callback to be called when the timer expires. */\r
156 \r
157         if( xOneShotTimer == NULL )\r
158         {\r
159                 xTestStatus = pdFAIL;\r
160                 configASSERT( xTestStatus );\r
161         }\r
162 \r
163 \r
164         /* Ensure all the timers are in their expected initial state.  This\r
165         depends on the timer service task having a higher priority than this task. */\r
166         prvTest2_CheckTaskAndTimersInitialState();\r
167 \r
168         for( ;; )\r
169         {\r
170                 /* Check the auto reload timers expire at the expected/correct rates. */\r
171                 prvTest3_CheckAutoReloadExpireRates();\r
172 \r
173                 /* Check the auto reload timers can be stopped correctly, and correctly\r
174                 report their state. */\r
175                 prvTest4_CheckAutoReloadTimersCanBeStopped();\r
176 \r
177                 /* Check the one shot timer only calls its callback once after it has been\r
178                 started, and that it reports its state correctly. */\r
179                 prvTest5_CheckBasicOneShotTimerBehaviour();\r
180 \r
181                 /* Check timer reset behaviour. */\r
182                 prvTest6_CheckAutoReloadResetBehaviour();\r
183 \r
184                 /* Start the timers again to restart all the tests over again. */\r
185                 prvResetStartConditionsForNextIteration();\r
186         }\r
187 }\r
188 /*-----------------------------------------------------------*/\r
189 \r
190 /* This is called to check that the created task is still running and has not\r
191 detected any errors. */\r
192 BaseType_t xAreTimerDemoTasksStillRunning( TickType_t xCycleFrequency )\r
193 {\r
194 static uint32_t ulLastLoopCounter = 0UL;\r
195 TickType_t xMaxBlockTimeUsedByTheseTests, xLoopCounterIncrementTimeMax;\r
196 static TickType_t xIterationsWithoutCounterIncrement = ( TickType_t ) 0, xLastCycleFrequency;\r
197 \r
198         if( xLastCycleFrequency != xCycleFrequency )\r
199         {\r
200                 /* The cycle frequency has probably become much faster due to an error\r
201                 elsewhere.  Start counting Iterations again. */\r
202                 xIterationsWithoutCounterIncrement = ( TickType_t ) 0;\r
203                 xLastCycleFrequency = xCycleFrequency;\r
204         }\r
205 \r
206         /* Calculate the maximum number of times that it is permissible for this\r
207         function to be called without ulLoopCounter being incremented.  This is\r
208         necessary because the tests in this file block for extended periods, and the\r
209         block period might be longer than the time between calls to this function. */\r
210         xMaxBlockTimeUsedByTheseTests = ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;\r
211         xLoopCounterIncrementTimeMax = ( xMaxBlockTimeUsedByTheseTests / xCycleFrequency ) + 1;\r
212 \r
213         /* If the demo task is still running then the loop counter is expected to\r
214         have incremented every xLoopCounterIncrementTimeMax calls. */\r
215         if( ulLastLoopCounter == ulLoopCounter )\r
216         {\r
217                 xIterationsWithoutCounterIncrement++;\r
218                 if( xIterationsWithoutCounterIncrement > xLoopCounterIncrementTimeMax )\r
219                 {\r
220                         /* The tests appear to be no longer running (stalled). */\r
221                         xTestStatus = pdFAIL;\r
222                         configASSERT( xTestStatus );\r
223                 }\r
224         }\r
225         else\r
226         {\r
227                 /* ulLoopCounter changed, so the count of times this function was called\r
228                 without a change can be reset to zero. */\r
229                 xIterationsWithoutCounterIncrement = ( TickType_t ) 0;\r
230         }\r
231 \r
232         ulLastLoopCounter = ulLoopCounter;\r
233 \r
234         /* Errors detected in the task itself will have latched xTestStatus\r
235         to pdFAIL. */\r
236 \r
237         return xTestStatus;\r
238 }\r
239 /*-----------------------------------------------------------*/\r
240 \r
241 static void prvTest1_CreateTimersWithoutSchedulerRunning( void )\r
242 {\r
243 TickType_t xTimer;\r
244 \r
245         for( xTimer = 0; xTimer < configTIMER_QUEUE_LENGTH; xTimer++ )\r
246         {\r
247                 /* As the timer queue is not yet full, it should be possible to both\r
248                 create and start a timer.  These timers are being started before the\r
249                 scheduler has been started, so their block times should get set to zero\r
250                 within the timer API itself. */\r
251                 xAutoReloadTimers[ xTimer ] = xTimerCreate( "FR Timer",                                                 /* Text name to facilitate debugging.  The kernel does not use this itself. */\r
252                                                                                                         ( ( xTimer + ( TickType_t ) 1 ) * xBasePeriod ),/* The period for the timer.  The plus 1 ensures a period of zero is not specified. */\r
253                                                                                                         pdTRUE,                                                         /* Auto-reload is set to true. */\r
254                                                                                                         ( void * ) xTimer,                                      /* An identifier for the timer as all the auto reload timers use the same callback. */\r
255                                                                                                         prvAutoReloadTimerCallback );           /* The callback to be called when the timer expires. */\r
256 \r
257                 if( xAutoReloadTimers[ xTimer ] == NULL )\r
258                 {\r
259                         xTestStatus = pdFAIL;\r
260                         configASSERT( xTestStatus );\r
261                 }\r
262                 else\r
263                 {\r
264                         configASSERT( strcmp( pcTimerGetName( xAutoReloadTimers[ xTimer ] ), "FR Timer" ) == 0 );\r
265 \r
266                         /* The scheduler has not yet started, so the block period of\r
267                         portMAX_DELAY should just get set to zero in xTimerStart().  Also,\r
268                         the timer queue is not yet full so xTimerStart() should return\r
269                         pdPASS. */\r
270                         if( xTimerStart( xAutoReloadTimers[ xTimer ], portMAX_DELAY ) != pdPASS )\r
271                         {\r
272                                 xTestStatus = pdFAIL;\r
273                                 configASSERT( xTestStatus );\r
274                         }\r
275                 }\r
276         }\r
277 \r
278         /* The timers queue should now be full, so it should be possible to create\r
279         another timer, but not possible to start it (the timer queue will not get\r
280         drained until the scheduler has been started. */\r
281         xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] = xTimerCreate( "FR Timer",                                       /* Text name to facilitate debugging.  The kernel does not use this itself. */\r
282                                                                                                         ( configTIMER_QUEUE_LENGTH * xBasePeriod ),     /* The period for the timer. */\r
283                                                                                                         pdTRUE,                                                                         /* Auto-reload is set to true. */\r
284                                                                                                         ( void * ) xTimer,                                                      /* An identifier for the timer as all the auto reload timers use the same callback. */\r
285                                                                                                         prvAutoReloadTimerCallback );                           /* The callback executed when the timer expires. */\r
286 \r
287         if( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] == NULL )\r
288         {\r
289                 xTestStatus = pdFAIL;\r
290                 configASSERT( xTestStatus );\r
291         }\r
292         else\r
293         {\r
294                 if( xTimerStart( xAutoReloadTimers[ xTimer ], portMAX_DELAY ) == pdPASS )\r
295                 {\r
296                         /* This time it would not be expected that the timer could be\r
297                         started at this point. */\r
298                         xTestStatus = pdFAIL;\r
299                         configASSERT( xTestStatus );\r
300                 }\r
301         }\r
302 \r
303         /* Create the timers that are used from the tick interrupt to test the timer\r
304         API functions that can be called from an ISR. */\r
305         xISRAutoReloadTimer = xTimerCreate( "ISR AR",                                                   /* The text name given to the timer. */\r
306                                                                                 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
307                                                                                 pdTRUE,                                                         /* This is an auto reload timer. */\r
308                                                                                 ( void * ) NULL,                                        /* The identifier is not required. */\r
309                                                                                 prvISRAutoReloadTimerCallback );        /* The callback that is executed when the timer expires. */\r
310 \r
311         xISROneShotTimer = xTimerCreate(        "ISR OS",                                                       /* The text name given to the timer. */\r
312                                                                                 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
313                                                                                 pdFALSE,                                                        /* This is a one shot timer. */\r
314                                                                                 ( void * ) NULL,                                        /* The identifier is not required. */\r
315                                                                                 prvISROneShotTimerCallback );           /* The callback that is executed when the timer expires. */\r
316 \r
317         if( ( xISRAutoReloadTimer == NULL ) || ( xISROneShotTimer == NULL ) )\r
318         {\r
319                 xTestStatus = pdFAIL;\r
320                 configASSERT( xTestStatus );\r
321         }\r
322 }\r
323 /*-----------------------------------------------------------*/\r
324 \r
325 static void prvTest2_CheckTaskAndTimersInitialState( void )\r
326 {\r
327 uint8_t ucTimer;\r
328 \r
329         /* Ensure all the timers are in their expected initial state.  This     depends\r
330         on the timer service task having a higher priority than this task.\r
331 \r
332         auto reload timers 0 to ( configTIMER_QUEUE_LENGTH - 1 ) should now be active,\r
333         and auto reload timer configTIMER_QUEUE_LENGTH should not yet be active (it\r
334         could not be started prior to the scheduler being started when it was\r
335         created). */\r
336         for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
337         {\r
338                 if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )\r
339                 {\r
340                         xTestStatus = pdFAIL;\r
341                         configASSERT( xTestStatus );\r
342                 }\r
343         }\r
344 \r
345         if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] ) != pdFALSE )\r
346         {\r
347                 xTestStatus = pdFAIL;\r
348                 configASSERT( xTestStatus );\r
349         }\r
350 }\r
351 /*-----------------------------------------------------------*/\r
352 \r
353 static void     prvTest3_CheckAutoReloadExpireRates( void )\r
354 {\r
355 uint8_t ucMaxAllowableValue, ucMinAllowableValue, ucTimer;\r
356 TickType_t xBlockPeriod, xTimerPeriod, xExpectedNumber;\r
357 UBaseType_t uxOriginalPriority;\r
358 \r
359         /* Check the auto reload timers expire at the expected rates.  Do this at a\r
360         high priority for maximum accuracy.  This is ok as most of the time is spent\r
361         in the Blocked state. */\r
362         uxOriginalPriority = uxTaskPriorityGet( NULL );\r
363         vTaskPrioritySet( NULL, ( configMAX_PRIORITIES - 1 ) );\r
364 \r
365         /* Delaying for configTIMER_QUEUE_LENGTH * xBasePeriod ticks should allow\r
366         all the auto reload timers to expire at least once. */\r
367         xBlockPeriod = ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;\r
368         vTaskDelay( xBlockPeriod );\r
369 \r
370         /* Check that all the auto reload timers have called their callback\r
371         function the expected number of times. */\r
372         for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
373         {\r
374                 /* The expected number of expiries is equal to the block period divided\r
375                 by the timer period. */\r
376                 xTimerPeriod = ( ( ( TickType_t ) ucTimer + ( TickType_t ) 1 ) * xBasePeriod );\r
377                 xExpectedNumber = xBlockPeriod / xTimerPeriod;\r
378 \r
379                 ucMaxAllowableValue = ( ( uint8_t ) xExpectedNumber ) ;\r
380                 ucMinAllowableValue = ( uint8_t ) ( ( uint8_t ) xExpectedNumber - ( uint8_t ) 1 ); /* Weird casting to try and please all compilers. */\r
381 \r
382                 if( ( ucAutoReloadTimerCounters[ ucTimer ] < ucMinAllowableValue ) ||\r
383                         ( ucAutoReloadTimerCounters[ ucTimer ] > ucMaxAllowableValue )\r
384                         )\r
385                 {\r
386                         xTestStatus = pdFAIL;\r
387                         configASSERT( xTestStatus );\r
388                 }\r
389         }\r
390 \r
391         /* Return to the original priority. */\r
392         vTaskPrioritySet( NULL, uxOriginalPriority );\r
393 \r
394         if( xTestStatus == pdPASS )\r
395         {\r
396                 /* No errors have been reported so increment the loop counter so the\r
397                 check task knows this task is still running. */\r
398                 ulLoopCounter++;\r
399         }\r
400 }\r
401 /*-----------------------------------------------------------*/\r
402 \r
403 static void prvTest4_CheckAutoReloadTimersCanBeStopped( void )\r
404 {\r
405 uint8_t ucTimer;\r
406 \r
407         /* Check the auto reload timers can be stopped correctly, and correctly\r
408         report their state. */\r
409 \r
410         /* Stop all the active timers. */\r
411         for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
412         {\r
413                 /* The timer has not been stopped yet! */\r
414                 if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )\r
415                 {\r
416                         xTestStatus = pdFAIL;\r
417                         configASSERT( xTestStatus );\r
418                 }\r
419 \r
420                 /* Now stop the timer.  This will appear to happen immediately to\r
421                 this task because this task is running at a priority below the\r
422                 timer service task. */\r
423                 xTimerStop( xAutoReloadTimers[ ucTimer ], tmrdemoDONT_BLOCK );\r
424 \r
425                 /* The timer should now be inactive. */\r
426                 if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) != pdFALSE )\r
427                 {\r
428                         xTestStatus = pdFAIL;\r
429                         configASSERT( xTestStatus );\r
430                 }\r
431         }\r
432 \r
433         taskENTER_CRITICAL();\r
434         {\r
435                 /* The timer in array position configTIMER_QUEUE_LENGTH should not\r
436                 be active.  The critical section is used to ensure the timer does\r
437                 not call its callback between the next line running and the array\r
438                 being cleared back to zero, as that would mask an error condition. */\r
439                 if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH ] != ( uint8_t ) 0 )\r
440                 {\r
441                         xTestStatus = pdFAIL;\r
442                         configASSERT( xTestStatus );\r
443                 }\r
444 \r
445                 /* Clear the timer callback count. */\r
446                 memset( ( void * ) ucAutoReloadTimerCounters, 0, sizeof( ucAutoReloadTimerCounters ) );\r
447         }\r
448         taskEXIT_CRITICAL();\r
449 \r
450         /* The timers are now all inactive, so this time, after delaying, none\r
451         of the callback counters should have incremented. */\r
452         vTaskDelay( ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod );\r
453         for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
454         {\r
455                 if( ucAutoReloadTimerCounters[ ucTimer ] != ( uint8_t ) 0 )\r
456                 {\r
457                         xTestStatus = pdFAIL;\r
458                         configASSERT( xTestStatus );\r
459                 }\r
460         }\r
461 \r
462         if( xTestStatus == pdPASS )\r
463         {\r
464                 /* No errors have been reported so increment the loop counter so\r
465                 the check task knows this task is still running. */\r
466                 ulLoopCounter++;\r
467         }\r
468 }\r
469 /*-----------------------------------------------------------*/\r
470 \r
471 static void prvTest5_CheckBasicOneShotTimerBehaviour( void )\r
472 {\r
473         /* Check the one shot timer only calls its callback once after it has been\r
474         started, and that it reports its state correctly. */\r
475 \r
476         /* The one shot timer should not be active yet. */\r
477         if( xTimerIsTimerActive( xOneShotTimer ) != pdFALSE )\r
478         {\r
479                 xTestStatus = pdFAIL;\r
480                 configASSERT( xTestStatus );\r
481         }\r
482 \r
483         if( ucOneShotTimerCounter != ( uint8_t ) 0 )\r
484         {\r
485                 xTestStatus = pdFAIL;\r
486                 configASSERT( xTestStatus );\r
487         }\r
488 \r
489         /* Start the one shot timer and check that it reports its state correctly. */\r
490         xTimerStart( xOneShotTimer, tmrdemoDONT_BLOCK );\r
491         if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )\r
492         {\r
493                 xTestStatus = pdFAIL;\r
494                 configASSERT( xTestStatus );\r
495         }\r
496 \r
497         /* Delay for three times as long as the one shot timer period, then check\r
498         to ensure it has only called its callback once, and is now not in the\r
499         active state. */\r
500         vTaskDelay( tmrdemoONE_SHOT_TIMER_PERIOD * ( TickType_t ) 3 );\r
501 \r
502         if( xTimerIsTimerActive( xOneShotTimer ) != pdFALSE )\r
503         {\r
504                 xTestStatus = pdFAIL;\r
505                 configASSERT( xTestStatus );\r
506         }\r
507 \r
508         if( ucOneShotTimerCounter != ( uint8_t ) 1 )\r
509         {\r
510                 xTestStatus = pdFAIL;\r
511                 configASSERT( xTestStatus );\r
512         }\r
513         else\r
514         {\r
515                 /* Reset the one shot timer callback count. */\r
516                 ucOneShotTimerCounter = ( uint8_t ) 0;\r
517         }\r
518 \r
519         if( xTestStatus == pdPASS )\r
520         {\r
521                 /* No errors have been reported so increment the loop counter so the\r
522                 check task knows this task is still running. */\r
523                 ulLoopCounter++;\r
524         }\r
525 }\r
526 /*-----------------------------------------------------------*/\r
527 \r
528 static void prvTest6_CheckAutoReloadResetBehaviour( void )\r
529 {\r
530 uint8_t ucTimer;\r
531 \r
532         /* Check timer reset behaviour. */\r
533 \r
534         /* Restart the one shot timer and check it reports its status correctly. */\r
535         xTimerStart( xOneShotTimer, tmrdemoDONT_BLOCK );\r
536         if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )\r
537         {\r
538                 xTestStatus = pdFAIL;\r
539                 configASSERT( xTestStatus );\r
540         }\r
541 \r
542         /* Restart one of the auto reload timers and check that it reports its\r
543         status correctly. */\r
544         xTimerStart( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ], tmrdemoDONT_BLOCK );\r
545         if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )\r
546         {\r
547                 xTestStatus = pdFAIL;\r
548                 configASSERT( xTestStatus );\r
549         }\r
550 \r
551         for( ucTimer = 0; ucTimer < trmdemoNUM_TIMER_RESETS; ucTimer++ )\r
552         {\r
553                 /* Delay for half as long as the one shot timer period, then reset it.\r
554                 It should never expire while this is done, so its callback count should\r
555                 never increment. */\r
556                 vTaskDelay( tmrdemoONE_SHOT_TIMER_PERIOD / 2 );\r
557 \r
558                 /* Check both running timers are still active, but have not called their\r
559                 callback functions. */\r
560                 if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )\r
561                 {\r
562                         xTestStatus = pdFAIL;\r
563                         configASSERT( xTestStatus );\r
564                 }\r
565 \r
566                 if( ucOneShotTimerCounter != ( uint8_t ) 0 )\r
567                 {\r
568                         xTestStatus = pdFAIL;\r
569                         configASSERT( xTestStatus );\r
570                 }\r
571 \r
572                 if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )\r
573                 {\r
574                         xTestStatus = pdFAIL;\r
575                         configASSERT( xTestStatus );\r
576                 }\r
577 \r
578                 if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] != ( uint8_t ) 0 )\r
579                 {\r
580                         xTestStatus = pdFAIL;\r
581                         configASSERT( xTestStatus );\r
582                 }\r
583 \r
584                 /* Reset both running timers. */\r
585                 xTimerReset( xOneShotTimer, tmrdemoDONT_BLOCK );\r
586                 xTimerReset( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ], tmrdemoDONT_BLOCK );\r
587 \r
588                 if( xTestStatus == pdPASS )\r
589                 {\r
590                         /* No errors have been reported so increment the loop counter so\r
591                         the check task knows this task is still running. */\r
592                         ulLoopCounter++;\r
593                 }\r
594         }\r
595 \r
596         /* Finally delay long enough for both running timers to expire. */\r
597         vTaskDelay( ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod );\r
598 \r
599         /* The timers were not reset during the above delay period so should now\r
600         both have called their callback functions. */\r
601         if( ucOneShotTimerCounter != ( uint8_t ) 1 )\r
602         {\r
603                 xTestStatus = pdFAIL;\r
604                 configASSERT( xTestStatus );\r
605         }\r
606 \r
607         if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] == 0 )\r
608         {\r
609                 xTestStatus = pdFAIL;\r
610                 configASSERT( xTestStatus );\r
611         }\r
612 \r
613         /* The one shot timer should no longer be active, while the auto reload\r
614         timer should still be active. */\r
615         if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )\r
616         {\r
617                 xTestStatus = pdFAIL;\r
618                 configASSERT( xTestStatus );\r
619         }\r
620 \r
621         if( xTimerIsTimerActive( xOneShotTimer ) == pdTRUE )\r
622         {\r
623                 xTestStatus = pdFAIL;\r
624                 configASSERT( xTestStatus );\r
625         }\r
626 \r
627         /* Stop the auto reload timer again. */\r
628         xTimerStop( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ], tmrdemoDONT_BLOCK );\r
629 \r
630         if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) != pdFALSE )\r
631         {\r
632                 xTestStatus = pdFAIL;\r
633                 configASSERT( xTestStatus );\r
634         }\r
635 \r
636         /* Clear the timer callback counts, ready for another iteration of these\r
637         tests. */\r
638         ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] = ( uint8_t ) 0;\r
639         ucOneShotTimerCounter = ( uint8_t ) 0;\r
640 \r
641         if( xTestStatus == pdPASS )\r
642         {\r
643                 /* No errors have been reported so increment the loop counter so the check\r
644                 task knows this task is still running. */\r
645                 ulLoopCounter++;\r
646         }\r
647 }\r
648 /*-----------------------------------------------------------*/\r
649 \r
650 static void prvResetStartConditionsForNextIteration( void )\r
651 {\r
652 uint8_t ucTimer;\r
653 \r
654         /* Start the timers again to start all the tests over again. */\r
655 \r
656         /* Start the timers again. */\r
657         for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )\r
658         {\r
659                 /* The timer has not been started yet! */\r
660                 if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) != pdFALSE )\r
661                 {\r
662                         xTestStatus = pdFAIL;\r
663                         configASSERT( xTestStatus );\r
664                 }\r
665 \r
666                 /* Now start the timer.  This will appear to happen immediately to\r
667                 this task because this task is running at a priority below the timer\r
668                 service task. */\r
669                 xTimerStart( xAutoReloadTimers[ ucTimer ], tmrdemoDONT_BLOCK );\r
670 \r
671                 /* The timer should now be active. */\r
672                 if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )\r
673                 {\r
674                         xTestStatus = pdFAIL;\r
675                         configASSERT( xTestStatus );\r
676                 }\r
677         }\r
678 \r
679         if( xTestStatus == pdPASS )\r
680         {\r
681                 /* No errors have been reported so increment the loop counter so the\r
682                 check task knows this task is still running. */\r
683                 ulLoopCounter++;\r
684         }\r
685 }\r
686 /*-----------------------------------------------------------*/\r
687 \r
688 void vTimerPeriodicISRTests( void )\r
689 {\r
690 static TickType_t uxTick = ( TickType_t ) -1;\r
691 \r
692 #if( configTIMER_TASK_PRIORITY != ( configMAX_PRIORITIES - 1 ) )\r
693         /* The timer service task is not the highest priority task, so it cannot\r
694         be assumed that timings will be exact.  Timers should never call their\r
695         callback before their expiry time, but a margin is permissible for calling\r
696         their callback after their expiry time.  If exact timing is required then\r
697         configTIMER_TASK_PRIORITY must be set to ensure the timer service task\r
698         is the highest priority task in the system.\r
699 \r
700         This function is called from the tick hook.  The tick hook is called\r
701         even when the scheduler is suspended.  Therefore it is possible that the\r
702         uxTick count maintained in this function is temporarily ahead of the tick\r
703         count maintained by the kernel.  When this is the case a message posted from\r
704         this function will assume a time stamp in advance of the real time stamp,\r
705         which can result in a timer being processed before this function expects it\r
706         to.  For example, if the kernel's tick count was 100, and uxTick was 102,\r
707         then this function will not expect the timer to have expired until the\r
708         kernel's tick count is (102 + xBasePeriod), whereas in reality the timer\r
709         will expire when the kernel's tick count is (100 + xBasePeriod).  For this\r
710         reason xMargin is used as an allowable margin for premature timer expiries\r
711         as well as late timer expiries. */\r
712         #ifdef _WINDOWS_\r
713                 /* Windows is not real real time. */\r
714                 const TickType_t xMargin = 20;\r
715         #else\r
716                 const TickType_t xMargin = 6;\r
717         #endif /* _WINDOWS_ */\r
718 #else\r
719         #ifdef _WINDOWS_\r
720                 /* Windows is not real real time. */\r
721                 const TickType_t xMargin = 20;\r
722         #else\r
723                 const TickType_t xMargin = 4;\r
724         #endif /* _WINDOWS_ */\r
725 #endif\r
726 \r
727 \r
728         uxTick++;\r
729 \r
730         if( uxTick == 0 )\r
731         {\r
732                 /* The timers will have been created, but not started.  Start them now\r
733                 by setting their period. */\r
734                 ucISRAutoReloadTimerCounter = 0;\r
735                 ucISROneShotTimerCounter = 0;\r
736 \r
737                 /* It is possible that the timer task has not yet made room in the\r
738                 timer queue.  If the timers cannot be started then reset uxTick so\r
739                 another attempt is made later. */\r
740                 uxTick = ( TickType_t ) -1;\r
741 \r
742                 /* Try starting first timer. */\r
743                 if( xTimerChangePeriodFromISR( xISRAutoReloadTimer, xBasePeriod, NULL ) == pdPASS )\r
744                 {\r
745                         /* First timer was started, try starting the second timer. */\r
746                         if( xTimerChangePeriodFromISR( xISROneShotTimer, xBasePeriod, NULL ) == pdPASS )\r
747                         {\r
748                                 /* Both timers were started, so set the uxTick back to its\r
749                                 proper value. */\r
750                                 uxTick = 0;\r
751                         }\r
752                         else\r
753                         {\r
754                                 /* Second timer could not be started, so stop the first one\r
755                                 again. */\r
756                                 xTimerStopFromISR( xISRAutoReloadTimer, NULL );\r
757                         }\r
758                 }\r
759         }\r
760         else if( uxTick == ( xBasePeriod - xMargin ) )\r
761         {\r
762                 /* Neither timer should have expired yet. */\r
763                 if( ( ucISRAutoReloadTimerCounter != 0 ) || ( ucISROneShotTimerCounter != 0 ) )\r
764                 {\r
765                         xTestStatus = pdFAIL;\r
766                         configASSERT( xTestStatus );\r
767                 }\r
768         }\r
769         else if( uxTick == ( xBasePeriod + xMargin ) )\r
770         {\r
771                 /* Both timers should now have expired once.  The auto reload timer will\r
772                 still be active, but the one shot timer should now have stopped. */\r
773                 if( ( ucISRAutoReloadTimerCounter != 1 ) || ( ucISROneShotTimerCounter != 1 ) )\r
774                 {\r
775                         xTestStatus = pdFAIL;\r
776                         configASSERT( xTestStatus );\r
777                 }\r
778         }\r
779         else if( uxTick == ( ( 2 * xBasePeriod ) - xMargin ) )\r
780         {\r
781                 /* The auto reload timer will still be active, but the one shot timer\r
782                 should now have stopped - however, at this time neither of the timers\r
783                 should have expired again since the last test. */\r
784                 if( ( ucISRAutoReloadTimerCounter != 1 ) || ( ucISROneShotTimerCounter != 1 ) )\r
785                 {\r
786                         xTestStatus = pdFAIL;\r
787                         configASSERT( xTestStatus );\r
788                 }\r
789         }\r
790         else if( uxTick == ( ( 2 * xBasePeriod ) + xMargin ) )\r
791         {\r
792                 /* The auto reload timer will still be active, but the one shot timer\r
793                 should now have stopped.  At this time the auto reload timer should have\r
794                 expired again, but the one shot timer count should not have changed. */\r
795                 if( ucISRAutoReloadTimerCounter != 2 )\r
796                 {\r
797                         xTestStatus = pdFAIL;\r
798                         configASSERT( xTestStatus );\r
799                 }\r
800 \r
801                 if( ucISROneShotTimerCounter != 1 )\r
802                 {\r
803                         xTestStatus = pdFAIL;\r
804                         configASSERT( xTestStatus );\r
805                 }\r
806         }\r
807         else if( uxTick == ( ( 2 * xBasePeriod ) + ( xBasePeriod >> ( TickType_t ) 2U ) ) )\r
808         {\r
809                 /* The auto reload timer will still be active, but the one shot timer\r
810                 should now have stopped.  Again though, at this time, neither timer call\r
811                 back should have been called since the last test. */\r
812                 if( ucISRAutoReloadTimerCounter != 2 )\r
813                 {\r
814                         xTestStatus = pdFAIL;\r
815                         configASSERT( xTestStatus );\r
816                 }\r
817 \r
818                 if( ucISROneShotTimerCounter != 1 )\r
819                 {\r
820                         xTestStatus = pdFAIL;\r
821                         configASSERT( xTestStatus );\r
822                 }\r
823         }\r
824         else if( uxTick == ( 3 * xBasePeriod ) )\r
825         {\r
826                 /* Start the one shot timer again. */\r
827                 xTimerStartFromISR( xISROneShotTimer, NULL );\r
828         }\r
829         else if( uxTick == ( ( 3 * xBasePeriod ) + xMargin ) )\r
830         {\r
831                 /* The auto reload timer and one shot timer will be active.  At\r
832                 this time the auto reload timer should have     expired again, but the one\r
833                 shot timer count should not have changed yet. */\r
834                 if( ucISRAutoReloadTimerCounter != 3 )\r
835                 {\r
836                         xTestStatus = pdFAIL;\r
837                         configASSERT( xTestStatus );\r
838                 }\r
839 \r
840                 if( ucISROneShotTimerCounter != 1 )\r
841                 {\r
842                         xTestStatus = pdFAIL;\r
843                         configASSERT( xTestStatus );\r
844                 }\r
845 \r
846                 /* Now stop the auto reload timer.  The one shot timer was started\r
847                 a few ticks ago. */\r
848                 xTimerStopFromISR( xISRAutoReloadTimer, NULL );\r
849         }\r
850         else if( uxTick == ( 4 * ( xBasePeriod - xMargin ) ) )\r
851         {\r
852                 /* The auto reload timer is now stopped, and the one shot timer is\r
853                 active, but at this time neither timer should have expired since the\r
854                 last test. */\r
855                 if( ucISRAutoReloadTimerCounter != 3 )\r
856                 {\r
857                         xTestStatus = pdFAIL;\r
858                         configASSERT( xTestStatus );\r
859                 }\r
860 \r
861                 if( ucISROneShotTimerCounter != 1 )\r
862                 {\r
863                         xTestStatus = pdFAIL;\r
864                         configASSERT( xTestStatus );\r
865                 }\r
866         }\r
867         else if( uxTick == ( ( 4 * xBasePeriod ) + xMargin ) )\r
868         {\r
869                 /* The auto reload timer is now stopped, and the one shot timer is\r
870                 active.  The one shot timer should have expired again, but the auto\r
871                 reload timer should not have executed its callback. */\r
872                 if( ucISRAutoReloadTimerCounter != 3 )\r
873                 {\r
874                         xTestStatus = pdFAIL;\r
875                         configASSERT( xTestStatus );\r
876                 }\r
877 \r
878                 if( ucISROneShotTimerCounter != 2 )\r
879                 {\r
880                         xTestStatus = pdFAIL;\r
881                         configASSERT( xTestStatus );\r
882                 }\r
883         }\r
884         else if( uxTick == ( 8 * xBasePeriod ) )\r
885         {\r
886                 /* The auto reload timer is now stopped, and the one shot timer has\r
887                 already expired and then stopped itself.  Both callback counters should\r
888                 not have incremented since the last test. */\r
889                 if( ucISRAutoReloadTimerCounter != 3 )\r
890                 {\r
891                         xTestStatus = pdFAIL;\r
892                         configASSERT( xTestStatus );\r
893                 }\r
894 \r
895                 if( ucISROneShotTimerCounter != 2 )\r
896                 {\r
897                         xTestStatus = pdFAIL;\r
898                         configASSERT( xTestStatus );\r
899                 }\r
900 \r
901                 /* Now reset the one shot timer. */\r
902                 xTimerResetFromISR( xISROneShotTimer, NULL );\r
903         }\r
904         else if( uxTick == ( ( 9 * xBasePeriod ) - xMargin ) )\r
905         {\r
906                 /* Only the one shot timer should be running, but it should not have\r
907                 expired since the last test.  Check the callback counters have not\r
908                 incremented, then reset the one shot timer again. */\r
909                 if( ucISRAutoReloadTimerCounter != 3 )\r
910                 {\r
911                         xTestStatus = pdFAIL;\r
912                         configASSERT( xTestStatus );\r
913                 }\r
914 \r
915                 if( ucISROneShotTimerCounter != 2 )\r
916                 {\r
917                         xTestStatus = pdFAIL;\r
918                         configASSERT( xTestStatus );\r
919                 }\r
920 \r
921                 xTimerResetFromISR( xISROneShotTimer, NULL );\r
922         }\r
923         else if( uxTick == ( ( 10 * xBasePeriod ) - ( 2 * xMargin ) ) )\r
924         {\r
925                 /* Only the one shot timer should be running, but it should not have\r
926                 expired since the last test.  Check the callback counters have not\r
927                 incremented, then reset the one shot timer again. */\r
928                 if( ucISRAutoReloadTimerCounter != 3 )\r
929                 {\r
930                         xTestStatus = pdFAIL;\r
931                         configASSERT( xTestStatus );\r
932                 }\r
933 \r
934                 if( ucISROneShotTimerCounter != 2 )\r
935                 {\r
936                         xTestStatus = pdFAIL;\r
937                         configASSERT( xTestStatus );\r
938                 }\r
939 \r
940                 xTimerResetFromISR( xISROneShotTimer, NULL );\r
941         }\r
942         else if( uxTick == ( ( 11 * xBasePeriod ) - ( 3 * xMargin ) ) )\r
943         {\r
944                 /* Only the one shot timer should be running, but it should not have\r
945                 expired since the last test.  Check the callback counters have not\r
946                 incremented, then reset the one shot timer once again. */\r
947                 if( ucISRAutoReloadTimerCounter != 3 )\r
948                 {\r
949                         xTestStatus = pdFAIL;\r
950                         configASSERT( xTestStatus );\r
951                 }\r
952 \r
953                 if( ucISROneShotTimerCounter != 2 )\r
954                 {\r
955                         xTestStatus = pdFAIL;\r
956                         configASSERT( xTestStatus );\r
957                 }\r
958 \r
959                 xTimerResetFromISR( xISROneShotTimer, NULL );\r
960         }\r
961         else if( uxTick == ( ( 12 * xBasePeriod ) - ( 2 * xMargin ) ) )\r
962         {\r
963                 /* Only the one shot timer should have been running and this time it\r
964                 should have     expired.  Check its callback count has been incremented.\r
965                 The auto reload timer is still not running so should still have the same\r
966                 count value.  This time the one shot timer is not reset so should not\r
967                 restart from its expiry period again. */\r
968                 if( ucISRAutoReloadTimerCounter != 3 )\r
969                 {\r
970                         xTestStatus = pdFAIL;\r
971                         configASSERT( xTestStatus );\r
972                 }\r
973 \r
974                 if( ucISROneShotTimerCounter != 3 )\r
975                 {\r
976                         xTestStatus = pdFAIL;\r
977                         configASSERT( xTestStatus );\r
978                 }\r
979         }\r
980         else if( uxTick == ( 15 * xBasePeriod ) )\r
981         {\r
982                 /* Neither timer should be running now.  Check neither callback count\r
983                 has incremented, then go back to the start to run these tests all\r
984                 over again. */\r
985                 if( ucISRAutoReloadTimerCounter != 3 )\r
986                 {\r
987                         xTestStatus = pdFAIL;\r
988                         configASSERT( xTestStatus );\r
989                 }\r
990 \r
991                 if( ucISROneShotTimerCounter != 3 )\r
992                 {\r
993                         xTestStatus = pdFAIL;\r
994                         configASSERT( xTestStatus );\r
995                 }\r
996 \r
997                 uxTick = ( TickType_t ) -1;\r
998         }\r
999 }\r
1000 /*-----------------------------------------------------------*/\r
1001 \r
1002 /*** Timer callback functions are defined below here. ***/\r
1003 \r
1004 static void prvAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer )\r
1005 {\r
1006 size_t uxTimerID;\r
1007 \r
1008         uxTimerID = ( size_t ) pvTimerGetTimerID( pxExpiredTimer );\r
1009         if( uxTimerID <= ( configTIMER_QUEUE_LENGTH + 1 ) )\r
1010         {\r
1011                 ( ucAutoReloadTimerCounters[ uxTimerID ] )++;\r
1012         }\r
1013         else\r
1014         {\r
1015                 /* The timer ID appears to be unexpected (invalid). */\r
1016                 xTestStatus = pdFAIL;\r
1017                 configASSERT( xTestStatus );\r
1018         }\r
1019 }\r
1020 /*-----------------------------------------------------------*/\r
1021 \r
1022 static void prvOneShotTimerCallback( TimerHandle_t pxExpiredTimer )\r
1023 {\r
1024 /* A count is kept of the number of times this callback function is executed.\r
1025 The count is stored as the timer's ID.  This is only done to test the\r
1026 vTimerSetTimerID() function. */\r
1027 static size_t uxCallCount = 0;\r
1028 size_t uxLastCallCount;\r
1029 \r
1030         /* Obtain the timer's ID, which should be a count of the number of times\r
1031         this callback function has been executed. */\r
1032         uxLastCallCount = ( size_t ) pvTimerGetTimerID( pxExpiredTimer );\r
1033         configASSERT( uxLastCallCount == uxCallCount );\r
1034 \r
1035         /* Increment the call count, then save it back as the timer's ID.  This is\r
1036         only done to test the vTimerSetTimerID() API function. */\r
1037         uxLastCallCount++;\r
1038         vTimerSetTimerID( pxExpiredTimer, ( void * ) uxLastCallCount );\r
1039         uxCallCount++;\r
1040 \r
1041         ucOneShotTimerCounter++;\r
1042 }\r
1043 /*-----------------------------------------------------------*/\r
1044 \r
1045 static void prvISRAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer )\r
1046 {\r
1047         /* The parameter is not used in this case as only one timer uses this\r
1048         callback function. */\r
1049         ( void ) pxExpiredTimer;\r
1050 \r
1051         ucISRAutoReloadTimerCounter++;\r
1052 }\r
1053 /*-----------------------------------------------------------*/\r
1054 \r
1055 static void prvISROneShotTimerCallback( TimerHandle_t pxExpiredTimer )\r
1056 {\r
1057         /* The parameter is not used in this case as only one timer uses this\r
1058         callback function. */\r
1059         ( void ) pxExpiredTimer;\r
1060 \r
1061         ucISROneShotTimerCounter++;\r
1062 }\r
1063 /*-----------------------------------------------------------*/\r
1064 \r
1065 \r
1066 \r
1067 \r