2 FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
67 * Tests the floating point context save and restore mechanism.
\r
69 * Two tasks are created - each of which is allocated a buffer of
\r
70 * portNO_FLOP_REGISTERS_TO_SAVE 32bit variables into which the flop context
\r
71 * of the task is saved when the task is switched out, and from which the
\r
72 * flop context of the task is restored when the task is switch in. Prior to
\r
73 * the tasks being created each position in the two buffers is filled with a
\r
74 * unique value - this way the flop context of each task is different.
\r
76 * The two test tasks never block so are always in either the Running or
\r
77 * Ready state. They execute at the lowest priority so will get pre-empted
\r
78 * regularly, although the yield frequently so will not get much execution
\r
79 * time. The lack of execution time is not a problem as its only the
\r
80 * switching in and out that is being tested.
\r
82 * Whenever a task is moved from the Ready to the Running state its flop
\r
83 * context will be loaded from the buffer, but while the task is in the
\r
84 * Running state the buffer is not used and can contain any value - in this
\r
85 * case and for test purposes the task itself clears the buffer to zero.
\r
86 * The next time the task is moved out of the Running state into the
\r
87 * Ready state the flop context will once more get saved to the buffer -
\r
88 * overwriting the zeros.
\r
90 * Therefore whenever the task is not in the Running state its buffer contains
\r
91 * the most recent values of its floating point registers - the zeroing out
\r
92 * of the buffer while the task was executing being used to ensure the values
\r
93 * the buffer contains are not stale.
\r
95 * When neither test task is in the Running state the buffers should contain
\r
96 * the unique values allocated before the tasks were created. If so then
\r
97 * the floating point context has been maintained. This check is performed
\r
98 * by the 'check' task (defined in main.c) by calling
\r
99 * xAreFlopRegisterTestsStillRunning().
\r
101 * The test tasks also increment a value each time they execute.
\r
102 * xAreFlopRegisterTestsStillRunning() also checks that this value has changed
\r
103 * since it last ran to ensure the test tasks are still getting processing time.
\r
106 /* Standard includes files. */
\r
107 #include <string.h>
\r
109 /* Scheduler include files. */
\r
110 #include "FreeRTOS.h"
\r
113 /*-----------------------------------------------------------*/
\r
115 #define flopNUMBER_OF_TASKS 2
\r
116 #define flopSTART_VALUE ( 0x0000000100000001LL )
\r
118 /*-----------------------------------------------------------*/
\r
120 /* The two test tasks as described at the top of this file. */
\r
121 static void vFlopTest1( void *pvParameters );
\r
122 static void vFlopTest2( void *pvParameters );
\r
124 /*-----------------------------------------------------------*/
\r
126 /* Buffers into which the flop registers will be saved. There is a buffer for
\r
128 static volatile portDOUBLE dFlopRegisters[ flopNUMBER_OF_TASKS ][ portNO_FLOP_REGISTERS_TO_SAVE ];
\r
130 /* Variables that are incremented by the tasks to indicate that they are still
\r
132 static volatile unsigned long ulFlop1CycleCount = 0, ulFlop2CycleCount = 0;
\r
134 /*-----------------------------------------------------------*/
\r
136 void vStartFlopRegTests( void )
\r
138 TaskHandle_t xTaskJustCreated;
\r
139 unsigned portBASE_TYPE x, y;
\r
140 portDOUBLE z = flopSTART_VALUE;
\r
142 /* Fill the arrays into which the flop registers are to be saved with
\r
143 known values. These are the values that will be written to the flop
\r
144 registers when the tasks start, and as the tasks do not perform any
\r
145 flop operations the values should never change. Each position in the
\r
146 buffer contains a different value so the flop context of each task
\r
147 will be different. */
\r
148 for( x = 0; x < flopNUMBER_OF_TASKS; x++ )
\r
150 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1); y++ )
\r
152 dFlopRegisters[ x ][ y ] = z;
\r
153 z+=flopSTART_VALUE;
\r
158 /* Create the first task. */
\r
159 xTaskCreate( vFlopTest1, "flop1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );
\r
161 /* The task tag value is a value that can be associated with a task, but
\r
162 is not used by the scheduler itself. Its use is down to the application so
\r
163 it makes a convenient place in this case to store the pointer to the buffer
\r
164 into which the flop context of the task will be stored. The first created
\r
165 task uses dFlopRegisters[ 0 ], the second dFlopRegisters[ 1 ]. */
\r
166 vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( dFlopRegisters[ 0 ][ 0 ] ) );
\r
168 /* Do the same for the second task. */
\r
169 xTaskCreate( vFlopTest2, "flop2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );
\r
170 vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( dFlopRegisters[ 1 ][ 0 ] ) );
\r
172 /*-----------------------------------------------------------*/
\r
174 static void vFlopTest1( void *pvParameters )
\r
176 /* Just to remove compiler warning. */
\r
177 ( 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. Being preempted during this memset
\r
184 could cause the test to fail, hence the critical section. */
\r
185 portENTER_CRITICAL();
\r
186 memset( ( void * ) dFlopRegisters[ 0 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( portDOUBLE ) ) );
\r
187 portEXIT_CRITICAL();
\r
189 /* We don't have to do anything other than indicate that we are
\r
191 ulFlop1CycleCount++;
\r
195 /*-----------------------------------------------------------*/
\r
197 static void vFlopTest2( void *pvParameters )
\r
199 /* Just to remove compiler warning. */
\r
200 ( void ) pvParameters;
\r
204 /* The values from the buffer should have now been written to the flop
\r
205 registers. Clear the buffer to ensure the same values then get written
\r
206 back the next time the task runs. */
\r
207 portENTER_CRITICAL();
\r
208 memset( ( void * ) dFlopRegisters[ 1 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( portDOUBLE ) ) );
\r
209 portEXIT_CRITICAL();
\r
211 /* We don't have to do anything other than indicate that we are
\r
213 ulFlop2CycleCount++;
\r
217 /*-----------------------------------------------------------*/
\r
219 portBASE_TYPE xAreFlopRegisterTestsStillRunning( void )
\r
221 portBASE_TYPE xReturn = pdPASS;
\r
222 unsigned portBASE_TYPE x, y;
\r
223 portDOUBLE z = flopSTART_VALUE;
\r
224 static unsigned long ulLastFlop1CycleCount = 0, ulLastFlop2CycleCount = 0;
\r
226 /* Called from the 'check' task.
\r
228 The flop tasks cannot be currently running, check their saved registers
\r
229 are as expected. The tests tasks do not perform any flop operations so
\r
230 their registers should be as per their initial setting. */
\r
231 for( x = 0; x < flopNUMBER_OF_TASKS; x++ )
\r
233 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )
\r
235 if( dFlopRegisters[ x ][ y ] != z )
\r
241 z+=flopSTART_VALUE;
\r
245 /* Check both tasks have actually been swapped in and out since this function
\r
247 if( ulFlop1CycleCount == ulLastFlop1CycleCount )
\r
252 if( ulFlop2CycleCount == ulLastFlop2CycleCount )
\r
257 ulLastFlop1CycleCount = ulFlop1CycleCount;
\r
258 ulLastFlop2CycleCount = ulFlop2CycleCount;
\r