3 FreeRTOS V8.2.0rc1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
6 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
8 This file is part of the FreeRTOS distribution.
\r
10 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
11 the terms of the GNU General Public License (version 2) as published by the
\r
12 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\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
19 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
20 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
21 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
22 link: http://www.freertos.org/a00114.html
\r
26 ***************************************************************************
\r
28 * Having a problem? Start by reading the FAQ "My application does *
\r
29 * not run, what could be wrong?". Have you defined configASSERT()? *
\r
31 * http://www.FreeRTOS.org/FAQHelp.html *
\r
33 ***************************************************************************
\r
35 ***************************************************************************
\r
37 * FreeRTOS provides completely free yet professionally developed, *
\r
38 * robust, strictly quality controlled, supported, and cross *
\r
39 * platform software that is more than just the market leader, it *
\r
40 * is the industry's de facto standard. *
\r
42 * Help yourself get started quickly while simultaneously helping *
\r
43 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
44 * tutorial book, reference manual, or both: *
\r
45 * http://www.FreeRTOS.org/Documentation *
\r
47 ***************************************************************************
\r
49 ***************************************************************************
\r
51 * Investing in training allows your team to be as productive as *
\r
52 * possible as early as possible, lowering your overall development *
\r
53 * cost, and enabling you to bring a more robust product to market *
\r
54 * earlier than would otherwise be possible. Richard Barry is both *
\r
55 * the architect and key author of FreeRTOS, and so also the world's *
\r
56 * leading authority on what is the world's most popular real time *
\r
57 * kernel for deeply embedded MCU designs. Obtaining your training *
\r
58 * from Richard ensures your team will gain directly from his in-depth *
\r
59 * product knowledge and years of usage experience. Contact Real Time *
\r
60 * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *
\r
61 * by Richard Barry: http://www.FreeRTOS.org/contact
\r
63 ***************************************************************************
\r
65 ***************************************************************************
\r
67 * You are receiving this top quality software for free. Please play *
\r
68 * fair and reciprocate by reporting any suspected issues and *
\r
69 * participating in the community forum: *
\r
70 * http://www.FreeRTOS.org/support *
\r
74 ***************************************************************************
\r
76 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
77 license and Real Time Engineers Ltd. contact details.
\r
79 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
80 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
81 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
83 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
84 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
86 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
87 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
88 licenses offer ticketed support, indemnification and commercial middleware.
\r
90 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
91 engineered and independently SIL3 certified version for use in safety and
\r
92 mission critical applications that require provable dependability.
\r
100 * vMain() is effectively the demo application entry point. It is called by
\r
101 * the main() function generated by the Processor Expert application.
\r
103 * vMain() creates all the demo application tasks, then starts the scheduler.
\r
104 * The WEB documentation provides more details of the demo application tasks.
\r
106 * Main.c also creates a task called "Check". This only executes every three
\r
107 * seconds but has the highest priority so is guaranteed to get processor time.
\r
108 * Its main function is to check that all the other tasks are still operational.
\r
109 * Each task (other than the "flash" tasks) maintains a unique count that is
\r
110 * incremented each time the task successfully completes its function. Should
\r
111 * any error occur within such a task the count is permanently halted. The
\r
112 * check task inspects the count of each task to ensure it has changed since
\r
113 * the last time the check task executed. If all the count variables have
\r
114 * changed all the tasks are still executing error free, and the check task
\r
115 * toggles the onboard LED. Should any task contain an error at any time
\r
116 * the LED toggle rate will change from 3 seconds to 500ms.
\r
118 * This file also includes the functionality implemented within the
\r
119 * standard demo application file integer.c. This is done to demonstrate the
\r
120 * use of an idle hook. See the documentation within integer.c for the
\r
121 * rationale of the integer task functionality.
\r
124 /* Kernel includes. */
\r
125 #include "FreeRTOS.h"
\r
129 /* Demo application includes. */
\r
132 #include "dynamic.h"
\r
133 #include "partest.h"
\r
134 #include "comtest2.h"
\r
135 #include "BlockQ.h"
\r
136 #include "integer.h"
\r
140 /*-----------------------------------------------------------
\r
142 -----------------------------------------------------------*/
\r
144 /* Priorities assigned to demo application tasks. */
\r
145 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
146 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
147 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
148 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
149 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
150 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
152 /* LED that is toggled by the check task. The check task periodically checks
\r
153 that all the other tasks are operating without error. If no errors are found
\r
154 the LED is toggled with mainCHECK_PERIOD frequency. If an error is found
\r
155 then the toggle rate increases to mainERROR_CHECK_PERIOD. */
\r
156 #define mainCHECK_TASK_LED ( 7 )
\r
157 #define mainCHECK_PERIOD ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
\r
158 #define mainERROR_CHECK_PERIOD ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
\r
160 /* The constants used in the idle task calculation. */
\r
161 #define intgCONST1 ( ( long ) 123 )
\r
162 #define intgCONST2 ( ( long ) 234567 )
\r
163 #define intgCONST3 ( ( long ) -3 )
\r
164 #define intgCONST4 ( ( long ) 7 )
\r
165 #define intgEXPECTED_ANSWER ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
\r
168 /* Baud rate used by the serial port tasks (ComTest tasks).
\r
169 IMPORTANT: The function COM0_SetBaudRateValue() which is generated by the
\r
170 Processor Expert is used to set the baud rate. As configured in the FreeRTOS
\r
171 download this value must be one of the following:
\r
173 0 to configure for 38400 baud.
\r
174 1 to configure for 19200 baud.
\r
175 2 to configure for 9600 baud.
\r
176 3 to configure for 4800 baud. */
\r
177 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 2 )
\r
179 /* LED used by the serial port tasks. This is toggled on each character Tx,
\r
180 and mainCOM_TEST_LED + 1 is toggles on each character Rx. */
\r
181 #define mainCOM_TEST_LED ( 3 )
\r
183 /*-----------------------------------------------------------
\r
184 Local functions prototypes.
\r
185 -----------------------------------------------------------*/
\r
188 * The 'Check' task function. See the explanation at the top of the file.
\r
190 static void vErrorChecks( void* pvParameters );
\r
193 * The idle task hook - in which the integer task is implemented. See the
\r
194 * explanation at the top of the file.
\r
196 void vApplicationIdleHook( void );
\r
199 * Checks the unique counts of other tasks to ensure they are still operational.
\r
201 static long prvCheckOtherTasksAreStillRunning( void );
\r
205 /*-----------------------------------------------------------
\r
207 -----------------------------------------------------------*/
\r
209 /* A few tasks are defined within this file. This flag is used to indicate
\r
210 their status. If an error is detected in one of the locally defined tasks then
\r
211 this flag is set to pdTRUE. */
\r
212 portBASE_TYPE xLocalError = pdFALSE;
\r
215 /*-----------------------------------------------------------*/
\r
218 * This is called from the main() function generated by the Processor Expert.
\r
222 /* Start some of the standard demo tasks. */
\r
223 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
224 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
225 vStartDynamicPriorityTasks();
\r
226 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
227 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
228 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
230 /* Start the locally defined tasks. There is also a task implemented as
\r
232 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
234 /* Must be the last demo created. */
\r
235 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
237 /* All the tasks have been created - start the scheduler. */
\r
238 vTaskStartScheduler();
\r
240 /* Should not reach here! */
\r
243 /*-----------------------------------------------------------*/
\r
245 static void vErrorChecks( void *pvParameters )
\r
247 TickType_t xDelayPeriod = mainCHECK_PERIOD;
\r
248 TickType_t xLastWakeTime;
\r
250 /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
\r
251 functions correctly. */
\r
252 xLastWakeTime = xTaskGetTickCount();
\r
256 /* Delay until it is time to execute again. The delay period is
\r
257 shorter following an error. */
\r
258 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
260 /* Check all the demo application tasks are executing without
\r
261 error. If an error is found the delay period is shortened - this
\r
262 has the effect of increasing the flash rate of the 'check' task
\r
264 if( prvCheckOtherTasksAreStillRunning() == pdFAIL )
\r
266 /* An error has been detected in one of the tasks - flash faster. */
\r
267 xDelayPeriod = mainERROR_CHECK_PERIOD;
\r
270 /* Toggle the LED each cycle round. */
\r
271 vParTestToggleLED( mainCHECK_TASK_LED );
\r
274 /*-----------------------------------------------------------*/
\r
276 static long prvCheckOtherTasksAreStillRunning( void )
\r
278 portBASE_TYPE xAllTasksPassed = pdPASS;
\r
280 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
282 xAllTasksPassed = pdFAIL;
\r
285 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
287 xAllTasksPassed = pdFAIL;
\r
290 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
292 xAllTasksPassed = pdFALSE;
\r
295 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
297 xAllTasksPassed = pdFALSE;
\r
300 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
302 xAllTasksPassed = pdFALSE;
\r
305 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
307 xAllTasksPassed = pdFALSE;
\r
310 /* Also check the status flag for the tasks defined within this function. */
\r
311 if( xLocalError != pdFALSE )
\r
313 xAllTasksPassed = pdFAIL;
\r
316 return xAllTasksPassed;
\r
318 /*-----------------------------------------------------------*/
\r
320 void vApplicationIdleHook( void )
\r
322 /* This variable is effectively set to a constant so it is made volatile to
\r
323 ensure the compiler does not just get rid of it. */
\r
324 volatile long lValue;
\r
326 /* Keep performing a calculation and checking the result against a constant. */
\r
328 /* Perform the calculation. This will store partial value in
\r
329 registers, resulting in a good test of the context switch mechanism. */
\r
330 lValue = intgCONST1;
\r
331 lValue += intgCONST2;
\r
332 lValue *= intgCONST3;
\r
333 lValue /= intgCONST4;
\r
335 /* Did we perform the calculation correctly with no corruption? */
\r
336 if( lValue != intgEXPECTED_ANSWER )
\r
339 portENTER_CRITICAL();
\r
340 xLocalError = pdTRUE;
\r
341 portEXIT_CRITICAL();
\r
344 /* Yield in case cooperative scheduling is being used. */
\r
345 #if configUSE_PREEMPTION == 0
\r
351 /*-----------------------------------------------------------*/
\r