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