3 FreeRTOS.org V4.0.3 - Copyright (C) 2003-2005 Richard Barry.
\r
5 This file is part of the FreeRTOS.org distribution.
\r
7 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
8 it under the terms of the GNU General Public License as published by
\r
9 the Free Software Foundation; either version 2 of the License, or
\r
10 (at your option) any later version.
\r
12 FreeRTOS.org is distributed in the hope that it will be useful,
\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 GNU General Public License for more details.
\r
17 You should have received a copy of the GNU General Public License
\r
18 along with FreeRTOS.org; if not, write to the Free Software
\r
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
21 A special exception to the GPL can be applied should you wish to distribute
\r
22 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
23 the source code for any proprietary components. See the licensing section
\r
24 of http://www.FreeRTOS.org for full details of how and when the exception
\r
27 ***************************************************************************
\r
28 See http://www.FreeRTOS.org for documentation, latest information, license
\r
29 and contact details. Please ensure to read the configuration and relevant
\r
30 port sections of the online documentation.
\r
31 ***************************************************************************
\r
37 * main() creates all the demo application tasks, then starts the scheduler.
\r
38 * The WEB documentation provides more details of the demo application tasks.
\r
40 * main.c also creates a task called "Check". This only executes every three
\r
41 * seconds but has the highest priority so is guaranteed to get processor time.
\r
42 * Its main function is to check that all the other tasks are still operational.
\r
43 * Each task (other than the "flash" tasks) maintains a unique count that is
\r
44 * incremented each time the task successfully completes its function. Should
\r
45 * any error occur within such a task the count is permanently halted. The
\r
46 * check task inspects the count of each task to ensure it has changed since
\r
47 * the last time the check task executed. If all the count variables have
\r
48 * changed all the tasks are still executing error free, and the check task
\r
49 * toggles the onboard LED. Should any task contain an error at any time
\r
50 * the LED toggle rate will change from 3 seconds to 500ms.
\r
52 * This file also includes the functionality implemented within the
\r
53 * standard demo application file integer.c. This is done to demonstrate the
\r
54 * use of an idle hook. See the documentation within integer.c for the
\r
55 * rationale of the integer task functionality.
\r
58 /* Kernel includes. */
\r
59 #include "FreeRTOS.h"
\r
65 /* special prototypes for memory-banked functions */
\r
66 void vStartPolledQueueTasks( unsigned portBASE_TYPE uxPriority );
\r
67 portBASE_TYPE xArePollingQueuesStillRunning( void );
\r
69 /* Demo application includes. */
\r
72 #include "dynamic.h"
\r
73 #include "partest.h"
\r
74 #include "comtest2.h"
\r
76 #include "integer.h"
\r
80 /*-----------------------------------------------------------
\r
82 -----------------------------------------------------------*/
\r
84 /* Priorities assigned to demo application tasks. */
\r
85 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
86 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
87 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
88 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
89 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
90 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
92 /* LED that is toggled by the check task. The check task periodically checks
\r
93 that all the other tasks are operating without error. If no errors are found
\r
94 the LED is toggled with mainCHECK_PERIOD frequency. If an error is found
\r
95 then the toggle rate increases to mainERROR_CHECK_PERIOD. */
\r
96 #define mainCHECK_TASK_LED ( 7 )
\r
97 #define mainCHECK_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
98 #define mainERROR_CHECK_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
100 /* The constants used in the idle task calculation. */
\r
101 #define intgCONST1 ( ( portLONG ) 123 )
\r
102 #define intgCONST2 ( ( portLONG ) 234567 )
\r
103 #define intgCONST3 ( ( portLONG ) -3 )
\r
104 #define intgCONST4 ( ( portLONG ) 7 )
\r
105 #define intgEXPECTED_ANSWER ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
\r
108 /* Baud rate used by the serial port tasks (ComTest tasks).
\r
109 IMPORTANT: The function COM0_SetBaudRateValue() which is generated by the
\r
110 Processor Expert is used to set the baud rate. As configured in the FreeRTOS
\r
111 download this value must be one of the following:
\r
113 0 to configure for 38400 baud.
\r
114 1 to configure for 19200 baud.
\r
115 2 to configure for 9600 baud.
\r
116 3 to configure for 4800 baud. */
\r
117 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 2 )
\r
119 /* LED used by the serial port tasks. This is toggled on each character Tx,
\r
120 and mainCOM_TEST_LED + 1 is toggles on each character Rx. */
\r
121 #define mainCOM_TEST_LED ( 3 )
\r
123 /*-----------------------------------------------------------
\r
124 Local functions prototypes.
\r
125 -----------------------------------------------------------*/
\r
128 * The 'Check' task function. See the explanation at the top of the file.
\r
130 static void ATTR_BANK1 vErrorChecks( void* pvParameters );
\r
133 * The idle task hook - in which the integer task is implemented. See the
\r
134 * explanation at the top of the file.
\r
136 void ATTR_BANK0 vApplicationIdleHook( void );
\r
139 * Checks the unique counts of other tasks to ensure they are still operational.
\r
141 static portLONG ATTR_BANK0 prvCheckOtherTasksAreStillRunning( void );
\r
145 /*-----------------------------------------------------------
\r
147 -----------------------------------------------------------*/
\r
149 /* A few tasks are defined within this file. This flag is used to indicate
\r
150 their status. If an error is detected in one of the locally defined tasks then
\r
151 this flag is set to pdTRUE. */
\r
152 portBASE_TYPE xLocalError = pdFALSE;
\r
155 /*-----------------------------------------------------------*/
\r
157 /* This is called from startup. */
\r
158 int ATTR_BANK0 main ( void )
\r
160 /* Start some of the standard demo tasks. */
\r
161 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
162 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
163 vStartDynamicPriorityTasks();
\r
164 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
165 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
166 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
168 /* Start the locally defined tasks. There is also a task implemented as
\r
170 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
172 /* Must be the last demo created. */
\r
173 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
175 /* All the tasks have been created - start the scheduler. */
\r
176 vTaskStartScheduler();
\r
178 /* Should not reach here! */
\r
182 /*-----------------------------------------------------------*/
\r
184 static void vErrorChecks( void *pvParameters )
\r
186 portTickType xDelayPeriod = mainCHECK_PERIOD;
\r
187 portTickType xLastWakeTime;
\r
189 /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
\r
190 functions correctly. */
\r
191 xLastWakeTime = xTaskGetTickCount();
\r
195 /* Delay until it is time to execute again. The delay period is
\r
196 shorter following an error. */
\r
197 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
199 /* Check all the demo application tasks are executing without
\r
200 error. If an error is found the delay period is shortened - this
\r
201 has the effect of increasing the flash rate of the 'check' task
\r
203 if( prvCheckOtherTasksAreStillRunning() == pdFAIL )
\r
205 /* An error has been detected in one of the tasks - flash faster. */
\r
206 xDelayPeriod = mainERROR_CHECK_PERIOD;
\r
209 /* Toggle the LED each cycle round. */
\r
210 vParTestToggleLED( mainCHECK_TASK_LED );
\r
213 /*-----------------------------------------------------------*/
\r
215 static portLONG prvCheckOtherTasksAreStillRunning( void )
\r
217 portBASE_TYPE xAllTasksPassed = pdPASS;
\r
219 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
221 xAllTasksPassed = pdFAIL;
\r
224 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
226 xAllTasksPassed = pdFAIL;
\r
229 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
231 xAllTasksPassed = pdFALSE;
\r
234 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
236 xAllTasksPassed = pdFALSE;
\r
239 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
241 xAllTasksPassed = pdFALSE;
\r
244 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
246 xAllTasksPassed = pdFALSE;
\r
249 /* Also check the status flag for the tasks defined within this function. */
\r
250 if( xLocalError != pdFALSE )
\r
252 xAllTasksPassed = pdFAIL;
\r
255 return xAllTasksPassed;
\r
257 /*-----------------------------------------------------------*/
\r
259 void vApplicationIdleHook( void )
\r
261 /* This variable is effectively set to a constant so it is made volatile to
\r
262 ensure the compiler does not just get rid of it. */
\r
263 volatile portLONG lValue;
\r
265 /* Keep performing a calculation and checking the result against a constant. */
\r
267 /* Perform the calculation. This will store partial value in
\r
268 registers, resulting in a good test of the context switch mechanism. */
\r
269 lValue = intgCONST1;
\r
270 lValue += intgCONST2;
\r
271 lValue *= intgCONST3;
\r
272 lValue /= intgCONST4;
\r
274 /* Did we perform the calculation correctly with no corruption? */
\r
275 if( lValue != intgEXPECTED_ANSWER )
\r
278 portENTER_CRITICAL();
\r
279 xLocalError = pdTRUE;
\r
280 portEXIT_CRITICAL();
\r
283 /* Yield in case cooperative scheduling is being used. */
\r
284 #if configUSE_PREEMPTION == 0
\r
290 /*-----------------------------------------------------------*/
\r