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