2 FreeRTOS V5.4.1 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
49 * This version of integer. c is for use on systems that have limited stack
\r
50 * space and no display facilities. The complete version can be found in
\r
51 * the Demo/Common/Full directory.
\r
53 * As with the full version, the tasks created in this file are a good test
\r
54 * of the scheduler context switch mechanism. The processor has to access
\r
55 * 32bit variables in two or four chunks (depending on the processor). The low
\r
56 * priority of these tasks means there is a high probability that a context
\r
57 * switch will occur mid calculation. See flop. c documentation for
\r
65 + The constants used in the calculations are larger to ensure the
\r
66 optimiser does not truncate them to 16 bits.
\r
70 + uxTaskCheck is now just used as a boolean. Instead of incrementing
\r
71 the variable each cycle of the task, the variable is simply set to
\r
72 true. sAreIntegerMathsTaskStillRunning() sets it back to false and
\r
73 expects it to have been set back to true by the time it is called
\r
75 + A division has been included in the calculation.
\r
80 /* Scheduler include files. */
\r
81 #include "FreeRTOS.h"
\r
84 /* Demo program include files. */
\r
85 #include "integer.h"
\r
87 /* The constants used in the calculation. */
\r
88 #define intgCONST1 ( ( portLONG ) 123 )
\r
89 #define intgCONST2 ( ( portLONG ) 234567 )
\r
90 #define intgCONST3 ( ( portLONG ) -3 )
\r
91 #define intgCONST4 ( ( portLONG ) 7 )
\r
92 #define intgEXPECTED_ANSWER ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
\r
94 #define intgSTACK_SIZE configMINIMAL_STACK_SIZE
\r
96 /* As this is the minimal version, we will only create one task. */
\r
97 #define intgNUMBER_OF_TASKS ( 1 )
\r
99 /* The task function. Repeatedly performs a 32 bit calculation, checking the
\r
100 result against the expected result. If the result is incorrect then the
\r
101 context switch must have caused some corruption. */
\r
102 static portTASK_FUNCTION_PROTO( vCompeteingIntMathTask, pvParameters );
\r
104 /* Variables that are set to true within the calculation task to indicate
\r
105 that the task is still executing. The check task sets the variable back to
\r
106 false, flagging an error if the variable is still false the next time it
\r
108 static volatile signed portBASE_TYPE xTaskCheck[ intgNUMBER_OF_TASKS ] = { ( signed portBASE_TYPE ) pdFALSE };
\r
110 /*-----------------------------------------------------------*/
\r
112 void vStartIntegerMathTasks( unsigned portBASE_TYPE uxPriority )
\r
116 for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
\r
118 xTaskCreate( vCompeteingIntMathTask, ( signed portCHAR * ) "IntMath", intgSTACK_SIZE, ( void * ) &( xTaskCheck[ sTask ] ), uxPriority, ( xTaskHandle * ) NULL );
\r
121 /*-----------------------------------------------------------*/
\r
123 static portTASK_FUNCTION( vCompeteingIntMathTask, pvParameters )
\r
125 /* These variables are all effectively set to constants so they are volatile to
\r
126 ensure the compiler does not just get rid of them. */
\r
127 volatile portLONG lValue;
\r
128 portSHORT sError = pdFALSE;
\r
129 volatile signed portBASE_TYPE *pxTaskHasExecuted;
\r
131 /* Set a pointer to the variable we are going to set to true each
\r
132 iteration. This is also a good test of the parameter passing mechanism
\r
133 within each port. */
\r
134 pxTaskHasExecuted = ( volatile signed portBASE_TYPE * ) pvParameters;
\r
136 /* Keep performing a calculation and checking the result against a constant. */
\r
139 /* Perform the calculation. This will store partial value in
\r
140 registers, resulting in a good test of the context switch mechanism. */
\r
141 lValue = intgCONST1;
\r
142 lValue += intgCONST2;
\r
144 /* Yield in case cooperative scheduling is being used. */
\r
145 #if configUSE_PREEMPTION == 0
\r
151 /* Finish off the calculation. */
\r
152 lValue *= intgCONST3;
\r
153 lValue /= intgCONST4;
\r
155 /* If the calculation is found to be incorrect we stop setting the
\r
156 TaskHasExecuted variable so the check task can see an error has
\r
158 if( lValue != intgEXPECTED_ANSWER ) /*lint !e774 volatile used to prevent this being optimised out. */
\r
163 if( sError == pdFALSE )
\r
165 /* We have not encountered any errors, so set the flag that show
\r
166 we are still executing. This will be periodically cleared by
\r
168 portENTER_CRITICAL();
\r
169 *pxTaskHasExecuted = pdTRUE;
\r
170 portEXIT_CRITICAL();
\r
173 /* Yield in case cooperative scheduling is being used. */
\r
174 #if configUSE_PREEMPTION == 0
\r
181 /*-----------------------------------------------------------*/
\r
183 /* This is called to check that all the created tasks are still running. */
\r
184 portBASE_TYPE xAreIntegerMathsTaskStillRunning( void )
\r
186 portBASE_TYPE xReturn = pdTRUE;
\r
189 /* Check the maths tasks are still running by ensuring their check variables
\r
190 are still being set to true. */
\r
191 for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
\r
193 if( xTaskCheck[ sTask ] == pdFALSE )
\r
195 /* The check has not incremented so an error exists. */
\r
199 /* Reset the check variable so we can tell if it has been set by
\r
200 the next time around. */
\r
201 xTaskCheck[ sTask ] = pdFALSE;
\r