]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PPC440_SP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/flop/flop-reg-test.c
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS / Demo / PPC440_SP_FPU_Xilinx_Virtex5_GCC / RTOSDemo / flop / flop-reg-test.c
1 /*\r
2     FreeRTOS V8.1.2 - Copyright (C) 2014 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     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS 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 ( 0x1 )\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 unsigned long ulFlopRegisters[ 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 TaskHandle_t xTaskJustCreated;\r
139 unsigned portBASE_TYPE x, y, z = flopSTART_VALUE;\r
140 \r
141         /* Fill the arrays into which the flop registers are to be saved with \r
142         known values.  These are the values that will be written to the flop\r
143         registers when the tasks start, and as the tasks do not perform any\r
144         flop operations the values should never change.  Each position in the\r
145         buffer contains a different value so the flop context of each task\r
146         will be different. */\r
147         for( x = 0; x < flopNUMBER_OF_TASKS; x++ )\r
148         {\r
149                 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1); y++ )\r
150                 {\r
151                         ulFlopRegisters[ x ][ y ] = z;\r
152                         z++;\r
153                 }\r
154         }\r
155 \r
156 \r
157         /* Create the first task. */\r
158         xTaskCreate( vFlopTest1, "flop1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );\r
159 \r
160         /* The task     tag value is a value that can be associated with a task, but \r
161         is not used by the scheduler itself.  Its use is down to the application so\r
162         it makes a convenient place in this case to store the pointer to the buffer\r
163         into which the flop context of the task will be stored.  The first created\r
164         task uses ulFlopRegisters[ 0 ], the second ulFlopRegisters[ 1 ]. */\r
165         vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 0 ][ 0 ] ) );\r
166 \r
167         /* Do the same for the second task. */\r
168         xTaskCreate( vFlopTest2, "flop2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );\r
169         vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 1 ][ 0 ] ) );\r
170 }\r
171 /*-----------------------------------------------------------*/\r
172 \r
173 static void vFlopTest1( void *pvParameters )\r
174 {\r
175         /* Just to remove compiler warning. */\r
176         ( void ) pvParameters;\r
177 \r
178         for( ;; )\r
179         {\r
180                 /* The values from the buffer should have now been written to the flop\r
181                 registers.  Clear the buffer to ensure the same values then get written\r
182                 back the next time the task runs.  Being preempted during this memset\r
183                 could cause the test to fail, hence the critical section. */\r
184                 portENTER_CRITICAL();\r
185                         memset( ( void * ) ulFlopRegisters[ 0 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );\r
186                 portEXIT_CRITICAL();\r
187 \r
188                 /* We don't have to do anything other than indicate that we are \r
189                 still running. */\r
190                 ulFlop1CycleCount++;\r
191                 taskYIELD();\r
192         }\r
193 }\r
194 /*-----------------------------------------------------------*/\r
195 \r
196 static void vFlopTest2( void *pvParameters )\r
197 {\r
198         /* Just to remove compiler warning. */\r
199         ( void ) pvParameters;\r
200 \r
201         for( ;; )\r
202         {\r
203                 /* The values from the buffer should have now been written to the flop\r
204                 registers.  Clear the buffer to ensure the same values then get written\r
205                 back the next time the task runs. */\r
206                 portENTER_CRITICAL();\r
207                         memset( ( void * ) ulFlopRegisters[ 1 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );\r
208                 portEXIT_CRITICAL();\r
209 \r
210                 /* We don't have to do anything other than indicate that we are \r
211                 still running. */\r
212                 ulFlop2CycleCount++;\r
213                 taskYIELD();\r
214         }\r
215 }\r
216 /*-----------------------------------------------------------*/\r
217 \r
218 portBASE_TYPE xAreFlopRegisterTestsStillRunning( void )\r
219 {\r
220 portBASE_TYPE xReturn = pdPASS;\r
221 unsigned portBASE_TYPE x, y, z = flopSTART_VALUE;\r
222 static unsigned long ulLastFlop1CycleCount = 0, ulLastFlop2CycleCount = 0;\r
223 \r
224         /* Called from the 'check' task.\r
225         \r
226         The flop tasks cannot be currently running, check their saved registers\r
227         are as expected.  The tests tasks do not perform any flop operations so\r
228         their registers should be as per their initial setting. */\r
229         for( x = 0; x < flopNUMBER_OF_TASKS; x++ )\r
230         {\r
231                 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )\r
232                 {\r
233                         if( ulFlopRegisters[ x ][ y ] != z )\r
234                         {\r
235                                 xReturn = pdFAIL;\r
236                                 break;\r
237                         }\r
238 \r
239                         z++;\r
240                 }\r
241         }\r
242 \r
243         /* Check both tasks have actually been swapped in and out since this function\r
244         last executed. */\r
245         if( ulFlop1CycleCount == ulLastFlop1CycleCount )\r
246         {\r
247                 xReturn = pdFAIL;\r
248         }\r
249 \r
250         if( ulFlop2CycleCount == ulLastFlop2CycleCount )\r
251         {\r
252                 xReturn = pdFAIL;\r
253         }\r
254 \r
255         ulLastFlop1CycleCount = ulFlop1CycleCount;\r
256         ulLastFlop2CycleCount = ulFlop2CycleCount;\r
257 \r
258         return xReturn;\r
259 }\r
260 \r