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