]> git.sur5r.net Git - freertos/blobdiff - Demo/Common/Minimal/TimerDemo.c
Check in the timer module test/demo task.
[freertos] / Demo / Common / Minimal / TimerDemo.c
index 1915ff3c0fe61e2179d284db84629c150639baca..18b0381a9ae7d0ab5c23a6a0316c56d68295ffb9 100644 (file)
@@ -260,7 +260,7 @@ static portTickType xIterationsWithoutCounterIncrement = ( portTickType ) 0, xLa
 \r
 static void prvTest1_CreateTimersWithoutSchedulerRunning( void )\r
 {\r
-portBASE_TYPE xTimer;\r
+unsigned portBASE_TYPE xTimer;\r
 \r
        for( xTimer = 0; xTimer < configTIMER_QUEUE_LENGTH; xTimer++ )\r
        {\r
@@ -269,7 +269,7 @@ portBASE_TYPE xTimer;
                been started, so their block times should get set to zero within the timer\r
                API itself. */\r
                xAutoReloadTimers[ xTimer ] = xTimerCreate( "FR Timer",                                         /* Text name to facilitate debugging.  The kernel does not use this itself. */\r
-                                                                                                       ( ( xTimer + 1 ) * xBasePeriod ),/* The period for the timer.  The plus 1 ensures a period of zero is not specified. */\r
+                                                                                                       ( ( xTimer + ( portTickType ) 1 ) * xBasePeriod ),/* The period for the timer.  The plus 1 ensures a period of zero is not specified. */\r
                                                                                                        pdTRUE,                                                         /* Auto-reload is set to true. */\r
                                                                                                        ( void * ) xTimer,                                      /* An identifier for the timer as all the auto reload timers use the same callback. */\r
                                                                                                        prvAutoReloadTimerCallback );           /* The callback to be called when the timer expires. */\r
@@ -314,20 +314,20 @@ portBASE_TYPE xTimer;
                        /* This time it would not be expected that the timer could be\r
                        started at this point. */\r
                        xTestStatus = pdFAIL;\r
-               configASSERT( xTestStatus );\r
+                       configASSERT( xTestStatus );\r
                }\r
        }\r
        \r
        /* Create the timers that are used from the tick interrupt to test the timer\r
        API functions that can be called from an ISR. */\r
        xISRAutoReloadTimer = xTimerCreate( "ISR AR",                                           /* The text name given to the timer. */\r
-                                                                               0,                                                              /* The timer is not given a period yet - this will be done from the tick hook. */\r
+                                                                               0xffff,                                                 /* The timer is not given a period yet - this will be done from the tick hook, but a period of 0 is invalid. */\r
                                                                                pdTRUE,                                                 /* This is an auto reload timer. */\r
                                                                                ( void * ) NULL,                                /* The identifier is not required. */\r
                                                                                prvISRAutoReloadTimerCallback );/* The callback that is executed when the timer expires. */\r
 \r
        xISROneShotTimer = xTimerCreate(        "ISR OS",                                               /* The text name given to the timer. */\r
-                                                                               0,                                                              /* The timer is not given a period yet - this will be done from the tick hook. */\r
+                                                                               0xffff,                                                 /* The timer is not given a period yet - this will be done from the tick hook, but a period of 0 is invalid. */\r
                                                                                pdFALSE,                                                /* This is a one shot timer. */\r
                                                                                ( void * ) NULL,                                /* The identifier is not required. */\r
                                                                                prvISROneShotTimerCallback );   /* The callback that is executed when the timer expires. */\r
@@ -698,13 +698,13 @@ unsigned char ucTimer;
 \r
 void vTimerPeriodicISRTests( void )\r
 {\r
-static unsigned portBASE_TYPE uxTick = ( unsigned portBASE_TYPE ) -1;\r
+static portTickType uxTick = ( portTickType ) -1;\r
 \r
 /* The xHigherPriorityTaskWoken parameter is not used in this case as this\r
 function is called from the tick hook anyway.  However the API required it\r
 to be present. */\r
 portBASE_TYPE xHigherPriorityTaskWoken = pdTRUE;\r
-portBASE_TYPE xMargin;\r
+portTickType xMargin;\r
 \r
        if( configTIMER_TASK_PRIORITY != ( configMAX_PRIORITIES - 1 ) )\r
        {\r
@@ -718,10 +718,24 @@ portBASE_TYPE xMargin;
        }\r
        else\r
        {\r
-               xMargin = 0;\r
+               xMargin = 1;\r
+       }\r
+\r
+       /* This test is called from the tick ISR even when the scheduler is suspended.\r
+       Therefore, it is possible for the xTickCount to be temporarily less than the\r
+       uxTicks count maintained in this function.  That can result in calculated\r
+       unblock times being too short, as this function is not called as missed ticks\r
+       (ticks that occur while the scheduler is suspended) are unwound to re-instate\r
+       the real tick value.  Therefore, if this happens, just abandon the test\r
+       and start again. */\r
+       if( xTaskGetSchedulerState() != taskSCHEDULER_RUNNING )\r
+       {\r
+               uxTick = ( portTickType ) -1;\r
+       }\r
+       else\r
+       {\r
+               uxTick++;\r
        }\r
-       \r
-       uxTick++;\r
 \r
        if( uxTick == 0 )\r
        {\r
@@ -969,7 +983,7 @@ portBASE_TYPE xMargin;
                        configASSERT( xTestStatus );\r
                }\r
                \r
-               uxTick = ( unsigned portBASE_TYPE ) -1;\r
+               uxTick = ( portTickType ) -1;\r
        }       \r
 }\r
 /*-----------------------------------------------------------*/\r