]> git.sur5r.net Git - freertos/blob - Demo/PPC440_DP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/flop/flop-reg-test.c
Remove unnecessary use of portLONG, portCHAR and portSHORT.
[freertos] / Demo / PPC440_DP_FPU_Xilinx_Virtex5_GCC / RTOSDemo / flop / flop-reg-test.c
1 /*\r
2     FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.\r
3 \r
4     This file is part of the FreeRTOS distribution.\r
5 \r
6     FreeRTOS is free software; you can redistribute it and/or modify it    under\r
7     the terms of the GNU General Public License (version 2) as published by the\r
8     Free Software Foundation and modified by the FreeRTOS exception.\r
9     **NOTE** The exception to the GPL is included to allow you to distribute a\r
10     combined work that includes FreeRTOS without being obliged to provide the\r
11     source code for proprietary components outside of the FreeRTOS kernel.\r
12     Alternative commercial license and support terms are also available upon\r
13     request.  See the licensing section of http://www.FreeRTOS.org for full\r
14     license details.\r
15 \r
16     FreeRTOS is distributed in the hope that it will be useful,    but WITHOUT\r
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
19     more details.\r
20 \r
21     You should have received a copy of the GNU General Public License along\r
22     with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59\r
23     Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
24 \r
25 \r
26     ***************************************************************************\r
27     *                                                                         *\r
28     * The FreeRTOS eBook and reference manual are available to purchase for a *\r
29     * small fee. Help yourself get started quickly while also helping the     *\r
30     * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *\r
31     *                                                                         *\r
32     ***************************************************************************\r
33 \r
34     1 tab == 4 spaces!\r
35 \r
36     Please ensure to read the configuration and relevant port sections of the\r
37     online documentation.\r
38 \r
39     http://www.FreeRTOS.org - Documentation, latest information, license and\r
40     contact details.\r
41 \r
42     http://www.SafeRTOS.com - A version that is certified for use in safety\r
43     critical systems.\r
44 \r
45     http://www.OpenRTOS.com - Commercial support, development, porting,\r
46     licensing and training services.\r
47 */\r
48 \r
49 /*\r
50  * Tests the floating point context save and restore mechanism.\r
51  *\r
52  * Two tasks are created - each of which is allocated a buffer of \r
53  * portNO_FLOP_REGISTERS_TO_SAVE 32bit variables into which the flop context\r
54  * of the task is saved when the task is switched out, and from which the\r
55  * flop context of the task is restored when the task is switch in.  Prior to \r
56  * the tasks being created each position in the two buffers is filled with a \r
57  * unique value - this way the flop context of each task is different.\r
58  *\r
59  * The two test tasks never block so are always in either the Running or\r
60  * Ready state.  They execute at the lowest priority so will get pre-empted\r
61  * regularly, although the yield frequently so will not get much execution\r
62  * time.  The lack of execution time is not a problem as its only the \r
63  * switching in and out that is being tested.\r
64  *\r
65  * Whenever a task is moved from the Ready to the Running state its flop \r
66  * context will be loaded from the buffer, but while the task is in the\r
67  * Running state the buffer is not used and can contain any value - in this\r
68  * case and for test purposes the task itself clears the buffer to zero.  \r
69  * The next time the task is moved out of the Running state into the\r
70  * Ready state the flop context will once more get saved to the buffer - \r
71  * overwriting the zeros.\r
72  *\r
73  * Therefore whenever the task is not in the Running state its buffer contains\r
74  * the most recent values of its floating point registers - the zeroing out\r
75  * of the buffer while the task was executing being used to ensure the values \r
76  * the buffer contains are not stale.\r
77  *\r
78  * When neither test task is in the Running state the buffers should contain\r
79  * the unique values allocated before the tasks were created.  If so then\r
80  * the floating point context has been maintained.  This check is performed\r
81  * by the 'check' task (defined in main.c) by calling \r
82  * xAreFlopRegisterTestsStillRunning().\r
83  *\r
84  * The test tasks also increment a value each time they execute.\r
85  * xAreFlopRegisterTestsStillRunning() also checks that this value has changed\r
86  * since it last ran to ensure the test tasks are still getting processing time.\r
87  */\r
88 \r
89 /* Standard includes files. */\r
90 #include <string.h>\r
91 \r
92 /* Scheduler include files. */\r
93 #include "FreeRTOS.h"\r
94 #include "task.h"\r
95 \r
96 /*-----------------------------------------------------------*/\r
97 \r
98 #define flopNUMBER_OF_TASKS             2\r
99 #define flopSTART_VALUE ( 0x0000000100000001LL )\r
100 \r
101 /*-----------------------------------------------------------*/\r
102 \r
103 /* The two test tasks as described at the top of this file. */\r
104 static void vFlopTest1( void *pvParameters );\r
105 static void vFlopTest2( void *pvParameters );\r
106 \r
107 /*-----------------------------------------------------------*/\r
108 \r
109 /* Buffers into which the flop registers will be saved.  There is a buffer for \r
110 both tasks. */\r
111 static volatile portDOUBLE dFlopRegisters[ flopNUMBER_OF_TASKS ][ portNO_FLOP_REGISTERS_TO_SAVE ];\r
112 \r
113 /* Variables that are incremented by the tasks to indicate that they are still\r
114 running. */\r
115 static volatile unsigned long ulFlop1CycleCount = 0, ulFlop2CycleCount = 0;\r
116 \r
117 /*-----------------------------------------------------------*/\r
118 \r
119 void vStartFlopRegTests( void )\r
120 {\r
121 xTaskHandle xTaskJustCreated;\r
122 unsigned portBASE_TYPE x, y;\r
123 portDOUBLE z = flopSTART_VALUE;\r
124 \r
125         /* Fill the arrays into which the flop registers are to be saved with \r
126         known values.  These are the values that will be written to the flop\r
127         registers when the tasks start, and as the tasks do not perform any\r
128         flop operations the values should never change.  Each position in the\r
129         buffer contains a different value so the flop context of each task\r
130         will be different. */\r
131         for( x = 0; x < flopNUMBER_OF_TASKS; x++ )\r
132         {\r
133                 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1); y++ )\r
134                 {\r
135                         dFlopRegisters[ x ][ y ] = z;\r
136                         z+=flopSTART_VALUE;\r
137                 }\r
138         }\r
139 \r
140 \r
141         /* Create the first task. */\r
142         xTaskCreate( vFlopTest1, ( signed char * ) "flop1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );\r
143 \r
144         /* The task     tag value is a value that can be associated with a task, but \r
145         is not used by the scheduler itself.  Its use is down to the application so\r
146         it makes a convenient place in this case to store the pointer to the buffer\r
147         into which the flop context of the task will be stored.  The first created\r
148         task uses dFlopRegisters[ 0 ], the second dFlopRegisters[ 1 ]. */\r
149         vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( dFlopRegisters[ 0 ][ 0 ] ) );\r
150 \r
151         /* Do the same for the second task. */\r
152         xTaskCreate( vFlopTest2, ( signed char * ) "flop2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );\r
153         vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( dFlopRegisters[ 1 ][ 0 ] ) );\r
154 }\r
155 /*-----------------------------------------------------------*/\r
156 \r
157 static void vFlopTest1( void *pvParameters )\r
158 {\r
159         /* Just to remove compiler warning. */\r
160         ( void ) pvParameters;\r
161 \r
162         for( ;; )\r
163         {\r
164                 /* The values from the buffer should have now been written to the flop\r
165                 registers.  Clear the buffer to ensure the same values then get written\r
166                 back the next time the task runs.  Being preempted during this memset\r
167                 could cause the test to fail, hence the critical section. */\r
168                 portENTER_CRITICAL();\r
169                         memset( ( void * ) dFlopRegisters[ 0 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( portDOUBLE ) ) );\r
170                 portEXIT_CRITICAL();\r
171 \r
172                 /* We don't have to do anything other than indicate that we are \r
173                 still running. */\r
174                 ulFlop1CycleCount++;\r
175                 taskYIELD();\r
176         }\r
177 }\r
178 /*-----------------------------------------------------------*/\r
179 \r
180 static void vFlopTest2( void *pvParameters )\r
181 {\r
182         /* Just to remove compiler warning. */\r
183         ( void ) pvParameters;\r
184 \r
185         for( ;; )\r
186         {\r
187                 /* The values from the buffer should have now been written to the flop\r
188                 registers.  Clear the buffer to ensure the same values then get written\r
189                 back the next time the task runs. */\r
190                 portENTER_CRITICAL();\r
191                         memset( ( void * ) dFlopRegisters[ 1 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( portDOUBLE ) ) );\r
192                 portEXIT_CRITICAL();\r
193 \r
194                 /* We don't have to do anything other than indicate that we are \r
195                 still running. */\r
196                 ulFlop2CycleCount++;\r
197                 taskYIELD();\r
198         }\r
199 }\r
200 /*-----------------------------------------------------------*/\r
201 \r
202 portBASE_TYPE xAreFlopRegisterTestsStillRunning( void )\r
203 {\r
204 portBASE_TYPE xReturn = pdPASS;\r
205 unsigned portBASE_TYPE x, y;\r
206 portDOUBLE z = flopSTART_VALUE;\r
207 static unsigned long ulLastFlop1CycleCount = 0, ulLastFlop2CycleCount = 0;\r
208 \r
209         /* Called from the 'check' task.\r
210         \r
211         The flop tasks cannot be currently running, check their saved registers\r
212         are as expected.  The tests tasks do not perform any flop operations so\r
213         their registers should be as per their initial setting. */\r
214         for( x = 0; x < flopNUMBER_OF_TASKS; x++ )\r
215         {\r
216                 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )\r
217                 {\r
218                         if( dFlopRegisters[ x ][ y ] != z )\r
219                         {\r
220                                 xReturn = pdFAIL;\r
221                                 break;\r
222                         }\r
223 \r
224                         z+=flopSTART_VALUE;\r
225                 }\r
226         }\r
227 \r
228         /* Check both tasks have actually been swapped in and out since this function\r
229         last executed. */\r
230         if( ulFlop1CycleCount == ulLastFlop1CycleCount )\r
231         {\r
232                 xReturn = pdFAIL;\r
233         }\r
234 \r
235         if( ulFlop2CycleCount == ulLastFlop2CycleCount )\r
236         {\r
237                 xReturn = pdFAIL;\r
238         }\r
239 \r
240         ulLastFlop1CycleCount = ulFlop1CycleCount;\r
241         ulLastFlop2CycleCount = ulFlop2CycleCount;\r
242 \r
243         return xReturn;\r
244 }\r
245 \r