]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PPC440_SP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/flop/flop-reg-test.c
e740fb5564685a30a857ce5f3b7cebeecff08502
[freertos] / FreeRTOS / Demo / PPC440_SP_FPU_Xilinx_Virtex5_GCC / RTOSDemo / flop / flop-reg-test.c
1 /*\r
2     FreeRTOS V8.2.0rc1 - 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     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
12 \r
13     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
14     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
15     >>!   obliged to provide the source code for proprietary components     !<<\r
16     >>!   outside of the FreeRTOS kernel.                                   !<<\r
17 \r
18     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
19     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
20     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
21     link: http://www.freertos.org/a00114.html\r
22 \r
23     1 tab == 4 spaces!\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    Having a problem?  Start by reading the FAQ "My application does   *\r
28      *    not run, what could be wrong?".  Have you defined configASSERT()?  *\r
29      *                                                                       *\r
30      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
31      *                                                                       *\r
32     ***************************************************************************\r
33 \r
34     ***************************************************************************\r
35      *                                                                       *\r
36      *    FreeRTOS provides completely free yet professionally developed,    *\r
37      *    robust, strictly quality controlled, supported, and cross          *\r
38      *    platform software that is more than just the market leader, it     *\r
39      *    is the industry's de facto standard.                               *\r
40      *                                                                       *\r
41      *    Help yourself get started quickly while simultaneously helping     *\r
42      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
43      *    tutorial book, reference manual, or both:                          *\r
44      *    http://www.FreeRTOS.org/Documentation                              *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     ***************************************************************************\r
49      *                                                                       *\r
50      *   Investing in training allows your team to be as productive as       *\r
51      *   possible as early as possible, lowering your overall development    *\r
52      *   cost, and enabling you to bring a more robust product to market     *\r
53      *   earlier than would otherwise be possible.  Richard Barry is both    *\r
54      *   the architect and key author of FreeRTOS, and so also the world's   *\r
55      *   leading authority on what is the world's most popular real time     *\r
56      *   kernel for deeply embedded MCU designs.  Obtaining your training    *\r
57      *   from Richard ensures your team will gain directly from his in-depth *\r
58      *   product knowledge and years of usage experience.  Contact Real Time *\r
59      *   Engineers Ltd to enquire about the FreeRTOS Masterclass, presented  *\r
60      *   by Richard Barry:  http://www.FreeRTOS.org/contact\r
61      *                                                                       *\r
62     ***************************************************************************\r
63 \r
64     ***************************************************************************\r
65      *                                                                       *\r
66      *    You are receiving this top quality software for free.  Please play *\r
67      *    fair and reciprocate by reporting any suspected issues and         *\r
68      *    participating in the community forum:                              *\r
69      *    http://www.FreeRTOS.org/support                                    *\r
70      *                                                                       *\r
71      *    Thank you!                                                         *\r
72      *                                                                       *\r
73     ***************************************************************************\r
74 \r
75     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
76     license and Real Time Engineers Ltd. contact details.\r
77 \r
78     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
79     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
80     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
81 \r
82     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
83     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
84 \r
85     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
86     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
87     licenses offer ticketed support, indemnification and commercial middleware.\r
88 \r
89     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
90     engineered and independently SIL3 certified version for use in safety and\r
91     mission critical applications that require provable dependability.\r
92 \r
93     1 tab == 4 spaces!\r
94 */\r
95 \r
96 /*\r
97  * Tests the floating point context save and restore mechanism.\r
98  *\r
99  * Two tasks are created - each of which is allocated a buffer of \r
100  * portNO_FLOP_REGISTERS_TO_SAVE 32bit variables into which the flop context\r
101  * of the task is saved when the task is switched out, and from which the\r
102  * flop context of the task is restored when the task is switch in.  Prior to \r
103  * the tasks being created each position in the two buffers is filled with a \r
104  * unique value - this way the flop context of each task is different.\r
105  *\r
106  * The two test tasks never block so are always in either the Running or\r
107  * Ready state.  They execute at the lowest priority so will get pre-empted\r
108  * regularly, although the yield frequently so will not get much execution\r
109  * time.  The lack of execution time is not a problem as its only the \r
110  * switching in and out that is being tested.\r
111  *\r
112  * Whenever a task is moved from the Ready to the Running state its flop \r
113  * context will be loaded from the buffer, but while the task is in the\r
114  * Running state the buffer is not used and can contain any value - in this\r
115  * case and for test purposes the task itself clears the buffer to zero.  \r
116  * The next time the task is moved out of the Running state into the\r
117  * Ready state the flop context will once more get saved to the buffer - \r
118  * overwriting the zeros.\r
119  *\r
120  * Therefore whenever the task is not in the Running state its buffer contains\r
121  * the most recent values of its floating point registers - the zeroing out\r
122  * of the buffer while the task was executing being used to ensure the values \r
123  * the buffer contains are not stale.\r
124  *\r
125  * When neither test task is in the Running state the buffers should contain\r
126  * the unique values allocated before the tasks were created.  If so then\r
127  * the floating point context has been maintained.  This check is performed\r
128  * by the 'check' task (defined in main.c) by calling \r
129  * xAreFlopRegisterTestsStillRunning().\r
130  *\r
131  * The test tasks also increment a value each time they execute.\r
132  * xAreFlopRegisterTestsStillRunning() also checks that this value has changed\r
133  * since it last ran to ensure the test tasks are still getting processing time.\r
134  */\r
135 \r
136 /* Standard includes files. */\r
137 #include <string.h>\r
138 \r
139 /* Scheduler include files. */\r
140 #include "FreeRTOS.h"\r
141 #include "task.h"\r
142 \r
143 /*-----------------------------------------------------------*/\r
144 \r
145 #define flopNUMBER_OF_TASKS             2\r
146 #define flopSTART_VALUE ( 0x1 )\r
147 \r
148 /*-----------------------------------------------------------*/\r
149 \r
150 /* The two test tasks as described at the top of this file. */\r
151 static void vFlopTest1( void *pvParameters );\r
152 static void vFlopTest2( void *pvParameters );\r
153 \r
154 /*-----------------------------------------------------------*/\r
155 \r
156 /* Buffers into which the flop registers will be saved.  There is a buffer for \r
157 both tasks. */\r
158 static volatile unsigned long ulFlopRegisters[ flopNUMBER_OF_TASKS ][ portNO_FLOP_REGISTERS_TO_SAVE ];\r
159 \r
160 /* Variables that are incremented by the tasks to indicate that they are still\r
161 running. */\r
162 static volatile unsigned long ulFlop1CycleCount = 0, ulFlop2CycleCount = 0;\r
163 \r
164 /*-----------------------------------------------------------*/\r
165 \r
166 void vStartFlopRegTests( void )\r
167 {\r
168 TaskHandle_t xTaskJustCreated;\r
169 unsigned portBASE_TYPE x, y, z = flopSTART_VALUE;\r
170 \r
171         /* Fill the arrays into which the flop registers are to be saved with \r
172         known values.  These are the values that will be written to the flop\r
173         registers when the tasks start, and as the tasks do not perform any\r
174         flop operations the values should never change.  Each position in the\r
175         buffer contains a different value so the flop context of each task\r
176         will be different. */\r
177         for( x = 0; x < flopNUMBER_OF_TASKS; x++ )\r
178         {\r
179                 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1); y++ )\r
180                 {\r
181                         ulFlopRegisters[ x ][ y ] = z;\r
182                         z++;\r
183                 }\r
184         }\r
185 \r
186 \r
187         /* Create the first task. */\r
188         xTaskCreate( vFlopTest1, "flop1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );\r
189 \r
190         /* The task     tag value is a value that can be associated with a task, but \r
191         is not used by the scheduler itself.  Its use is down to the application so\r
192         it makes a convenient place in this case to store the pointer to the buffer\r
193         into which the flop context of the task will be stored.  The first created\r
194         task uses ulFlopRegisters[ 0 ], the second ulFlopRegisters[ 1 ]. */\r
195         vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 0 ][ 0 ] ) );\r
196 \r
197         /* Do the same for the second task. */\r
198         xTaskCreate( vFlopTest2, "flop2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );\r
199         vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 1 ][ 0 ] ) );\r
200 }\r
201 /*-----------------------------------------------------------*/\r
202 \r
203 static void vFlopTest1( void *pvParameters )\r
204 {\r
205         /* Just to remove compiler warning. */\r
206         ( void ) pvParameters;\r
207 \r
208         for( ;; )\r
209         {\r
210                 /* The values from the buffer should have now been written to the flop\r
211                 registers.  Clear the buffer to ensure the same values then get written\r
212                 back the next time the task runs.  Being preempted during this memset\r
213                 could cause the test to fail, hence the critical section. */\r
214                 portENTER_CRITICAL();\r
215                         memset( ( void * ) ulFlopRegisters[ 0 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );\r
216                 portEXIT_CRITICAL();\r
217 \r
218                 /* We don't have to do anything other than indicate that we are \r
219                 still running. */\r
220                 ulFlop1CycleCount++;\r
221                 taskYIELD();\r
222         }\r
223 }\r
224 /*-----------------------------------------------------------*/\r
225 \r
226 static void vFlopTest2( void *pvParameters )\r
227 {\r
228         /* Just to remove compiler warning. */\r
229         ( void ) pvParameters;\r
230 \r
231         for( ;; )\r
232         {\r
233                 /* The values from the buffer should have now been written to the flop\r
234                 registers.  Clear the buffer to ensure the same values then get written\r
235                 back the next time the task runs. */\r
236                 portENTER_CRITICAL();\r
237                         memset( ( void * ) ulFlopRegisters[ 1 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );\r
238                 portEXIT_CRITICAL();\r
239 \r
240                 /* We don't have to do anything other than indicate that we are \r
241                 still running. */\r
242                 ulFlop2CycleCount++;\r
243                 taskYIELD();\r
244         }\r
245 }\r
246 /*-----------------------------------------------------------*/\r
247 \r
248 portBASE_TYPE xAreFlopRegisterTestsStillRunning( void )\r
249 {\r
250 portBASE_TYPE xReturn = pdPASS;\r
251 unsigned portBASE_TYPE x, y, z = flopSTART_VALUE;\r
252 static unsigned long ulLastFlop1CycleCount = 0, ulLastFlop2CycleCount = 0;\r
253 \r
254         /* Called from the 'check' task.\r
255         \r
256         The flop tasks cannot be currently running, check their saved registers\r
257         are as expected.  The tests tasks do not perform any flop operations so\r
258         their registers should be as per their initial setting. */\r
259         for( x = 0; x < flopNUMBER_OF_TASKS; x++ )\r
260         {\r
261                 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )\r
262                 {\r
263                         if( ulFlopRegisters[ x ][ y ] != z )\r
264                         {\r
265                                 xReturn = pdFAIL;\r
266                                 break;\r
267                         }\r
268 \r
269                         z++;\r
270                 }\r
271         }\r
272 \r
273         /* Check both tasks have actually been swapped in and out since this function\r
274         last executed. */\r
275         if( ulFlop1CycleCount == ulLastFlop1CycleCount )\r
276         {\r
277                 xReturn = pdFAIL;\r
278         }\r
279 \r
280         if( ulFlop2CycleCount == ulLastFlop2CycleCount )\r
281         {\r
282                 xReturn = pdFAIL;\r
283         }\r
284 \r
285         ulLastFlop1CycleCount = ulFlop1CycleCount;\r
286         ulLastFlop2CycleCount = ulFlop2CycleCount;\r
287 \r
288         return xReturn;\r
289 }\r
290 \r