2 FreeRTOS.org V4.7.1 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
28 Please ensure to read the configuration and relevant port sections of the
\r
29 online documentation.
\r
31 +++ http://www.FreeRTOS.org +++
\r
32 Documentation, latest information, license and contact details.
\r
34 +++ http://www.SafeRTOS.com +++
\r
35 A version that is certified for use in safety critical systems.
\r
37 +++ http://www.OpenRTOS.com +++
\r
38 Commercial support, development, porting, licensing and training services.
\r
40 ***************************************************************************
\r
44 * This version of integer. c is for use on systems that have limited stack
\r
45 * space and no display facilities. The complete version can be found in
\r
46 * the Demo/Common/Full directory.
\r
48 * As with the full version, the tasks created in this file are a good test
\r
49 * of the scheduler context switch mechanism. The processor has to access
\r
50 * 32bit variables in two or four chunks (depending on the processor). The low
\r
51 * priority of these tasks means there is a high probability that a context
\r
52 * switch will occur mid calculation. See flop. c documentation for
\r
60 + The constants used in the calculations are larger to ensure the
\r
61 optimiser does not truncate them to 16 bits.
\r
65 + uxTaskCheck is now just used as a boolean. Instead of incrementing
\r
66 the variable each cycle of the task, the variable is simply set to
\r
67 true. sAreIntegerMathsTaskStillRunning() sets it back to false and
\r
68 expects it to have been set back to true by the time it is called
\r
70 + A division has been included in the calculation.
\r
75 /* Scheduler include files. */
\r
76 #include "FreeRTOS.h"
\r
79 /* Demo program include files. */
\r
80 #include "integer.h"
\r
82 /* The constants used in the calculation. */
\r
83 #define intgCONST1 ( ( portLONG ) 123 )
\r
84 #define intgCONST2 ( ( portLONG ) 234567 )
\r
85 #define intgCONST3 ( ( portLONG ) -3 )
\r
86 #define intgCONST4 ( ( portLONG ) 7 )
\r
87 #define intgEXPECTED_ANSWER ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
\r
89 #define intgSTACK_SIZE configMINIMAL_STACK_SIZE
\r
91 /* As this is the minimal version, we will only create one task. */
\r
92 #define intgNUMBER_OF_TASKS ( 1 )
\r
94 /* The task function. Repeatedly performs a 32 bit calculation, checking the
\r
95 result against the expected result. If the result is incorrect then the
\r
96 context switch must have caused some corruption. */
\r
97 static portTASK_FUNCTION_PROTO( vCompeteingIntMathTask, pvParameters );
\r
99 /* Variables that are set to true within the calculation task to indicate
\r
100 that the task is still executing. The check task sets the variable back to
\r
101 false, flagging an error if the variable is still false the next time it
\r
103 static volatile signed portBASE_TYPE xTaskCheck[ intgNUMBER_OF_TASKS ] = { ( signed portBASE_TYPE ) pdFALSE };
\r
105 /*-----------------------------------------------------------*/
\r
107 void vStartIntegerMathTasks( unsigned portBASE_TYPE uxPriority )
\r
111 for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
\r
113 xTaskCreate( vCompeteingIntMathTask, ( signed portCHAR * ) "IntMath", intgSTACK_SIZE, ( void * ) &( xTaskCheck[ sTask ] ), uxPriority, ( xTaskHandle * ) NULL );
\r
116 /*-----------------------------------------------------------*/
\r
118 static portTASK_FUNCTION( vCompeteingIntMathTask, pvParameters )
\r
120 /* These variables are all effectively set to constants so they are volatile to
\r
121 ensure the compiler does not just get rid of them. */
\r
122 volatile portLONG lValue;
\r
123 portSHORT sError = pdFALSE;
\r
124 volatile signed portBASE_TYPE *pxTaskHasExecuted;
\r
126 /* Set a pointer to the variable we are going to set to true each
\r
127 iteration. This is also a good test of the parameter passing mechanism
\r
128 within each port. */
\r
129 pxTaskHasExecuted = ( volatile signed portBASE_TYPE * ) pvParameters;
\r
131 /* Keep performing a calculation and checking the result against a constant. */
\r
134 /* Perform the calculation. This will store partial value in
\r
135 registers, resulting in a good test of the context switch mechanism. */
\r
136 lValue = intgCONST1;
\r
137 lValue += intgCONST2;
\r
139 /* Yield in case cooperative scheduling is being used. */
\r
140 #if configUSE_PREEMPTION == 0
\r
146 /* Finish off the calculation. */
\r
147 lValue *= intgCONST3;
\r
148 lValue /= intgCONST4;
\r
150 /* If the calculation is found to be incorrect we stop setting the
\r
151 TaskHasExecuted variable so the check task can see an error has
\r
153 if( lValue != intgEXPECTED_ANSWER ) /*lint !e774 volatile used to prevent this being optimised out. */
\r
158 if( sError == pdFALSE )
\r
160 /* We have not encountered any errors, so set the flag that show
\r
161 we are still executing. This will be periodically cleared by
\r
163 portENTER_CRITICAL();
\r
164 *pxTaskHasExecuted = pdTRUE;
\r
165 portEXIT_CRITICAL();
\r
168 /* Yield in case cooperative scheduling is being used. */
\r
169 #if configUSE_PREEMPTION == 0
\r
176 /*-----------------------------------------------------------*/
\r
178 /* This is called to check that all the created tasks are still running. */
\r
179 portBASE_TYPE xAreIntegerMathsTaskStillRunning( void )
\r
181 portBASE_TYPE xReturn = pdTRUE;
\r
184 /* Check the maths tasks are still running by ensuring their check variables
\r
185 are still being set to true. */
\r
186 for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
\r
188 if( xTaskCheck[ sTask ] == pdFALSE )
\r
190 /* The check has not incremented so an error exists. */
\r
194 /* Reset the check variable so we can tell if it has been set by
\r
195 the next time around. */
\r
196 xTaskCheck[ sTask ] = pdFALSE;
\r