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