2 FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
31 Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along
\r
32 with commercial development and support options.
\r
33 ***************************************************************************
\r
37 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
38 * documentation provides more details of the standard demo application tasks.
\r
39 * In addition to the standard demo tasks, the following tasks are defined
\r
42 * "Register test" tasks - These tasks first set all the general purpose
\r
43 * registers to a known value (with each register containing a different value)
\r
44 * then test each general purpose register to ensure it still contains the
\r
45 * set value. There are two register test tasks, with different values being
\r
46 * used by each. The register test tasks will be preempted frequently due to
\r
47 * their low priority. Setting then testing the value of each register in this
\r
48 * manner ensures the context of the tasks is being correctly saved and then
\r
49 * restored as the preemptive context switches occur. An error is flagged
\r
50 * should any register be found to contain an unexpected value. In addition
\r
51 * the register test tasks maintain a count of the number of times they cycle,
\r
52 * so an error can also be flagged should the cycle count not increment as
\r
53 * expected (indicating the the tasks are not executing at all).
\r
55 * "Check" task - This only executes every three seconds but has the highest
\r
56 * priority so is guaranteed to get processor time. Its main function is to
\r
57 * check that all the other tasks are still operational. Each task maintains a
\r
58 * unique count that is incremented each time the task successfully completes
\r
59 * its function. Should any error occur within such a task the count is
\r
60 * permanently halted. The check task inspects the count of each task to
\r
61 * ensure it has changed since the last time the check task executed. If all
\r
62 * the count variables have changed all the tasks are still executing error
\r
63 * free, and the check task toggles the onboard LED. Should any task contain
\r
64 * an error at any time check task cycle frequency is increased to 500ms,
\r
65 * causing the LED toggle rate to increase from 3 seconds to 500ms and in so
\r
66 * doing providing visual feedback that an error has occurred.
\r
70 /* Scheduler includes. */
\r
71 #include "FreeRTOS.h"
\r
73 #include "croutine.h"
\r
75 /* Demo application includes. */
\r
77 #include "crflash.h"
\r
78 #include "blocktim.h"
\r
79 #include "integer.h"
\r
80 #include "comtest2.h"
\r
81 #include "partest.h"
\r
83 /* Demo task priorities. */
\r
84 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
85 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
86 #define mainCOM_TEST_PRIORITY ( 2 )
\r
88 /* Delay between check task cycles when an error has/has not been detected. */
\r
89 #define mainNO_ERROR_DELAY ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
90 #define mainERROR_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
92 /* The number of flash co-routines to create. */
\r
93 #define mainNUM_FLASH_COROUTINES ( 3 )
\r
95 /* Baud rate used by the comtest tasks. */
\r
96 #define mainCOM_TEST_BAUD_RATE ( 19200 )
\r
98 /* The LED used by the comtest tasks. mainCOM_TEST_LED + 1 is also used.
\r
99 See the comtest.c file for more information. */
\r
100 #define mainCOM_TEST_LED ( 4 )
\r
102 /* The LED used by the check task. */
\r
103 #define mainCHECK_LED ( 7 )
\r
105 /*-----------------------------------------------------------*/
\r
108 * The register test tasks as described at the top of this file.
\r
110 void xRegisterTest1( void *pvParameters );
\r
111 void xRegisterTest2( void *pvParameters );
\r
114 * The check task as described at the top of this file.
\r
116 static void vCheckTask( void *pvParameters );
\r
119 * Setup the processor ready for the demo.
\r
121 static void prvSetupHardware( void );
\r
123 /*-----------------------------------------------------------*/
\r
125 /* Variables used to detect errors within the register test tasks. */
\r
126 static volatile unsigned portSHORT usTest1CycleCounter = 0, usTest2CycleCounter = 0;
\r
127 static unsigned portSHORT usPreviousTest1Count = 0, usPreviousTest2Count = 0;
\r
129 /* Set to pdTRUE should an error be detected in any of the standard demo tasks
\r
130 or tasks defined within this file. */
\r
131 static unsigned portSHORT usErrorDetected = pdFALSE;
\r
133 /*-----------------------------------------------------------*/
\r
136 * Create the demo tasks then start the scheduler.
\r
140 /* Configure any hardware required for this demo. */
\r
141 prvSetupHardware();
\r
143 /* Create the standard demo tasks. */
\r
144 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
145 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
146 vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
\r
147 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
148 vCreateBlockTimeTasks();
\r
150 /* Create the test tasks defined within this file. */
\r
151 xTaskCreate( xRegisterTest1, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) &usTest1CycleCounter, tskIDLE_PRIORITY, NULL );
\r
152 xTaskCreate( xRegisterTest2, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) &usTest2CycleCounter, tskIDLE_PRIORITY, NULL );
\r
153 xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
155 /* Finally start the scheduler. */
\r
156 vTaskStartScheduler();
\r
158 /* Will only reach here if there is insufficient heap available to start
\r
162 /*-----------------------------------------------------------*/
\r
164 static void prvSetupHardware( void )
\r
166 vParTestInitialise();
\r
168 /*-----------------------------------------------------------*/
\r
170 static void vCheckTask( void *pvParameters )
\r
172 portTickType xLastExecutionTime;
\r
174 /* Start with the no error delay. The long delay will cause the LED to flash
\r
176 portTickType xDelay = mainNO_ERROR_DELAY;
\r
178 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
179 works correctly. */
\r
180 xLastExecutionTime = xTaskGetTickCount();
\r
184 /* Wait until it is time for the next cycle. */
\r
185 vTaskDelayUntil( &xLastExecutionTime, xDelay );
\r
187 /* Has an error been found in any of the standard demo tasks? */
\r
189 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
191 usErrorDetected = pdTRUE;
\r
194 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
196 usErrorDetected = pdTRUE;
\r
199 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
201 usErrorDetected = pdTRUE;
\r
204 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
206 usErrorDetected = pdTRUE;
\r
210 /* Are the register test tasks still cycling? */
\r
212 if( usTest1CycleCounter == usPreviousTest1Count )
\r
214 usErrorDetected = pdTRUE;
\r
217 if( usTest2CycleCounter == usPreviousTest2Count )
\r
219 usErrorDetected = pdTRUE;
\r
222 usPreviousTest2Count = usTest2CycleCounter;
\r
223 usPreviousTest1Count = usTest1CycleCounter;
\r
226 /* If an error has been detected in any task then the delay will be
\r
227 reduced to increase the cycle rate of this task. This has the effect
\r
228 of causing the LED to flash much faster giving a visual indication of
\r
229 the error condition. */
\r
230 if( usErrorDetected != pdFALSE )
\r
232 xDelay = mainERROR_DELAY;
\r
235 /* Finally, toggle the LED before returning to delay to wait for the
\r
237 vParTestToggleLED( mainCHECK_LED );
\r
240 /*-----------------------------------------------------------*/
\r
242 void xRegisterTest1( void *pvParameters )
\r
244 /* This static so as not to use the frame pointer. They are volatile
\r
245 also to avoid it being stored in a register that we clobber during the test. */
\r
246 static unsigned portSHORT * volatile pusParameter;
\r
248 /* The variable incremented by this task is passed in as the parameter
\r
249 even though it is defined within this file. This is just to test the
\r
250 parameter passing mechanism. */
\r
251 pusParameter = pvParameters;
\r
255 /* Increment the variable to show this task is still cycling. */
\r
256 ( *pusParameter )++;
\r
258 /* Set the w registers to known values, then check that each register
\r
259 contains the expected value. See the explanation at the top of this
\r
260 file for more information. */
\r
261 asm volatile( "mov.w #0x0101, W0 \n" \
\r
262 "mov.w #0x0102, W1 \n" \
\r
263 "mov.w #0x0103, W2 \n" \
\r
264 "mov.w #0x0104, W3 \n" \
\r
265 "mov.w #0x0105, W4 \n" \
\r
266 "mov.w #0x0106, W5 \n" \
\r
267 "mov.w #0x0107, W6 \n" \
\r
268 "mov.w #0x0108, W7 \n" \
\r
269 "mov.w #0x0109, W8 \n" \
\r
270 "mov.w #0x010a, W9 \n" \
\r
271 "mov.w #0x010b, W10 \n" \
\r
272 "mov.w #0x010c, W11 \n" \
\r
273 "mov.w #0x010d, W12 \n" \
\r
274 "mov.w #0x010e, W13 \n" \
\r
275 "mov.w #0x010f, W14 \n" \
\r
276 "sub #0x0101, W0 \n" \
\r
278 "bra NZ, ERROR_TEST1 \n" \
\r
279 "sub #0x0102, W1 \n" \
\r
281 "bra NZ, ERROR_TEST1 \n" \
\r
282 "sub #0x0103, W2 \n" \
\r
284 "bra NZ, ERROR_TEST1 \n" \
\r
285 "sub #0x0104, W3 \n" \
\r
287 "bra NZ, ERROR_TEST1 \n" \
\r
288 "sub #0x0105, W4 \n" \
\r
290 "bra NZ, ERROR_TEST1 \n" \
\r
291 "sub #0x0106, W5 \n" \
\r
293 "bra NZ, ERROR_TEST1 \n" \
\r
294 "sub #0x0107, W6 \n" \
\r
296 "bra NZ, ERROR_TEST1 \n" \
\r
297 "sub #0x0108, W7 \n" \
\r
299 "bra NZ, ERROR_TEST1 \n" \
\r
300 "sub #0x0109, W8 \n" \
\r
302 "bra NZ, ERROR_TEST1 \n" \
\r
303 "sub #0x010a, W9 \n" \
\r
305 "bra NZ, ERROR_TEST1 \n" \
\r
306 "sub #0x010b, W10 \n" \
\r
308 "bra NZ, ERROR_TEST1 \n" \
\r
309 "sub #0x010c, W11 \n" \
\r
311 "bra NZ, ERROR_TEST1 \n" \
\r
312 "sub #0x010d, W12 \n" \
\r
314 "bra NZ, ERROR_TEST1 \n" \
\r
315 "sub #0x010e, W13 \n" \
\r
317 "bra NZ, ERROR_TEST1 \n" \
\r
318 "sub #0x010f, W14 \n" \
\r
320 "bra NZ, ERROR_TEST1 \n" \
\r
321 "bra NO_ERROR1 \n" \
\r
322 "ERROR_TEST1: \n" \
\r
323 "mov.w #1, W0 \n" \
\r
324 "mov.w W0, _usErrorDetected\n" \
\r
328 /*-----------------------------------------------------------*/
\r
330 void xRegisterTest2( void *pvParameters )
\r
332 /* This static so as not to use the frame pointer. They are volatile
\r
333 also to avoid it being stored in a register that we clobber during the test. */
\r
334 static unsigned portSHORT * volatile pusParameter;
\r
336 /* The variable incremented by this task is passed in as the parameter
\r
337 even though it is defined within this file. This is just to test the
\r
338 parameter passing mechanism. */
\r
339 pusParameter = pvParameters;
\r
343 /* Increment the variable to show this task is still cycling. */
\r
344 ( *pusParameter )++;
\r
346 /* Set the w registers to known values, then check that each register
\r
347 contains the expected value. See the explanation at the top of this
\r
348 file for more information. */
\r
349 asm volatile( "mov.w #0x0100, W0 \n" \
\r
350 "mov.w #0x0101, W1 \n" \
\r
351 "mov.w #0x0102, W2 \n" \
\r
352 "mov.w #0x0103, W3 \n" \
\r
353 "mov.w #0x0104, W4 \n" \
\r
354 "mov.w #0x0105, W5 \n" \
\r
355 "mov.w #0x0106, W6 \n" \
\r
356 "mov.w #0x0107, W7 \n" \
\r
357 "mov.w #0x0108, W8 \n" \
\r
358 "mov.w #0x0109, W9 \n" \
\r
359 "mov.w #0x010a, W10 \n" \
\r
360 "mov.w #0x010b, W11 \n" \
\r
361 "mov.w #0x010c, W12 \n" \
\r
362 "mov.w #0x010d, W13 \n" \
\r
363 "mov.w #0x010e, W14 \n" \
\r
364 "sub #0x0100, W0 \n" \
\r
366 "bra NZ, ERROR_TEST2 \n" \
\r
367 "sub #0x0101, W1 \n" \
\r
369 "bra NZ, ERROR_TEST2 \n" \
\r
370 "sub #0x0102, W2 \n" \
\r
372 "bra NZ, ERROR_TEST2 \n" \
\r
373 "sub #0x0103, W3 \n" \
\r
375 "bra NZ, ERROR_TEST2 \n" \
\r
376 "sub #0x0104, W4 \n" \
\r
378 "bra NZ, ERROR_TEST2 \n" \
\r
379 "sub #0x0105, W5 \n" \
\r
381 "bra NZ, ERROR_TEST2 \n" \
\r
382 "sub #0x0106, W6 \n" \
\r
384 "bra NZ, ERROR_TEST2 \n" \
\r
385 "sub #0x0107, W7 \n" \
\r
387 "bra NZ, ERROR_TEST2 \n" \
\r
388 "sub #0x0108, W8 \n" \
\r
390 "bra NZ, ERROR_TEST2 \n" \
\r
391 "sub #0x0109, W9 \n" \
\r
393 "bra NZ, ERROR_TEST2 \n" \
\r
394 "sub #0x010a, W10 \n" \
\r
396 "bra NZ, ERROR_TEST2 \n" \
\r
397 "sub #0x010b, W11 \n" \
\r
399 "bra NZ, ERROR_TEST2 \n" \
\r
400 "sub #0x010c, W12 \n" \
\r
402 "bra NZ, ERROR_TEST2 \n" \
\r
403 "sub #0x010d, W13 \n" \
\r
405 "bra NZ, ERROR_TEST2 \n" \
\r
406 "sub #0x010e, W14 \n" \
\r
408 "bra NZ, ERROR_TEST2 \n" \
\r
409 "bra NO_ERROR2 \n" \
\r
410 "ERROR_TEST2: \n" \
\r
411 "mov.w #1, W0 \n" \
\r
412 "mov.w W0, _usErrorDetected\n" \
\r
416 /*-----------------------------------------------------------*/
\r
418 void vApplicationIdleHook( void )
\r
420 /* Schedule the co-routines from within the idle task hook. */
\r
421 vCoRoutineSchedule();
\r
423 /*-----------------------------------------------------------*/
\r