2 FreeRTOS V7.4.2 - Copyright (C) 2013 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
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not it can be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
76 * Tests the floating point context save and restore mechanism.
\r
78 * Two tasks are created - each of which is allocated a buffer of
\r
79 * portNO_FLOP_REGISTERS_TO_SAVE 32bit variables into which the flop context
\r
80 * of the task is saved when the task is switched out, and from which the
\r
81 * flop context of the task is restored when the task is switch in. Prior to
\r
82 * the tasks being created each position in the two buffers is filled with a
\r
83 * unique value - this way the flop context of each task is different.
\r
85 * The two test tasks never block so are always in either the Running or
\r
86 * Ready state. They execute at the lowest priority so will get pre-empted
\r
87 * regularly, although the yield frequently so will not get much execution
\r
88 * time. The lack of execution time is not a problem as its only the
\r
89 * switching in and out that is being tested.
\r
91 * Whenever a task is moved from the Ready to the Running state its flop
\r
92 * context will be loaded from the buffer, but while the task is in the
\r
93 * Running state the buffer is not used and can contain any value - in this
\r
94 * case and for test purposes the task itself clears the buffer to zero.
\r
95 * The next time the task is moved out of the Running state into the
\r
96 * Ready state the flop context will once more get saved to the buffer -
\r
97 * overwriting the zeros.
\r
99 * Therefore whenever the task is not in the Running state its buffer contains
\r
100 * the most recent values of its floating point registers - the zeroing out
\r
101 * of the buffer while the task was executing being used to ensure the values
\r
102 * the buffer contains are not stale.
\r
104 * When neither test task is in the Running state the buffers should contain
\r
105 * the unique values allocated before the tasks were created. If so then
\r
106 * the floating point context has been maintained. This check is performed
\r
107 * by the 'check' task (defined in main.c) by calling
\r
108 * xAreFlopRegisterTestsStillRunning().
\r
110 * The test tasks also increment a value each time they execute.
\r
111 * xAreFlopRegisterTestsStillRunning() also checks that this value has changed
\r
112 * since it last ran to ensure the test tasks are still getting processing time.
\r
115 /* Standard includes files. */
\r
116 #include <string.h>
\r
118 /* Scheduler include files. */
\r
119 #include "FreeRTOS.h"
\r
122 /*-----------------------------------------------------------*/
\r
124 #define flopNUMBER_OF_TASKS 2
\r
125 #define flopSTART_VALUE ( 0x0000000100000001LL )
\r
127 /*-----------------------------------------------------------*/
\r
129 /* The two test tasks as described at the top of this file. */
\r
130 static void vFlopTest1( void *pvParameters );
\r
131 static void vFlopTest2( void *pvParameters );
\r
133 /*-----------------------------------------------------------*/
\r
135 /* Buffers into which the flop registers will be saved. There is a buffer for
\r
137 static volatile portDOUBLE dFlopRegisters[ flopNUMBER_OF_TASKS ][ portNO_FLOP_REGISTERS_TO_SAVE ];
\r
139 /* Variables that are incremented by the tasks to indicate that they are still
\r
141 static volatile unsigned long ulFlop1CycleCount = 0, ulFlop2CycleCount = 0;
\r
143 /*-----------------------------------------------------------*/
\r
145 void vStartFlopRegTests( void )
\r
147 xTaskHandle xTaskJustCreated;
\r
148 unsigned portBASE_TYPE x, y;
\r
149 portDOUBLE z = flopSTART_VALUE;
\r
151 /* Fill the arrays into which the flop registers are to be saved with
\r
152 known values. These are the values that will be written to the flop
\r
153 registers when the tasks start, and as the tasks do not perform any
\r
154 flop operations the values should never change. Each position in the
\r
155 buffer contains a different value so the flop context of each task
\r
156 will be different. */
\r
157 for( x = 0; x < flopNUMBER_OF_TASKS; x++ )
\r
159 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1); y++ )
\r
161 dFlopRegisters[ x ][ y ] = z;
\r
162 z+=flopSTART_VALUE;
\r
167 /* Create the first task. */
\r
168 xTaskCreate( vFlopTest1, ( signed char * ) "flop1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );
\r
170 /* The task tag value is a value that can be associated with a task, but
\r
171 is not used by the scheduler itself. Its use is down to the application so
\r
172 it makes a convenient place in this case to store the pointer to the buffer
\r
173 into which the flop context of the task will be stored. The first created
\r
174 task uses dFlopRegisters[ 0 ], the second dFlopRegisters[ 1 ]. */
\r
175 vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( dFlopRegisters[ 0 ][ 0 ] ) );
\r
177 /* Do the same for the second task. */
\r
178 xTaskCreate( vFlopTest2, ( signed char * ) "flop2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );
\r
179 vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( dFlopRegisters[ 1 ][ 0 ] ) );
\r
181 /*-----------------------------------------------------------*/
\r
183 static void vFlopTest1( void *pvParameters )
\r
185 /* Just to remove compiler warning. */
\r
186 ( void ) pvParameters;
\r
190 /* The values from the buffer should have now been written to the flop
\r
191 registers. Clear the buffer to ensure the same values then get written
\r
192 back the next time the task runs. Being preempted during this memset
\r
193 could cause the test to fail, hence the critical section. */
\r
194 portENTER_CRITICAL();
\r
195 memset( ( void * ) dFlopRegisters[ 0 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( portDOUBLE ) ) );
\r
196 portEXIT_CRITICAL();
\r
198 /* We don't have to do anything other than indicate that we are
\r
200 ulFlop1CycleCount++;
\r
204 /*-----------------------------------------------------------*/
\r
206 static void vFlopTest2( void *pvParameters )
\r
208 /* Just to remove compiler warning. */
\r
209 ( void ) pvParameters;
\r
213 /* The values from the buffer should have now been written to the flop
\r
214 registers. Clear the buffer to ensure the same values then get written
\r
215 back the next time the task runs. */
\r
216 portENTER_CRITICAL();
\r
217 memset( ( void * ) dFlopRegisters[ 1 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( portDOUBLE ) ) );
\r
218 portEXIT_CRITICAL();
\r
220 /* We don't have to do anything other than indicate that we are
\r
222 ulFlop2CycleCount++;
\r
226 /*-----------------------------------------------------------*/
\r
228 portBASE_TYPE xAreFlopRegisterTestsStillRunning( void )
\r
230 portBASE_TYPE xReturn = pdPASS;
\r
231 unsigned portBASE_TYPE x, y;
\r
232 portDOUBLE z = flopSTART_VALUE;
\r
233 static unsigned long ulLastFlop1CycleCount = 0, ulLastFlop2CycleCount = 0;
\r
235 /* Called from the 'check' task.
\r
237 The flop tasks cannot be currently running, check their saved registers
\r
238 are as expected. The tests tasks do not perform any flop operations so
\r
239 their registers should be as per their initial setting. */
\r
240 for( x = 0; x < flopNUMBER_OF_TASKS; x++ )
\r
242 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )
\r
244 if( dFlopRegisters[ x ][ y ] != z )
\r
250 z+=flopSTART_VALUE;
\r
254 /* Check both tasks have actually been swapped in and out since this function
\r
256 if( ulFlop1CycleCount == ulLastFlop1CycleCount )
\r
261 if( ulFlop2CycleCount == ulLastFlop2CycleCount )
\r
266 ulLastFlop1CycleCount = ulFlop1CycleCount;
\r
267 ulLastFlop2CycleCount = ulFlop2CycleCount;
\r