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