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