2 FreeRTOS.org V5.0.0 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
\r
30 * and even write all or part of your application on your behalf. *
\r
31 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
32 * expedite your project. *
\r
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
51 * Tests the floating point context save and restore mechanism.
\r
53 * Two tasks are created - each of which is allocated a buffer of
\r
54 * portNO_FLOP_REGISTERS_TO_SAVE 32bit variables into which the flop context
\r
55 * of the task is saved when the task is switched out, and from which the
\r
56 * flop context of the task is restored when the task is switch in. Prior to
\r
57 * the tasks being created each position in the two buffers is filled with a
\r
58 * unique value - this way the flop context of each task is different.
\r
60 * The two test tasks never block so are always in either the Running or
\r
61 * Ready state. They execute at the lowest priority so will get pre-empted
\r
62 * regularly, although the yield frequently so will not get much execution
\r
63 * time. The lack of execution time is not a problem as its only the
\r
64 * switching in and out that is being tested.
\r
66 * Whenever a task is moved from the Ready to the Running state its flop
\r
67 * context will be loaded from the buffer, but while the task is in the
\r
68 * Running state the buffer is not used and can contain any value - in this
\r
69 * case and for test purposes the task itself clears the buffer to zero.
\r
70 * The next time the task is moved out of the Running state into the
\r
71 * Ready state the flop context will once more get saved to the buffer -
\r
72 * overwriting the zeros.
\r
74 * Therefore whenever the task is not in the Running state its buffer contains
\r
75 * the most recent values of its floating point registers - the zeroing out
\r
76 * of the buffer while the task was executing being used to ensure the values
\r
77 * the buffer contains are not stale.
\r
79 * When neither test task is in the Running state the buffers should contain
\r
80 * the unique values allocated before the tasks were created. If so then
\r
81 * the floating point context has been maintained. This check is performed
\r
82 * by the 'check' task (defined in main.c) by calling
\r
83 * xAreFlopRegisterTestsStillRunning().
\r
85 * The test tasks also increment a value each time they execute.
\r
86 * xAreFlopRegisterTestsStillRunning() also checks that this value has changed
\r
87 * since it last ran to ensure the test tasks are still getting processing time.
\r
90 /* Standard includes files. */
\r
93 /* Scheduler include files. */
\r
94 #include "FreeRTOS.h"
\r
97 /*-----------------------------------------------------------*/
\r
99 #define flopNUMBER_OF_TASKS 2
\r
100 #define flopSTART_VALUE ( 0x1 )
\r
102 /*-----------------------------------------------------------*/
\r
104 /* The two test tasks as described at the top of this file. */
\r
105 static void vFlopTest1( void *pvParameters );
\r
106 static void vFlopTest2( void *pvParameters );
\r
108 /*-----------------------------------------------------------*/
\r
110 /* Buffers into which the flop registers will be saved. There is a buffer for
\r
112 static volatile unsigned portLONG ulFlopRegisters[ flopNUMBER_OF_TASKS ][ portNO_FLOP_REGISTERS_TO_SAVE ] = { 0 };
\r
114 /* Variables that are incremented by the tasks to indicate that they are still
\r
116 static volatile unsigned portLONG ulFlop1CycleCount = 0, ulFlop2CycleCount = 0;
\r
118 /*-----------------------------------------------------------*/
\r
120 void vStartFlopRegTests( void )
\r
122 xTaskHandle xTaskJustCreated;
\r
123 unsigned portBASE_TYPE x, y, 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 ulFlopRegisters[ x ][ y ] = z;
\r
141 /* Create the first task. */
\r
142 xTaskCreate( vFlopTest1, ( signed portCHAR * ) "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 ulFlopRegisters[ 0 ], the second ulFlopRegisters[ 1 ]. */
\r
149 vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 0 ][ 0 ] ) );
\r
151 /* Do the same for the second task. */
\r
152 xTaskCreate( vFlopTest2, ( signed portCHAR * ) "flop2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );
\r
153 vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 1 ][ 0 ] ) );
\r
155 /*-----------------------------------------------------------*/
\r
157 static void vFlopTest1( void *pvParameters )
\r
161 /* The values from the buffer should have now been written to the flop
\r
162 registers. Clear the buffer to ensure the same values then get written
\r
163 back the next time the task runs. Being preempted during this memset
\r
164 could cause the test to fail, hence the critical section. */
\r
165 portENTER_CRITICAL();
\r
166 memset( ( void * ) ulFlopRegisters[ 0 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );
\r
167 portEXIT_CRITICAL();
\r
169 /* We don't have to do anything other than indicate that we are
\r
171 ulFlop1CycleCount++;
\r
175 /*-----------------------------------------------------------*/
\r
177 static void vFlopTest2( void *pvParameters )
\r
181 /* The values from the buffer should have now been written to the flop
\r
182 registers. Clear the buffer to ensure the same values then get written
\r
183 back the next time the task runs. */
\r
184 portENTER_CRITICAL();
\r
185 memset( ( void * ) ulFlopRegisters[ 1 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );
\r
186 portEXIT_CRITICAL();
\r
188 /* We don't have to do anything other than indicate that we are
\r
190 ulFlop2CycleCount++;
\r
194 /*-----------------------------------------------------------*/
\r
196 portBASE_TYPE xAreFlopRegisterTestsStillRunning( void )
\r
198 portBASE_TYPE xReturn = pdPASS;
\r
199 unsigned portBASE_TYPE x, y, z = flopSTART_VALUE;
\r
200 static unsigned portLONG ulLastFlop1CycleCount = 0, ulLastFlop2CycleCount = 0;
\r
202 /* Called from the 'check' task.
\r
204 The flop tasks cannot be currently running, check their saved registers
\r
205 are as expected. The tests tasks do not perform any flop operations so
\r
206 their registers should be as per their initial setting. */
\r
207 for( x = 0; x < flopNUMBER_OF_TASKS; x++ )
\r
209 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )
\r
211 if( ulFlopRegisters[ x ][ y ] != z )
\r
221 /* Check both tasks have actually been swapped in and out since this function
\r
223 if( ulFlop1CycleCount == ulLastFlop1CycleCount )
\r
228 if( ulFlop2CycleCount == ulLastFlop2CycleCount )
\r
233 ulLastFlop1CycleCount = ulFlop1CycleCount;
\r
234 ulLastFlop2CycleCount = ulFlop2CycleCount;
\r