]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PPC440_DP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/flop/flop-reg-test.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / PPC440_DP_FPU_Xilinx_Virtex5_GCC / RTOSDemo / flop / flop-reg-test.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /*\r
29  * Tests the floating point context save and restore mechanism.\r
30  *\r
31  * Two tasks are created - each of which is allocated a buffer of \r
32  * portNO_FLOP_REGISTERS_TO_SAVE 32bit variables into which the flop context\r
33  * of the task is saved when the task is switched out, and from which the\r
34  * flop context of the task is restored when the task is switch in.  Prior to \r
35  * the tasks being created each position in the two buffers is filled with a \r
36  * unique value - this way the flop context of each task is different.\r
37  *\r
38  * The two test tasks never block so are always in either the Running or\r
39  * Ready state.  They execute at the lowest priority so will get pre-empted\r
40  * regularly, although the yield frequently so will not get much execution\r
41  * time.  The lack of execution time is not a problem as its only the \r
42  * switching in and out that is being tested.\r
43  *\r
44  * Whenever a task is moved from the Ready to the Running state its flop \r
45  * context will be loaded from the buffer, but while the task is in the\r
46  * Running state the buffer is not used and can contain any value - in this\r
47  * case and for test purposes the task itself clears the buffer to zero.  \r
48  * The next time the task is moved out of the Running state into the\r
49  * Ready state the flop context will once more get saved to the buffer - \r
50  * overwriting the zeros.\r
51  *\r
52  * Therefore whenever the task is not in the Running state its buffer contains\r
53  * the most recent values of its floating point registers - the zeroing out\r
54  * of the buffer while the task was executing being used to ensure the values \r
55  * the buffer contains are not stale.\r
56  *\r
57  * When neither test task is in the Running state the buffers should contain\r
58  * the unique values allocated before the tasks were created.  If so then\r
59  * the floating point context has been maintained.  This check is performed\r
60  * by the 'check' task (defined in main.c) by calling \r
61  * xAreFlopRegisterTestsStillRunning().\r
62  *\r
63  * The test tasks also increment a value each time they execute.\r
64  * xAreFlopRegisterTestsStillRunning() also checks that this value has changed\r
65  * since it last ran to ensure the test tasks are still getting processing time.\r
66  */\r
67 \r
68 /* Standard includes files. */\r
69 #include <string.h>\r
70 \r
71 /* Scheduler include files. */\r
72 #include "FreeRTOS.h"\r
73 #include "task.h"\r
74 \r
75 /*-----------------------------------------------------------*/\r
76 \r
77 #define flopNUMBER_OF_TASKS             2\r
78 #define flopSTART_VALUE ( 0x0000000100000001LL )\r
79 \r
80 /*-----------------------------------------------------------*/\r
81 \r
82 /* The two test tasks as described at the top of this file. */\r
83 static void vFlopTest1( void *pvParameters );\r
84 static void vFlopTest2( void *pvParameters );\r
85 \r
86 /*-----------------------------------------------------------*/\r
87 \r
88 /* Buffers into which the flop registers will be saved.  There is a buffer for \r
89 both tasks. */\r
90 static volatile portDOUBLE dFlopRegisters[ flopNUMBER_OF_TASKS ][ portNO_FLOP_REGISTERS_TO_SAVE ];\r
91 \r
92 /* Variables that are incremented by the tasks to indicate that they are still\r
93 running. */\r
94 static volatile unsigned long ulFlop1CycleCount = 0, ulFlop2CycleCount = 0;\r
95 \r
96 /*-----------------------------------------------------------*/\r
97 \r
98 void vStartFlopRegTests( void )\r
99 {\r
100 TaskHandle_t xTaskJustCreated;\r
101 unsigned portBASE_TYPE x, y;\r
102 portDOUBLE z = flopSTART_VALUE;\r
103 \r
104         /* Fill the arrays into which the flop registers are to be saved with \r
105         known values.  These are the values that will be written to the flop\r
106         registers when the tasks start, and as the tasks do not perform any\r
107         flop operations the values should never change.  Each position in the\r
108         buffer contains a different value so the flop context of each task\r
109         will be different. */\r
110         for( x = 0; x < flopNUMBER_OF_TASKS; x++ )\r
111         {\r
112                 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1); y++ )\r
113                 {\r
114                         dFlopRegisters[ x ][ y ] = z;\r
115                         z+=flopSTART_VALUE;\r
116                 }\r
117         }\r
118 \r
119 \r
120         /* Create the first task. */\r
121         xTaskCreate( vFlopTest1, "flop1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );\r
122 \r
123         /* The task     tag value is a value that can be associated with a task, but \r
124         is not used by the scheduler itself.  Its use is down to the application so\r
125         it makes a convenient place in this case to store the pointer to the buffer\r
126         into which the flop context of the task will be stored.  The first created\r
127         task uses dFlopRegisters[ 0 ], the second dFlopRegisters[ 1 ]. */\r
128         vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( dFlopRegisters[ 0 ][ 0 ] ) );\r
129 \r
130         /* Do the same for the second task. */\r
131         xTaskCreate( vFlopTest2, "flop2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );\r
132         vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( dFlopRegisters[ 1 ][ 0 ] ) );\r
133 }\r
134 /*-----------------------------------------------------------*/\r
135 \r
136 static void vFlopTest1( void *pvParameters )\r
137 {\r
138         /* Just to remove compiler warning. */\r
139         ( void ) pvParameters;\r
140 \r
141         for( ;; )\r
142         {\r
143                 /* The values from the buffer should have now been written to the flop\r
144                 registers.  Clear the buffer to ensure the same values then get written\r
145                 back the next time the task runs.  Being preempted during this memset\r
146                 could cause the test to fail, hence the critical section. */\r
147                 portENTER_CRITICAL();\r
148                         memset( ( void * ) dFlopRegisters[ 0 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( portDOUBLE ) ) );\r
149                 portEXIT_CRITICAL();\r
150 \r
151                 /* We don't have to do anything other than indicate that we are \r
152                 still running. */\r
153                 ulFlop1CycleCount++;\r
154                 taskYIELD();\r
155         }\r
156 }\r
157 /*-----------------------------------------------------------*/\r
158 \r
159 static void vFlopTest2( void *pvParameters )\r
160 {\r
161         /* Just to remove compiler warning. */\r
162         ( void ) pvParameters;\r
163 \r
164         for( ;; )\r
165         {\r
166                 /* The values from the buffer should have now been written to the flop\r
167                 registers.  Clear the buffer to ensure the same values then get written\r
168                 back the next time the task runs. */\r
169                 portENTER_CRITICAL();\r
170                         memset( ( void * ) dFlopRegisters[ 1 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( portDOUBLE ) ) );\r
171                 portEXIT_CRITICAL();\r
172 \r
173                 /* We don't have to do anything other than indicate that we are \r
174                 still running. */\r
175                 ulFlop2CycleCount++;\r
176                 taskYIELD();\r
177         }\r
178 }\r
179 /*-----------------------------------------------------------*/\r
180 \r
181 portBASE_TYPE xAreFlopRegisterTestsStillRunning( void )\r
182 {\r
183 portBASE_TYPE xReturn = pdPASS;\r
184 unsigned portBASE_TYPE x, y;\r
185 portDOUBLE z = flopSTART_VALUE;\r
186 static unsigned long ulLastFlop1CycleCount = 0, ulLastFlop2CycleCount = 0;\r
187 \r
188         /* Called from the 'check' task.\r
189         \r
190         The flop tasks cannot be currently running, check their saved registers\r
191         are as expected.  The tests tasks do not perform any flop operations so\r
192         their registers should be as per their initial setting. */\r
193         for( x = 0; x < flopNUMBER_OF_TASKS; x++ )\r
194         {\r
195                 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )\r
196                 {\r
197                         if( dFlopRegisters[ x ][ y ] != z )\r
198                         {\r
199                                 xReturn = pdFAIL;\r
200                                 break;\r
201                         }\r
202 \r
203                         z+=flopSTART_VALUE;\r
204                 }\r
205         }\r
206 \r
207         /* Check both tasks have actually been swapped in and out since this function\r
208         last executed. */\r
209         if( ulFlop1CycleCount == ulLastFlop1CycleCount )\r
210         {\r
211                 xReturn = pdFAIL;\r
212         }\r
213 \r
214         if( ulFlop2CycleCount == ulLastFlop2CycleCount )\r
215         {\r
216                 xReturn = pdFAIL;\r
217         }\r
218 \r
219         ulLastFlop1CycleCount = ulFlop1CycleCount;\r
220         ulLastFlop2CycleCount = ulFlop2CycleCount;\r
221 \r
222         return xReturn;\r
223 }\r
224 \r