]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PPC440_DP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/flop/flop-reg-test.c
Change version numbers in preparation for V7.6.0 release.
[freertos] / FreeRTOS / Demo / PPC440_DP_FPU_Xilinx_Virtex5_GCC / RTOSDemo / flop / flop-reg-test.c
1 /*\r
2     FreeRTOS V7.6.0 - Copyright (C) 2013 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 distribute\r
28     >>! a combined work that includes FreeRTOS without being obliged to provide\r
29     >>! the source code for proprietary components outside of the FreeRTOS\r
30     >>! 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  * Tests the floating point context save and restore mechanism.\r
68  *\r
69  * Two tasks are created - each of which is allocated a buffer of \r
70  * portNO_FLOP_REGISTERS_TO_SAVE 32bit variables into which the flop context\r
71  * of the task is saved when the task is switched out, and from which the\r
72  * flop context of the task is restored when the task is switch in.  Prior to \r
73  * the tasks being created each position in the two buffers is filled with a \r
74  * unique value - this way the flop context of each task is different.\r
75  *\r
76  * The two test tasks never block so are always in either the Running or\r
77  * Ready state.  They execute at the lowest priority so will get pre-empted\r
78  * regularly, although the yield frequently so will not get much execution\r
79  * time.  The lack of execution time is not a problem as its only the \r
80  * switching in and out that is being tested.\r
81  *\r
82  * Whenever a task is moved from the Ready to the Running state its flop \r
83  * context will be loaded from the buffer, but while the task is in the\r
84  * Running state the buffer is not used and can contain any value - in this\r
85  * case and for test purposes the task itself clears the buffer to zero.  \r
86  * The next time the task is moved out of the Running state into the\r
87  * Ready state the flop context will once more get saved to the buffer - \r
88  * overwriting the zeros.\r
89  *\r
90  * Therefore whenever the task is not in the Running state its buffer contains\r
91  * the most recent values of its floating point registers - the zeroing out\r
92  * of the buffer while the task was executing being used to ensure the values \r
93  * the buffer contains are not stale.\r
94  *\r
95  * When neither test task is in the Running state the buffers should contain\r
96  * the unique values allocated before the tasks were created.  If so then\r
97  * the floating point context has been maintained.  This check is performed\r
98  * by the 'check' task (defined in main.c) by calling \r
99  * xAreFlopRegisterTestsStillRunning().\r
100  *\r
101  * The test tasks also increment a value each time they execute.\r
102  * xAreFlopRegisterTestsStillRunning() also checks that this value has changed\r
103  * since it last ran to ensure the test tasks are still getting processing time.\r
104  */\r
105 \r
106 /* Standard includes files. */\r
107 #include <string.h>\r
108 \r
109 /* Scheduler include files. */\r
110 #include "FreeRTOS.h"\r
111 #include "task.h"\r
112 \r
113 /*-----------------------------------------------------------*/\r
114 \r
115 #define flopNUMBER_OF_TASKS             2\r
116 #define flopSTART_VALUE ( 0x0000000100000001LL )\r
117 \r
118 /*-----------------------------------------------------------*/\r
119 \r
120 /* The two test tasks as described at the top of this file. */\r
121 static void vFlopTest1( void *pvParameters );\r
122 static void vFlopTest2( void *pvParameters );\r
123 \r
124 /*-----------------------------------------------------------*/\r
125 \r
126 /* Buffers into which the flop registers will be saved.  There is a buffer for \r
127 both tasks. */\r
128 static volatile portDOUBLE dFlopRegisters[ flopNUMBER_OF_TASKS ][ portNO_FLOP_REGISTERS_TO_SAVE ];\r
129 \r
130 /* Variables that are incremented by the tasks to indicate that they are still\r
131 running. */\r
132 static volatile unsigned long ulFlop1CycleCount = 0, ulFlop2CycleCount = 0;\r
133 \r
134 /*-----------------------------------------------------------*/\r
135 \r
136 void vStartFlopRegTests( void )\r
137 {\r
138 xTaskHandle xTaskJustCreated;\r
139 unsigned portBASE_TYPE x, y;\r
140 portDOUBLE z = flopSTART_VALUE;\r
141 \r
142         /* Fill the arrays into which the flop registers are to be saved with \r
143         known values.  These are the values that will be written to the flop\r
144         registers when the tasks start, and as the tasks do not perform any\r
145         flop operations the values should never change.  Each position in the\r
146         buffer contains a different value so the flop context of each task\r
147         will be different. */\r
148         for( x = 0; x < flopNUMBER_OF_TASKS; x++ )\r
149         {\r
150                 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1); y++ )\r
151                 {\r
152                         dFlopRegisters[ x ][ y ] = z;\r
153                         z+=flopSTART_VALUE;\r
154                 }\r
155         }\r
156 \r
157 \r
158         /* Create the first task. */\r
159         xTaskCreate( vFlopTest1, ( signed char * ) "flop1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );\r
160 \r
161         /* The task     tag value is a value that can be associated with a task, but \r
162         is not used by the scheduler itself.  Its use is down to the application so\r
163         it makes a convenient place in this case to store the pointer to the buffer\r
164         into which the flop context of the task will be stored.  The first created\r
165         task uses dFlopRegisters[ 0 ], the second dFlopRegisters[ 1 ]. */\r
166         vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( dFlopRegisters[ 0 ][ 0 ] ) );\r
167 \r
168         /* Do the same for the second task. */\r
169         xTaskCreate( vFlopTest2, ( signed char * ) "flop2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );\r
170         vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( dFlopRegisters[ 1 ][ 0 ] ) );\r
171 }\r
172 /*-----------------------------------------------------------*/\r
173 \r
174 static void vFlopTest1( void *pvParameters )\r
175 {\r
176         /* Just to remove compiler warning. */\r
177         ( void ) pvParameters;\r
178 \r
179         for( ;; )\r
180         {\r
181                 /* The values from the buffer should have now been written to the flop\r
182                 registers.  Clear the buffer to ensure the same values then get written\r
183                 back the next time the task runs.  Being preempted during this memset\r
184                 could cause the test to fail, hence the critical section. */\r
185                 portENTER_CRITICAL();\r
186                         memset( ( void * ) dFlopRegisters[ 0 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( portDOUBLE ) ) );\r
187                 portEXIT_CRITICAL();\r
188 \r
189                 /* We don't have to do anything other than indicate that we are \r
190                 still running. */\r
191                 ulFlop1CycleCount++;\r
192                 taskYIELD();\r
193         }\r
194 }\r
195 /*-----------------------------------------------------------*/\r
196 \r
197 static void vFlopTest2( void *pvParameters )\r
198 {\r
199         /* Just to remove compiler warning. */\r
200         ( void ) pvParameters;\r
201 \r
202         for( ;; )\r
203         {\r
204                 /* The values from the buffer should have now been written to the flop\r
205                 registers.  Clear the buffer to ensure the same values then get written\r
206                 back the next time the task runs. */\r
207                 portENTER_CRITICAL();\r
208                         memset( ( void * ) dFlopRegisters[ 1 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( portDOUBLE ) ) );\r
209                 portEXIT_CRITICAL();\r
210 \r
211                 /* We don't have to do anything other than indicate that we are \r
212                 still running. */\r
213                 ulFlop2CycleCount++;\r
214                 taskYIELD();\r
215         }\r
216 }\r
217 /*-----------------------------------------------------------*/\r
218 \r
219 portBASE_TYPE xAreFlopRegisterTestsStillRunning( void )\r
220 {\r
221 portBASE_TYPE xReturn = pdPASS;\r
222 unsigned portBASE_TYPE x, y;\r
223 portDOUBLE z = flopSTART_VALUE;\r
224 static unsigned long ulLastFlop1CycleCount = 0, ulLastFlop2CycleCount = 0;\r
225 \r
226         /* Called from the 'check' task.\r
227         \r
228         The flop tasks cannot be currently running, check their saved registers\r
229         are as expected.  The tests tasks do not perform any flop operations so\r
230         their registers should be as per their initial setting. */\r
231         for( x = 0; x < flopNUMBER_OF_TASKS; x++ )\r
232         {\r
233                 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )\r
234                 {\r
235                         if( dFlopRegisters[ x ][ y ] != z )\r
236                         {\r
237                                 xReturn = pdFAIL;\r
238                                 break;\r
239                         }\r
240 \r
241                         z+=flopSTART_VALUE;\r
242                 }\r
243         }\r
244 \r
245         /* Check both tasks have actually been swapped in and out since this function\r
246         last executed. */\r
247         if( ulFlop1CycleCount == ulLastFlop1CycleCount )\r
248         {\r
249                 xReturn = pdFAIL;\r
250         }\r
251 \r
252         if( ulFlop2CycleCount == ulLastFlop2CycleCount )\r
253         {\r
254                 xReturn = pdFAIL;\r
255         }\r
256 \r
257         ulLastFlop1CycleCount = ulFlop1CycleCount;\r
258         ulLastFlop2CycleCount = ulFlop2CycleCount;\r
259 \r
260         return xReturn;\r
261 }\r
262 \r