2 FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 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
27 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
31 Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along
\r
32 with commercial development and support options.
\r
33 ***************************************************************************
\r
37 * This version of integer. c is for use on systems that have limited stack
\r
38 * space and no display facilities. The complete version can be found in
\r
39 * the Demo/Common/Full directory.
\r
41 * As with the full version, the tasks created in this file are a good test
\r
42 * of the scheduler context switch mechanism. The processor has to access
\r
43 * 32bit variables in two or four chunks (depending on the processor). The low
\r
44 * priority of these tasks means there is a high probability that a context
\r
45 * switch will occur mid calculation. See flop. c documentation for
\r
53 + The constants used in the calculations are larger to ensure the
\r
54 optimiser does not truncate them to 16 bits.
\r
58 + uxTaskCheck is now just used as a boolean. Instead of incrementing
\r
59 the variable each cycle of the task, the variable is simply set to
\r
60 true. sAreIntegerMathsTaskStillRunning() sets it back to false and
\r
61 expects it to have been set back to true by the time it is called
\r
63 + A division has been included in the calculation.
\r
68 /* Scheduler include files. */
\r
69 #include "FreeRTOS.h"
\r
72 /* Demo program include files. */
\r
73 #include "integer.h"
\r
75 /* The constants used in the calculation. */
\r
76 #define intgCONST1 ( ( portLONG ) 123 )
\r
77 #define intgCONST2 ( ( portLONG ) 234567 )
\r
78 #define intgCONST3 ( ( portLONG ) -3 )
\r
79 #define intgCONST4 ( ( portLONG ) 7 )
\r
80 #define intgEXPECTED_ANSWER ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
\r
82 #define intgSTACK_SIZE configMINIMAL_STACK_SIZE
\r
84 /* As this is the minimal version, we will only create one task. */
\r
85 #define intgNUMBER_OF_TASKS ( 1 )
\r
87 /* The task function. Repeatedly performs a 32 bit calculation, checking the
\r
88 result against the expected result. If the result is incorrect then the
\r
89 context switch must have caused some corruption. */
\r
90 static portTASK_FUNCTION_PROTO( vCompeteingIntMathTask, pvParameters );
\r
92 /* Variables that are set to true within the calculation task to indicate
\r
93 that the task is still executing. The check task sets the variable back to
\r
94 false, flagging an error if the variable is still false the next time it
\r
96 static volatile signed portBASE_TYPE xTaskCheck[ intgNUMBER_OF_TASKS ] = { ( signed portBASE_TYPE ) pdFALSE };
\r
98 /*-----------------------------------------------------------*/
\r
100 void vStartIntegerMathTasks( unsigned portBASE_TYPE uxPriority )
\r
104 for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
\r
106 xTaskCreate( vCompeteingIntMathTask, ( signed portCHAR * ) "IntMath", intgSTACK_SIZE, ( void * ) &( xTaskCheck[ sTask ] ), uxPriority, ( xTaskHandle * ) NULL );
\r
109 /*-----------------------------------------------------------*/
\r
111 static portTASK_FUNCTION( vCompeteingIntMathTask, pvParameters )
\r
113 /* These variables are all effectively set to constants so they are volatile to
\r
114 ensure the compiler does not just get rid of them. */
\r
115 volatile portLONG lValue;
\r
116 portSHORT sError = pdFALSE;
\r
117 volatile signed portBASE_TYPE *pxTaskHasExecuted;
\r
119 /* Set a pointer to the variable we are going to set to true each
\r
120 iteration. This is also a good test of the parameter passing mechanism
\r
121 within each port. */
\r
122 pxTaskHasExecuted = ( volatile signed portBASE_TYPE * ) pvParameters;
\r
124 /* Keep performing a calculation and checking the result against a constant. */
\r
127 /* Perform the calculation. This will store partial value in
\r
128 registers, resulting in a good test of the context switch mechanism. */
\r
129 lValue = intgCONST1;
\r
130 lValue += intgCONST2;
\r
132 /* Yield in case cooperative scheduling is being used. */
\r
133 #if configUSE_PREEMPTION == 0
\r
139 /* Finish off the calculation. */
\r
140 lValue *= intgCONST3;
\r
141 lValue /= intgCONST4;
\r
143 /* If the calculation is found to be incorrect we stop setting the
\r
144 TaskHasExecuted variable so the check task can see an error has
\r
146 if( lValue != intgEXPECTED_ANSWER ) /*lint !e774 volatile used to prevent this being optimised out. */
\r
151 if( sError == pdFALSE )
\r
153 /* We have not encountered any errors, so set the flag that show
\r
154 we are still executing. This will be periodically cleared by
\r
156 portENTER_CRITICAL();
\r
157 *pxTaskHasExecuted = pdTRUE;
\r
158 portEXIT_CRITICAL();
\r
161 /* Yield in case cooperative scheduling is being used. */
\r
162 #if configUSE_PREEMPTION == 0
\r
169 /*-----------------------------------------------------------*/
\r
171 /* This is called to check that all the created tasks are still running. */
\r
172 portBASE_TYPE xAreIntegerMathsTaskStillRunning( void )
\r
174 portBASE_TYPE xReturn = pdTRUE;
\r
177 /* Check the maths tasks are still running by ensuring their check variables
\r
178 are still being set to true. */
\r
179 for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
\r
181 if( xTaskCheck[ sTask ] == pdFALSE )
\r
183 /* The check has not incremented so an error exists. */
\r
187 /* Reset the check variable so we can tell if it has been set by
\r
188 the next time around. */
\r
189 xTaskCheck[ sTask ] = pdFALSE;
\r