2 FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
32 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
33 distribute a combined work that includes FreeRTOS without being obliged to
\r
34 provide the source code for proprietary components outside of the FreeRTOS
\r
35 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
36 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
37 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
38 more details. You should have received a copy of the GNU General Public
\r
39 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
40 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
41 by writing to Richard Barry, contact details for whom are available on the
\r
46 ***************************************************************************
\r
48 * Having a problem? Start by reading the FAQ "My application does *
\r
49 * not run, what could be wrong?" *
\r
51 * http://www.FreeRTOS.org/FAQHelp.html *
\r
53 ***************************************************************************
\r
56 http://www.FreeRTOS.org - Documentation, training, latest versions, license
\r
57 and contact details.
\r
59 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
60 including FreeRTOS+Trace - an indispensable productivity tool.
\r
62 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
63 the code with commercial support, indemnification, and middleware, under
\r
64 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
65 provide a safety engineered and independently SIL3 certified version under
\r
66 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
70 * Creates one or more tasks that repeatedly perform a set of integer
\r
71 * calculations. The result of each run-time calculation is compared to the
\r
72 * known expected result - with a mismatch being indicative of an error in the
\r
73 * context switch mechanism.
\r
78 /* Scheduler include files. */
\r
79 #include "FreeRTOS.h"
\r
82 /* Demo program include files. */
\r
83 #include "integer.h"
\r
85 /* The constants used in the calculation. */
\r
86 #define intgCONST1 ( ( long ) 123 )
\r
87 #define intgCONST2 ( ( long ) 234567 )
\r
88 #define intgCONST3 ( ( long ) -3 )
\r
89 #define intgCONST4 ( ( long ) 7 )
\r
90 #define intgEXPECTED_ANSWER ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
\r
92 #define intgSTACK_SIZE configMINIMAL_STACK_SIZE
\r
94 /* As this is the minimal version, we will only create one task. */
\r
95 #define intgNUMBER_OF_TASKS ( 1 )
\r
97 /* The task function. Repeatedly performs a 32 bit calculation, checking the
\r
98 result against the expected result. If the result is incorrect then the
\r
99 context switch must have caused some corruption. */
\r
100 static portTASK_FUNCTION_PROTO( vCompeteingIntMathTask, pvParameters );
\r
102 /* Variables that are set to true within the calculation task to indicate
\r
103 that the task is still executing. The check task sets the variable back to
\r
104 false, flagging an error if the variable is still false the next time it
\r
106 static volatile signed portBASE_TYPE xTaskCheck[ intgNUMBER_OF_TASKS ] = { ( signed portBASE_TYPE ) pdFALSE };
\r
108 /*-----------------------------------------------------------*/
\r
110 void vStartIntegerMathTasks( unsigned portBASE_TYPE uxPriority )
\r
114 for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
\r
116 xTaskCreate( vCompeteingIntMathTask, ( signed char * ) "IntMath", intgSTACK_SIZE, ( void * ) &( xTaskCheck[ sTask ] ), uxPriority, ( xTaskHandle * ) NULL );
\r
119 /*-----------------------------------------------------------*/
\r
121 static portTASK_FUNCTION( vCompeteingIntMathTask, pvParameters )
\r
123 /* These variables are all effectively set to constants so they are volatile to
\r
124 ensure the compiler does not just get rid of them. */
\r
125 volatile long lValue;
\r
126 short sError = pdFALSE;
\r
127 volatile signed portBASE_TYPE *pxTaskHasExecuted;
\r
129 /* Set a pointer to the variable we are going to set to true each
\r
130 iteration. This is also a good test of the parameter passing mechanism
\r
131 within each port. */
\r
132 pxTaskHasExecuted = ( volatile signed portBASE_TYPE * ) pvParameters;
\r
134 /* Keep performing a calculation and checking the result against a constant. */
\r
137 /* Perform the calculation. This will store partial value in
\r
138 registers, resulting in a good test of the context switch mechanism. */
\r
139 lValue = intgCONST1;
\r
140 lValue += intgCONST2;
\r
142 /* Yield in case cooperative scheduling is being used. */
\r
143 #if configUSE_PREEMPTION == 0
\r
149 /* Finish off the calculation. */
\r
150 lValue *= intgCONST3;
\r
151 lValue /= intgCONST4;
\r
153 /* If the calculation is found to be incorrect we stop setting the
\r
154 TaskHasExecuted variable so the check task can see an error has
\r
156 if( lValue != intgEXPECTED_ANSWER ) /*lint !e774 volatile used to prevent this being optimised out. */
\r
161 if( sError == pdFALSE )
\r
163 /* We have not encountered any errors, so set the flag that show
\r
164 we are still executing. This will be periodically cleared by
\r
166 portENTER_CRITICAL();
\r
167 *pxTaskHasExecuted = pdTRUE;
\r
168 portEXIT_CRITICAL();
\r
171 /* Yield in case cooperative scheduling is being used. */
\r
172 #if configUSE_PREEMPTION == 0
\r
179 /*-----------------------------------------------------------*/
\r
181 /* This is called to check that all the created tasks are still running. */
\r
182 portBASE_TYPE xAreIntegerMathsTaskStillRunning( void )
\r
184 portBASE_TYPE xReturn = pdTRUE;
\r
187 /* Check the maths tasks are still running by ensuring their check variables
\r
188 are still being set to true. */
\r
189 for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
\r
191 if( xTaskCheck[ sTask ] == pdFALSE )
\r
193 /* The check has not incremented so an error exists. */
\r
197 /* Reset the check variable so we can tell if it has been set by
\r
198 the next time around. */
\r
199 xTaskCheck[ sTask ] = pdFALSE;
\r