2 FreeRTOS V8.2.2 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
71 * Creates one or more tasks that repeatedly perform a set of integer
\r
72 * calculations. The result of each run-time calculation is compared to the
\r
73 * known expected result - with a mismatch being indicative of an error in the
\r
74 * context switch mechanism.
\r
79 /* Scheduler include files. */
\r
80 #include "FreeRTOS.h"
\r
83 /* Demo program include files. */
\r
84 #include "integer.h"
\r
86 /* The constants used in the calculation. */
\r
87 #define intgCONST1 ( ( long ) 123 )
\r
88 #define intgCONST2 ( ( long ) 234567 )
\r
89 #define intgCONST3 ( ( long ) -3 )
\r
90 #define intgCONST4 ( ( long ) 7 )
\r
91 #define intgEXPECTED_ANSWER ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
\r
93 #define intgSTACK_SIZE configMINIMAL_STACK_SIZE
\r
95 /* As this is the minimal version, we will only create one task. */
\r
96 #define intgNUMBER_OF_TASKS ( 1 )
\r
98 /* The task function. Repeatedly performs a 32 bit calculation, checking the
\r
99 result against the expected result. If the result is incorrect then the
\r
100 context switch must have caused some corruption. */
\r
101 static portTASK_FUNCTION_PROTO( vCompeteingIntMathTask, pvParameters );
\r
103 /* Variables that are set to true within the calculation task to indicate
\r
104 that the task is still executing. The check task sets the variable back to
\r
105 false, flagging an error if the variable is still false the next time it
\r
107 static volatile BaseType_t xTaskCheck[ intgNUMBER_OF_TASKS ] = { ( BaseType_t ) pdFALSE };
\r
109 /*-----------------------------------------------------------*/
\r
111 void vStartIntegerMathTasks( UBaseType_t uxPriority )
\r
115 for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
\r
117 xTaskCreate( vCompeteingIntMathTask, "IntMath", intgSTACK_SIZE, ( void * ) &( xTaskCheck[ sTask ] ), uxPriority, ( TaskHandle_t * ) NULL );
\r
120 /*-----------------------------------------------------------*/
\r
122 static portTASK_FUNCTION( vCompeteingIntMathTask, pvParameters )
\r
124 /* These variables are all effectively set to constants so they are volatile to
\r
125 ensure the compiler does not just get rid of them. */
\r
126 volatile long lValue;
\r
127 short sError = pdFALSE;
\r
128 volatile BaseType_t *pxTaskHasExecuted;
\r
130 /* Set a pointer to the variable we are going to set to true each
\r
131 iteration. This is also a good test of the parameter passing mechanism
\r
132 within each port. */
\r
133 pxTaskHasExecuted = ( volatile BaseType_t * ) pvParameters;
\r
135 /* Keep performing a calculation and checking the result against a constant. */
\r
138 /* Perform the calculation. This will store partial value in
\r
139 registers, resulting in a good test of the context switch mechanism. */
\r
140 lValue = intgCONST1;
\r
141 lValue += intgCONST2;
\r
143 /* Yield in case cooperative scheduling is being used. */
\r
144 #if configUSE_PREEMPTION == 0
\r
150 /* Finish off the calculation. */
\r
151 lValue *= intgCONST3;
\r
152 lValue /= intgCONST4;
\r
154 /* If the calculation is found to be incorrect we stop setting the
\r
155 TaskHasExecuted variable so the check task can see an error has
\r
157 if( lValue != intgEXPECTED_ANSWER ) /*lint !e774 volatile used to prevent this being optimised out. */
\r
162 if( sError == pdFALSE )
\r
164 /* We have not encountered any errors, so set the flag that show
\r
165 we are still executing. This will be periodically cleared by
\r
167 portENTER_CRITICAL();
\r
168 *pxTaskHasExecuted = pdTRUE;
\r
169 portEXIT_CRITICAL();
\r
172 /* Yield in case cooperative scheduling is being used. */
\r
173 #if configUSE_PREEMPTION == 0
\r
180 /*-----------------------------------------------------------*/
\r
182 /* This is called to check that all the created tasks are still running. */
\r
183 BaseType_t xAreIntegerMathsTaskStillRunning( void )
\r
185 BaseType_t xReturn = pdTRUE;
\r
188 /* Check the maths tasks are still running by ensuring their check variables
\r
189 are still being set to true. */
\r
190 for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
\r
192 if( xTaskCheck[ sTask ] == pdFALSE )
\r
194 /* The check has not incremented so an error exists. */
\r
198 /* Reset the check variable so we can tell if it has been set by
\r
199 the next time around. */
\r
200 xTaskCheck[ sTask ] = pdFALSE;
\r