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