]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PPC405_FPU_Xilinx_Virtex4_GCC/RTOSDemo/flop/flop-reg-test.c
Prepare for V7.2.0 release.
[freertos] / FreeRTOS / Demo / PPC405_FPU_Xilinx_Virtex4_GCC / RTOSDemo / flop / flop-reg-test.c
1 /*\r
2     FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\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 modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or 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     ***************************************************************************\r
45      *                                                                       *\r
46      *    Having a problem?  Start by reading the FAQ "My application does   *\r
47      *    not run, what could be wrong?                                      *\r
48      *                                                                       *\r
49      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
50      *                                                                       *\r
51     ***************************************************************************\r
52 \r
53     \r
54     http://www.FreeRTOS.org - Documentation, training, latest information, \r
55     license and contact details.\r
56     \r
57     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
58     including FreeRTOS+Trace - an indispensable productivity tool.\r
59 \r
60     Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
61     the code with commercial support, indemnification, and middleware, under \r
62     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
63     provide a safety engineered and independently SIL3 certified version under \r
64     the SafeRTOS brand: http://www.SafeRTOS.com.\r
65 */\r
66 \r
67 /*\r
68  * Tests the floating point context save and restore mechanism.\r
69  *\r
70  * Two tasks are created - each of which is allocated a buffer of \r
71  * portNO_FLOP_REGISTERS_TO_SAVE 32bit variables into which the flop context\r
72  * of the task is saved when the task is switched out, and from which the\r
73  * flop context of the task is restored when the task is switch in.  Prior to \r
74  * the tasks being created each position in the two buffers is filled with a \r
75  * unique value - this way the flop context of each task is different.\r
76  *\r
77  * The two test tasks never block so are always in either the Running or\r
78  * Ready state.  They execute at the lowest priority so will get pre-empted\r
79  * regularly, although the yield frequently so will not get much execution\r
80  * time.  The lack of execution time is not a problem as its only the \r
81  * switching in and out that is being tested.\r
82  *\r
83  * Whenever a task is moved from the Ready to the Running state its flop \r
84  * context will be loaded from the buffer, but while the task is in the\r
85  * Running state the buffer is not used and can contain any value - in this\r
86  * case and for test purposes the task itself clears the buffer to zero.  \r
87  * The next time the task is moved out of the Running state into the\r
88  * Ready state the flop context will once more get saved to the buffer - \r
89  * overwriting the zeros.\r
90  *\r
91  * Therefore whenever the task is not in the Running state its buffer contains\r
92  * the most recent values of its floating point registers - the zeroing out\r
93  * of the buffer while the task was executing being used to ensure the values \r
94  * the buffer contains are not stale.\r
95  *\r
96  * When neither test task is in the Running state the buffers should contain\r
97  * the unique values allocated before the tasks were created.  If so then\r
98  * the floating point context has been maintained.  This check is performed\r
99  * by the 'check' task (defined in main.c) by calling \r
100  * xAreFlopRegisterTestsStillRunning().\r
101  *\r
102  * The test tasks also increment a value each time they execute.\r
103  * xAreFlopRegisterTestsStillRunning() also checks that this value has changed\r
104  * since it last ran to ensure the test tasks are still getting processing time.\r
105  */\r
106 \r
107 /* Standard includes files. */\r
108 #include <string.h>\r
109 \r
110 /* Scheduler include files. */\r
111 #include "FreeRTOS.h"\r
112 #include "task.h"\r
113 \r
114 /*-----------------------------------------------------------*/\r
115 \r
116 #define flopNUMBER_OF_TASKS             2\r
117 #define flopSTART_VALUE ( 0x1 )\r
118 \r
119 /*-----------------------------------------------------------*/\r
120 \r
121 /* The two test tasks as described at the top of this file. */\r
122 static void vFlopTest1( void *pvParameters );\r
123 static void vFlopTest2( void *pvParameters );\r
124 \r
125 /*-----------------------------------------------------------*/\r
126 \r
127 /* Buffers into which the flop registers will be saved.  There is a buffer for \r
128 both tasks. */\r
129 static volatile unsigned portLONG ulFlopRegisters[ flopNUMBER_OF_TASKS ][ portNO_FLOP_REGISTERS_TO_SAVE ];\r
130 \r
131 /* Variables that are incremented by the tasks to indicate that they are still\r
132 running. */\r
133 static volatile unsigned portLONG ulFlop1CycleCount = 0, ulFlop2CycleCount = 0;\r
134 \r
135 /*-----------------------------------------------------------*/\r
136 \r
137 void vStartFlopRegTests( void )\r
138 {\r
139 xTaskHandle xTaskJustCreated;\r
140 unsigned portBASE_TYPE x, y, 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                         ulFlopRegisters[ x ][ y ] = z;\r
153                         z++;\r
154                 }\r
155         }\r
156 \r
157 \r
158         /* Create the first task. */\r
159         xTaskCreate( vFlopTest1, ( signed portCHAR * ) "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 ulFlopRegisters[ 0 ], the second ulFlopRegisters[ 1 ]. */\r
166         vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 0 ][ 0 ] ) );\r
167 \r
168         /* Do the same for the second task. */\r
169         xTaskCreate( vFlopTest2, ( signed portCHAR * ) "flop2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );\r
170         vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 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 * ) ulFlopRegisters[ 0 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );\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 * ) ulFlopRegisters[ 1 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );\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, z = flopSTART_VALUE;\r
223 static unsigned portLONG ulLastFlop1CycleCount = 0, ulLastFlop2CycleCount = 0;\r
224 \r
225         /* Called from the 'check' task.\r
226         \r
227         The flop tasks cannot be currently running, check their saved registers\r
228         are as expected.  The tests tasks do not perform any flop operations so\r
229         their registers should be as per their initial setting. */\r
230         for( x = 0; x < flopNUMBER_OF_TASKS; x++ )\r
231         {\r
232                 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )\r
233                 {\r
234                         if( ulFlopRegisters[ x ][ y ] != z )\r
235                         {\r
236                                 xReturn = pdFAIL;\r
237                                 break;\r
238                         }\r
239 \r
240                         z++;\r
241                 }\r
242         }\r
243 \r
244         /* Check both tasks have actually been swapped in and out since this function\r
245         last executed. */\r
246         if( ulFlop1CycleCount == ulLastFlop1CycleCount )\r
247         {\r
248                 xReturn = pdFAIL;\r
249         }\r
250 \r
251         if( ulFlop2CycleCount == ulLastFlop2CycleCount )\r
252         {\r
253                 xReturn = pdFAIL;\r
254         }\r
255 \r
256         ulLastFlop1CycleCount = ulFlop1CycleCount;\r
257         ulLastFlop2CycleCount = ulFlop2CycleCount;\r
258 \r
259         return xReturn;\r
260 }\r
261 \r