]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R4_RM48_TMS570_CCS5/flop_hercules.c
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS / Demo / CORTEX_R4_RM48_TMS570_CCS5 / flop_hercules.c
1 /*\r
2     FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS kernel.                                   !<<\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 /*\r
67  * Creates eight tasks, each of which loops continuously performing an (emulated)\r
68  * floating point calculation.\r
69  *\r
70  * All the tasks run at the idle priority and never block or yield.  This causes\r
71  * all eight tasks to time slice with the idle task.  Running at the idle priority\r
72  * means that these tasks will get pre-empted any time another task is ready to run\r
73  * or a time slice occurs.  More often than not the pre-emption will occur mid\r
74  * calculation, creating a good test of the schedulers context switch mechanism - a\r
75  * calculation producing an unexpected result could be a symptom of a corruption in\r
76  * the context of a task.\r
77  */\r
78 \r
79 #include <stdlib.h>\r
80 #include <math.h>\r
81 \r
82 /* Scheduler include files. */\r
83 #include "FreeRTOS.h"\r
84 #include "task.h"\r
85 \r
86 /* Demo program include files. */\r
87 #include "flop.h"\r
88 \r
89 #define mathSTACK_SIZE          configMINIMAL_STACK_SIZE\r
90 #define mathNUMBER_OF_TASKS  ( 8 )\r
91 \r
92 /* Four tasks, each of which performs a different floating point calculation.\r
93 Each of the four is created twice. */\r
94 static portTASK_FUNCTION_PROTO( vCompetingMathTask1, pvParameters );\r
95 static portTASK_FUNCTION_PROTO( vCompetingMathTask2, pvParameters );\r
96 static portTASK_FUNCTION_PROTO( vCompetingMathTask3, pvParameters );\r
97 static portTASK_FUNCTION_PROTO( vCompetingMathTask4, pvParameters );\r
98 \r
99 /* These variables are used to check that all the tasks are still running.  If a\r
100 task gets a calculation wrong it will\r
101 stop incrementing its check variable. */\r
102 static volatile unsigned long ulTaskCheck[ mathNUMBER_OF_TASKS ] = { 0 };\r
103 \r
104 /* Must be called before any hardware floating point operations are\r
105 performed to let the RTOS portable layer know that this task requires\r
106 a floating point context. */\r
107 #if __TI_VFP_SUPPORT__\r
108         extern void vPortTaskUsesFPU( void );\r
109 #endif\r
110 \r
111 /*-----------------------------------------------------------*/\r
112 \r
113 void vStartMathTasks( unsigned portBASE_TYPE uxPriority )\r
114 {\r
115         xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 0 ] ), uxPriority, NULL );\r
116         xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 1 ] ), uxPriority, NULL );\r
117         xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 2 ] ), uxPriority, NULL );\r
118         xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 3 ] ), uxPriority, NULL );\r
119         xTaskCreate( vCompetingMathTask1, "Math5", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 4 ] ), uxPriority, NULL );\r
120         xTaskCreate( vCompetingMathTask2, "Math6", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 5 ] ), uxPriority, NULL );\r
121         xTaskCreate( vCompetingMathTask3, "Math7", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 6 ] ), uxPriority, NULL );\r
122         xTaskCreate( vCompetingMathTask4, "Math8", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 7 ] ), uxPriority, NULL );\r
123 }\r
124 /*-----------------------------------------------------------*/\r
125 \r
126 static portTASK_FUNCTION( vCompetingMathTask1, pvParameters )\r
127 {\r
128 volatile portDOUBLE d1, d2, d3, d4;\r
129 volatile unsigned long *pulTaskCheckVariable;\r
130 volatile portDOUBLE dAnswer;\r
131 short sError = pdFALSE;\r
132 \r
133 \r
134         /* Must be called before any hardware floating point operations are\r
135         performed to let the RTOS portable layer know that this task requires\r
136         a floating point context. */\r
137         #if __TI_VFP_SUPPORT__\r
138                 vPortTaskUsesFPU();\r
139         #endif\r
140 \r
141         d1 = 123.4567;\r
142         d2 = 2345.6789;\r
143         d3 = -918.222;\r
144 \r
145         dAnswer = ( d1 + d2 ) * d3;\r
146 \r
147         /* The variable this task increments to show it is still running is passed in\r
148         as the parameter. */\r
149         pulTaskCheckVariable = ( unsigned long * ) pvParameters;\r
150 \r
151         /* Keep performing a calculation and checking the result against a constant. */\r
152         for(;;)\r
153         {\r
154                 d1 = 123.4567;\r
155                 d2 = 2345.6789;\r
156                 d3 = -918.222;\r
157 \r
158                 d4 = ( d1 + d2 ) * d3;\r
159 \r
160                 #if configUSE_PREEMPTION == 0\r
161                         taskYIELD();\r
162                 #endif\r
163 \r
164                 /* If the calculation does not match the expected constant, stop the\r
165                 increment of the check variable. */\r
166                 if( fabs( d4 - dAnswer ) > 0.001 )\r
167                 {\r
168                         sError = pdTRUE;\r
169                 }\r
170 \r
171                 if( sError == pdFALSE )\r
172                 {\r
173                         /* If the calculation has always been correct, increment the check\r
174                         variable so we know this task is still running okay. */\r
175                         ( *pulTaskCheckVariable )++;\r
176                 }\r
177 \r
178                 #if configUSE_PREEMPTION == 0\r
179                         taskYIELD();\r
180                 #endif\r
181 \r
182         }\r
183 }\r
184 /*-----------------------------------------------------------*/\r
185 \r
186 static portTASK_FUNCTION( vCompetingMathTask2, pvParameters )\r
187 {\r
188 volatile portDOUBLE d1, d2, d3, d4;\r
189 volatile unsigned long *pulTaskCheckVariable;\r
190 volatile portDOUBLE dAnswer;\r
191 short sError = pdFALSE;\r
192 \r
193         /* Must be called before any hardware floating point operations are\r
194         performed to let the RTOS portable layer know that this task requires\r
195         a floating point context. */\r
196         #if __TI_VFP_SUPPORT__\r
197                 vPortTaskUsesFPU();\r
198         #endif\r
199 \r
200         d1 = -389.38;\r
201         d2 = 32498.2;\r
202         d3 = -2.0001;\r
203 \r
204         dAnswer = ( d1 / d2 ) * d3;\r
205 \r
206 \r
207         /* The variable this task increments to show it is still running is passed in\r
208         as the parameter. */\r
209         pulTaskCheckVariable = ( unsigned long * ) pvParameters;\r
210 \r
211         /* Keep performing a calculation and checking the result against a constant. */\r
212         for( ;; )\r
213         {\r
214                 d1 = -389.38;\r
215                 d2 = 32498.2;\r
216                 d3 = -2.0001;\r
217 \r
218                 d4 = ( d1 / d2 ) * d3;\r
219 \r
220                 #if configUSE_PREEMPTION == 0\r
221                         taskYIELD();\r
222                 #endif\r
223 \r
224                 /* If the calculation does not match the expected constant, stop the\r
225                 increment of the check variable. */\r
226                 if( fabs( d4 - dAnswer ) > 0.001 )\r
227                 {\r
228                         sError = pdTRUE;\r
229                 }\r
230 \r
231                 if( sError == pdFALSE )\r
232                 {\r
233                         /* If the calculation has always been correct, increment the check\r
234                         variable so we know\r
235                         this task is still running okay. */\r
236                         ( *pulTaskCheckVariable )++;\r
237                 }\r
238 \r
239                 #if configUSE_PREEMPTION == 0\r
240                         taskYIELD();\r
241                 #endif\r
242         }\r
243 }\r
244 /*-----------------------------------------------------------*/\r
245 \r
246 static portTASK_FUNCTION( vCompetingMathTask3, pvParameters )\r
247 {\r
248 volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;\r
249 volatile unsigned long *pulTaskCheckVariable;\r
250 const size_t xArraySize = 10;\r
251 size_t xPosition;\r
252 short sError = pdFALSE;\r
253 \r
254         /* Must be called before any hardware floating point operations are\r
255         performed to let the RTOS portable layer know that this task requires\r
256         a floating point context. */\r
257         #if __TI_VFP_SUPPORT__\r
258                 vPortTaskUsesFPU();\r
259         #endif\r
260 \r
261         /* The variable this task increments to show it is still running is passed in\r
262         as the parameter. */\r
263         pulTaskCheckVariable = ( unsigned long * ) pvParameters;\r
264 \r
265         pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );\r
266 \r
267         /* Keep filling an array, keeping a running total of the values placed in the\r
268         array.  Then run through the array adding up all the values.  If the two totals\r
269         do not match, stop the check variable from incrementing. */\r
270         for( ;; )\r
271         {\r
272                 dTotal1 = 0.0;\r
273                 dTotal2 = 0.0;\r
274 \r
275                 for( xPosition = 0; xPosition < xArraySize; xPosition++ )\r
276                 {\r
277                         pdArray[ xPosition ] = ( portDOUBLE ) xPosition + 5.5;\r
278                         dTotal1 += ( portDOUBLE ) xPosition + 5.5;\r
279                 }\r
280 \r
281                 #if configUSE_PREEMPTION == 0\r
282                         taskYIELD();\r
283                 #endif\r
284 \r
285                 for( xPosition = 0; xPosition < xArraySize; xPosition++ )\r
286                 {\r
287                         dTotal2 += pdArray[ xPosition ];\r
288                 }\r
289 \r
290                 dDifference = dTotal1 - dTotal2;\r
291                 if( fabs( dDifference ) > 0.001 )\r
292                 {\r
293                         sError = pdTRUE;\r
294                 }\r
295 \r
296                 #if configUSE_PREEMPTION == 0\r
297                         taskYIELD();\r
298                 #endif\r
299 \r
300                 if( sError == pdFALSE )\r
301                 {\r
302                         /* If the calculation has always been correct, increment the check\r
303                         variable so we know     this task is still running okay. */\r
304                         ( *pulTaskCheckVariable )++;\r
305                 }\r
306         }\r
307 }\r
308 /*-----------------------------------------------------------*/\r
309 \r
310 static portTASK_FUNCTION( vCompetingMathTask4, pvParameters )\r
311 {\r
312 volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;\r
313 volatile unsigned long *pulTaskCheckVariable;\r
314 const size_t xArraySize = 10;\r
315 size_t xPosition;\r
316 short sError = pdFALSE;\r
317 \r
318         /* Must be called before any hardware floating point operations are\r
319         performed to let the RTOS portable layer know that this task requires\r
320         a floating point context. */\r
321         #if __TI_VFP_SUPPORT__\r
322                 vPortTaskUsesFPU();\r
323         #endif\r
324 \r
325         /* The variable this task increments to show it is still running is passed in\r
326         as the parameter. */\r
327         pulTaskCheckVariable = ( unsigned long * ) pvParameters;\r
328 \r
329         pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );\r
330 \r
331         /* Keep filling an array, keeping a running total of the values placed in the\r
332         array.  Then run through the array adding up all the values.  If the two totals\r
333         do not match, stop the check variable from incrementing. */\r
334         for( ;; )\r
335         {\r
336                 dTotal1 = 0.0;\r
337                 dTotal2 = 0.0;\r
338 \r
339                 for( xPosition = 0; xPosition < xArraySize; xPosition++ )\r
340                 {\r
341                         pdArray[ xPosition ] = ( portDOUBLE ) xPosition * 12.123;\r
342                         dTotal1 += ( portDOUBLE ) xPosition * 12.123;\r
343                 }\r
344 \r
345                 #if configUSE_PREEMPTION == 0\r
346                         taskYIELD();\r
347                 #endif\r
348 \r
349                 for( xPosition = 0; xPosition < xArraySize; xPosition++ )\r
350                 {\r
351                         dTotal2 += pdArray[ xPosition ];\r
352                 }\r
353 \r
354                 dDifference = dTotal1 - dTotal2;\r
355                 if( fabs( dDifference ) > 0.001 )\r
356                 {\r
357                         sError = pdTRUE;\r
358                 }\r
359 \r
360                 #if configUSE_PREEMPTION == 0\r
361                         taskYIELD();\r
362                 #endif\r
363 \r
364                 if( sError == pdFALSE )\r
365                 {\r
366                         /* If the calculation has always been correct, increment the check\r
367                         variable so we know     this task is still running okay. */\r
368                         ( *pulTaskCheckVariable )++;\r
369                 }\r
370         }\r
371 }\r
372 /*-----------------------------------------------------------*/\r
373 \r
374 /* This is called to check that all the created tasks are still running. */\r
375 portBASE_TYPE xAreMathsTaskStillRunning( void )\r
376 {\r
377 /* Keep a history of the check variables so we know if they have been incremented\r
378 since the last call. */\r
379 static unsigned long ulLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };\r
380 portBASE_TYPE xReturn = pdTRUE, xTask;\r
381 \r
382         /* Check the maths tasks are still running by ensuring their check variables\r
383         are still incrementing. */\r
384         for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )\r
385         {\r
386                 if( ulTaskCheck[ xTask ] == ulLastTaskCheck[ xTask ] )\r
387                 {\r
388                         /* The check has not incremented so an error exists. */\r
389                         xReturn = pdFALSE;\r
390                 }\r
391 \r
392                 ulLastTaskCheck[ xTask ] = ulTaskCheck[ xTask ];\r
393         }\r
394 \r
395         return xReturn;\r
396 }\r
397 \r
398 \r
399 \r