2 FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
77 * Tests the behaviour of timers. Some timers are created before the scheduler
\r
78 * is started, and some after.
\r
81 /* Standard includes. */
\r
84 /* Scheduler include files. */
\r
85 #include "FreeRTOS.h"
\r
89 /* Demo program include files. */
\r
90 #include "TimerDemo.h"
\r
92 #if ( configTIMER_TASK_PRIORITY < 1 )
\r
93 #error configTIMER_TASK_PRIORITY must be set to at least 1 for this test/demo to function correctly.
\r
96 #define tmrdemoDONT_BLOCK ( ( portTickType ) 0 )
\r
97 #define tmrdemoONE_SHOT_TIMER_PERIOD ( xBasePeriod * ( portTickType ) 3 )
\r
98 #define trmdemoNUM_TIMER_RESETS ( ( unsigned char ) 10 )
\r
100 /*-----------------------------------------------------------*/
\r
102 /* The callback functions used by the timers. These each increment a counter
\r
103 to indicate which timer has expired. The auto-reload timers that are used by
\r
104 the test task (as opposed to being used from an ISR) all share the same
\r
105 prvAutoReloadTimerCallback() callback function, and use the ID of the
\r
106 pxExpiredTimer parameter passed into that function to know which counter to
\r
107 increment. The other timers all have their own unique callback function and
\r
108 simply increment their counters without using the callback function parameter. */
\r
109 static void prvAutoReloadTimerCallback( xTimerHandle pxExpiredTimer );
\r
110 static void prvOneShotTimerCallback( xTimerHandle pxExpiredTimer );
\r
111 static void prvTimerTestTask( void *pvParameters );
\r
112 static void prvISRAutoReloadTimerCallback( xTimerHandle pxExpiredTimer );
\r
113 static void prvISROneShotTimerCallback( xTimerHandle pxExpiredTimer );
\r
115 /* The test functions used by the timer test task. These manipulate the auto
\r
116 reload and one shot timers in various ways, then delay, then inspect the timers
\r
117 to ensure they have behaved as expected. */
\r
118 static void prvTest1_CreateTimersWithoutSchedulerRunning( void );
\r
119 static void prvTest2_CheckTaskAndTimersInitialState( void );
\r
120 static void prvTest3_CheckAutoReloadExpireRates( void );
\r
121 static void prvTest4_CheckAutoReloadTimersCanBeStopped( void );
\r
122 static void prvTest5_CheckBasicOneShotTimerBehaviour( void );
\r
123 static void prvTest6_CheckAutoReloadResetBehaviour( void );
\r
124 static void prvResetStartConditionsForNextIteration( void );
\r
126 /*-----------------------------------------------------------*/
\r
128 /* Flag that will be latched to pdFAIL should any unexpected behaviour be
\r
129 detected in any of the demo tests. */
\r
130 static volatile portBASE_TYPE xTestStatus = pdPASS;
\r
132 /* Counter that is incremented on each cycle of a test. This is used to
\r
133 detect a stalled task - a test that is no longer running. */
\r
134 static volatile unsigned long ulLoopCounter = 0;
\r
136 /* A set of auto reload timers - each of which use the same callback function.
\r
137 The callback function uses the timer ID to index into, and then increment, a
\r
138 counter in the ucAutoReloadTimerCounters[] array. The auto reload timers
\r
139 referenced from xAutoReloadTimers[] are used by the prvTimerTestTask task. */
\r
140 static xTimerHandle xAutoReloadTimers[ configTIMER_QUEUE_LENGTH + 1 ] = { 0 };
\r
141 static unsigned char ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH + 1 ] = { 0 };
\r
143 /* The one shot timer is configured to use a callback function that increments
\r
144 ucOneShotTimerCounter each time it gets called. */
\r
145 static xTimerHandle xOneShotTimer = NULL;
\r
146 static unsigned char ucOneShotTimerCounter = ( unsigned char ) 0;
\r
148 /* The ISR reload timer is controlled from the tick hook to exercise the timer
\r
149 API functions that can be used from an ISR. It is configured to increment
\r
150 ucISRReloadTimerCounter each time its callback function is executed. */
\r
151 static xTimerHandle xISRAutoReloadTimer = NULL;
\r
152 static unsigned char ucISRAutoReloadTimerCounter = ( unsigned char ) 0;
\r
154 /* The ISR one shot timer is controlled from the tick hook to exercise the timer
\r
155 API functions that can be used from an ISR. It is configured to increment
\r
156 ucISRReloadTimerCounter each time its callback function is executed. */
\r
157 static xTimerHandle xISROneShotTimer = NULL;
\r
158 static unsigned char ucISROneShotTimerCounter = ( unsigned char ) 0;
\r
160 /* The period of all the timers are a multiple of the base period. The base
\r
161 period is configured by the parameter to vStartTimerDemoTask(). */
\r
162 static portTickType xBasePeriod = 0;
\r
164 /*-----------------------------------------------------------*/
\r
166 void vStartTimerDemoTask( portTickType xBasePeriodIn )
\r
168 /* Start with the timer and counter arrays clear - this is only necessary
\r
169 where the compiler does not clear them automatically on start up. */
\r
170 memset( ucAutoReloadTimerCounters, 0x00, sizeof( ucAutoReloadTimerCounters ) );
\r
171 memset( xAutoReloadTimers, 0x00, sizeof( xAutoReloadTimers ) );
\r
173 /* Store the period from which all the timer periods will be generated from
\r
175 xBasePeriod = xBasePeriodIn;
\r
177 /* Create a set of timers for use by this demo/test. */
\r
178 prvTest1_CreateTimersWithoutSchedulerRunning();
\r
180 /* Create the task that will control and monitor the timers. This is
\r
181 created at a lower priority than the timer service task to ensure, as
\r
182 far as it is concerned, commands on timers are actioned immediately
\r
183 (sending a command to the timer service task will unblock the timer service
\r
184 task, which will then preempt this task). */
\r
185 if( xTestStatus != pdFAIL )
\r
187 xTaskCreate( prvTimerTestTask, ( signed portCHAR * ) "Tmr Tst", configMINIMAL_STACK_SIZE, NULL, configTIMER_TASK_PRIORITY - 1, NULL );
\r
190 /*-----------------------------------------------------------*/
\r
192 static void prvTimerTestTask( void *pvParameters )
\r
194 ( void ) pvParameters;
\r
196 /* Create a one-shot timer for use later on in this test. */
\r
197 xOneShotTimer = xTimerCreate( ( const signed char * ) "Oneshot Timer",/* Text name to facilitate debugging. The kernel does not use this itself. */
\r
198 tmrdemoONE_SHOT_TIMER_PERIOD, /* The period for the timer. */
\r
199 pdFALSE, /* Don't auto-reload - hence a one shot timer. */
\r
200 ( void * ) 0, /* The timer identifier. In this case this is not used as the timer has its own callback. */
\r
201 prvOneShotTimerCallback ); /* The callback to be called when the timer expires. */
\r
203 if( xOneShotTimer == NULL )
\r
205 xTestStatus = pdFAIL;
\r
206 configASSERT( xTestStatus );
\r
210 /* Ensure all the timers are in their expected initial state. This
\r
211 depends on the timer service task having a higher priority than this task. */
\r
212 prvTest2_CheckTaskAndTimersInitialState();
\r
216 /* Check the auto reload timers expire at the expected/correct rates. */
\r
217 prvTest3_CheckAutoReloadExpireRates();
\r
219 /* Check the auto reload timers can be stopped correctly, and correctly
\r
220 report their state. */
\r
221 prvTest4_CheckAutoReloadTimersCanBeStopped();
\r
223 /* Check the one shot timer only calls its callback once after it has been
\r
224 started, and that it reports its state correctly. */
\r
225 prvTest5_CheckBasicOneShotTimerBehaviour();
\r
227 /* Check timer reset behaviour. */
\r
228 prvTest6_CheckAutoReloadResetBehaviour();
\r
230 /* Start the timers again to restart all the tests over again. */
\r
231 prvResetStartConditionsForNextIteration();
\r
234 /*-----------------------------------------------------------*/
\r
236 /* This is called to check that the created task is still running and has not
\r
237 detected any errors. */
\r
238 portBASE_TYPE xAreTimerDemoTasksStillRunning( portTickType xCycleFrequency )
\r
240 static unsigned long ulLastLoopCounter = 0UL;
\r
241 portTickType xMaxBlockTimeUsedByTheseTests, xLoopCounterIncrementTimeMax;
\r
242 static portTickType xIterationsWithoutCounterIncrement = ( portTickType ) 0, xLastCycleFrequency;
\r
244 if( xLastCycleFrequency != xCycleFrequency )
\r
246 /* The cycle frequency has probably become much faster due to an error
\r
247 elsewhere. Start counting Iterations again. */
\r
248 xIterationsWithoutCounterIncrement = ( portTickType ) 0;
\r
249 xLastCycleFrequency = xCycleFrequency;
\r
252 /* Calculate the maximum number of times that it is permissible for this
\r
253 function to be called without ulLoopCounter being incremented. This is
\r
254 necessary because the tests in this file block for extended periods, and the
\r
255 block period might be longer than the time between calls to this function. */
\r
256 xMaxBlockTimeUsedByTheseTests = ( ( portTickType ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;
\r
257 xLoopCounterIncrementTimeMax = xMaxBlockTimeUsedByTheseTests / xCycleFrequency;
\r
259 /* If the demo task is still running then we expect the loopcounter to
\r
260 have incremented every xLoopCounterIncrementTimeMax calls. */
\r
261 if( ulLastLoopCounter == ulLoopCounter )
\r
263 xIterationsWithoutCounterIncrement++;
\r
264 if( xIterationsWithoutCounterIncrement > xLoopCounterIncrementTimeMax )
\r
266 /* The tests appear to be no longer running (stalled). */
\r
267 xTestStatus = pdFAIL;
\r
268 configASSERT( xTestStatus );
\r
273 /* ulLoopCounter changed, so the count of times this function was called
\r
274 without a change can be reset to zero. */
\r
275 xIterationsWithoutCounterIncrement = ( portTickType ) 0;
\r
278 ulLastLoopCounter = ulLoopCounter;
\r
280 /* Errors detected in the task itself will have latched xTestStatus
\r
283 return xTestStatus;
\r
285 /*-----------------------------------------------------------*/
\r
287 static void prvTest1_CreateTimersWithoutSchedulerRunning( void )
\r
289 unsigned portBASE_TYPE xTimer;
\r
291 for( xTimer = 0; xTimer < configTIMER_QUEUE_LENGTH; xTimer++ )
\r
293 /* As the timer queue is not yet full, it should be possible to both create
\r
294 and start a timer. These timers are being started before the scheduler has
\r
295 been started, so their block times should get set to zero within the timer
\r
297 xAutoReloadTimers[ xTimer ] = xTimerCreate( ( const signed char * )"FR Timer", /* Text name to facilitate debugging. The kernel does not use this itself. */
\r
298 ( ( xTimer + ( portTickType ) 1 ) * xBasePeriod ),/* The period for the timer. The plus 1 ensures a period of zero is not specified. */
\r
299 pdTRUE, /* Auto-reload is set to true. */
\r
300 ( void * ) xTimer, /* An identifier for the timer as all the auto reload timers use the same callback. */
\r
301 prvAutoReloadTimerCallback ); /* The callback to be called when the timer expires. */
\r
303 if( xAutoReloadTimers[ xTimer ] == NULL )
\r
305 xTestStatus = pdFAIL;
\r
306 configASSERT( xTestStatus );
\r
310 /* The scheduler has not yet started, so the block period of
\r
311 portMAX_DELAY should just get set to zero in xTimerStart(). Also,
\r
312 the timer queue is not yet full so xTimerStart() should return
\r
314 if( xTimerStart( xAutoReloadTimers[ xTimer ], portMAX_DELAY ) != pdPASS )
\r
316 xTestStatus = pdFAIL;
\r
317 configASSERT( xTestStatus );
\r
322 /* The timers queue should now be full, so it should be possible to create
\r
323 another timer, but not possible to start it (the timer queue will not get
\r
324 drained until the scheduler has been started. */
\r
325 xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] = xTimerCreate( ( const signed char * ) "FR Timer", /* Text name to facilitate debugging. The kernel does not use this itself. */
\r
326 ( configTIMER_QUEUE_LENGTH * xBasePeriod ), /* The period for the timer. */
\r
327 pdTRUE, /* Auto-reload is set to true. */
\r
328 ( void * ) xTimer, /* An identifier for the timer as all the auto reload timers use the same callback. */
\r
329 prvAutoReloadTimerCallback ); /* The callback executed when the timer expires. */
\r
331 if( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] == NULL )
\r
333 xTestStatus = pdFAIL;
\r
334 configASSERT( xTestStatus );
\r
338 if( xTimerStart( xAutoReloadTimers[ xTimer ], portMAX_DELAY ) == pdPASS )
\r
340 /* This time it would not be expected that the timer could be
\r
341 started at this point. */
\r
342 xTestStatus = pdFAIL;
\r
343 configASSERT( xTestStatus );
\r
347 /* Create the timers that are used from the tick interrupt to test the timer
\r
348 API functions that can be called from an ISR. */
\r
349 xISRAutoReloadTimer = xTimerCreate( ( const signed char * ) "ISR AR", /* The text name given to the timer. */
\r
350 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
351 pdTRUE, /* This is an auto reload timer. */
\r
352 ( void * ) NULL, /* The identifier is not required. */
\r
353 prvISRAutoReloadTimerCallback ); /* The callback that is executed when the timer expires. */
\r
355 xISROneShotTimer = xTimerCreate( ( const signed char * ) "ISR OS", /* The text name given to the timer. */
\r
356 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
357 pdFALSE, /* This is a one shot timer. */
\r
358 ( void * ) NULL, /* The identifier is not required. */
\r
359 prvISROneShotTimerCallback ); /* The callback that is executed when the timer expires. */
\r
361 if( ( xISRAutoReloadTimer == NULL ) || ( xISROneShotTimer == NULL ) )
\r
363 xTestStatus = pdFAIL;
\r
364 configASSERT( xTestStatus );
\r
367 /*-----------------------------------------------------------*/
\r
369 static void prvTest2_CheckTaskAndTimersInitialState( void )
\r
371 unsigned char ucTimer;
\r
373 /* Ensure all the timers are in their expected initial state. This depends
\r
374 on the timer service task having a higher priority than this task.
\r
376 auto reload timers 0 to ( configTIMER_QUEUE_LENGTH - 1 ) should now be active,
\r
377 and auto reload timer configTIMER_QUEUE_LENGTH should not yet be active (it
\r
378 could not be started prior to the scheduler being started when it was
\r
380 for( ucTimer = 0; ucTimer < ( unsigned char ) configTIMER_QUEUE_LENGTH; ucTimer++ )
\r
382 if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )
\r
384 xTestStatus = pdFAIL;
\r
385 configASSERT( xTestStatus );
\r
389 if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] ) != pdFALSE )
\r
391 xTestStatus = pdFAIL;
\r
392 configASSERT( xTestStatus );
\r
395 /*-----------------------------------------------------------*/
\r
397 static void prvTest3_CheckAutoReloadExpireRates( void )
\r
399 unsigned char ucMaxAllowableValue, ucMinAllowableValue, ucTimer;
\r
400 portTickType xBlockPeriod, xTimerPeriod, xExpectedNumber;
\r
402 /* Check the auto reload timers expire at the expected rates. */
\r
405 /* Delaying for configTIMER_QUEUE_LENGTH * xBasePeriod ticks should allow
\r
406 all the auto reload timers to expire at least once. */
\r
407 xBlockPeriod = ( ( portTickType ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;
\r
408 vTaskDelay( xBlockPeriod );
\r
410 /* Check that all the auto reload timers have called their callback
\r
411 function the expected number of times. */
\r
412 for( ucTimer = 0; ucTimer < ( unsigned char ) configTIMER_QUEUE_LENGTH; ucTimer++ )
\r
414 /* The expected number of expiries is equal to the block period divided
\r
415 by the timer period. */
\r
416 xTimerPeriod = ( ( ( portTickType ) ucTimer + ( portTickType ) 1 ) * xBasePeriod );
\r
417 xExpectedNumber = xBlockPeriod / xTimerPeriod;
\r
419 ucMaxAllowableValue = ( ( unsigned char ) xExpectedNumber ) ;
\r
420 ucMinAllowableValue = ( ( unsigned char ) xExpectedNumber - ( unsigned char ) 1 );
\r
422 if( ( ucAutoReloadTimerCounters[ ucTimer ] < ucMinAllowableValue ) ||
\r
423 ( ucAutoReloadTimerCounters[ ucTimer ] > ucMaxAllowableValue )
\r
426 xTestStatus = pdFAIL;
\r
427 configASSERT( xTestStatus );
\r
431 if( xTestStatus == pdPASS )
\r
433 /* No errors have been reported so increment the loop counter so the
\r
434 check task knows this task is still running. */
\r
438 /*-----------------------------------------------------------*/
\r
440 static void prvTest4_CheckAutoReloadTimersCanBeStopped( void )
\r
442 unsigned char ucTimer;
\r
444 /* Check the auto reload timers can be stopped correctly, and correctly
\r
445 report their state. */
\r
447 /* Stop all the active timers. */
\r
448 for( ucTimer = 0; ucTimer < ( unsigned char ) configTIMER_QUEUE_LENGTH; ucTimer++ )
\r
450 /* The timer has not been stopped yet! */
\r
451 if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )
\r
453 xTestStatus = pdFAIL;
\r
454 configASSERT( xTestStatus );
\r
457 /* Now stop the timer. This will appear to happen immediately to
\r
458 this task because this task is running at a priority below the
\r
459 timer service task. */
\r
460 xTimerStop( xAutoReloadTimers[ ucTimer ], tmrdemoDONT_BLOCK );
\r
462 /* The timer should now be inactive. */
\r
463 if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) != pdFALSE )
\r
465 xTestStatus = pdFAIL;
\r
466 configASSERT( xTestStatus );
\r
470 taskENTER_CRITICAL();
\r
472 /* The timer in array position configTIMER_QUEUE_LENGTH should not
\r
473 be active. The critical section is used to ensure the timer does
\r
474 not call its callback between the next line running and the array
\r
475 being cleared back to zero, as that would mask an error condition. */
\r
476 if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH ] != ( unsigned char ) 0 )
\r
478 xTestStatus = pdFAIL;
\r
479 configASSERT( xTestStatus );
\r
482 /* Clear the timer callback count. */
\r
483 memset( ( void * ) ucAutoReloadTimerCounters, 0, sizeof( ucAutoReloadTimerCounters ) );
\r
485 taskEXIT_CRITICAL();
\r
487 /* The timers are now all inactive, so this time, after delaying, none
\r
488 of the callback counters should have incremented. */
\r
489 vTaskDelay( ( ( portTickType ) configTIMER_QUEUE_LENGTH ) * xBasePeriod );
\r
490 for( ucTimer = 0; ucTimer < ( unsigned char ) configTIMER_QUEUE_LENGTH; ucTimer++ )
\r
492 if( ucAutoReloadTimerCounters[ ucTimer ] != ( unsigned char ) 0 )
\r
494 xTestStatus = pdFAIL;
\r
495 configASSERT( xTestStatus );
\r
499 if( xTestStatus == pdPASS )
\r
501 /* No errors have been reported so increment the loop counter so
\r
502 the check task knows this task is still running. */
\r
506 /*-----------------------------------------------------------*/
\r
508 static void prvTest5_CheckBasicOneShotTimerBehaviour( void )
\r
510 /* Check the one shot timer only calls its callback once after it has been
\r
511 started, and that it reports its state correctly. */
\r
513 /* The one shot timer should not be active yet. */
\r
514 if( xTimerIsTimerActive( xOneShotTimer ) != pdFALSE )
\r
516 xTestStatus = pdFAIL;
\r
517 configASSERT( xTestStatus );
\r
520 if( ucOneShotTimerCounter != ( unsigned char ) 0 )
\r
522 xTestStatus = pdFAIL;
\r
523 configASSERT( xTestStatus );
\r
526 /* Start the one shot timer and check that it reports its state correctly. */
\r
527 xTimerStart( xOneShotTimer, tmrdemoDONT_BLOCK );
\r
528 if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )
\r
530 xTestStatus = pdFAIL;
\r
531 configASSERT( xTestStatus );
\r
534 /* Delay for three times as long as the one shot timer period, then check
\r
535 to ensure it has only called its callback once, and is now not in the
\r
537 vTaskDelay( tmrdemoONE_SHOT_TIMER_PERIOD * ( portTickType ) 3 );
\r
539 if( xTimerIsTimerActive( xOneShotTimer ) != pdFALSE )
\r
541 xTestStatus = pdFAIL;
\r
542 configASSERT( xTestStatus );
\r
545 if( ucOneShotTimerCounter != ( unsigned char ) 1 )
\r
547 xTestStatus = pdFAIL;
\r
548 configASSERT( xTestStatus );
\r
552 /* Reset the one shot timer callback count. */
\r
553 ucOneShotTimerCounter = ( unsigned char ) 0;
\r
556 if( xTestStatus == pdPASS )
\r
558 /* No errors have been reported so increment the loop counter so the
\r
559 check task knows this task is still running. */
\r
563 /*-----------------------------------------------------------*/
\r
565 static void prvTest6_CheckAutoReloadResetBehaviour( void )
\r
567 unsigned char ucTimer;
\r
569 /* Check timer reset behaviour. */
\r
571 /* Restart the one shot timer and check it reports its status correctly. */
\r
572 xTimerStart( xOneShotTimer, tmrdemoDONT_BLOCK );
\r
573 if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )
\r
575 xTestStatus = pdFAIL;
\r
576 configASSERT( xTestStatus );
\r
579 /* Restart one of the auto reload timers and check that it reports its
\r
580 status correctly. */
\r
581 xTimerStart( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ], tmrdemoDONT_BLOCK );
\r
582 if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )
\r
584 xTestStatus = pdFAIL;
\r
585 configASSERT( xTestStatus );
\r
588 for( ucTimer = 0; ucTimer < trmdemoNUM_TIMER_RESETS; ucTimer++ )
\r
590 /* Delay for half as long as the one shot timer period, then reset it.
\r
591 It should never expire while this is done, so its callback count should
\r
592 never increment. */
\r
593 vTaskDelay( tmrdemoONE_SHOT_TIMER_PERIOD / 2 );
\r
595 /* Check both running timers are still active, but have not called their
\r
596 callback functions. */
\r
597 if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )
\r
599 xTestStatus = pdFAIL;
\r
600 configASSERT( xTestStatus );
\r
603 if( ucOneShotTimerCounter != ( unsigned char ) 0 )
\r
605 xTestStatus = pdFAIL;
\r
606 configASSERT( xTestStatus );
\r
609 if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )
\r
611 xTestStatus = pdFAIL;
\r
612 configASSERT( xTestStatus );
\r
615 if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] != ( unsigned char ) 0 )
\r
617 xTestStatus = pdFAIL;
\r
618 configASSERT( xTestStatus );
\r
621 /* Reset both running timers. */
\r
622 xTimerReset( xOneShotTimer, tmrdemoDONT_BLOCK );
\r
623 xTimerReset( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ], tmrdemoDONT_BLOCK );
\r
625 if( xTestStatus == pdPASS )
\r
627 /* No errors have been reported so increment the loop counter so
\r
628 the check task knows this task is still running. */
\r
633 /* Finally delay long enough for both running timers to expire. */
\r
634 vTaskDelay( ( ( portTickType ) configTIMER_QUEUE_LENGTH ) * xBasePeriod );
\r
636 /* The timers were not reset during the above delay period so should now
\r
637 both have called their callback functions. */
\r
638 if( ucOneShotTimerCounter != ( unsigned char ) 1 )
\r
640 xTestStatus = pdFAIL;
\r
641 configASSERT( xTestStatus );
\r
644 if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] == 0 )
\r
646 xTestStatus = pdFAIL;
\r
647 configASSERT( xTestStatus );
\r
650 /* The one shot timer should no longer be active, while the auto reload
\r
651 timer should still be active. */
\r
652 if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )
\r
654 xTestStatus = pdFAIL;
\r
655 configASSERT( xTestStatus );
\r
658 if( xTimerIsTimerActive( xOneShotTimer ) == pdTRUE )
\r
660 xTestStatus = pdFAIL;
\r
661 configASSERT( xTestStatus );
\r
664 /* Stop the auto reload timer again. */
\r
665 xTimerStop( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ], tmrdemoDONT_BLOCK );
\r
667 if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) != pdFALSE )
\r
669 xTestStatus = pdFAIL;
\r
670 configASSERT( xTestStatus );
\r
673 /* Clear the timer callback counts, ready for another iteration of these
\r
675 ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] = ( unsigned char ) 0;
\r
676 ucOneShotTimerCounter = ( unsigned char ) 0;
\r
678 if( xTestStatus == pdPASS )
\r
680 /* No errors have been reported so increment the loop counter so the check
\r
681 task knows this task is still running. */
\r
685 /*-----------------------------------------------------------*/
\r
687 static void prvResetStartConditionsForNextIteration( void )
\r
689 unsigned char ucTimer;
\r
691 /* Start the timers again to start all the tests over again. */
\r
693 /* Start the timers again. */
\r
694 for( ucTimer = 0; ucTimer < ( unsigned char ) configTIMER_QUEUE_LENGTH; ucTimer++ )
\r
696 /* The timer has not been started yet! */
\r
697 if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) != pdFALSE )
\r
699 xTestStatus = pdFAIL;
\r
700 configASSERT( xTestStatus );
\r
703 /* Now start the timer. This will appear to happen immediately to
\r
704 this task because this task is running at a priority below the timer
\r
706 xTimerStart( xAutoReloadTimers[ ucTimer ], tmrdemoDONT_BLOCK );
\r
708 /* The timer should now be active. */
\r
709 if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )
\r
711 xTestStatus = pdFAIL;
\r
712 configASSERT( xTestStatus );
\r
716 if( xTestStatus == pdPASS )
\r
718 /* No errors have been reported so increment the loop counter so the
\r
719 check task knows this task is still running. */
\r
723 /*-----------------------------------------------------------*/
\r
725 void vTimerPeriodicISRTests( void )
\r
727 static portTickType uxTick = ( portTickType ) -1;
\r
729 /* The xHigherPriorityTaskWoken parameter is not used in this case as this
\r
730 function is called from the tick hook anyway. However the API required it
\r
732 signed portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
733 portTickType xMargin;
\r
735 if( configTIMER_TASK_PRIORITY != ( configMAX_PRIORITIES - 1 ) )
\r
737 /* The timer service task is not the highest priority task, so it cannot
\r
738 be assumed that timings will be exact. Timers should never call their
\r
739 callback before their expiry time, but a margin is permissible for calling
\r
740 their callback after their expiry time. If exact timing is required then
\r
741 configTIMER_TASK_PRIORITY must be set to ensure the timer service task
\r
742 is the highest priority task in the system. */
\r
750 /* This test is called from the tick ISR even when the scheduler is suspended.
\r
751 Therefore, it is possible for the xTickCount to be temporarily less than the
\r
752 uxTicks count maintained in this function. That can result in calculated
\r
753 unblock times being too short, as this function is not called as missed ticks
\r
754 (ticks that occur while the scheduler is suspended) are unwound to re-instate
\r
755 the real tick value. Therefore, if this happens, just abandon the test
\r
756 and start again. */
\r
757 if( xTaskGetSchedulerState() != taskSCHEDULER_RUNNING )
\r
759 uxTick = ( portTickType ) -1;
\r
768 /* The timers will have been created, but not started. Start them
\r
769 now by setting their period. */
\r
770 ucISRAutoReloadTimerCounter = 0;
\r
771 ucISROneShotTimerCounter = 0;
\r
772 xTimerChangePeriodFromISR( xISRAutoReloadTimer, xBasePeriod, &xHigherPriorityTaskWoken );
\r
773 xTimerChangePeriodFromISR( xISROneShotTimer, xBasePeriod, &xHigherPriorityTaskWoken );
\r
775 else if( uxTick == xBasePeriod )
\r
777 /* Neither timer should have expired yet. */
\r
778 if( ( ucISRAutoReloadTimerCounter != 0 ) || ( ucISROneShotTimerCounter != 0 ) )
\r
780 xTestStatus = pdFAIL;
\r
781 configASSERT( xTestStatus );
\r
784 else if( uxTick == ( xBasePeriod + xMargin ) )
\r
786 /* Both timers should now have expired once. The auto reload timer will
\r
787 still be active, but the one shot timer should now have stopped. */
\r
788 if( ( ucISRAutoReloadTimerCounter != 1 ) || ( ucISROneShotTimerCounter != 1 ) )
\r
790 xTestStatus = pdFAIL;
\r
791 configASSERT( xTestStatus );
\r
794 else if( uxTick == ( 2 * xBasePeriod ) )
\r
796 /* The auto reload timer will still be active, but the one shot timer
\r
797 should now have stopped - however, at this time neither of the timers
\r
798 should have expired again since the last test. */
\r
799 if( ( ucISRAutoReloadTimerCounter != 1 ) || ( ucISROneShotTimerCounter != 1 ) )
\r
801 xTestStatus = pdFAIL;
\r
802 configASSERT( xTestStatus );
\r
805 else if( uxTick == ( ( 2 * xBasePeriod ) + xMargin ) )
\r
807 /* The auto reload timer will still be active, but the one shot timer
\r
808 should now have stopped. At this time the auto reload timer should have
\r
809 expired again, but the one shot timer count should not have changed. */
\r
810 if( ucISRAutoReloadTimerCounter != 2 )
\r
812 xTestStatus = pdFAIL;
\r
813 configASSERT( xTestStatus );
\r
816 if( ucISROneShotTimerCounter != 1 )
\r
818 xTestStatus = pdFAIL;
\r
819 configASSERT( xTestStatus );
\r
822 else if( uxTick == ( ( 2 * xBasePeriod ) + ( xBasePeriod >> ( portTickType ) 2U ) ) )
\r
824 /* The auto reload timer will still be active, but the one shot timer
\r
825 should now have stopped. Again though, at this time, neither timer call
\r
826 back should have been called since the last test. */
\r
827 if( ucISRAutoReloadTimerCounter != 2 )
\r
829 xTestStatus = pdFAIL;
\r
830 configASSERT( xTestStatus );
\r
833 if( ucISROneShotTimerCounter != 1 )
\r
835 xTestStatus = pdFAIL;
\r
836 configASSERT( xTestStatus );
\r
839 else if( uxTick == ( 3 * xBasePeriod ) )
\r
841 /* Start the one shot timer again. */
\r
842 xTimerStartFromISR( xISROneShotTimer, &xHigherPriorityTaskWoken );
\r
844 else if( uxTick == ( ( 3 * xBasePeriod ) + xMargin ) )
\r
846 /* The auto reload timer and one shot timer will be active. At
\r
847 this time the auto reload timer should have expired again, but the one
\r
848 shot timer count should not have changed yet. */
\r
849 if( ucISRAutoReloadTimerCounter != 3 )
\r
851 xTestStatus = pdFAIL;
\r
852 configASSERT( xTestStatus );
\r
855 if( ucISROneShotTimerCounter != 1 )
\r
857 xTestStatus = pdFAIL;
\r
858 configASSERT( xTestStatus );
\r
861 /* Now stop the auto reload timer. The one shot timer was started
\r
862 a few ticks ago. */
\r
863 xTimerStopFromISR( xISRAutoReloadTimer, &xHigherPriorityTaskWoken );
\r
865 else if( uxTick == ( 4 * xBasePeriod ) )
\r
867 /* The auto reload timer is now stopped, and the one shot timer is
\r
868 active, but at this time neither timer should have expired since the
\r
870 if( ucISRAutoReloadTimerCounter != 3 )
\r
872 xTestStatus = pdFAIL;
\r
873 configASSERT( xTestStatus );
\r
876 if( ucISROneShotTimerCounter != 1 )
\r
878 xTestStatus = pdFAIL;
\r
879 configASSERT( xTestStatus );
\r
882 else if( uxTick == ( ( 4 * xBasePeriod ) + xMargin ) )
\r
884 /* The auto reload timer is now stopped, and the one shot timer is
\r
885 active. The one shot timer should have expired again, but the auto
\r
886 reload timer should not have executed its callback. */
\r
887 if( ucISRAutoReloadTimerCounter != 3 )
\r
889 xTestStatus = pdFAIL;
\r
890 configASSERT( xTestStatus );
\r
893 if( ucISROneShotTimerCounter != 2 )
\r
895 xTestStatus = pdFAIL;
\r
896 configASSERT( xTestStatus );
\r
899 else if( uxTick == ( ( 8 * xBasePeriod ) + xMargin ) )
\r
901 /* The auto reload timer is now stopped, and the one shot timer has
\r
902 already expired and then stopped itself. Both callback counters should
\r
903 not have incremented since the last test. */
\r
904 if( ucISRAutoReloadTimerCounter != 3 )
\r
906 xTestStatus = pdFAIL;
\r
907 configASSERT( xTestStatus );
\r
910 if( ucISROneShotTimerCounter != 2 )
\r
912 xTestStatus = pdFAIL;
\r
913 configASSERT( xTestStatus );
\r
916 /* Now reset the one shot timer. */
\r
917 xTimerResetFromISR( xISROneShotTimer, &xHigherPriorityTaskWoken );
\r
919 else if( uxTick == ( 9 * xBasePeriod ) )
\r
921 /* Only the one shot timer should be running, but it should not have
\r
922 expired since the last test. Check the callback counters have not
\r
923 incremented, then reset the one shot timer again. */
\r
924 if( ucISRAutoReloadTimerCounter != 3 )
\r
926 xTestStatus = pdFAIL;
\r
927 configASSERT( xTestStatus );
\r
930 if( ucISROneShotTimerCounter != 2 )
\r
932 xTestStatus = pdFAIL;
\r
933 configASSERT( xTestStatus );
\r
936 xTimerResetFromISR( xISROneShotTimer, &xHigherPriorityTaskWoken );
\r
938 else if( uxTick == ( 10 * xBasePeriod ) )
\r
940 /* Only the one shot timer should be running, but it should not have
\r
941 expired since the last test. Check the callback counters have not
\r
942 incremented, then reset the one shot timer again. */
\r
943 if( ucISRAutoReloadTimerCounter != 3 )
\r
945 xTestStatus = pdFAIL;
\r
946 configASSERT( xTestStatus );
\r
949 if( ucISROneShotTimerCounter != 2 )
\r
951 xTestStatus = pdFAIL;
\r
952 configASSERT( xTestStatus );
\r
955 xTimerResetFromISR( xISROneShotTimer, &xHigherPriorityTaskWoken );
\r
957 else if( uxTick == ( 11 * xBasePeriod ) )
\r
959 /* Only the one shot timer should be running, but it should not have
\r
960 expired since the last test. Check the callback counters have not
\r
961 incremented, then reset the one shot timer once again. */
\r
962 if( ucISRAutoReloadTimerCounter != 3 )
\r
964 xTestStatus = pdFAIL;
\r
965 configASSERT( xTestStatus );
\r
968 if( ucISROneShotTimerCounter != 2 )
\r
970 xTestStatus = pdFAIL;
\r
971 configASSERT( xTestStatus );
\r
974 xTimerResetFromISR( xISROneShotTimer, &xHigherPriorityTaskWoken );
\r
976 else if( uxTick == ( ( 12 * xBasePeriod ) + xMargin ) )
\r
978 /* Only the one shot timer should have been running and this time it
\r
979 should have expired. Check its callback count has been incremented.
\r
980 The auto reload timer is still not running so should still have the same
\r
981 count value. This time the one shot timer is not reset so should not
\r
982 restart from its expiry period again. */
\r
983 if( ucISRAutoReloadTimerCounter != 3 )
\r
985 xTestStatus = pdFAIL;
\r
986 configASSERT( xTestStatus );
\r
989 if( ucISROneShotTimerCounter != 3 )
\r
991 xTestStatus = pdFAIL;
\r
992 configASSERT( xTestStatus );
\r
995 else if( uxTick == ( 15 * xBasePeriod ) )
\r
997 /* Neither timer should be running now. Check neither callback count
\r
998 has incremented, then go back to the start to run these tests all
\r
1000 if( ucISRAutoReloadTimerCounter != 3 )
\r
1002 xTestStatus = pdFAIL;
\r
1003 configASSERT( xTestStatus );
\r
1006 if( ucISROneShotTimerCounter != 3 )
\r
1008 xTestStatus = pdFAIL;
\r
1009 configASSERT( xTestStatus );
\r
1012 uxTick = ( portTickType ) -1;
\r
1015 /*-----------------------------------------------------------*/
\r
1017 /*** Timer callback functions are defined below here. ***/
\r
1019 static void prvAutoReloadTimerCallback( xTimerHandle pxExpiredTimer )
\r
1021 unsigned long ulTimerID;
\r
1023 ulTimerID = ( unsigned long ) pvTimerGetTimerID( pxExpiredTimer );
\r
1024 if( ulTimerID <= ( configTIMER_QUEUE_LENGTH + 1 ) )
\r
1026 ( ucAutoReloadTimerCounters[ ulTimerID ] )++;
\r
1030 /* The timer ID appears to be unexpected (invalid). */
\r
1031 xTestStatus = pdFAIL;
\r
1032 configASSERT( xTestStatus );
\r
1035 /*-----------------------------------------------------------*/
\r
1037 static void prvOneShotTimerCallback( xTimerHandle pxExpiredTimer )
\r
1039 /* The parameter is not used in this case as only one timer uses this
\r
1040 callback function. */
\r
1041 ( void ) pxExpiredTimer;
\r
1043 ucOneShotTimerCounter++;
\r
1045 /*-----------------------------------------------------------*/
\r
1047 static void prvISRAutoReloadTimerCallback( xTimerHandle pxExpiredTimer )
\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
1053 ucISRAutoReloadTimerCounter++;
\r
1055 /*-----------------------------------------------------------*/
\r
1057 static void prvISROneShotTimerCallback( xTimerHandle pxExpiredTimer )
\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
1063 ucISROneShotTimerCounter++;
\r
1065 /*-----------------------------------------------------------*/
\r