2 FreeRTOS.org V4.7.1 - Copyright (C) 2003-2008 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
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
28 Please ensure to read the configuration and relevant port sections of the
\r
29 online documentation.
\r
31 +++ http://www.FreeRTOS.org +++
\r
32 Documentation, latest information, license and contact details.
\r
34 +++ http://www.SafeRTOS.com +++
\r
35 A version that is certified for use in safety critical systems.
\r
37 +++ http://www.OpenRTOS.com +++
\r
38 Commercial support, development, porting, licensing and training services.
\r
40 ***************************************************************************
\r
44 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
45 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
46 called. The demo applications included in the FreeRTOS.org download switch
\r
47 to supervisor mode prior to main being called. If you are not using one of
\r
48 these demo application projects then ensure Supervisor mode is used.
\r
53 * Creates all the application tasks, then starts the scheduler.
\r
55 * A task is created called "uIP". This executes the uIP stack and small
\r
56 * WEB server sample. All the other tasks are from the set of standard
\r
57 * demo tasks. The WEB documentation provides more details of the standard
\r
58 * demo application tasks.
\r
60 * Main.c also creates a task called "Check". This only executes every three
\r
61 * seconds but has the highest priority so is guaranteed to get processor time.
\r
62 * Its main function is to check that all the other tasks are still operational.
\r
63 * Each standard demo task maintains a unique count that is incremented each
\r
64 * time the task successfully completes its function. Should any error occur
\r
65 * within such a task the count is permanently halted. The check task inspects
\r
66 * the count of each task to ensure it has changed since the last time the
\r
67 * check task executed. If all the count variables have changed all the tasks
\r
68 * are still executing error free, and the check task toggles the yellow LED.
\r
69 * Should any task contain an error at any time the LED toggle rate will change
\r
70 * from 3 seconds to 500ms.
\r
75 /* Standard includes. */
\r
79 /* Scheduler includes. */
\r
80 #include "FreeRTOS.h"
\r
83 /* Demo application includes. */
\r
85 #include "dynamic.h"
\r
86 #include "semtest.h"
\r
88 /*-----------------------------------------------------------*/
\r
90 /* Constants to setup the PLL. */
\r
91 #define mainPLL_MUL_4 ( ( unsigned portCHAR ) 0x0003 )
\r
92 #define mainPLL_DIV_1 ( ( unsigned portCHAR ) 0x0000 )
\r
93 #define mainPLL_ENABLE ( ( unsigned portCHAR ) 0x0001 )
\r
94 #define mainPLL_CONNECT ( ( unsigned portCHAR ) 0x0003 )
\r
95 #define mainPLL_FEED_BYTE1 ( ( unsigned portCHAR ) 0xaa )
\r
96 #define mainPLL_FEED_BYTE2 ( ( unsigned portCHAR ) 0x55 )
\r
97 #define mainPLL_LOCK ( ( unsigned portLONG ) 0x0400 )
\r
99 /* Constants to setup the MAM. */
\r
100 #define mainMAM_TIM_3 ( ( unsigned portCHAR ) 0x03 )
\r
101 #define mainMAM_MODE_FULL ( ( unsigned portCHAR ) 0x02 )
\r
103 /* Constants to setup the peripheral bus. */
\r
104 #define mainBUS_CLK_FULL ( ( unsigned portCHAR ) 0x01 )
\r
106 /* Priorities/stacks for the demo application tasks. */
\r
107 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
108 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
109 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
110 #define mainUIP_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
111 #define mainUIP_TASK_STACK_SIZE ( 150 )
\r
113 /* The rate at which the on board LED will toggle when there is/is not an
\r
115 #define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
116 #define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
117 #define mainON_BOARD_LED_BIT ( ( unsigned portLONG ) 0x80 )
\r
118 #define mainYELLOW_LED ( 1 << 11 )
\r
120 /*-----------------------------------------------------------*/
\r
123 * This is the uIP task which is defined within the uip.c file. This has not
\r
124 * been placed into a header file in order to minimise the changes to the uip
\r
127 extern void ( vuIP_TASK ) ( void *pvParameters );
\r
130 * The Yellow LED is under the control of the Check task. All the other LED's
\r
131 * are under the control of the uIP task.
\r
133 void prvToggleOnBoardLED( void );
\r
136 * Checks that all the demo application tasks are still executing without error
\r
137 * - as described at the top of the file.
\r
139 static portLONG prvCheckOtherTasksAreStillRunning( void );
\r
142 * The task that executes at the highest priority and calls
\r
143 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
146 static void vErrorChecks( void *pvParameters );
\r
149 * Configure the processor for use with the Olimex demo board. This includes
\r
150 * setup for the I/O, system clock, and access timings.
\r
152 static void prvSetupHardware( void );
\r
154 /*-----------------------------------------------------------*/
\r
157 * Starts all the other tasks, then starts the scheduler.
\r
161 /* Configure the processor. */
\r
162 prvSetupHardware();
\r
164 /* Start the task that handles the TCP/IP functionality. */
\r
165 xTaskCreate( vuIP_TASK, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );
\r
167 /* Start the demo/test application tasks. These are created in addition
\r
168 to the TCP/IP task for demonstration and test purposes. */
\r
169 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
170 vStartDynamicPriorityTasks();
\r
171 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
173 /* Start the check task - which is defined in this file. */
\r
174 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
176 /* Now all the tasks have been started - start the scheduler.
\r
178 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
179 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
180 called. The demo applications included in the FreeRTOS.org download switch
\r
181 to supervisor mode prior to main being called. If you are not using one of
\r
182 these demo application projects then ensure Supervisor mode is used here. */
\r
183 vTaskStartScheduler();
\r
185 /* Should never reach here! */
\r
188 /*-----------------------------------------------------------*/
\r
190 static void vErrorChecks( void *pvParameters )
\r
192 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
194 /* Cycle for ever, delaying then checking all the other tasks are still
\r
195 operating without error. If an error is detected then the delay period
\r
196 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
197 the on board LED flash rate will increase. */
\r
200 /* Delay until it is time to execute again. */
\r
201 vTaskDelay( xDelayPeriod );
\r
203 /* Check all the standard demo application tasks are executing without
\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 prvToggleOnBoardLED();
\r
214 /*-----------------------------------------------------------*/
\r
216 static void prvSetupHardware( void )
\r
218 #ifdef RUN_FROM_RAM
\r
219 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
223 /* Setup the PLL to multiply the XTAL input by 4. */
\r
224 SCB_PLLCFG = ( mainPLL_MUL_4 | mainPLL_DIV_1 );
\r
226 /* Activate the PLL by turning it on then feeding the correct sequence of
\r
228 SCB_PLLCON = mainPLL_ENABLE;
\r
229 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
230 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
232 /* Wait for the PLL to lock... */
\r
233 while( !( SCB_PLLSTAT & mainPLL_LOCK ) );
\r
235 /* ...before connecting it using the feed sequence again. */
\r
236 SCB_PLLCON = mainPLL_CONNECT;
\r
237 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
238 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
240 /* Setup and turn on the MAM. Three cycle access is used due to the fast
\r
241 PLL used. It is possible faster overall performance could be obtained by
\r
242 tuning the MAM and PLL settings. */
\r
243 MAM_TIM = mainMAM_TIM_3;
\r
244 MAM_CR = mainMAM_MODE_FULL;
\r
246 /* Setup the peripheral bus to be the same as the PLL output. */
\r
247 SCB_VPBDIV = mainBUS_CLK_FULL;
\r
249 /*-----------------------------------------------------------*/
\r
251 void prvToggleOnBoardLED( void )
\r
253 unsigned portLONG ulState;
\r
255 ulState = GPIO0_IOPIN;
\r
256 if( ulState & mainYELLOW_LED )
\r
258 GPIO_IOCLR = mainYELLOW_LED;
\r
262 GPIO_IOSET = mainYELLOW_LED;
\r
265 /*-----------------------------------------------------------*/
\r
267 static portLONG prvCheckOtherTasksAreStillRunning( void )
\r
269 portLONG lReturn = ( portLONG ) pdPASS;
\r
271 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
272 that they are all still running, and that none of them have detected
\r
275 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
277 lReturn = ( portLONG ) pdFAIL;
\r
280 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
282 lReturn = ( portLONG ) pdFAIL;
\r
285 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
287 lReturn = ( portLONG ) pdFAIL;
\r