2 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * The FreeRTOS eBook and reference manual are available to purchase for a *
\r
29 * small fee. Help yourself get started quickly while also helping the *
\r
30 * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *
\r
32 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
50 * Tests the floating point context save and restore mechanism.
\r
52 * Two tasks are created - each of which is allocated a buffer of
\r
53 * portNO_FLOP_REGISTERS_TO_SAVE 32bit variables into which the flop context
\r
54 * of the task is saved when the task is switched out, and from which the
\r
55 * flop context of the task is restored when the task is switch in. Prior to
\r
56 * the tasks being created each position in the two buffers is filled with a
\r
57 * unique value - this way the flop context of each task is different.
\r
59 * The two test tasks never block so are always in either the Running or
\r
60 * Ready state. They execute at the lowest priority so will get pre-empted
\r
61 * regularly, although the yield frequently so will not get much execution
\r
62 * time. The lack of execution time is not a problem as its only the
\r
63 * switching in and out that is being tested.
\r
65 * Whenever a task is moved from the Ready to the Running state its flop
\r
66 * context will be loaded from the buffer, but while the task is in the
\r
67 * Running state the buffer is not used and can contain any value - in this
\r
68 * case and for test purposes the task itself clears the buffer to zero.
\r
69 * The next time the task is moved out of the Running state into the
\r
70 * Ready state the flop context will once more get saved to the buffer -
\r
71 * overwriting the zeros.
\r
73 * Therefore whenever the task is not in the Running state its buffer contains
\r
74 * the most recent values of its floating point registers - the zeroing out
\r
75 * of the buffer while the task was executing being used to ensure the values
\r
76 * the buffer contains are not stale.
\r
78 * When neither test task is in the Running state the buffers should contain
\r
79 * the unique values allocated before the tasks were created. If so then
\r
80 * the floating point context has been maintained. This check is performed
\r
81 * by the 'check' task (defined in main.c) by calling
\r
82 * xAreFlopRegisterTestsStillRunning().
\r
84 * The test tasks also increment a value each time they execute.
\r
85 * xAreFlopRegisterTestsStillRunning() also checks that this value has changed
\r
86 * since it last ran to ensure the test tasks are still getting processing time.
\r
89 /* Standard includes files. */
\r
92 /* Scheduler include files. */
\r
93 #include "FreeRTOS.h"
\r
96 /*-----------------------------------------------------------*/
\r
98 #define flopNUMBER_OF_TASKS 2
\r
99 #define flopSTART_VALUE ( 0x0000000100000001LL )
\r
101 /*-----------------------------------------------------------*/
\r
103 /* The two test tasks as described at the top of this file. */
\r
104 static void vFlopTest1( void *pvParameters );
\r
105 static void vFlopTest2( void *pvParameters );
\r
107 /*-----------------------------------------------------------*/
\r
109 /* Buffers into which the flop registers will be saved. There is a buffer for
\r
111 static volatile portDOUBLE dFlopRegisters[ flopNUMBER_OF_TASKS ][ portNO_FLOP_REGISTERS_TO_SAVE ];
\r
113 /* Variables that are incremented by the tasks to indicate that they are still
\r
115 static volatile unsigned long ulFlop1CycleCount = 0, ulFlop2CycleCount = 0;
\r
117 /*-----------------------------------------------------------*/
\r
119 void vStartFlopRegTests( void )
\r
121 xTaskHandle xTaskJustCreated;
\r
122 unsigned portBASE_TYPE x, y;
\r
123 portDOUBLE z = flopSTART_VALUE;
\r
125 /* Fill the arrays into which the flop registers are to be saved with
\r
126 known values. These are the values that will be written to the flop
\r
127 registers when the tasks start, and as the tasks do not perform any
\r
128 flop operations the values should never change. Each position in the
\r
129 buffer contains a different value so the flop context of each task
\r
130 will be different. */
\r
131 for( x = 0; x < flopNUMBER_OF_TASKS; x++ )
\r
133 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1); y++ )
\r
135 dFlopRegisters[ x ][ y ] = z;
\r
136 z+=flopSTART_VALUE;
\r
141 /* Create the first task. */
\r
142 xTaskCreate( vFlopTest1, ( signed char * ) "flop1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );
\r
144 /* The task tag value is a value that can be associated with a task, but
\r
145 is not used by the scheduler itself. Its use is down to the application so
\r
146 it makes a convenient place in this case to store the pointer to the buffer
\r
147 into which the flop context of the task will be stored. The first created
\r
148 task uses dFlopRegisters[ 0 ], the second dFlopRegisters[ 1 ]. */
\r
149 vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( dFlopRegisters[ 0 ][ 0 ] ) );
\r
151 /* Do the same for the second task. */
\r
152 xTaskCreate( vFlopTest2, ( signed char * ) "flop2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );
\r
153 vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( dFlopRegisters[ 1 ][ 0 ] ) );
\r
155 /*-----------------------------------------------------------*/
\r
157 static void vFlopTest1( void *pvParameters )
\r
159 /* Just to remove compiler warning. */
\r
160 ( void ) pvParameters;
\r
164 /* The values from the buffer should have now been written to the flop
\r
165 registers. Clear the buffer to ensure the same values then get written
\r
166 back the next time the task runs. Being preempted during this memset
\r
167 could cause the test to fail, hence the critical section. */
\r
168 portENTER_CRITICAL();
\r
169 memset( ( void * ) dFlopRegisters[ 0 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( portDOUBLE ) ) );
\r
170 portEXIT_CRITICAL();
\r
172 /* We don't have to do anything other than indicate that we are
\r
174 ulFlop1CycleCount++;
\r
178 /*-----------------------------------------------------------*/
\r
180 static void vFlopTest2( void *pvParameters )
\r
182 /* Just to remove compiler warning. */
\r
183 ( void ) pvParameters;
\r
187 /* The values from the buffer should have now been written to the flop
\r
188 registers. Clear the buffer to ensure the same values then get written
\r
189 back the next time the task runs. */
\r
190 portENTER_CRITICAL();
\r
191 memset( ( void * ) dFlopRegisters[ 1 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( portDOUBLE ) ) );
\r
192 portEXIT_CRITICAL();
\r
194 /* We don't have to do anything other than indicate that we are
\r
196 ulFlop2CycleCount++;
\r
200 /*-----------------------------------------------------------*/
\r
202 portBASE_TYPE xAreFlopRegisterTestsStillRunning( void )
\r
204 portBASE_TYPE xReturn = pdPASS;
\r
205 unsigned portBASE_TYPE x, y;
\r
206 portDOUBLE z = flopSTART_VALUE;
\r
207 static unsigned long ulLastFlop1CycleCount = 0, ulLastFlop2CycleCount = 0;
\r
209 /* Called from the 'check' task.
\r
211 The flop tasks cannot be currently running, check their saved registers
\r
212 are as expected. The tests tasks do not perform any flop operations so
\r
213 their registers should be as per their initial setting. */
\r
214 for( x = 0; x < flopNUMBER_OF_TASKS; x++ )
\r
216 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )
\r
218 if( dFlopRegisters[ x ][ y ] != z )
\r
224 z+=flopSTART_VALUE;
\r
228 /* Check both tasks have actually been swapped in and out since this function
\r
230 if( ulFlop1CycleCount == ulLastFlop1CycleCount )
\r
235 if( ulFlop2CycleCount == ulLastFlop2CycleCount )
\r
240 ulLastFlop1CycleCount = ulFlop1CycleCount;
\r
241 ulLastFlop2CycleCount = ulFlop2CycleCount;
\r