2 FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
55 * This version of integer. c is for use on systems that have limited stack
\r
56 * space and no display facilities. The complete version can be found in
\r
57 * the Demo/Common/Full directory.
\r
59 * As with the full version, the tasks created in this file are a good test
\r
60 * of the scheduler context switch mechanism. The processor has to access
\r
61 * 32bit variables in two or four chunks (depending on the processor). The low
\r
62 * priority of these tasks means there is a high probability that a context
\r
63 * switch will occur mid calculation. See flop. c documentation for
\r
71 + The constants used in the calculations are larger to ensure the
\r
72 optimiser does not truncate them to 16 bits.
\r
76 + uxTaskCheck is now just used as a boolean. Instead of incrementing
\r
77 the variable each cycle of the task, the variable is simply set to
\r
78 true. sAreIntegerMathsTaskStillRunning() sets it back to false and
\r
79 expects it to have been set back to true by the time it is called
\r
81 + A division has been included in the calculation.
\r
86 /* Scheduler include files. */
\r
87 #include "FreeRTOS.h"
\r
90 /* Demo program include files. */
\r
91 #include "integer.h"
\r
93 /* The constants used in the calculation. */
\r
94 #define intgCONST1 ( ( long ) 123 )
\r
95 #define intgCONST2 ( ( long ) 234567 )
\r
96 #define intgCONST3 ( ( long ) -3 )
\r
97 #define intgCONST4 ( ( long ) 7 )
\r
98 #define intgEXPECTED_ANSWER ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
\r
100 #define intgSTACK_SIZE configMINIMAL_STACK_SIZE
\r
102 /* As this is the minimal version, we will only create one task. */
\r
103 #define intgNUMBER_OF_TASKS ( 1 )
\r
105 /* The task function. Repeatedly performs a 32 bit calculation, checking the
\r
106 result against the expected result. If the result is incorrect then the
\r
107 context switch must have caused some corruption. */
\r
108 static portTASK_FUNCTION_PROTO( vCompeteingIntMathTask, pvParameters );
\r
110 /* Variables that are set to true within the calculation task to indicate
\r
111 that the task is still executing. The check task sets the variable back to
\r
112 false, flagging an error if the variable is still false the next time it
\r
114 static volatile signed portBASE_TYPE xTaskCheck[ intgNUMBER_OF_TASKS ] = { ( signed portBASE_TYPE ) pdFALSE };
\r
116 /*-----------------------------------------------------------*/
\r
118 void vStartIntegerMathTasks( unsigned portBASE_TYPE uxPriority )
\r
122 for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
\r
124 xTaskCreate( vCompeteingIntMathTask, ( signed char * ) "IntMath", intgSTACK_SIZE, ( void * ) &( xTaskCheck[ sTask ] ), uxPriority, ( xTaskHandle * ) NULL );
\r
127 /*-----------------------------------------------------------*/
\r
129 static portTASK_FUNCTION( vCompeteingIntMathTask, pvParameters )
\r
131 /* These variables are all effectively set to constants so they are volatile to
\r
132 ensure the compiler does not just get rid of them. */
\r
133 volatile long lValue;
\r
134 short sError = pdFALSE;
\r
135 volatile signed portBASE_TYPE *pxTaskHasExecuted;
\r
137 /* Set a pointer to the variable we are going to set to true each
\r
138 iteration. This is also a good test of the parameter passing mechanism
\r
139 within each port. */
\r
140 pxTaskHasExecuted = ( volatile signed portBASE_TYPE * ) pvParameters;
\r
142 /* Keep performing a calculation and checking the result against a constant. */
\r
145 /* Perform the calculation. This will store partial value in
\r
146 registers, resulting in a good test of the context switch mechanism. */
\r
147 lValue = intgCONST1;
\r
148 lValue += intgCONST2;
\r
150 /* Yield in case cooperative scheduling is being used. */
\r
151 #if configUSE_PREEMPTION == 0
\r
157 /* Finish off the calculation. */
\r
158 lValue *= intgCONST3;
\r
159 lValue /= intgCONST4;
\r
161 /* If the calculation is found to be incorrect we stop setting the
\r
162 TaskHasExecuted variable so the check task can see an error has
\r
164 if( lValue != intgEXPECTED_ANSWER ) /*lint !e774 volatile used to prevent this being optimised out. */
\r
169 if( sError == pdFALSE )
\r
171 /* We have not encountered any errors, so set the flag that show
\r
172 we are still executing. This will be periodically cleared by
\r
174 portENTER_CRITICAL();
\r
175 *pxTaskHasExecuted = pdTRUE;
\r
176 portEXIT_CRITICAL();
\r
179 /* Yield in case cooperative scheduling is being used. */
\r
180 #if configUSE_PREEMPTION == 0
\r
187 /*-----------------------------------------------------------*/
\r
189 /* This is called to check that all the created tasks are still running. */
\r
190 portBASE_TYPE xAreIntegerMathsTaskStillRunning( void )
\r
192 portBASE_TYPE xReturn = pdTRUE;
\r
195 /* Check the maths tasks are still running by ensuring their check variables
\r
196 are still being set to true. */
\r
197 for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
\r
199 if( xTaskCheck[ sTask ] == pdFALSE )
\r
201 /* The check has not incremented so an error exists. */
\r
205 /* Reset the check variable so we can tell if it has been set by
\r
206 the next time around. */
\r
207 xTaskCheck[ sTask ] = pdFALSE;
\r