]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PPC440_DP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/flop/flop-reg-test.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Demo / PPC440_DP_FPU_Xilinx_Virtex5_GCC / RTOSDemo / flop / flop-reg-test.c
1 /*\r
2     FreeRTOS V9.0.0rc2 - Copyright (C) 2016 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     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /*\r
71  * Tests the floating point context save and restore mechanism.\r
72  *\r
73  * Two tasks are created - each of which is allocated a buffer of \r
74  * portNO_FLOP_REGISTERS_TO_SAVE 32bit variables into which the flop context\r
75  * of the task is saved when the task is switched out, and from which the\r
76  * flop context of the task is restored when the task is switch in.  Prior to \r
77  * the tasks being created each position in the two buffers is filled with a \r
78  * unique value - this way the flop context of each task is different.\r
79  *\r
80  * The two test tasks never block so are always in either the Running or\r
81  * Ready state.  They execute at the lowest priority so will get pre-empted\r
82  * regularly, although the yield frequently so will not get much execution\r
83  * time.  The lack of execution time is not a problem as its only the \r
84  * switching in and out that is being tested.\r
85  *\r
86  * Whenever a task is moved from the Ready to the Running state its flop \r
87  * context will be loaded from the buffer, but while the task is in the\r
88  * Running state the buffer is not used and can contain any value - in this\r
89  * case and for test purposes the task itself clears the buffer to zero.  \r
90  * The next time the task is moved out of the Running state into the\r
91  * Ready state the flop context will once more get saved to the buffer - \r
92  * overwriting the zeros.\r
93  *\r
94  * Therefore whenever the task is not in the Running state its buffer contains\r
95  * the most recent values of its floating point registers - the zeroing out\r
96  * of the buffer while the task was executing being used to ensure the values \r
97  * the buffer contains are not stale.\r
98  *\r
99  * When neither test task is in the Running state the buffers should contain\r
100  * the unique values allocated before the tasks were created.  If so then\r
101  * the floating point context has been maintained.  This check is performed\r
102  * by the 'check' task (defined in main.c) by calling \r
103  * xAreFlopRegisterTestsStillRunning().\r
104  *\r
105  * The test tasks also increment a value each time they execute.\r
106  * xAreFlopRegisterTestsStillRunning() also checks that this value has changed\r
107  * since it last ran to ensure the test tasks are still getting processing time.\r
108  */\r
109 \r
110 /* Standard includes files. */\r
111 #include <string.h>\r
112 \r
113 /* Scheduler include files. */\r
114 #include "FreeRTOS.h"\r
115 #include "task.h"\r
116 \r
117 /*-----------------------------------------------------------*/\r
118 \r
119 #define flopNUMBER_OF_TASKS             2\r
120 #define flopSTART_VALUE ( 0x0000000100000001LL )\r
121 \r
122 /*-----------------------------------------------------------*/\r
123 \r
124 /* The two test tasks as described at the top of this file. */\r
125 static void vFlopTest1( void *pvParameters );\r
126 static void vFlopTest2( void *pvParameters );\r
127 \r
128 /*-----------------------------------------------------------*/\r
129 \r
130 /* Buffers into which the flop registers will be saved.  There is a buffer for \r
131 both tasks. */\r
132 static volatile portDOUBLE dFlopRegisters[ flopNUMBER_OF_TASKS ][ portNO_FLOP_REGISTERS_TO_SAVE ];\r
133 \r
134 /* Variables that are incremented by the tasks to indicate that they are still\r
135 running. */\r
136 static volatile unsigned long ulFlop1CycleCount = 0, ulFlop2CycleCount = 0;\r
137 \r
138 /*-----------------------------------------------------------*/\r
139 \r
140 void vStartFlopRegTests( void )\r
141 {\r
142 TaskHandle_t xTaskJustCreated;\r
143 unsigned portBASE_TYPE x, y;\r
144 portDOUBLE z = flopSTART_VALUE;\r
145 \r
146         /* Fill the arrays into which the flop registers are to be saved with \r
147         known values.  These are the values that will be written to the flop\r
148         registers when the tasks start, and as the tasks do not perform any\r
149         flop operations the values should never change.  Each position in the\r
150         buffer contains a different value so the flop context of each task\r
151         will be different. */\r
152         for( x = 0; x < flopNUMBER_OF_TASKS; x++ )\r
153         {\r
154                 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1); y++ )\r
155                 {\r
156                         dFlopRegisters[ x ][ y ] = z;\r
157                         z+=flopSTART_VALUE;\r
158                 }\r
159         }\r
160 \r
161 \r
162         /* Create the first task. */\r
163         xTaskCreate( vFlopTest1, "flop1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );\r
164 \r
165         /* The task     tag value is a value that can be associated with a task, but \r
166         is not used by the scheduler itself.  Its use is down to the application so\r
167         it makes a convenient place in this case to store the pointer to the buffer\r
168         into which the flop context of the task will be stored.  The first created\r
169         task uses dFlopRegisters[ 0 ], the second dFlopRegisters[ 1 ]. */\r
170         vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( dFlopRegisters[ 0 ][ 0 ] ) );\r
171 \r
172         /* Do the same for the second task. */\r
173         xTaskCreate( vFlopTest2, "flop2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );\r
174         vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( dFlopRegisters[ 1 ][ 0 ] ) );\r
175 }\r
176 /*-----------------------------------------------------------*/\r
177 \r
178 static void vFlopTest1( void *pvParameters )\r
179 {\r
180         /* Just to remove compiler warning. */\r
181         ( void ) pvParameters;\r
182 \r
183         for( ;; )\r
184         {\r
185                 /* The values from the buffer should have now been written to the flop\r
186                 registers.  Clear the buffer to ensure the same values then get written\r
187                 back the next time the task runs.  Being preempted during this memset\r
188                 could cause the test to fail, hence the critical section. */\r
189                 portENTER_CRITICAL();\r
190                         memset( ( void * ) dFlopRegisters[ 0 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( portDOUBLE ) ) );\r
191                 portEXIT_CRITICAL();\r
192 \r
193                 /* We don't have to do anything other than indicate that we are \r
194                 still running. */\r
195                 ulFlop1CycleCount++;\r
196                 taskYIELD();\r
197         }\r
198 }\r
199 /*-----------------------------------------------------------*/\r
200 \r
201 static void vFlopTest2( void *pvParameters )\r
202 {\r
203         /* Just to remove compiler warning. */\r
204         ( void ) pvParameters;\r
205 \r
206         for( ;; )\r
207         {\r
208                 /* The values from the buffer should have now been written to the flop\r
209                 registers.  Clear the buffer to ensure the same values then get written\r
210                 back the next time the task runs. */\r
211                 portENTER_CRITICAL();\r
212                         memset( ( void * ) dFlopRegisters[ 1 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( portDOUBLE ) ) );\r
213                 portEXIT_CRITICAL();\r
214 \r
215                 /* We don't have to do anything other than indicate that we are \r
216                 still running. */\r
217                 ulFlop2CycleCount++;\r
218                 taskYIELD();\r
219         }\r
220 }\r
221 /*-----------------------------------------------------------*/\r
222 \r
223 portBASE_TYPE xAreFlopRegisterTestsStillRunning( void )\r
224 {\r
225 portBASE_TYPE xReturn = pdPASS;\r
226 unsigned portBASE_TYPE x, y;\r
227 portDOUBLE z = flopSTART_VALUE;\r
228 static unsigned long ulLastFlop1CycleCount = 0, ulLastFlop2CycleCount = 0;\r
229 \r
230         /* Called from the 'check' task.\r
231         \r
232         The flop tasks cannot be currently running, check their saved registers\r
233         are as expected.  The tests tasks do not perform any flop operations so\r
234         their registers should be as per their initial setting. */\r
235         for( x = 0; x < flopNUMBER_OF_TASKS; x++ )\r
236         {\r
237                 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )\r
238                 {\r
239                         if( dFlopRegisters[ x ][ y ] != z )\r
240                         {\r
241                                 xReturn = pdFAIL;\r
242                                 break;\r
243                         }\r
244 \r
245                         z+=flopSTART_VALUE;\r
246                 }\r
247         }\r
248 \r
249         /* Check both tasks have actually been swapped in and out since this function\r
250         last executed. */\r
251         if( ulFlop1CycleCount == ulLastFlop1CycleCount )\r
252         {\r
253                 xReturn = pdFAIL;\r
254         }\r
255 \r
256         if( ulFlop2CycleCount == ulLastFlop2CycleCount )\r
257         {\r
258                 xReturn = pdFAIL;\r
259         }\r
260 \r
261         ulLastFlop1CycleCount = ulFlop1CycleCount;\r
262         ulLastFlop2CycleCount = ulFlop2CycleCount;\r
263 \r
264         return xReturn;\r
265 }\r
266 \r