2 FreeRTOS.org V5.2.0 - Copyright (C) 2003-2009 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 it
\r
7 under the terms of the GNU General Public License (version 2) as published
\r
8 by the Free Software Foundation and modified by the FreeRTOS exception.
\r
10 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
15 You should have received a copy of the GNU General Public License along
\r
16 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
17 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
19 A special exception to the GPL is included to allow you to distribute a
\r
20 combined work that includes FreeRTOS.org without being obliged to provide
\r
21 the source code for any proprietary components. See the licensing section
\r
22 of http://www.FreeRTOS.org for full details.
\r
25 ***************************************************************************
\r
27 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
29 * This is a concise, step by step, 'hands on' guide that describes both *
\r
30 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
31 * explains numerous examples that are written using the FreeRTOS API. *
\r
32 * Full source code for all the examples is provided in an accompanying *
\r
35 ***************************************************************************
\r
39 Please ensure to read the configuration and relevant port sections of the
\r
40 online documentation.
\r
42 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
45 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
48 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
49 licensing and training services.
\r
53 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
54 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
55 called. The demo applications included in the FreeRTOS.org download switch
\r
56 to supervisor mode prior to main being called. If you are not using one of
\r
57 these demo application projects then ensure Supervisor mode is used.
\r
62 * Creates all the application tasks, then starts the scheduler.
\r
64 * A task is created called "uIP". This executes the uIP stack and small
\r
65 * WEB server sample. All the other tasks are from the set of standard
\r
66 * demo tasks. The WEB documentation provides more details of the standard
\r
67 * demo application tasks.
\r
69 * Main.c also creates a task called "Check". This only executes every three
\r
70 * seconds but has the highest priority so is guaranteed to get processor time.
\r
71 * Its main function is to check that all the other tasks are still operational.
\r
72 * Each standard demo task maintains a unique count that is incremented each
\r
73 * time the task successfully completes its function. Should any error occur
\r
74 * within such a task the count is permanently halted. The check task inspects
\r
75 * the count of each task to ensure it has changed since the last time the
\r
76 * check task executed. If all the count variables have changed all the tasks
\r
77 * are still executing error free, and the check task toggles the yellow LED.
\r
78 * Should any task contain an error at any time the LED toggle rate will change
\r
79 * from 3 seconds to 500ms.
\r
84 /* Standard includes. */
\r
88 /* Scheduler includes. */
\r
89 #include "FreeRTOS.h"
\r
92 /* Demo application includes. */
\r
94 #include "dynamic.h"
\r
95 #include "semtest.h"
\r
97 /*-----------------------------------------------------------*/
\r
99 /* Constants to setup the PLL. */
\r
100 #define mainPLL_MUL_4 ( ( unsigned portCHAR ) 0x0003 )
\r
101 #define mainPLL_DIV_1 ( ( unsigned portCHAR ) 0x0000 )
\r
102 #define mainPLL_ENABLE ( ( unsigned portCHAR ) 0x0001 )
\r
103 #define mainPLL_CONNECT ( ( unsigned portCHAR ) 0x0003 )
\r
104 #define mainPLL_FEED_BYTE1 ( ( unsigned portCHAR ) 0xaa )
\r
105 #define mainPLL_FEED_BYTE2 ( ( unsigned portCHAR ) 0x55 )
\r
106 #define mainPLL_LOCK ( ( unsigned portLONG ) 0x0400 )
\r
108 /* Constants to setup the MAM. */
\r
109 #define mainMAM_TIM_3 ( ( unsigned portCHAR ) 0x03 )
\r
110 #define mainMAM_MODE_FULL ( ( unsigned portCHAR ) 0x02 )
\r
112 /* Constants to setup the peripheral bus. */
\r
113 #define mainBUS_CLK_FULL ( ( unsigned portCHAR ) 0x01 )
\r
115 /* Priorities/stacks for the demo application tasks. */
\r
116 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
117 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
118 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
119 #define mainUIP_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
120 #define mainUIP_TASK_STACK_SIZE ( 150 )
\r
122 /* The rate at which the on board LED will toggle when there is/is not an
\r
124 #define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
125 #define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
126 #define mainON_BOARD_LED_BIT ( ( unsigned portLONG ) 0x80 )
\r
127 #define mainYELLOW_LED ( 1 << 11 )
\r
129 /*-----------------------------------------------------------*/
\r
132 * This is the uIP task which is defined within the uip.c file. This has not
\r
133 * been placed into a header file in order to minimise the changes to the uip
\r
136 extern void ( vuIP_TASK ) ( void *pvParameters );
\r
139 * The Yellow LED is under the control of the Check task. All the other LED's
\r
140 * are under the control of the uIP task.
\r
142 void prvToggleOnBoardLED( 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 portLONG prvCheckOtherTasksAreStillRunning( void );
\r
151 * The task that executes at the highest priority and calls
\r
152 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
155 static void vErrorChecks( void *pvParameters );
\r
158 * Configure the processor for use with the Olimex demo board. This includes
\r
159 * setup for the I/O, system clock, and access timings.
\r
161 static void prvSetupHardware( void );
\r
163 /*-----------------------------------------------------------*/
\r
166 * Starts all the other tasks, then starts the scheduler.
\r
170 /* Configure the processor. */
\r
171 prvSetupHardware();
\r
173 /* Start the task that handles the TCP/IP functionality. */
\r
174 xTaskCreate( vuIP_TASK, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );
\r
176 /* Start the demo/test application tasks. These are created in addition
\r
177 to the TCP/IP task for demonstration and test purposes. */
\r
178 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
179 vStartDynamicPriorityTasks();
\r
180 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
182 /* Start the check task - which is defined in this file. */
\r
183 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
185 /* Now all the tasks have been started - start the scheduler.
\r
187 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
188 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
189 called. The demo applications included in the FreeRTOS.org download switch
\r
190 to supervisor mode prior to main being called. If you are not using one of
\r
191 these demo application projects then ensure Supervisor mode is used here. */
\r
192 vTaskStartScheduler();
\r
194 /* Should never reach here! */
\r
197 /*-----------------------------------------------------------*/
\r
199 static void vErrorChecks( void *pvParameters )
\r
201 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
203 /* Cycle for ever, delaying then checking all the other tasks are still
\r
204 operating without error. If an error is detected then the delay period
\r
205 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
206 the on board LED flash rate will increase. */
\r
209 /* Delay until it is time to execute again. */
\r
210 vTaskDelay( 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 prvToggleOnBoardLED();
\r
223 /*-----------------------------------------------------------*/
\r
225 static void prvSetupHardware( void )
\r
227 #ifdef RUN_FROM_RAM
\r
228 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
232 /* Setup the PLL to multiply the XTAL input by 4. */
\r
233 SCB_PLLCFG = ( mainPLL_MUL_4 | mainPLL_DIV_1 );
\r
235 /* Activate the PLL by turning it on then feeding the correct sequence of
\r
237 SCB_PLLCON = mainPLL_ENABLE;
\r
238 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
239 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
241 /* Wait for the PLL to lock... */
\r
242 while( !( SCB_PLLSTAT & mainPLL_LOCK ) );
\r
244 /* ...before connecting it using the feed sequence again. */
\r
245 SCB_PLLCON = mainPLL_CONNECT;
\r
246 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
247 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
249 /* Setup and turn on the MAM. Three cycle access is used due to the fast
\r
250 PLL used. It is possible faster overall performance could be obtained by
\r
251 tuning the MAM and PLL settings. */
\r
252 MAM_TIM = mainMAM_TIM_3;
\r
253 MAM_CR = mainMAM_MODE_FULL;
\r
255 /* Setup the peripheral bus to be the same as the PLL output. */
\r
256 SCB_VPBDIV = mainBUS_CLK_FULL;
\r
258 /*-----------------------------------------------------------*/
\r
260 void prvToggleOnBoardLED( void )
\r
262 unsigned portLONG ulState;
\r
264 ulState = GPIO0_IOPIN;
\r
265 if( ulState & mainYELLOW_LED )
\r
267 GPIO_IOCLR = mainYELLOW_LED;
\r
271 GPIO_IOSET = mainYELLOW_LED;
\r
274 /*-----------------------------------------------------------*/
\r
276 static portLONG prvCheckOtherTasksAreStillRunning( void )
\r
278 portLONG lReturn = ( portLONG ) pdPASS;
\r
280 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
281 that they are all still running, and that none of them have detected
\r
284 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
286 lReturn = ( portLONG ) pdFAIL;
\r
289 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
291 lReturn = ( portLONG ) pdFAIL;
\r
294 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
296 lReturn = ( portLONG ) pdFAIL;
\r