2 FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
49 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
50 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
51 called. The demo applications included in the FreeRTOS.org download switch
\r
52 to supervisor mode prior to main being called. If you are not using one of
\r
53 these demo application projects then ensure Supervisor mode is used.
\r
58 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
59 * documentation provides more details of the demo application tasks.
\r
61 * Main.c also creates a task called "Check". This only executes every three
\r
62 * seconds but has the highest priority so is guaranteed to get processor time.
\r
63 * Its main function is to check that all the other tasks are still operational.
\r
64 * Each task (other than the "flash" tasks) maintains a unique count that is
\r
65 * incremented each time the task successfully completes its function. Should
\r
66 * any error occur within such a task the count is permanently halted. The
\r
67 * check task inspects the count of each task to ensure it has changed since
\r
68 * the last time the check task executed. If all the count variables have
\r
69 * changed all the tasks are still executing error free, and the check task
\r
70 * toggles the onboard LED. Should any task contain an error at any time
\r
71 * the LED toggle rate will change from 3 seconds to 500ms.
\r
75 /* Standard includes. */
\r
78 /* Scheduler includes. */
\r
79 #include "FreeRTOS.h"
\r
82 /* Demo application includes. */
\r
83 #include "partest.h"
\r
85 #include "comtest2.h"
\r
89 #include "semtest.h"
\r
90 #include "dynamic.h"
\r
92 /*-----------------------------------------------------------*/
\r
94 /* Constants to setup I/O and processor. */
\r
95 #define mainTX_ENABLE ( ( unsigned portLONG ) 0x00010000 ) /* UART1. */
\r
96 #define mainRX_ENABLE ( ( unsigned portLONG ) 0x00040000 ) /* UART1. */
\r
97 #define mainBUS_CLK_FULL ( ( unsigned portCHAR ) 0x01 )
\r
98 #define mainLED_TO_OUTPUT ( ( unsigned portLONG ) 0xff0000 )
\r
100 /* Constants for the ComTest demo application tasks. */
\r
101 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 115200 )
\r
102 #define mainCOM_TEST_LED ( 3 )
\r
104 /* Priorities for the demo application tasks. */
\r
105 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
106 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
107 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
108 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
109 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
110 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
112 /* Constants used by the "check" task. As described at the head of this file
\r
113 the check task toggles an LED. The rate at which the LED flashes is used to
\r
114 indicate whether an error has been detected or not. If the LED toggles every
\r
115 3 seconds then no errors have been detected. If the rate increases to 500ms
\r
116 then an error has been detected in at least one of the demo application tasks. */
\r
117 #define mainCHECK_LED ( 7 )
\r
118 #define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
119 #define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
121 /*-----------------------------------------------------------*/
\r
124 * Checks that all the demo application tasks are still executing without error
\r
125 * - as described at the top of the file.
\r
127 static portLONG prvCheckOtherTasksAreStillRunning( void );
\r
130 * The task that executes at the highest priority and calls
\r
131 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
134 static void vErrorChecks( void *pvParameters );
\r
137 * Configure the processor for use with the Keil demo board. This is very
\r
138 * minimal as most of the setup is managed by the settings in the project
\r
141 static void prvSetupHardware( void );
\r
143 /*-----------------------------------------------------------*/
\r
148 * Application entry point:
\r
149 * Starts all the other tasks, then starts the scheduler.
\r
153 /* Setup the hardware for use with the Keil demo board. */
\r
154 prvSetupHardware();
\r
156 /* Start the demo/test application tasks. */
\r
157 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
158 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
159 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
160 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
161 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
162 vStartDynamicPriorityTasks();
\r
164 /* Start the check task - which is defined in this file. This is the task
\r
165 that periodically checks to see that all the other tasks are executing
\r
167 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
169 /* Now all the tasks have been started - start the scheduler.
\r
171 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
172 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
173 called. The demo applications included in the FreeRTOS.org download switch
\r
174 to supervisor mode prior to main being called. If you are not using one of
\r
175 these demo application projects then ensure Supervisor mode is used here. */
\r
176 vTaskStartScheduler();
\r
178 /* Should never reach here! If you do then there was not enough heap
\r
179 available for the idle task to be created. */
\r
182 /*-----------------------------------------------------------*/
\r
184 static void vErrorChecks( void *pvParameters )
\r
186 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
188 /* Parameters are not used. */
\r
189 ( void ) pvParameters;
\r
191 /* Cycle for ever, delaying then checking all the other tasks are still
\r
192 operating without error. If an error is detected then the delay period
\r
193 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
194 the on board LED flash rate will increase.
\r
196 This task runs at the highest priority. */
\r
200 /* The period of the delay depends on whether an error has been
\r
201 detected or not. If an error has been detected then the period
\r
202 is reduced to increase the LED flash rate. */
\r
203 vTaskDelay( xDelayPeriod );
\r
205 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
207 /* An error has been detected in one of the tasks - flash faster. */
\r
208 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
211 /* Toggle the LED before going back to wait for the next cycle. */
\r
212 vParTestToggleLED( mainCHECK_LED );
\r
215 /*-----------------------------------------------------------*/
\r
217 static void prvSetupHardware( void )
\r
219 /* Perform the hardware setup required. This is minimal as most of the
\r
220 setup is managed by the settings in the project file. */
\r
222 /* Configure the UART1 pins. All other pins remain at their default of 0. */
\r
223 PINSEL0 |= mainTX_ENABLE;
\r
224 PINSEL0 |= mainRX_ENABLE;
\r
226 /* LED pins need to be output. */
\r
227 IODIR1 = mainLED_TO_OUTPUT;
\r
229 /* Setup the peripheral bus to be the same as the PLL output. */
\r
230 VPBDIV = mainBUS_CLK_FULL;
\r
232 /*-----------------------------------------------------------*/
\r
234 static portLONG prvCheckOtherTasksAreStillRunning( void )
\r
236 portLONG lReturn = pdPASS;
\r
238 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
239 that they are all still running, and that none of them have detected
\r
241 if( xAreComTestTasksStillRunning() != pdPASS )
\r
246 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
251 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
256 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
261 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
268 /*-----------------------------------------------------------*/
\r