2 FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
55 * Creates all the demo application tasks, then starts the scheduler.
\r
57 * Main.c also creates a task called "Check". This only executes every three
\r
58 * seconds but has the highest priority so is guaranteed to get processor time.
\r
59 * Its main function is to check that all the other tasks are still operational.
\r
60 * Each task (other than the "flash" tasks) maintains a unique count that is
\r
61 * incremented each time the task successfully completes its function. Should
\r
62 * any error occur within such a task the count is permanently halted. The
\r
63 * check task inspects the count of each task to ensure it has changed since
\r
64 * the last time the check task executed. If all the count variables have
\r
65 * changed all the tasks are still executing error free, and the check task
\r
66 * toggles the on board LED. Should any task contain an error at any time
\r
67 * the LED toggle rate will change from 3 seconds to 500ms.
\r
69 * NOTE: The demo application includes tasks that send and receive characters
\r
70 * over the UART. The characters sent by one task are received by another -
\r
71 * with an error condition being flagged should any characters be missed or
\r
72 * received out of order. A loopback connector is required on the 9way D socket
\r
73 * for this mechanism to operation (pins 2 and 3 the socket should be connected
\r
74 * together - a paper clip is normally sufficient).
\r
78 /* Standard includes. */
\r
82 /* Scheduler includes. */
\r
83 #include "FreeRTOS.h"
\r
86 /* Demo application includes. */
\r
87 #include "partest.h"
\r
89 #include "integer.h"
\r
91 #include "comtest2.h"
\r
92 #include "semtest.h"
\r
94 #include "dynamic.h"
\r
97 #include "demoGpio.h"
\r
99 #include "RegTest.h"
\r
101 /*-----------------------------------------------------------*/
\r
103 /* Constants for the ComTest tasks. */
\r
104 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 115200 )
\r
105 #define mainCOM_TEST_LED ( 5 )
\r
107 /* Priorities for the demo application tasks. */
\r
108 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
109 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
110 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
111 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
112 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
113 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
114 #define main7SEG_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
116 /* The rate at which the on board LED will toggle when there is/is not an
\r
118 #define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
119 #define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
120 #define mainON_BOARD_LED_BIT ( ( unsigned long ) 7 )
\r
122 /* The size of the memory blocks allocated by the vMemCheckTask() task. */
\r
123 #define mainMEM_CHECK_SIZE_1 ( ( size_t ) 51 )
\r
124 #define mainMEM_CHECK_SIZE_2 ( ( size_t ) 52 )
\r
125 #define mainMEM_CHECK_SIZE_3 ( ( size_t ) 151 )
\r
127 /*-----------------------------------------------------------*/
\r
130 * Checks that all the demo application tasks are still executing without error
\r
131 * - as described at the top of the file.
\r
133 static long prvCheckOtherTasksAreStillRunning( void );
\r
136 * The task that executes at the highest priority and calls
\r
137 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
140 static void vErrorChecks( void *pvParameters );
\r
143 * Configure the processor for use with the Olimex demo board. This includes
\r
144 * setup for the I/O, system clock, and access timings.
\r
146 static void prvSetupHardware( void );
\r
149 /*-----------------------------------------------------------*/
\r
152 * Starts all the other tasks, then starts the scheduler.
\r
156 /* Setup the hardware for use with the Xilinx evaluation board. */
\r
157 prvSetupHardware();
\r
159 /* Start the demo/test application tasks. */
\r
160 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
161 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
162 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
163 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
164 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
165 vStartDynamicPriorityTasks();
\r
166 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
167 vStart7SegTasks( main7SEG_TASK_PRIORITY );
\r
168 vStartRegTestTasks();
\r
170 /* Start the check task - which is defined in this file. */
\r
171 xTaskCreate( vErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
173 /* Now all the tasks have been started - start the scheduler. */
\r
174 vTaskStartScheduler();
\r
176 /* Should never reach here! */
\r
179 /*-----------------------------------------------------------*/
\r
181 static void vErrorChecks( void *pvParameters )
\r
183 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
185 /* Just to stop compiler warnings. */
\r
186 ( void ) pvParameters;
\r
188 /* Cycle for ever, delaying then checking all the other tasks are still
\r
189 operating without error. If an error is detected then the delay period
\r
190 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
191 the on board LED flash rate will increase. */
\r
195 /* Delay until it is time to execute again. */
\r
196 vTaskDelay( xDelayPeriod );
\r
198 /* Check all the standard demo application tasks are executing without
\r
200 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
202 /* An error has been detected in one of the tasks - flash faster. */
\r
203 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
206 /* The toggle rate of the LED depends on how long this task delays for.
\r
207 An error reduces the delay period and so increases the toggle rate. */
\r
208 vParTestToggleLED( mainON_BOARD_LED_BIT );
\r
211 /*-----------------------------------------------------------*/
\r
213 static void prvSetupHardware( void )
\r
215 /* Initialise LED outputs. */
\r
216 vParTestInitialise();
\r
218 /*-----------------------------------------------------------*/
\r
220 static long prvCheckOtherTasksAreStillRunning( void )
\r
222 long lReturn = pdPASS;
\r
224 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
225 that they are all still running, and that none of them have detected
\r
228 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
233 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
238 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
243 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
248 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
253 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
258 if( xAreRegTestTasksStillRunning() != pdTRUE )
\r
265 /*-----------------------------------------------------------*/
\r
267 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
269 /* This function will be called if a task overflows its stack. Inspect
\r
270 pxCurrentTCB to find the offending task if the overflow was sever enough
\r
271 to corrupt the pcTaskName parameter. */
\r
272 vParTestSetLED( 4, 1 );
\r
275 /*-----------------------------------------------------------*/
\r
277 void vApplicationMallocFailedHook( void )
\r
279 /* This function will be called if a call to pvPortMalloc() fails to return
\r
280 the requested memory. pvPortMalloc() is called internally by the scheduler
\r
281 whenever a task, queue or semaphore is created. */
\r
282 vParTestSetLED( 4, 1 );
\r
285 /*-----------------------------------------------------------*/
\r
287 /* Provide an exit function to prevent a whole load of standard library functions
\r
288 being brought into the build. */
\r
289 void exit( int status )
\r