]> 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 6f24605adeb81be16d045d92b5eb1c4dd1d29f72..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
 /* 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            ( 1931UL )\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
@@ -101,19 +136,9 @@ unsigned long ulCompareMatchBits;
        \r
        /* Setup the interrupt itself.  The STM module clock divider is setup when \r
        the tick interrupt is configured - which is when the scheduler is started - \r
-       so there is no need     to do it here. */\r
-\r
-       unlock_wdtcon();\r
-       {\r
-               /* Wait until access to Endint protected register is enabled. */\r
-               while( 0 != ( WDT_CON0.reg & 0x1UL ) );\r
-\r
-               /* RMC == 1 so STM Clock == FPI */\r
-               STM_CLC.reg = ( 1UL << 8 );\r
-       }\r
-       lock_wdtcon();\r
+       so there is no need     to do it here.\r
 \r
-       /* The tick interrupt uses compare match 0, so this test uses compare match\r
+       The tick interrupt uses compare match 0, so this test uses compare match\r
        1, which means shifting up the values by 16 before writing them to the\r
        register. */\r
        ulCompareMatchBits = ( 0x1fUL - __CLZ( ulCompareMatchValue ) );\r
@@ -127,10 +152,10 @@ unsigned long ulCompareMatchBits;
                STM_CMCON.reg |= ulCompareMatchBits;\r
                STM_CMP1.reg = ulCompareMatchValue;\r
 \r
-               if( 0 != _install_int_handler( configMAX_SYSCALL_INTERRUPT_PRIORITY - 5, prvPortHighFrequencyTimerHandler, 0 ) )\r
+               if( 0 != _install_int_handler( configHIGH_FREQUENCY_TIMER_PRIORITY, prvPortHighFrequencyTimerHandler, 0 ) )\r
                {\r
                        /* Set-up the interrupt. */\r
-                       STM_SRC1.reg = ( ( configMAX_SYSCALL_INTERRUPT_PRIORITY - 5 ) | 0x00005000UL );\r
+                       STM_SRC1.reg = ( configHIGH_FREQUENCY_TIMER_PRIORITY | 0x00005000UL );\r
        \r
                        /* Enable the Interrupt. */\r
                        STM_ISRR.reg &= ~( 0x03UL << 2UL );\r
@@ -150,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
@@ -167,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
@@ -199,5 +232,6 @@ unsigned long ulHigherPriorityTaskWoken = pdFALSE;
                ulExecutionCounter = 0UL;\r
        }\r
        \r
+       /* Context switch on exit if necessary. */\r
        portYIELD_FROM_ISR( ulHigherPriorityTaskWoken );\r
 }\r