]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/PIC32MZ_MPLAB/flop_mz.c
Preparing for maintenance release -
[freertos] / FreeRTOS / Demo / PIC32MZ_MPLAB / flop_mz.c
diff --git a/FreeRTOS/Demo/PIC32MZ_MPLAB/flop_mz.c b/FreeRTOS/Demo/PIC32MZ_MPLAB/flop_mz.c
new file mode 100644 (file)
index 0000000..2dd5c32
--- /dev/null
@@ -0,0 +1,388 @@
+/*\r
+    FreeRTOS V8.2.2 - Copyright (C) 2015 Real Time Engineers Ltd.\r
+    All rights reserved\r
+\r
+    VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
+\r
+    This file is part of the FreeRTOS distribution.\r
+\r
+    FreeRTOS is free software; you can redistribute it and/or modify it under\r
+    the terms of the GNU General Public License (version 2) as published by the\r
+    Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
+\r
+    ***************************************************************************\r
+    >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
+    >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
+    >>!   obliged to provide the source code for proprietary components     !<<\r
+    >>!   outside of the FreeRTOS kernel.                                   !<<\r
+    ***************************************************************************\r
+\r
+    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
+    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
+    FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
+    link: http://www.freertos.org/a00114.html\r
+\r
+    ***************************************************************************\r
+     *                                                                       *\r
+     *    FreeRTOS provides completely free yet professionally developed,    *\r
+     *    robust, strictly quality controlled, supported, and cross          *\r
+     *    platform software that is more than just the market leader, it     *\r
+     *    is the industry's de facto standard.                               *\r
+     *                                                                       *\r
+     *    Help yourself get started quickly while simultaneously helping     *\r
+     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
+     *    tutorial book, reference manual, or both:                          *\r
+     *    http://www.FreeRTOS.org/Documentation                              *\r
+     *                                                                       *\r
+    ***************************************************************************\r
+\r
+    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
+    the FAQ page "My application does not run, what could be wrong?".  Have you\r
+    defined configASSERT()?\r
+\r
+    http://www.FreeRTOS.org/support - In return for receiving this top quality\r
+    embedded software for free we request you assist our global community by\r
+    participating in the support forum.\r
+\r
+    http://www.FreeRTOS.org/training - Investing in training allows your team to\r
+    be as productive as possible as early as possible.  Now you can receive\r
+    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
+    Ltd, and the world's leading authority on the world's leading RTOS.\r
+\r
+    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
+    including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
+    compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
+\r
+    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
+    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
+\r
+    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
+    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
+    licenses offer ticketed support, indemnification and commercial middleware.\r
+\r
+    http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
+    engineered and independently SIL3 certified version for use in safety and\r
+    mission critical applications that require provable dependability.\r
+\r
+    1 tab == 4 spaces!\r
+*/\r
+\r
+/*\r
+ * Creates eight tasks, each of which loops continuously performing a\r
+ * floating point calculation.\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
+ */\r
+\r
+#include <stdlib.h>\r
+#include <math.h>\r
+\r
+/* Scheduler include files. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+\r
+/* Demo program include files. */\r
+#include "flop_mz.h"\r
+\r
+#define mathSTACK_SIZE         (configMINIMAL_STACK_SIZE + 100)\r
+#define mathNUMBER_OF_TASKS  ( 8 )\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
+\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
+static volatile unsigned long ulTaskCheck[ mathNUMBER_OF_TASKS ] = { 0 };\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void vStartMathTasks( unsigned portBASE_TYPE uxPriority )\r
+{\r
+       xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 0 ] ), uxPriority, NULL );\r
+       xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 1 ] ), uxPriority, NULL );\r
+       xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 2 ] ), uxPriority, NULL );\r
+       xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 3 ] ), uxPriority, NULL );\r
+       xTaskCreate( vCompetingMathTask1, "Math5", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 4 ] ), uxPriority, NULL );\r
+       xTaskCreate( vCompetingMathTask2, "Math6", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 5 ] ), uxPriority, NULL );\r
+       xTaskCreate( vCompetingMathTask3, "Math7", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 6 ] ), uxPriority, NULL );\r
+       xTaskCreate( vCompetingMathTask4, "Math8", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 7 ] ), uxPriority, NULL );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static portTASK_FUNCTION( vCompetingMathTask1, pvParameters )\r
+{\r
+volatile portDOUBLE d1, d2, d3, d4;\r
+volatile unsigned long *pulTaskCheckVariable;\r
+volatile portDOUBLE dAnswer;\r
+short sError = pdFALSE;\r
+\r
+\r
+       /* Must be called before any hardware floating point operations are\r
+       performed to let the RTOS portable layer know that this task requires\r
+       a floating point context. */\r
+       portTASK_USES_FLOATING_POINT();\r
+\r
+       d1 = 123.4567;\r
+       d2 = 2345.6789;\r
+       d3 = -918.222;\r
+\r
+       dAnswer = ( d1 + d2 ) * d3;\r
+\r
+       /* The variable this task increments to show it is still running is passed in\r
+       as the parameter. */\r
+       pulTaskCheckVariable = ( unsigned long * ) pvParameters;\r
+    \r
+       /* Keep performing a calculation and checking the result against a constant. */\r
+       for(;;)\r
+       {\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
+               {\r
+                       sError = pdTRUE;\r
+               }\r
+\r
+               if( sError == pdFALSE )\r
+               {\r
+                       /* If the calculation has always been correct, increment the check\r
+                       variable so we know this task is still running okay. */\r
+                       ( *pulTaskCheckVariable )++;\r
+               }\r
+\r
+               #if configUSE_PREEMPTION == 0\r
+                       taskYIELD();\r
+               #endif\r
+\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static portTASK_FUNCTION( vCompetingMathTask2, pvParameters )\r
+{\r
+volatile portDOUBLE d1, d2, d3, d4;\r
+volatile unsigned long *pulTaskCheckVariable;\r
+volatile portDOUBLE dAnswer;\r
+short sError = pdFALSE;\r
+\r
+       /* Must be called before any hardware floating point operations are\r
+       performed to let the RTOS portable layer know that this task requires\r
+       a floating point context. */\r
+       portTASK_USES_FLOATING_POINT();\r
+\r
+       d1 = -389.38;\r
+       d2 = 32498.2;\r
+       d3 = -2.0001;\r
+\r
+       dAnswer = ( d1 / d2 ) * d3;\r
+\r
+\r
+       /* The variable this task increments to show it is still running is passed in\r
+       as the parameter. */\r
+       pulTaskCheckVariable = ( unsigned long * ) pvParameters;\r
+\r
+       /* Keep performing a calculation and checking the result against a constant. */\r
+       for( ;; )\r
+       {\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
+               {\r
+                       sError = pdTRUE;\r
+               }\r
+\r
+               if( sError == pdFALSE )\r
+               {\r
+                       /* If the calculation has always been correct, increment the check\r
+                       variable so we know\r
+                       this task is still running okay. */\r
+                       ( *pulTaskCheckVariable )++;\r
+               }\r
+\r
+               #if configUSE_PREEMPTION == 0\r
+                       taskYIELD();\r
+               #endif\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static portTASK_FUNCTION( vCompetingMathTask3, pvParameters )\r
+{\r
+volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;\r
+volatile unsigned long *pulTaskCheckVariable;\r
+const size_t xArraySize = 10;\r
+size_t xPosition;\r
+short sError = pdFALSE;\r
+\r
+       /* Must be called before any hardware floating point operations are\r
+       performed to let the RTOS portable layer know that this task requires\r
+       a floating point context. */\r
+       portTASK_USES_FLOATING_POINT();\r
+\r
+       /* The variable this task increments to show it is still running is passed in\r
+       as the parameter. */\r
+       pulTaskCheckVariable = ( unsigned long * ) pvParameters;\r
+\r
+       pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );\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
+       for( ;; )\r
+       {\r
+               dTotal1 = 0.0;\r
+               dTotal2 = 0.0;\r
+\r
+               for( xPosition = 0; xPosition < xArraySize; xPosition++ )\r
+               {\r
+                       pdArray[ xPosition ] = ( portDOUBLE ) xPosition + 5.5;\r
+                       dTotal1 += ( portDOUBLE ) 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
+               }\r
+\r
+               dDifference = dTotal1 - dTotal2;\r
+               if( fabs( dDifference ) > 0.001 )\r
+               {\r
+                       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
+                       variable so we know     this task is still running okay. */\r
+                       ( *pulTaskCheckVariable )++;\r
+               }\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static portTASK_FUNCTION( vCompetingMathTask4, pvParameters )\r
+{\r
+volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;\r
+volatile unsigned long *pulTaskCheckVariable;\r
+const size_t xArraySize = 10;\r
+size_t xPosition;\r
+short sError = pdFALSE;\r
+\r
+       /* Must be called before any hardware floating point operations are\r
+       performed to let the RTOS portable layer know that this task requires\r
+       a floating point context. */\r
+       portTASK_USES_FLOATING_POINT();\r
+\r
+       /* The variable this task increments to show it is still running is passed in\r
+       as the parameter. */\r
+       pulTaskCheckVariable = ( unsigned long * ) pvParameters;\r
+\r
+       pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );\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
+       for( ;; )\r
+       {\r
+               dTotal1 = 0.0;\r
+               dTotal2 = 0.0;\r
+\r
+               for( xPosition = 0; xPosition < xArraySize; xPosition++ )\r
+               {\r
+                       pdArray[ xPosition ] = ( portDOUBLE ) xPosition * 12.123;\r
+                       dTotal1 += ( portDOUBLE ) 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
+               }\r
+\r
+               dDifference = dTotal1 - dTotal2;\r
+               if( fabs( dDifference ) > 0.001 )\r
+               {\r
+                       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
+                       variable so we know     this task is still running okay. */\r
+                       ( *pulTaskCheckVariable )++;\r
+               }\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+/* 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
+static unsigned long ulLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };\r
+portBASE_TYPE xReturn = pdTRUE, xTask;\r
+\r
+       /* Check the maths tasks are still running by ensuring their check variables\r
+       are still incrementing. */\r
+       for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )\r
+       {\r
+               if( ulTaskCheck[ xTask ] == ulLastTaskCheck[ xTask ] )\r
+               {\r
+                       /* The check has not incremented so an error exists. */\r
+                       xReturn = pdFALSE;\r
+               }\r
+\r
+               ulLastTaskCheck[ xTask ] = ulTaskCheck[ xTask ];\r
+       }\r
+\r
+       return xReturn;\r
+}\r
+\r
+\r
+\r