]> git.sur5r.net Git - freertos/blobdiff - Demo/SuperH_SH7216_Renesas/RTOSDemo/flop.c
Just updated comments.
[freertos] / Demo / SuperH_SH7216_Renesas / RTOSDemo / flop.c
index 6f0342e142b71717228d8ffb6cd4938dfa82f4b3..992e6f761221498fb0877d03fb30f043870dfd1c 100644 (file)
 */\r
 \r
 /*\r
- * Creates eight tasks, each of which loops continuously performing an (emulated) \r
- * floating point calculation.\r
+ * Creates eight tasks, each of which loops continuously performing a floating \r
+ * point calculation and in so doing test the floating point context switching.\r
+ * This file also demonstrates the use of the xPortUsesFloatingPoint() function\r
+ * which informs the kernel that the task requires its floating point context\r
+ * saved on each switch.\r
  *\r
  * All the tasks run at the idle priority and never block or yield.  This causes \r
- * all eight tasks to time slice with the idle task.  Running at the idle priority \r
- * means that these tasks will get pre-empted any time another task is ready to run\r
- * or a time slice occurs.  More often than not the pre-emption will occur mid \r
- * calculation, creating a good test of the schedulers context switch mechanism - a \r
- * calculation producing an unexpected result could be a symptom of a corruption in \r
- * the context of a task.\r
+ * all eight tasks to time slice with the idle task.  Running at the idle \r
+ * priority means that these tasks will get pre-empted any time another task is \r
+ * ready to run or a time slice occurs.  More often than not the pre-emption \r
+ * will occur mid calculation, creating a good test of the schedulers context \r
+ * switch mechanism - a calculation producing an unexpected result could be a \r
+ * symptom of a corruption in the context of a task.\r
  */\r
 \r
 #include <stdlib.h>\r
 \r
 /* Four tasks, each of which performs a different floating point calculation.  \r
 Each of the four is created twice. */\r
-static portTASK_FUNCTION_PROTO( vCompetingMathTask1, pvParameters );\r
-static portTASK_FUNCTION_PROTO( vCompetingMathTask2, pvParameters );\r
-static portTASK_FUNCTION_PROTO( vCompetingMathTask3, pvParameters );\r
-static portTASK_FUNCTION_PROTO( vCompetingMathTask4, pvParameters );\r
+static void vCompetingMathTask1( void *pvParameters );\r
+static void vCompetingMathTask2( void *pvParameters );\r
+static void vCompetingMathTask3( void *pvParameters );\r
+static void vCompetingMathTask4( void *pvParameters );\r
 \r
 /* These variables are used to check that all the tasks are still running.  If a \r
-task gets a calculation wrong it will\r
-stop incrementing its check variable. */\r
+task gets a calculation wrong it will stop incrementing its check variable,\r
+otherwise the check variable will get incremented on each iteration of the \r
+tasks execution. */\r
 static volatile unsigned short usTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };\r
 \r
 /*-----------------------------------------------------------*/\r
@@ -125,7 +129,7 @@ xTaskHandle xCreatedTask;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static portTASK_FUNCTION( vCompetingMathTask1, pvParameters )\r
+static void vCompetingMathTask1( void *pvParameters )\r
 {\r
 volatile double d1, d2, d3, d4;\r
 volatile unsigned short *pusTaskCheckVariable;\r
@@ -136,6 +140,7 @@ short sError = pdFALSE;
        d2 = 2345.6789;\r
        d3 = -918.222;\r
 \r
+       /* Calculate the expected answer. */\r
        dAnswer = ( d1 + d2 ) * d3;\r
 \r
        /* The variable this task increments to show it is still running is passed in \r
@@ -145,16 +150,13 @@ short sError = pdFALSE;
        /* Keep performing a calculation and checking the result against a constant. */\r
        for(;;)\r
        {\r
+               /* Perform the calculation. */\r
                d1 = 123.4567;\r
                d2 = 2345.6789;\r
                d3 = -918.222;\r
 \r
                d4 = ( d1 + d2 ) * d3;\r
 \r
-               #if configUSE_PREEMPTION == 0\r
-                       taskYIELD();\r
-               #endif\r
-\r
                /* If the calculation does not match the expected constant, stop the \r
                increment of the check variable. */\r
                if( fabs( d4 - dAnswer ) > 0.001 )\r
@@ -168,16 +170,11 @@ short sError = pdFALSE;
                        variable so we know this task is still running okay. */\r
                        ( *pusTaskCheckVariable )++;\r
                }\r
-\r
-               #if configUSE_PREEMPTION == 0\r
-                       taskYIELD();\r
-               #endif\r
-\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static portTASK_FUNCTION( vCompetingMathTask2, pvParameters )\r
+static void vCompetingMathTask2( void *pvParameters )\r
 {\r
 volatile double d1, d2, d3, d4;\r
 volatile unsigned short *pusTaskCheckVariable;\r
@@ -188,6 +185,7 @@ short sError = pdFALSE;
        d2 = 32498.2;\r
        d3 = -2.0001;\r
 \r
+       /* Calculate the expected answer. */\r
        dAnswer = ( d1 / d2 ) * d3;\r
 \r
 \r
@@ -198,16 +196,13 @@ short sError = pdFALSE;
        /* Keep performing a calculation and checking the result against a constant. */\r
        for( ;; )\r
        {\r
+               /* Perform the calculation. */\r
                d1 = -389.38;\r
                d2 = 32498.2;\r
                d3 = -2.0001;\r
 \r
                d4 = ( d1 / d2 ) * d3;\r
 \r
-               #if configUSE_PREEMPTION == 0\r
-                       taskYIELD();\r
-               #endif\r
-               \r
                /* If the calculation does not match the expected constant, stop the \r
                increment of the check variable. */\r
                if( fabs( d4 - dAnswer ) > 0.001 )\r
@@ -222,15 +217,11 @@ short sError = pdFALSE;
                        this task is still running okay. */\r
                        ( *pusTaskCheckVariable )++;\r
                }\r
-\r
-               #if configUSE_PREEMPTION == 0\r
-                       taskYIELD();\r
-               #endif\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static portTASK_FUNCTION( vCompetingMathTask3, pvParameters )\r
+static void vCompetingMathTask3( void *pvParameters )\r
 {\r
 volatile double *pdArray, dTotal1, dTotal2, dDifference;\r
 volatile unsigned short *pusTaskCheckVariable;\r
@@ -238,15 +229,16 @@ const size_t xArraySize = 10;
 size_t xPosition;\r
 short sError = pdFALSE;\r
 \r
-       /* The variable this task increments to show it is still running is passed in \r
-       as the parameter. */\r
+       /* The variable this task increments to show it is still running is passed \r
+       in as the parameter. */\r
        pusTaskCheckVariable = ( unsigned short * ) pvParameters;\r
 \r
+       /* Allocate memory for use as an array. */\r
        pdArray = ( double * ) pvPortMalloc( xArraySize * sizeof( double ) );\r
 \r
-       /* Keep filling an array, keeping a running total of the values placed in the \r
-       array.  Then run through the array adding up all the values.  If the two totals \r
-       do not match, stop the check variable from incrementing. */\r
+       /* Keep filling an array, keeping a running total of the values placed in \r
+       the array.  Then run through the array adding up all the values.  If the two \r
+       totals do not match, stop the check variable from incrementing. */\r
        for( ;; )\r
        {\r
                dTotal1 = 0.0;\r
@@ -258,10 +250,6 @@ short sError = pdFALSE;
                        dTotal1 += ( double ) xPosition + 5.5;  \r
                }\r
 \r
-               #if configUSE_PREEMPTION == 0\r
-                       taskYIELD();\r
-               #endif\r
-\r
                for( xPosition = 0; xPosition < xArraySize; xPosition++ )\r
                {\r
                        dTotal2 += pdArray[ xPosition ];\r
@@ -273,10 +261,6 @@ short sError = pdFALSE;
                        sError = pdTRUE;\r
                }\r
 \r
-               #if configUSE_PREEMPTION == 0\r
-                       taskYIELD();\r
-               #endif\r
-\r
                if( sError == pdFALSE )\r
                {\r
                        /* If the calculation has always been correct, increment the check \r
@@ -287,7 +271,7 @@ short sError = pdFALSE;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static portTASK_FUNCTION( vCompetingMathTask4, pvParameters )\r
+static void vCompetingMathTask4( void *pvParameters )\r
 {\r
 volatile double *pdArray, dTotal1, dTotal2, dDifference;\r
 volatile unsigned short *pusTaskCheckVariable;\r
@@ -299,6 +283,7 @@ short sError = pdFALSE;
        as the parameter. */\r
        pusTaskCheckVariable = ( unsigned short * ) pvParameters;\r
 \r
+       /* Allocate RAM for use as an array. */\r
        pdArray = ( double * ) pvPortMalloc( xArraySize * sizeof( double ) );\r
 \r
        /* Keep filling an array, keeping a running total of the values placed in the \r
@@ -315,10 +300,6 @@ short sError = pdFALSE;
                        dTotal1 += ( double ) xPosition * 12.123;       \r
                }\r
 \r
-               #if configUSE_PREEMPTION == 0\r
-                       taskYIELD();\r
-               #endif\r
-\r
                for( xPosition = 0; xPosition < xArraySize; xPosition++ )\r
                {\r
                        dTotal2 += pdArray[ xPosition ];\r
@@ -330,10 +311,6 @@ short sError = pdFALSE;
                        sError = pdTRUE;\r
                }\r
 \r
-               #if configUSE_PREEMPTION == 0\r
-                       taskYIELD();\r
-               #endif\r
-\r
                if( sError == pdFALSE )\r
                {\r
                        /* If the calculation has always been correct, increment the check \r
@@ -347,8 +324,8 @@ short sError = pdFALSE;
 /* This is called to check that all the created tasks are still running. */\r
 portBASE_TYPE xAreMathsTaskStillRunning( void )\r
 {\r
-/* Keep a history of the check variables so we know if they have been incremented \r
-since the last call. */\r
+/* Keep a history of the check variables so we know if they have been \r
+incremented since the last call. */\r
 static unsigned short usLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };\r
 portBASE_TYPE xReturn = pdTRUE, xTask;\r
 \r