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
50 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
51 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
52 called. The demo applications included in the FreeRTOS.org download switch
\r
53 to supervisor mode prior to main being called. If you are not using one of
\r
54 these demo application projects then ensure Supervisor mode is used.
\r
59 * Program entry point.
\r
61 * main() is responsible for setting up the microcontroller peripherals, then
\r
62 * starting the demo application tasks. Once the tasks have been created the
\r
63 * scheduler is started and main() should never complete.
\r
65 * The demo creates the three standard 'flash' tasks to provide some visual
\r
66 * feedback that the system and scheduler are still operating correctly.
\r
68 * The HTTP server task operates at the highest priority so will always preempt
\r
69 * the flash or idle task on TCP/IP events.
\r
72 /* Standard includes. */
\r
75 /* Scheduler include files. */
\r
76 #include "FreeRTOS.h"
\r
80 /* Application includes. */
\r
82 #include "HTTP_Serv.h"
\r
84 #include "partest.h"
\r
85 #include "dynamic.h"
\r
86 #include "semtest.h"
\r
89 #include "integer.h"
\r
91 /*-----------------------------------------------------------*/
\r
93 /* Constants to setup the PLL. */
\r
94 #define mainPLL_MUL_4 ( ( unsigned char ) 0x0003 )
\r
95 #define mainPLL_DIV_1 ( ( unsigned char ) 0x0000 )
\r
96 #define mainPLL_ENABLE ( ( unsigned char ) 0x0001 )
\r
97 #define mainPLL_CONNECT ( ( unsigned char ) 0x0003 )
\r
98 #define mainPLL_FEED_BYTE1 ( ( unsigned char ) 0xaa )
\r
99 #define mainPLL_FEED_BYTE2 ( ( unsigned char ) 0x55 )
\r
100 #define mainPLL_LOCK ( ( unsigned long ) 0x0400 )
\r
102 /* Constants to setup the MAM. */
\r
103 #define mainMAM_TIM_3 ( ( unsigned char ) 0x03 )
\r
104 #define mainMAM_MODE_FULL ( ( unsigned char ) 0x02 )
\r
106 /* Constants to setup the peripheral bus. */
\r
107 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
109 /* Constants to setup I/O and processor. */
\r
110 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
111 #define mainLED_TO_OUTPUT ( ( unsigned long ) 0xff0000 )
\r
112 #define mainJTAG_PORT ( ( unsigned long ) 0x3E0000UL )
\r
114 /* Priorities for the demo application tasks. */
\r
115 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
116 #define mainHTTP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
117 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
118 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
119 #define mainERROR_CHECK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
121 /* Flash rates of the on board LED to indicate the health of the system. */
\r
122 #define mainNO_ERROR_DELAY ( 3000 )
\r
123 #define mainERROR_DELAY ( 500 )
\r
124 #define mainON_BOARD_LED_BIT ( ( unsigned long ) 0x80 )
\r
126 /*-----------------------------------------------------------*/
\r
129 * The Olimex demo board has a single built in LED. This function simply
\r
130 * toggles its state.
\r
132 void prvToggleOnBoardLED( void );
\r
135 * Configure the processor for use with the Olimex demo board.
\r
137 static void prvSetupHardware( void );
\r
140 * Simply check for errors and toggle the onboard LED.
\r
142 static void prvErrorChecks( void *pvParameters );
\r
145 * Return true if the demo tasks are executing without error - otherwise
\r
148 static void prvMainCheckOtherTasksAreStillRunning( void );
\r
149 /*-----------------------------------------------------------*/
\r
151 /* Flag set by prvMainCheckOtherTasksAreStillExecuting(). */
\r
152 long lErrorInTask = pdFALSE;
\r
155 * Application entry point:
\r
156 * Starts all the other tasks, then starts the scheduler.
\r
160 /* Setup the hardware for use with the Olimex demo board. */
\r
161 prvSetupHardware();
\r
163 /* Start the standard flash tasks so the WEB server is not the only thing
\r
165 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
166 vStartSemaphoreTasks( tskIDLE_PRIORITY );
\r
167 vStartDynamicPriorityTasks();
\r
168 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
169 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
170 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
172 /* Start the WEB server task and the error check task. */
\r
173 xTaskCreate( vHTTPServerTask, ( signed char * ) "HTTP", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );
\r
174 xTaskCreate( prvErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainERROR_CHECK_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. */
\r
183 vTaskStartScheduler();
\r
185 /* Should never reach here! */
\r
188 /*-----------------------------------------------------------*/
\r
190 static void prvSetupHardware( void )
\r
192 #ifdef RUN_FROM_RAM
\r
193 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
197 /* Set all GPIO to output other than the P0.14 (BSL), and the JTAG pins.
\r
198 The JTAG pins are left as input as I'm not sure what will happen if the
\r
199 Wiggler is connected after powerup - not that it would be a good idea to
\r
201 GPIO_IODIR = ~( mainJTAG_PORT );
\r
203 /* Setup the PLL to multiply the XTAL input by 4. */
\r
204 SCB_PLLCFG = ( mainPLL_MUL_4 | mainPLL_DIV_1 );
\r
206 /* Activate the PLL by turning it on then feeding the correct sequence of
\r
208 SCB_PLLCON = mainPLL_ENABLE;
\r
209 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
210 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
212 /* Wait for the PLL to lock... */
\r
213 while( !( SCB_PLLSTAT & mainPLL_LOCK ) );
\r
215 /* ...before connecting it using the feed sequence again. */
\r
216 SCB_PLLCON = mainPLL_CONNECT;
\r
217 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
218 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
220 /* Setup and turn on the MAM. Three cycle access is used due to the fast
\r
221 PLL used. It is possible faster overall performance could be obtained by
\r
222 tuning the MAM and PLL settings. */
\r
223 MAM_TIM = mainMAM_TIM_3;
\r
224 MAM_CR = mainMAM_MODE_FULL;
\r
226 /* Setup the peripheral bus to be the same as the PLL output. */
\r
227 SCB_VPBDIV = mainBUS_CLK_FULL;
\r
229 /* Initialise the i2c peripheral. */
\r
232 /* Initialise the LED's used by the flash tasks. */
\r
233 vParTestInitialise();
\r
235 /*-----------------------------------------------------------*/
\r
237 static void prvMainCheckOtherTasksAreStillRunning( void )
\r
239 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
240 that they are all still running, and that none of them have detected
\r
243 /* This function is called from more than one task. */
\r
244 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
246 lErrorInTask = pdTRUE;
\r
249 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
251 lErrorInTask = pdTRUE;
\r
254 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
256 lErrorInTask = pdTRUE;
\r
259 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
261 lErrorInTask = pdTRUE;
\r
264 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
266 lErrorInTask = pdTRUE;
\r
269 /*-----------------------------------------------------------*/
\r
271 void prvToggleOnBoardLED( void )
\r
273 unsigned long ulState;
\r
275 ulState = GPIO0_IOPIN;
\r
276 if( ulState & mainON_BOARD_LED_BIT )
\r
278 GPIO_IOCLR = mainON_BOARD_LED_BIT;
\r
282 GPIO_IOSET = mainON_BOARD_LED_BIT;
\r
285 /*-----------------------------------------------------------*/
\r
287 static void prvErrorChecks( void *pvParameters )
\r
289 portTickType xDelay = mainNO_ERROR_DELAY;
\r
291 /* The parameters are not used. */
\r
292 ( void ) pvParameters;
\r
296 /* How long we delay depends on whether an error has been detected
\r
297 or not. Therefore the flash rate of the on board LED indicates
\r
298 whether or not an error has occurred. */
\r
299 vTaskDelay( xDelay );
\r
301 /* Update the lErrorInTask flag. */
\r
302 prvMainCheckOtherTasksAreStillRunning();
\r
306 /* An error has been found so reduce the delay period and in so
\r
307 doing speed up the flash rate of the on board LED. */
\r
308 xDelay = mainERROR_DELAY;
\r
311 prvToggleOnBoardLED();
\r