2 FreeRTOS V6.0.0 - 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 * The FreeRTOS eBook and reference manual are available to purchase for a *
\r
29 * small fee. Help yourself get started quickly while also helping the *
\r
30 * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *
\r
32 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
51 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
52 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
53 called. The demo applications included in the FreeRTOS.org download switch
\r
54 to supervisor mode prior to main being called. If you are not using one of
\r
55 these demo application projects then ensure Supervisor mode is used.
\r
60 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
61 * documentation provides more details of the demo application tasks.
\r
63 * Main.c also creates a task called "Check". This only executes every three
\r
64 * seconds but has the highest priority so is guaranteed to get processor time.
\r
65 * Its main function is to check that all the other tasks are still operational.
\r
66 * Each task (other than the "flash" tasks) maintains a unique count that is
\r
67 * incremented each time the task successfully completes its function. Should
\r
68 * any error occur within such a task the count is permanently halted. The
\r
69 * check task inspects the count of each task to ensure it has changed since
\r
70 * the last time the check task executed. If all the count variables have
\r
71 * changed all the tasks are still executing error free, and the check task
\r
72 * toggles the onboard LED. Should any task contain an error at any time
\r
73 * the LED toggle rate will change from 3 seconds to 500ms.
\r
77 /* Standard includes. */
\r
80 /* Scheduler includes. */
\r
81 #include "FreeRTOS.h"
\r
84 /* Demo application includes. */
\r
86 #include "integer.h"
\r
89 #include "semtest.h"
\r
90 #include "dynamic.h"
\r
91 #include "partest.h"
\r
92 #include "comtest2.h"
\r
94 /* Priorities for the demo application tasks. */
\r
95 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
96 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
97 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
98 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
99 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
100 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
102 /* Constants required by the 'Check' task. */
\r
103 #define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
104 #define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
105 #define mainCHECK_TASK_LED ( 7 )
\r
107 /* Constants for the ComTest tasks. */
\r
108 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 115200 )
\r
109 #define mainCOM_TEST_LED ( 4 )
\r
110 #define mainTX_ENABLE ( ( unsigned long ) 0x0001 )
\r
111 #define mainRX_ENABLE ( ( unsigned long ) 0x0004 )
\r
113 /* Constants to setup the PLL. */
\r
114 #define mainPLL_MUL_5 ( ( unsigned char ) 0x0004 )
\r
115 #define mainPLL_DIV_1 ( ( unsigned char ) 0x0000 )
\r
116 #define mainPLL_ENABLE ( ( unsigned char ) 0x0001 )
\r
117 #define mainPLL_CONNECT ( ( unsigned char ) 0x0003 )
\r
118 #define mainPLL_FEED_BYTE1 ( ( unsigned char ) 0xaa )
\r
119 #define mainPLL_FEED_BYTE2 ( ( unsigned char ) 0x55 )
\r
120 #define mainPLL_LOCK ( ( unsigned long ) 0x0400 )
\r
122 /* Constants to setup the MAM. */
\r
123 #define mainMAM_TIM_3 ( ( unsigned char ) 0x03 )
\r
124 #define mainMAM_MODE_FULL ( ( unsigned char ) 0x02 )
\r
126 /* Constants to setup the peripheral bus. */
\r
127 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
129 /* And finally, constant to setup the port for the LED's. */
\r
130 #define mainLED_TO_OUTPUT ( ( unsigned long ) 0xff0000 )
\r
133 * The task that executes at the highest priority and calls
\r
134 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
137 static void vErrorChecks( void *pvParameters );
\r
140 * Configures the processor for use with this demo.
\r
142 static void prvSetupHardware( void );
\r
145 * Checks that all the demo application tasks are still executing without error
\r
146 * - as described at the top of the file.
\r
148 static long prvCheckOtherTasksAreStillRunning( void );
\r
151 /*-----------------------------------------------------------*/
\r
154 * Starts all the other tasks, then starts the scheduler.
\r
158 /* Setup the processor. */
\r
159 prvSetupHardware();
\r
161 /* Start all the standard demo application tasks. */
\r
162 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
163 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
164 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
165 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
166 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
167 vStartDynamicPriorityTasks();
\r
168 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
170 /* Start the check task - which is defined in this file. */
\r
171 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
173 /* Start the scheduler.
\r
175 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
176 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
177 called. The demo applications included in the FreeRTOS.org download switch
\r
178 to supervisor mode prior to main being called. If you are not using one of
\r
179 these demo application projects then ensure Supervisor mode is used here.
\r
181 vTaskStartScheduler();
\r
183 /* We should never get here as control is now taken by the scheduler. */
\r
186 /*-----------------------------------------------------------*/
\r
188 static void prvSetupHardware( void )
\r
190 /* Setup the PLL to multiply the XTAL input by 5. */
\r
191 PLLCFG = ( mainPLL_MUL_5 | mainPLL_DIV_1 );
\r
193 /* Activate the PLL by turning it on then feeding the correct sequence of
\r
195 PLLCON = mainPLL_ENABLE;
\r
196 PLLFEED = mainPLL_FEED_BYTE1;
\r
197 PLLFEED = mainPLL_FEED_BYTE2;
\r
199 /* Wait for the PLL to lock... */
\r
200 while( !( PLLSTAT & mainPLL_LOCK ) );
\r
202 /* ...before connecting it using the feed sequence again. */
\r
203 PLLCON = mainPLL_CONNECT;
\r
204 PLLFEED = mainPLL_FEED_BYTE1;
\r
205 PLLFEED = mainPLL_FEED_BYTE2;
\r
207 /* Setup and turn on the MAM. Three cycle access is used due to the fast
\r
208 PLL used. It is possible faster overall performance could be obtained by
\r
209 tuning the MAM and PLL settings. */
\r
210 MAMTIM = mainMAM_TIM_3;
\r
211 MAMCR = mainMAM_MODE_FULL;
\r
213 /* Setup the peripheral bus to be the same as the PLL output. */
\r
214 APBDIV = mainBUS_CLK_FULL;
\r
216 /* Configure the RS2332 pins. All other pins remain at their default of 0. */
\r
217 PINSEL0 |= mainTX_ENABLE;
\r
218 PINSEL0 |= mainRX_ENABLE;
\r
220 /* LED pins need to be output. */
\r
221 IO1DIR = mainLED_TO_OUTPUT;
\r
223 /* Setup the peripheral bus to be the same as the PLL output. */
\r
224 APBDIV = mainBUS_CLK_FULL;
\r
226 /*-----------------------------------------------------------*/
\r
228 static void vErrorChecks( void *pvParameters )
\r
230 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
232 /* The parameters are not used in this task. */
\r
233 ( void ) pvParameters;
\r
235 /* Cycle for ever, delaying then checking all the other tasks are still
\r
236 operating without error. If an error is detected then the delay period
\r
237 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
238 the on board LED flash rate will increase. */
\r
242 /* Delay until it is time to execute again. */
\r
243 vTaskDelay( xDelayPeriod );
\r
245 /* Check all the standard demo application tasks are executing without
\r
247 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
249 /* An error has been detected in one of the tasks - flash faster. */
\r
250 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
253 vParTestToggleLED( mainCHECK_TASK_LED );
\r
256 /*-----------------------------------------------------------*/
\r
258 static long prvCheckOtherTasksAreStillRunning( void )
\r
260 long lReturn = ( long ) pdPASS;
\r
262 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
263 that they are all still running, and that none of them have detected
\r
266 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
268 lReturn = ( long ) pdFAIL;
\r
271 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
273 lReturn = ( long ) pdFAIL;
\r
276 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
278 lReturn = ( long ) pdFAIL;
\r
281 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
283 lReturn = ( long ) pdFAIL;
\r
286 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
288 lReturn = ( long ) pdFAIL;
\r
291 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
293 lReturn = ( long ) pdFAIL;
\r
298 /*-----------------------------------------------------------*/
\r