]> git.sur5r.net Git - freertos/blobdiff - Demo/TriCore_TC1782_TriBoard_GCC/RTOSDemo/InterruptNestTest.c
All for the TriCore demo:
[freertos] / Demo / TriCore_TC1782_TriBoard_GCC / RTOSDemo / InterruptNestTest.c
index 0464b3942a6d08fb6048b99728c716b5ba4991c6..64e5ac76c6f9ed624f8d1eaf3cd7fc14bad3df39 100644 (file)
     licensing and training services.\r
 */\r
 \r
+/*\r
+ * It is intended that the tasks and timers in this file cause interrupts to\r
+ * nest at least one level deeper than they would otherwise.\r
+ *\r
+ * A timer is configured to create an interrupt at moderately high frequency,\r
+ * as defined by the tmrtestHIGH_FREQUENCY_TIMER_TEST_HZ constant.  The\r
+ * interrupt priority is by configHIGH_FREQUENCY_TIMER_PRIORITY, which is set\r
+ * to ( configMAX_SYSCALL_INTERRUPT_PRIORITY - 1UL ), the second highest\r
+ * priority from which interrupt safe FreeRTOS API calls can be made.\r
+ *\r
+ * The timer interrupt handler counts the number of times it is called.  When\r
+ * it has determined that the number of calls means that 10ms has passed, it\r
+ * 'gives' a semaphore, and resets it call count.\r
+ *\r
+ * A high priority task is used to receive the data posted to the queue by the\r
+ * interrupt service routine.  The task should, then, leave the blocked state\r
+ * and 'take' the available semaphore every 10ms.  The frequency at which it\r
+ * actually leaves the blocked state is verified by the demo's check task (see\r
+ * the the documentation for the entire demo on the FreeRTOS.org web site),\r
+ * which then flags an error if the frequency lower than expected.\r
+ */\r
+\r
 /* Standard includes. */\r
 #include <stdlib.h>\r
 #include <string.h>\r
 #include <machine/cint.h>\r
 #include <machine/wdtcon.h>\r
 \r
-#warning DOCUMENT THIS\r
 /* This constant is specific to this test application.  It allows the high\r
 frequency (interrupt nesting test) timer to know how often to trigger, and the\r
 check task to know how many iterations to expect at any given time. */\r
 #define tmrtestHIGH_FREQUENCY_TIMER_TEST_HZ            ( 8931UL )\r
 \r
+/*\r
+ * The handler for the high priority timer interrupt.\r
+ */\r
 static void prvPortHighFrequencyTimerHandler( int iArg ) __attribute__((longcall));\r
+\r
+/*\r
+ * The task that receives messages posted to a queue by the higher priority\r
+ * timer interrupt.\r
+ */\r
 static void prvHighFrequencyTimerTask( void *pvParameters );\r
 \r
+/* Constants used to configure the timer and determine how often the task\r
+should receive data. */\r
 static const unsigned long ulCompareMatchValue = configPERIPHERAL_CLOCK_HZ / tmrtestHIGH_FREQUENCY_TIMER_TEST_HZ;\r
 static const unsigned long ulInterruptsPer10ms = tmrtestHIGH_FREQUENCY_TIMER_TEST_HZ / 100UL;\r
 static const unsigned long ulSemaphoreGiveRate_ms = 10UL;\r
 \r
+/* The semaphore used to synchronise the interrupt with the task. */\r
 static xSemaphoreHandle xHighFrequencyTimerSemaphore = NULL;\r
-static unsigned long ulHighFrequencyCounterIterations = 0UL;\r
+\r
+/* Holds the count of the number of times the task is unblocked by the timer. */\r
+static volatile unsigned long ulHighFrequencyTaskIterations = 0UL;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
@@ -141,8 +175,16 @@ unsigned long ulCompareMatchBits;
 \r
 unsigned long ulInterruptNestingTestGetIterationCount( unsigned long *pulExpectedIncFrequency_ms )\r
 {\r
+unsigned long ulReturn;\r
+\r
        *pulExpectedIncFrequency_ms = ulSemaphoreGiveRate_ms;\r
-       return ulHighFrequencyCounterIterations;\r
+       portENTER_CRITICAL();\r
+       {\r
+               ulReturn = ulHighFrequencyTaskIterations;\r
+               ulHighFrequencyTaskIterations = 0UL;\r
+       }\r
+\r
+       return ulReturn;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -158,7 +200,7 @@ static void prvHighFrequencyTimerTask( void *pvParameters )
                \r
                /* Just count how many times the task has been unblocked before\r
                returning to wait for the semaphore again. */\r
-               ulHighFrequencyCounterIterations++;\r
+               ulHighFrequencyTaskIterations++;\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -168,7 +210,6 @@ static void prvPortHighFrequencyTimerHandler( int iArg )
 static volatile unsigned long ulExecutionCounter = 0UL;\r
 unsigned long ulHigherPriorityTaskWoken = pdFALSE;\r
 \r
-COUNT_NEST();\r
        /* Just to avoid compiler warnings about unused parameters. */\r
        ( void ) iArg;\r
 \r
@@ -191,6 +232,6 @@ COUNT_NEST();
                ulExecutionCounter = 0UL;\r
        }\r
        \r
+       /* Context switch on exit if necessary. */\r
        portYIELD_FROM_ISR( ulHigherPriorityTaskWoken );\r
-ulNest--;\r
 }\r