2 * FreeRTOS Kernel V10.1.1
\r
3 * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
29 * Tests the floating point context save and restore mechanism.
\r
31 * Two tasks are created - each of which is allocated a buffer of
\r
32 * portNO_FLOP_REGISTERS_TO_SAVE 32bit variables into which the flop context
\r
33 * of the task is saved when the task is switched out, and from which the
\r
34 * flop context of the task is restored when the task is switch in. Prior to
\r
35 * the tasks being created each position in the two buffers is filled with a
\r
36 * unique value - this way the flop context of each task is different.
\r
38 * The two test tasks never block so are always in either the Running or
\r
39 * Ready state. They execute at the lowest priority so will get pre-empted
\r
40 * regularly, although the yield frequently so will not get much execution
\r
41 * time. The lack of execution time is not a problem as its only the
\r
42 * switching in and out that is being tested.
\r
44 * Whenever a task is moved from the Ready to the Running state its flop
\r
45 * context will be loaded from the buffer, but while the task is in the
\r
46 * Running state the buffer is not used and can contain any value - in this
\r
47 * case and for test purposes the task itself clears the buffer to zero.
\r
48 * The next time the task is moved out of the Running state into the
\r
49 * Ready state the flop context will once more get saved to the buffer -
\r
50 * overwriting the zeros.
\r
52 * Therefore whenever the task is not in the Running state its buffer contains
\r
53 * the most recent values of its floating point registers - the zeroing out
\r
54 * of the buffer while the task was executing being used to ensure the values
\r
55 * the buffer contains are not stale.
\r
57 * When neither test task is in the Running state the buffers should contain
\r
58 * the unique values allocated before the tasks were created. If so then
\r
59 * the floating point context has been maintained. This check is performed
\r
60 * by the 'check' task (defined in main.c) by calling
\r
61 * xAreFlopRegisterTestsStillRunning().
\r
63 * The test tasks also increment a value each time they execute.
\r
64 * xAreFlopRegisterTestsStillRunning() also checks that this value has changed
\r
65 * since it last ran to ensure the test tasks are still getting processing time.
\r
68 /* Standard includes files. */
\r
71 /* Scheduler include files. */
\r
72 #include "FreeRTOS.h"
\r
75 /*-----------------------------------------------------------*/
\r
77 #define flopNUMBER_OF_TASKS 2
\r
78 #define flopSTART_VALUE ( 0x1 )
\r
80 /*-----------------------------------------------------------*/
\r
82 /* The two test tasks as described at the top of this file. */
\r
83 static void vFlopTest1( void *pvParameters );
\r
84 static void vFlopTest2( void *pvParameters );
\r
86 /*-----------------------------------------------------------*/
\r
88 /* Buffers into which the flop registers will be saved. There is a buffer for
\r
90 static volatile unsigned long ulFlopRegisters[ flopNUMBER_OF_TASKS ][ portNO_FLOP_REGISTERS_TO_SAVE ];
\r
92 /* Variables that are incremented by the tasks to indicate that they are still
\r
94 static volatile unsigned long ulFlop1CycleCount = 0, ulFlop2CycleCount = 0;
\r
96 /*-----------------------------------------------------------*/
\r
98 void vStartFlopRegTests( void )
\r
100 TaskHandle_t xTaskJustCreated;
\r
101 unsigned portBASE_TYPE x, y, z = flopSTART_VALUE;
\r
103 /* Fill the arrays into which the flop registers are to be saved with
\r
104 known values. These are the values that will be written to the flop
\r
105 registers when the tasks start, and as the tasks do not perform any
\r
106 flop operations the values should never change. Each position in the
\r
107 buffer contains a different value so the flop context of each task
\r
108 will be different. */
\r
109 for( x = 0; x < flopNUMBER_OF_TASKS; x++ )
\r
111 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1); y++ )
\r
113 ulFlopRegisters[ x ][ y ] = z;
\r
119 /* Create the first task. */
\r
120 xTaskCreate( vFlopTest1, "flop1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );
\r
122 /* The task tag value is a value that can be associated with a task, but
\r
123 is not used by the scheduler itself. Its use is down to the application so
\r
124 it makes a convenient place in this case to store the pointer to the buffer
\r
125 into which the flop context of the task will be stored. The first created
\r
126 task uses ulFlopRegisters[ 0 ], the second ulFlopRegisters[ 1 ]. */
\r
127 vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 0 ][ 0 ] ) );
\r
129 /* Do the same for the second task. */
\r
130 xTaskCreate( vFlopTest2, "flop2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTaskJustCreated );
\r
131 vTaskSetApplicationTaskTag( xTaskJustCreated, ( void * ) &( ulFlopRegisters[ 1 ][ 0 ] ) );
\r
133 /*-----------------------------------------------------------*/
\r
135 static void vFlopTest1( void *pvParameters )
\r
137 /* Just to remove compiler warning. */
\r
138 ( void ) pvParameters;
\r
142 /* The values from the buffer should have now been written to the flop
\r
143 registers. Clear the buffer to ensure the same values then get written
\r
144 back the next time the task runs. Being preempted during this memset
\r
145 could cause the test to fail, hence the critical section. */
\r
146 portENTER_CRITICAL();
\r
147 memset( ( void * ) ulFlopRegisters[ 0 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );
\r
148 portEXIT_CRITICAL();
\r
150 /* We don't have to do anything other than indicate that we are
\r
152 ulFlop1CycleCount++;
\r
156 /*-----------------------------------------------------------*/
\r
158 static void vFlopTest2( void *pvParameters )
\r
160 /* Just to remove compiler warning. */
\r
161 ( void ) pvParameters;
\r
165 /* The values from the buffer should have now been written to the flop
\r
166 registers. Clear the buffer to ensure the same values then get written
\r
167 back the next time the task runs. */
\r
168 portENTER_CRITICAL();
\r
169 memset( ( void * ) ulFlopRegisters[ 1 ], 0x00, ( portNO_FLOP_REGISTERS_TO_SAVE * sizeof( unsigned portBASE_TYPE ) ) );
\r
170 portEXIT_CRITICAL();
\r
172 /* We don't have to do anything other than indicate that we are
\r
174 ulFlop2CycleCount++;
\r
178 /*-----------------------------------------------------------*/
\r
180 portBASE_TYPE xAreFlopRegisterTestsStillRunning( void )
\r
182 portBASE_TYPE xReturn = pdPASS;
\r
183 unsigned portBASE_TYPE x, y, z = flopSTART_VALUE;
\r
184 static unsigned long ulLastFlop1CycleCount = 0, ulLastFlop2CycleCount = 0;
\r
186 /* Called from the 'check' task.
\r
188 The flop tasks cannot be currently running, check their saved registers
\r
189 are as expected. The tests tasks do not perform any flop operations so
\r
190 their registers should be as per their initial setting. */
\r
191 for( x = 0; x < flopNUMBER_OF_TASKS; x++ )
\r
193 for( y = 0; y < ( portNO_FLOP_REGISTERS_TO_SAVE - 1 ); y++ )
\r
195 if( ulFlopRegisters[ x ][ y ] != z )
\r
205 /* Check both tasks have actually been swapped in and out since this function
\r
207 if( ulFlop1CycleCount == ulLastFlop1CycleCount )
\r
212 if( ulFlop2CycleCount == ulLastFlop2CycleCount )
\r
217 ulLastFlop1CycleCount = ulFlop1CycleCount;
\r
218 ulLastFlop2CycleCount = ulFlop2CycleCount;
\r