2 FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
4 ***************************************************************************
\r
8 * + New to FreeRTOS, *
\r
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
\r
10 * + Looking for basic training, *
\r
11 * + Wanting to improve your FreeRTOS skills and productivity *
\r
13 * then take a look at the FreeRTOS books - available as PDF or paperback *
\r
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
\r
16 * http://www.FreeRTOS.org/Documentation *
\r
18 * A pdf reference manual is also available. Both are usually delivered *
\r
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
\r
20 * and 8pm GMT (although please allow up to 24 hours in case of *
\r
21 * exceptional circumstances). Thank you for your support! *
\r
23 ***************************************************************************
\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 exception to the GPL is included to allow you to distribute
\r
31 a combined work that includes FreeRTOS without being obliged to provide the
\r
32 source code for proprietary components outside of the FreeRTOS kernel.
\r
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
35 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 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
56 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
57 called. The demo applications included in the FreeRTOS.org download switch
\r
58 to supervisor mode prior to main being called. If you are not using one of
\r
59 these demo application projects then ensure Supervisor mode is used.
\r
63 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
64 * documentation provides more details of the demo application tasks.
\r
66 * Main.c also creates a task called "Check". This only executes every three
\r
67 * seconds but has the highest priority so is guaranteed to get processor time.
\r
68 * Its main function is to check that all the other tasks are still operational.
\r
69 * Each task (other than the "flash" tasks) maintains a unique count that is
\r
70 * incremented each time the task successfully completes its function. Should
\r
71 * any error occur within such a task the count is permanently halted. The
\r
72 * check task inspects the count of each task to ensure it has changed since
\r
73 * the last time the check task executed. If all the count variables have
\r
74 * changed all the tasks are still executing error free, and the check task
\r
75 * toggles the onboard LED. Should any task contain an error at any time
\r
76 * the LED toggle rate will change from 3 seconds to 500ms.
\r
80 /* Library includes. */
\r
84 /* Scheduler includes. */
\r
85 #include "FreeRTOS.h"
\r
88 /* Demo application includes. */
\r
90 #include "integer.h"
\r
93 #include "semtest.h"
\r
94 #include "dynamic.h"
\r
95 #include "partest.h"
\r
96 #include "comtest2.h"
\r
98 /* Priorities for the demo application tasks. */
\r
99 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
100 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
101 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
102 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
103 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
104 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
106 /* Constants required by the 'Check' task. */
\r
107 #define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
108 #define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
109 #define mainCHECK_TASK_LED ( 4 )
\r
111 /* Constants for the ComTest tasks. */
\r
112 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 115200 )
\r
113 #define mainCOM_TEST_LED ( 6 ) /* The LED built onto the kickstart board. */
\r
116 * The task that executes at the highest priority and calls
\r
117 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
120 static void vErrorChecks( void *pvParameters );
\r
123 * Configure the processor for use with the IAR STR71x demo board. This
\r
124 * just sets the PLL for the required frequency.
\r
126 static void prvSetupHardware( void );
\r
129 * Checks that all the demo application tasks are still executing without error
\r
130 * - as described at the top of the file. Called by vErrorChecks().
\r
132 static long prvCheckOtherTasksAreStillRunning( void );
\r
135 /*-----------------------------------------------------------*/
\r
138 * Starts all the other tasks, then starts the scheduler.
\r
142 /* Setup any hardware that has not already been configured by the low
\r
143 level init routines. */
\r
144 prvSetupHardware();
\r
146 /* Initialise the LED outputs for use by the demo application tasks. */
\r
147 vParTestInitialise();
\r
149 /* Start all the standard demo application tasks. */
\r
150 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
151 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
152 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
153 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
154 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
155 vStartDynamicPriorityTasks();
\r
156 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
158 /* Start the check task - which is defined in this file. */
\r
159 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
161 /* Start the scheduler.
\r
163 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
164 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
165 called. The demo applications included in the FreeRTOS.org download switch
\r
166 to supervisor mode prior to main being called. If you are not using one of
\r
167 these demo application projects then ensure Supervisor mode is used here. */
\r
169 vTaskStartScheduler();
\r
171 /* We should never get here as control is now taken by the scheduler. */
\r
174 /*-----------------------------------------------------------*/
\r
176 static void prvSetupHardware( void )
\r
178 /* Setup the PLL to generate a 48MHz clock from the 4MHz CLK. */
\r
180 /* Turn of the div by two. */
\r
181 RCCU_Div2Config( DISABLE );
\r
183 /* 48MHz = ( 4MHz * 12 ) / 1 */
\r
184 RCCU_PLL1Config( RCCU_PLL1_Mul_12, RCCU_Div_1 );
\r
185 RCCU_RCLKSourceConfig( RCCU_PLL1_Output );
\r
187 /*-----------------------------------------------------------*/
\r
189 static void vErrorChecks( void *pvParameters )
\r
191 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
192 portTickType xLastWakeTime;
\r
194 /* The parameters are not used in this task. */
\r
195 ( void ) pvParameters;
\r
197 /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
\r
198 functions correctly. */
\r
199 xLastWakeTime = xTaskGetTickCount();
\r
201 /* Cycle for ever, delaying then checking all the other tasks are still
\r
202 operating without error. If an error is detected then the delay period
\r
203 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
204 the on board LED flash rate will increase. */
\r
208 /* Delay until it is time to execute again. The delay period is
\r
209 shorter following an error so the LED flashes faster. */
\r
210 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
212 /* Check all the standard demo application tasks are executing without
\r
214 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
216 /* An error has been detected in one of the tasks - flash faster. */
\r
217 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
220 vParTestToggleLED( mainCHECK_TASK_LED );
\r
223 /*-----------------------------------------------------------*/
\r
225 static long prvCheckOtherTasksAreStillRunning( void )
\r
227 long lReturn = ( long ) pdPASS;
\r
229 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
230 that they are all still running, and that none of them have detected
\r
233 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
235 lReturn = ( long ) pdFAIL;
\r
238 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
240 lReturn = ( long ) pdFAIL;
\r
243 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
245 lReturn = ( long ) pdFAIL;
\r
248 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
250 lReturn = ( long ) pdFAIL;
\r
253 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
255 lReturn = ( long ) pdFAIL;
\r
258 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
260 lReturn = ( long ) pdFAIL;
\r
265 /*-----------------------------------------------------------*/
\r