2 FreeRTOS V8.2.0rc1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
14 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
15 >>! obliged to provide the source code for proprietary components !<<
\r
16 >>! outside of the FreeRTOS kernel. !<<
\r
18 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
20 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
21 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * Having a problem? Start by reading the FAQ "My application does *
\r
28 * not run, what could be wrong?". Have you defined configASSERT()? *
\r
30 * http://www.FreeRTOS.org/FAQHelp.html *
\r
32 ***************************************************************************
\r
34 ***************************************************************************
\r
36 * FreeRTOS provides completely free yet professionally developed, *
\r
37 * robust, strictly quality controlled, supported, and cross *
\r
38 * platform software that is more than just the market leader, it *
\r
39 * is the industry's de facto standard. *
\r
41 * Help yourself get started quickly while simultaneously helping *
\r
42 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
43 * tutorial book, reference manual, or both: *
\r
44 * http://www.FreeRTOS.org/Documentation *
\r
46 ***************************************************************************
\r
48 ***************************************************************************
\r
50 * Investing in training allows your team to be as productive as *
\r
51 * possible as early as possible, lowering your overall development *
\r
52 * cost, and enabling you to bring a more robust product to market *
\r
53 * earlier than would otherwise be possible. Richard Barry is both *
\r
54 * the architect and key author of FreeRTOS, and so also the world's *
\r
55 * leading authority on what is the world's most popular real time *
\r
56 * kernel for deeply embedded MCU designs. Obtaining your training *
\r
57 * from Richard ensures your team will gain directly from his in-depth *
\r
58 * product knowledge and years of usage experience. Contact Real Time *
\r
59 * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *
\r
60 * by Richard Barry: http://www.FreeRTOS.org/contact
\r
62 ***************************************************************************
\r
64 ***************************************************************************
\r
66 * You are receiving this top quality software for free. Please play *
\r
67 * fair and reciprocate by reporting any suspected issues and *
\r
68 * participating in the community forum: *
\r
69 * http://www.FreeRTOS.org/support *
\r
73 ***************************************************************************
\r
75 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
76 license and Real Time Engineers Ltd. contact details.
\r
78 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
79 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
80 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
82 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
83 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
85 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
86 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
87 licenses offer ticketed support, indemnification and commercial middleware.
\r
89 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
90 engineered and independently SIL3 certified version for use in safety and
\r
91 mission critical applications that require provable dependability.
\r
97 * Tests the floating point context save and restore mechanism.
\r
99 * Two tasks are created - each of which is allocated a buffer of
\r
100 * portNO_FLOP_REGISTERS_TO_SAVE 32bit variables into which the flop context
\r
101 * of the task is saved when the task is switched out, and from which the
\r
102 * flop context of the task is restored when the task is switch in. Prior to
\r
103 * the tasks being created each position in the two buffers is filled with a
\r
104 * unique value - this way the flop context of each task is different.
\r
106 * The two test tasks never block so are always in either the Running or
\r
107 * Ready state. They execute at the lowest priority so will get pre-empted
\r
108 * regularly, although the yield frequently so will not get much execution
\r
109 * time. The lack of execution time is not a problem as its only the
\r
110 * switching in and out that is being tested.
\r
112 * Whenever a task is moved from the Ready to the Running state its flop
\r
113 * context will be loaded from the buffer, but while the task is in the
\r
114 * Running state the buffer is not used and can contain any value - in this
\r
115 * case and for test purposes the task itself clears the buffer to zero.
\r
116 * The next time the task is moved out of the Running state into the
\r
117 * Ready state the flop context will once more get saved to the buffer -
\r
118 * overwriting the zeros.
\r
120 * Therefore whenever the task is not in the Running state its buffer contains
\r
121 * the most recent values of its floating point registers - the zeroing out
\r
122 * of the buffer while the task was executing being used to ensure the values
\r
123 * the buffer contains are not stale.
\r
125 * When neither test task is in the Running state the buffers should contain
\r
126 * the unique values allocated before the tasks were created. If so then
\r
127 * the floating point context has been maintained. This check is performed
\r
128 * by the 'check' task (defined in main.c) by calling
\r
129 * xAreFlopRegisterTestsStillRunning().
\r
131 * The test tasks also increment a value each time they execute.
\r
132 * xAreFlopRegisterTestsStillRunning() also checks that this value has changed
\r
133 * since it last ran to ensure the test tasks are still getting processing time.
\r
136 /* Standard includes files. */
\r
137 #include <string.h>
\r
139 /* Scheduler include files. */
\r
140 #include "FreeRTOS.h"
\r
143 /*-----------------------------------------------------------*/
\r
145 #define flopNUMBER_OF_TASKS 2
\r
146 #define flopSTART_VALUE ( 0x1 )
\r
148 /*-----------------------------------------------------------*/
\r
150 /* The two test tasks as described at the top of this file. */
\r
151 static void vFlopTest1( void *pvParameters );
\r
152 static void vFlopTest2( void *pvParameters );
\r
154 /*-----------------------------------------------------------*/
\r
156 /* Buffers into which the flop registers will be saved. There is a buffer for
\r
158 static volatile unsigned long ulFlopRegisters[ flopNUMBER_OF_TASKS ][ portNO_FLOP_REGISTERS_TO_SAVE ];
\r
160 /* Variables that are incremented by the tasks to indicate that they are still
\r
162 static volatile unsigned long ulFlop1CycleCount = 0, ulFlop2CycleCount = 0;
\r
164 /*-----------------------------------------------------------*/
\r
166 void vStartFlopRegTests( void )
\r
168 TaskHandle_t xTaskJustCreated;
\r
169 unsigned portBASE_TYPE x, y, z = flopSTART_VALUE;
\r
171 /* Fill the arrays into which the flop registers are to be saved with
\r
172 known values. These are the values that will be written to the flop
\r
173 registers when the tasks start, and as the tasks do not perform any
\r
174 flop operations the values should never change. Each position in the
\r
175 buffer contains a different value so the flop context of each task
\r
176 will be different. */
\r
177 for( x = 0; x < flopNUMBER_OF_TASKS; x++ )
\r
179 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1); y++ )
\r
181 ulFlopRegisters[ x ][ y ] = z;
\r
187 /* Create the first task. */
\r
188 xTaskCreate( vFlopTest1, "flop1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );
\r
190 /* The task tag value is a value that can be associated with a task, but
\r
191 is not used by the scheduler itself. Its use is down to the application so
\r
192 it makes a convenient place in this case to store the pointer to the buffer
\r
193 into which the flop context of the task will be stored. The first created
\r
194 task uses ulFlopRegisters[ 0 ], the second ulFlopRegisters[ 1 ]. */
\r
195 vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 0 ][ 0 ] ) );
\r
197 /* Do the same for the second task. */
\r
198 xTaskCreate( vFlopTest2, "flop2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );
\r
199 vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 1 ][ 0 ] ) );
\r
201 /*-----------------------------------------------------------*/
\r
203 static void vFlopTest1( void *pvParameters )
\r
205 /* Just to remove compiler warning. */
\r
206 ( void ) pvParameters;
\r
210 /* The values from the buffer should have now been written to the flop
\r
211 registers. Clear the buffer to ensure the same values then get written
\r
212 back the next time the task runs. Being preempted during this memset
\r
213 could cause the test to fail, hence the critical section. */
\r
214 portENTER_CRITICAL();
\r
215 memset( ( void * ) ulFlopRegisters[ 0 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );
\r
216 portEXIT_CRITICAL();
\r
218 /* We don't have to do anything other than indicate that we are
\r
220 ulFlop1CycleCount++;
\r
224 /*-----------------------------------------------------------*/
\r
226 static void vFlopTest2( void *pvParameters )
\r
228 /* Just to remove compiler warning. */
\r
229 ( void ) pvParameters;
\r
233 /* The values from the buffer should have now been written to the flop
\r
234 registers. Clear the buffer to ensure the same values then get written
\r
235 back the next time the task runs. */
\r
236 portENTER_CRITICAL();
\r
237 memset( ( void * ) ulFlopRegisters[ 1 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );
\r
238 portEXIT_CRITICAL();
\r
240 /* We don't have to do anything other than indicate that we are
\r
242 ulFlop2CycleCount++;
\r
246 /*-----------------------------------------------------------*/
\r
248 portBASE_TYPE xAreFlopRegisterTestsStillRunning( void )
\r
250 portBASE_TYPE xReturn = pdPASS;
\r
251 unsigned portBASE_TYPE x, y, z = flopSTART_VALUE;
\r
252 static unsigned long ulLastFlop1CycleCount = 0, ulLastFlop2CycleCount = 0;
\r
254 /* Called from the 'check' task.
\r
256 The flop tasks cannot be currently running, check their saved registers
\r
257 are as expected. The tests tasks do not perform any flop operations so
\r
258 their registers should be as per their initial setting. */
\r
259 for( x = 0; x < flopNUMBER_OF_TASKS; x++ )
\r
261 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )
\r
263 if( ulFlopRegisters[ x ][ y ] != z )
\r
273 /* Check both tasks have actually been swapped in and out since this function
\r
275 if( ulFlop1CycleCount == ulLastFlop1CycleCount )
\r
280 if( ulFlop2CycleCount == ulLastFlop2CycleCount )
\r
285 ulLastFlop1CycleCount = ulFlop1CycleCount;
\r
286 ulLastFlop2CycleCount = ulFlop2CycleCount;
\r