2 FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
32 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
33 distribute a combined work that includes FreeRTOS without being obliged to
\r
34 provide the source code for proprietary components outside of the FreeRTOS
\r
35 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
36 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
37 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
38 more details. You should have received a copy of the GNU General Public
\r
39 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
40 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
41 by writing to Richard Barry, contact details for whom are available on the
\r
46 ***************************************************************************
\r
48 * Having a problem? Start by reading the FAQ "My application does *
\r
49 * not run, what could be wrong?" *
\r
51 * http://www.FreeRTOS.org/FAQHelp.html *
\r
53 ***************************************************************************
\r
56 http://www.FreeRTOS.org - Documentation, training, latest versions, license
\r
57 and contact details.
\r
59 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
60 including FreeRTOS+Trace - an indispensable productivity tool.
\r
62 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
63 the code with commercial support, indemnification, and middleware, under
\r
64 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
65 provide a safety engineered and independently SIL3 certified version under
\r
66 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
70 * Tests the floating point context save and restore mechanism.
\r
72 * Two tasks are created - each of which is allocated a buffer of
\r
73 * portNO_FLOP_REGISTERS_TO_SAVE 32bit variables into which the flop context
\r
74 * of the task is saved when the task is switched out, and from which the
\r
75 * flop context of the task is restored when the task is switch in. Prior to
\r
76 * the tasks being created each position in the two buffers is filled with a
\r
77 * unique value - this way the flop context of each task is different.
\r
79 * The two test tasks never block so are always in either the Running or
\r
80 * Ready state. They execute at the lowest priority so will get pre-empted
\r
81 * regularly, although the yield frequently so will not get much execution
\r
82 * time. The lack of execution time is not a problem as its only the
\r
83 * switching in and out that is being tested.
\r
85 * Whenever a task is moved from the Ready to the Running state its flop
\r
86 * context will be loaded from the buffer, but while the task is in the
\r
87 * Running state the buffer is not used and can contain any value - in this
\r
88 * case and for test purposes the task itself clears the buffer to zero.
\r
89 * The next time the task is moved out of the Running state into the
\r
90 * Ready state the flop context will once more get saved to the buffer -
\r
91 * overwriting the zeros.
\r
93 * Therefore whenever the task is not in the Running state its buffer contains
\r
94 * the most recent values of its floating point registers - the zeroing out
\r
95 * of the buffer while the task was executing being used to ensure the values
\r
96 * the buffer contains are not stale.
\r
98 * When neither test task is in the Running state the buffers should contain
\r
99 * the unique values allocated before the tasks were created. If so then
\r
100 * the floating point context has been maintained. This check is performed
\r
101 * by the 'check' task (defined in main.c) by calling
\r
102 * xAreFlopRegisterTestsStillRunning().
\r
104 * The test tasks also increment a value each time they execute.
\r
105 * xAreFlopRegisterTestsStillRunning() also checks that this value has changed
\r
106 * since it last ran to ensure the test tasks are still getting processing time.
\r
109 /* Standard includes files. */
\r
110 #include <string.h>
\r
112 /* Scheduler include files. */
\r
113 #include "FreeRTOS.h"
\r
116 /*-----------------------------------------------------------*/
\r
118 #define flopNUMBER_OF_TASKS 2
\r
119 #define flopSTART_VALUE ( 0x1 )
\r
121 /*-----------------------------------------------------------*/
\r
123 /* The two test tasks as described at the top of this file. */
\r
124 static void vFlopTest1( void *pvParameters );
\r
125 static void vFlopTest2( void *pvParameters );
\r
127 /*-----------------------------------------------------------*/
\r
129 /* Buffers into which the flop registers will be saved. There is a buffer for
\r
131 static volatile unsigned long ulFlopRegisters[ flopNUMBER_OF_TASKS ][ portNO_FLOP_REGISTERS_TO_SAVE ];
\r
133 /* Variables that are incremented by the tasks to indicate that they are still
\r
135 static volatile unsigned long ulFlop1CycleCount = 0, ulFlop2CycleCount = 0;
\r
137 /*-----------------------------------------------------------*/
\r
139 void vStartFlopRegTests( void )
\r
141 xTaskHandle xTaskJustCreated;
\r
142 unsigned portBASE_TYPE x, y, z = flopSTART_VALUE;
\r
144 /* Fill the arrays into which the flop registers are to be saved with
\r
145 known values. These are the values that will be written to the flop
\r
146 registers when the tasks start, and as the tasks do not perform any
\r
147 flop operations the values should never change. Each position in the
\r
148 buffer contains a different value so the flop context of each task
\r
149 will be different. */
\r
150 for( x = 0; x < flopNUMBER_OF_TASKS; x++ )
\r
152 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1); y++ )
\r
154 ulFlopRegisters[ x ][ y ] = z;
\r
160 /* Create the first task. */
\r
161 xTaskCreate( vFlopTest1, ( signed char * ) "flop1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );
\r
163 /* The task tag value is a value that can be associated with a task, but
\r
164 is not used by the scheduler itself. Its use is down to the application so
\r
165 it makes a convenient place in this case to store the pointer to the buffer
\r
166 into which the flop context of the task will be stored. The first created
\r
167 task uses ulFlopRegisters[ 0 ], the second ulFlopRegisters[ 1 ]. */
\r
168 vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 0 ][ 0 ] ) );
\r
170 /* Do the same for the second task. */
\r
171 xTaskCreate( vFlopTest2, ( signed char * ) "flop2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );
\r
172 vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 1 ][ 0 ] ) );
\r
174 /*-----------------------------------------------------------*/
\r
176 static void vFlopTest1( void *pvParameters )
\r
178 /* Just to remove compiler warning. */
\r
179 ( void ) pvParameters;
\r
183 /* The values from the buffer should have now been written to the flop
\r
184 registers. Clear the buffer to ensure the same values then get written
\r
185 back the next time the task runs. Being preempted during this memset
\r
186 could cause the test to fail, hence the critical section. */
\r
187 portENTER_CRITICAL();
\r
188 memset( ( void * ) ulFlopRegisters[ 0 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );
\r
189 portEXIT_CRITICAL();
\r
191 /* We don't have to do anything other than indicate that we are
\r
193 ulFlop1CycleCount++;
\r
197 /*-----------------------------------------------------------*/
\r
199 static void vFlopTest2( void *pvParameters )
\r
201 /* Just to remove compiler warning. */
\r
202 ( void ) pvParameters;
\r
206 /* The values from the buffer should have now been written to the flop
\r
207 registers. Clear the buffer to ensure the same values then get written
\r
208 back the next time the task runs. */
\r
209 portENTER_CRITICAL();
\r
210 memset( ( void * ) ulFlopRegisters[ 1 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );
\r
211 portEXIT_CRITICAL();
\r
213 /* We don't have to do anything other than indicate that we are
\r
215 ulFlop2CycleCount++;
\r
219 /*-----------------------------------------------------------*/
\r
221 portBASE_TYPE xAreFlopRegisterTestsStillRunning( void )
\r
223 portBASE_TYPE xReturn = pdPASS;
\r
224 unsigned portBASE_TYPE x, y, z = flopSTART_VALUE;
\r
225 static unsigned long ulLastFlop1CycleCount = 0, ulLastFlop2CycleCount = 0;
\r
227 /* Called from the 'check' task.
\r
229 The flop tasks cannot be currently running, check their saved registers
\r
230 are as expected. The tests tasks do not perform any flop operations so
\r
231 their registers should be as per their initial setting. */
\r
232 for( x = 0; x < flopNUMBER_OF_TASKS; x++ )
\r
234 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )
\r
236 if( ulFlopRegisters[ x ][ y ] != z )
\r
246 /* Check both tasks have actually been swapped in and out since this function
\r
248 if( ulFlop1CycleCount == ulLastFlop1CycleCount )
\r
253 if( ulFlop2CycleCount == ulLastFlop2CycleCount )
\r
258 ulLastFlop1CycleCount = ulFlop1CycleCount;
\r
259 ulLastFlop2CycleCount = ulFlop2CycleCount;
\r