2 FreeRTOS V6.0.1 - Copyright (C) 2009 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 eBook *
\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
64 * Program entry point.
\r
66 * main() is responsible for setting up the microcontroller peripherals, then
\r
67 * starting the demo application tasks. Once the tasks have been created the
\r
68 * scheduler is started and main() should never complete.
\r
70 * The demo creates the three standard 'flash' tasks to provide some visual
\r
71 * feedback that the system and scheduler are still operating correctly.
\r
73 * The HTTP server task operates at the highest priority so will always preempt
\r
74 * the flash or idle task on TCP/IP events.
\r
77 /* Standard includes. */
\r
80 /* Scheduler include files. */
\r
81 #include "FreeRTOS.h"
\r
85 /* Application includes. */
\r
87 #include "HTTP_Serv.h"
\r
89 #include "partest.h"
\r
90 #include "dynamic.h"
\r
91 #include "semtest.h"
\r
94 #include "integer.h"
\r
96 /*-----------------------------------------------------------*/
\r
98 /* Constants to setup the PLL. */
\r
99 #define mainPLL_MUL_4 ( ( unsigned char ) 0x0003 )
\r
100 #define mainPLL_DIV_1 ( ( unsigned char ) 0x0000 )
\r
101 #define mainPLL_ENABLE ( ( unsigned char ) 0x0001 )
\r
102 #define mainPLL_CONNECT ( ( unsigned char ) 0x0003 )
\r
103 #define mainPLL_FEED_BYTE1 ( ( unsigned char ) 0xaa )
\r
104 #define mainPLL_FEED_BYTE2 ( ( unsigned char ) 0x55 )
\r
105 #define mainPLL_LOCK ( ( unsigned long ) 0x0400 )
\r
107 /* Constants to setup the MAM. */
\r
108 #define mainMAM_TIM_3 ( ( unsigned char ) 0x03 )
\r
109 #define mainMAM_MODE_FULL ( ( unsigned char ) 0x02 )
\r
111 /* Constants to setup the peripheral bus. */
\r
112 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
114 /* Constants to setup I/O and processor. */
\r
115 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
116 #define mainLED_TO_OUTPUT ( ( unsigned long ) 0xff0000 )
\r
117 #define mainJTAG_PORT ( ( unsigned long ) 0x3E0000UL )
\r
119 /* Priorities for the demo application tasks. */
\r
120 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
121 #define mainHTTP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
122 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
123 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
124 #define mainERROR_CHECK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
126 /* Flash rates of the on board LED to indicate the health of the system. */
\r
127 #define mainNO_ERROR_DELAY ( 3000 )
\r
128 #define mainERROR_DELAY ( 500 )
\r
129 #define mainON_BOARD_LED_BIT ( ( unsigned long ) 0x80 )
\r
131 /*-----------------------------------------------------------*/
\r
134 * The Olimex demo board has a single built in LED. This function simply
\r
135 * toggles its state.
\r
137 void prvToggleOnBoardLED( void );
\r
140 * Configure the processor for use with the Olimex demo board.
\r
142 static void prvSetupHardware( void );
\r
145 * Simply check for errors and toggle the onboard LED.
\r
147 static void prvErrorChecks( void *pvParameters );
\r
150 * Return true if the demo tasks are executing without error - otherwise
\r
153 static void prvMainCheckOtherTasksAreStillRunning( void );
\r
154 /*-----------------------------------------------------------*/
\r
156 /* Flag set by prvMainCheckOtherTasksAreStillExecuting(). */
\r
157 long lErrorInTask = pdFALSE;
\r
160 * Application entry point:
\r
161 * Starts all the other tasks, then starts the scheduler.
\r
165 /* Setup the hardware for use with the Olimex demo board. */
\r
166 prvSetupHardware();
\r
168 /* Start the standard flash tasks so the WEB server is not the only thing
\r
170 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
171 vStartSemaphoreTasks( tskIDLE_PRIORITY );
\r
172 vStartDynamicPriorityTasks();
\r
173 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
174 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
175 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
177 /* Start the WEB server task and the error check task. */
\r
178 xTaskCreate( vHTTPServerTask, ( signed char * ) "HTTP", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );
\r
179 xTaskCreate( prvErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainERROR_CHECK_PRIORITY, NULL );
\r
181 /* Now all the tasks have been started - start the scheduler.
\r
183 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
184 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
185 called. The demo applications included in the FreeRTOS.org download switch
\r
186 to supervisor mode prior to main being called. If you are not using one of
\r
187 these demo application projects then ensure Supervisor mode is used. */
\r
188 vTaskStartScheduler();
\r
190 /* Should never reach here! */
\r
193 /*-----------------------------------------------------------*/
\r
195 static void prvSetupHardware( void )
\r
197 #ifdef RUN_FROM_RAM
\r
198 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
202 /* Set all GPIO to output other than the P0.14 (BSL), and the JTAG pins.
\r
203 The JTAG pins are left as input as I'm not sure what will happen if the
\r
204 Wiggler is connected after powerup - not that it would be a good idea to
\r
206 GPIO_IODIR = ~( mainJTAG_PORT );
\r
208 /* Setup the PLL to multiply the XTAL input by 4. */
\r
209 SCB_PLLCFG = ( mainPLL_MUL_4 | mainPLL_DIV_1 );
\r
211 /* Activate the PLL by turning it on then feeding the correct sequence of
\r
213 SCB_PLLCON = mainPLL_ENABLE;
\r
214 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
215 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
217 /* Wait for the PLL to lock... */
\r
218 while( !( SCB_PLLSTAT & mainPLL_LOCK ) );
\r
220 /* ...before connecting it using the feed sequence again. */
\r
221 SCB_PLLCON = mainPLL_CONNECT;
\r
222 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
223 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
225 /* Setup and turn on the MAM. Three cycle access is used due to the fast
\r
226 PLL used. It is possible faster overall performance could be obtained by
\r
227 tuning the MAM and PLL settings. */
\r
228 MAM_TIM = mainMAM_TIM_3;
\r
229 MAM_CR = mainMAM_MODE_FULL;
\r
231 /* Setup the peripheral bus to be the same as the PLL output. */
\r
232 SCB_VPBDIV = mainBUS_CLK_FULL;
\r
234 /* Initialise the i2c peripheral. */
\r
237 /* Initialise the LED's used by the flash tasks. */
\r
238 vParTestInitialise();
\r
240 /*-----------------------------------------------------------*/
\r
242 static void prvMainCheckOtherTasksAreStillRunning( void )
\r
244 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
245 that they are all still running, and that none of them have detected
\r
248 /* This function is called from more than one task. */
\r
249 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
251 lErrorInTask = pdTRUE;
\r
254 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
256 lErrorInTask = pdTRUE;
\r
259 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
261 lErrorInTask = pdTRUE;
\r
264 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
266 lErrorInTask = pdTRUE;
\r
269 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
271 lErrorInTask = pdTRUE;
\r
274 /*-----------------------------------------------------------*/
\r
276 void prvToggleOnBoardLED( void )
\r
278 unsigned long ulState;
\r
280 ulState = GPIO0_IOPIN;
\r
281 if( ulState & mainON_BOARD_LED_BIT )
\r
283 GPIO_IOCLR = mainON_BOARD_LED_BIT;
\r
287 GPIO_IOSET = mainON_BOARD_LED_BIT;
\r
290 /*-----------------------------------------------------------*/
\r
292 static void prvErrorChecks( void *pvParameters )
\r
294 portTickType xDelay = mainNO_ERROR_DELAY;
\r
296 /* The parameters are not used. */
\r
297 ( void ) pvParameters;
\r
301 /* How long we delay depends on whether an error has been detected
\r
302 or not. Therefore the flash rate of the on board LED indicates
\r
303 whether or not an error has occurred. */
\r
304 vTaskDelay( xDelay );
\r
306 /* Update the lErrorInTask flag. */
\r
307 prvMainCheckOtherTasksAreStillRunning();
\r
311 /* An error has been found so reduce the delay period and in so
\r
312 doing speed up the flash rate of the on board LED. */
\r
313 xDelay = mainERROR_DELAY;
\r
316 prvToggleOnBoardLED();
\r