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 * Program entry point.
\r
55 * main() is responsible for setting up the microcontroller peripherals, then
\r
56 * starting the demo application tasks. Once the tasks have been created the
\r
57 * scheduler is started and main() should never complete.
\r
59 * The demo creates the three standard 'flash' tasks to provide some visual
\r
60 * feedback that the system and scheduler are still operating correctly.
\r
62 * The HTTP server task operates at the highest priority so will always preempt
\r
63 * the flash or idle task on TCP/IP events.
\r
66 /* Standard includes. */
\r
69 /* Scheduler include files. */
\r
70 #include "FreeRTOS.h"
\r
74 /* Application includes. */
\r
76 #include "HTTP_Serv.h"
\r
78 #include "partest.h"
\r
79 #include "dynamic.h"
\r
80 #include "semtest.h"
\r
83 #include "integer.h"
\r
85 /*-----------------------------------------------------------*/
\r
87 /* Constants to setup the PLL. */
\r
88 #define mainPLL_MUL_4 ( ( unsigned portCHAR ) 0x0003 )
\r
89 #define mainPLL_DIV_1 ( ( unsigned portCHAR ) 0x0000 )
\r
90 #define mainPLL_ENABLE ( ( unsigned portCHAR ) 0x0001 )
\r
91 #define mainPLL_CONNECT ( ( unsigned portCHAR ) 0x0003 )
\r
92 #define mainPLL_FEED_BYTE1 ( ( unsigned portCHAR ) 0xaa )
\r
93 #define mainPLL_FEED_BYTE2 ( ( unsigned portCHAR ) 0x55 )
\r
94 #define mainPLL_LOCK ( ( unsigned portLONG ) 0x0400 )
\r
96 /* Constants to setup the MAM. */
\r
97 #define mainMAM_TIM_3 ( ( unsigned portCHAR ) 0x03 )
\r
98 #define mainMAM_MODE_FULL ( ( unsigned portCHAR ) 0x02 )
\r
100 /* Constants to setup the peripheral bus. */
\r
101 #define mainBUS_CLK_FULL ( ( unsigned portCHAR ) 0x01 )
\r
103 /* Constants to setup I/O and processor. */
\r
104 #define mainBUS_CLK_FULL ( ( unsigned portCHAR ) 0x01 )
\r
105 #define mainLED_TO_OUTPUT ( ( unsigned portLONG ) 0xff0000 )
\r
106 #define mainJTAG_PORT ( ( unsigned portLONG ) 0x3E0000UL )
\r
108 /* Priorities for the demo application tasks. */
\r
109 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
110 #define mainHTTP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
111 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
112 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
113 #define mainERROR_CHECK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
115 /* Flash rates of the on board LED to indicate the health of the system. */
\r
116 #define mainNO_ERROR_DELAY ( 3000 )
\r
117 #define mainERROR_DELAY ( 500 )
\r
118 #define mainON_BOARD_LED_BIT ( ( unsigned portLONG ) 0x80 )
\r
120 /*-----------------------------------------------------------*/
\r
123 * The Olimex demo board has a single built in LED. This function simply
\r
124 * toggles its state.
\r
126 void prvToggleOnBoardLED( void );
\r
129 * Configure the processor for use with the Olimex demo board.
\r
131 static void prvSetupHardware( void );
\r
134 * Simply check for errors and toggle the onboard LED.
\r
136 static void prvErrorChecks( void *pvParameters );
\r
139 * Return true if the demo tasks are executing without error - otherwise
\r
142 static void prvMainCheckOtherTasksAreStillRunning( void );
\r
143 /*-----------------------------------------------------------*/
\r
145 /* Flag set by prvMainCheckOtherTasksAreStillExecuting(). */
\r
146 portLONG lErrorInTask = pdFALSE;
\r
149 * Application entry point:
\r
150 * Starts all the other tasks, then starts the scheduler.
\r
154 /* Setup the hardware for use with the Olimex demo board. */
\r
155 prvSetupHardware();
\r
157 /* Start the standard flash tasks so the WEB server is not the only thing
\r
159 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
160 vStartSemaphoreTasks( tskIDLE_PRIORITY );
\r
161 vStartDynamicPriorityTasks();
\r
162 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
163 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
164 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
166 /* Start the WEB server task and the error check task. */
\r
167 xTaskCreate( vHTTPServerTask, ( signed portCHAR * ) "HTTP", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );
\r
168 xTaskCreate( prvErrorChecks, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainERROR_CHECK_PRIORITY, NULL );
\r
170 /* Now all the tasks have been started - start the scheduler.
\r
172 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
173 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
174 called. The demo applications included in the FreeRTOS.org download switch
\r
175 to supervisor mode prior to main being called. If you are not using one of
\r
176 these demo application projects then ensure Supervisor mode is used. */
\r
177 vTaskStartScheduler();
\r
179 /* Should never reach here! */
\r
182 /*-----------------------------------------------------------*/
\r
184 static void prvSetupHardware( void )
\r
186 #ifdef RUN_FROM_RAM
\r
187 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
191 /* Set all GPIO to output other than the P0.14 (BSL), and the JTAG pins.
\r
192 The JTAG pins are left as input as I'm not sure what will happen if the
\r
193 Wiggler is connected after powerup - not that it would be a good idea to
\r
195 GPIO_IODIR = ~( mainJTAG_PORT );
\r
197 /* Setup the PLL to multiply the XTAL input by 4. */
\r
198 SCB_PLLCFG = ( mainPLL_MUL_4 | mainPLL_DIV_1 );
\r
200 /* Activate the PLL by turning it on then feeding the correct sequence of
\r
202 SCB_PLLCON = mainPLL_ENABLE;
\r
203 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
204 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
206 /* Wait for the PLL to lock... */
\r
207 while( !( SCB_PLLSTAT & mainPLL_LOCK ) );
\r
209 /* ...before connecting it using the feed sequence again. */
\r
210 SCB_PLLCON = mainPLL_CONNECT;
\r
211 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
212 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
214 /* Setup and turn on the MAM. Three cycle access is used due to the fast
\r
215 PLL used. It is possible faster overall performance could be obtained by
\r
216 tuning the MAM and PLL settings. */
\r
217 MAM_TIM = mainMAM_TIM_3;
\r
218 MAM_CR = mainMAM_MODE_FULL;
\r
220 /* Setup the peripheral bus to be the same as the PLL output. */
\r
221 SCB_VPBDIV = mainBUS_CLK_FULL;
\r
223 /* Initialise the i2c peripheral. */
\r
226 /* Initialise the LED's used by the flash tasks. */
\r
227 vParTestInitialise();
\r
229 /*-----------------------------------------------------------*/
\r
231 static void prvMainCheckOtherTasksAreStillRunning( void )
\r
233 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
234 that they are all still running, and that none of them have detected
\r
237 /* This function is called from more than one task. */
\r
238 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
240 lErrorInTask = pdTRUE;
\r
243 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
245 lErrorInTask = pdTRUE;
\r
248 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
250 lErrorInTask = pdTRUE;
\r
253 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
255 lErrorInTask = pdTRUE;
\r
258 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
260 lErrorInTask = pdTRUE;
\r
263 /*-----------------------------------------------------------*/
\r
265 void prvToggleOnBoardLED( void )
\r
267 unsigned portLONG ulState;
\r
269 ulState = GPIO0_IOPIN;
\r
270 if( ulState & mainON_BOARD_LED_BIT )
\r
272 GPIO_IOCLR = mainON_BOARD_LED_BIT;
\r
276 GPIO_IOSET = mainON_BOARD_LED_BIT;
\r
279 /*-----------------------------------------------------------*/
\r
281 static void prvErrorChecks( void *pvParameters )
\r
283 portTickType xDelay = mainNO_ERROR_DELAY;
\r
285 /* The parameters are not used. */
\r
286 ( void ) pvParameters;
\r
290 /* How long we delay depends on whether an error has been detected
\r
291 or not. Therefore the flash rate of the on board LED indicates
\r
292 whether or not an error has occurred. */
\r
293 vTaskDelay( xDelay );
\r
295 /* Update the lErrorInTask flag. */
\r
296 prvMainCheckOtherTasksAreStillRunning();
\r
300 /* An error has been found so reduce the delay period and in so
\r
301 doing speed up the flash rate of the on board LED. */
\r
302 xDelay = mainERROR_DELAY;
\r
305 prvToggleOnBoardLED();
\r