2 FreeRTOS.org V4.6.1 - Copyright (C) 2003-2007 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
27 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
31 Also see http://www.SafeRTOS.com a version that has been certified for use
\r
32 in safety critical systems, plus commercial licensing, development and
\r
34 ***************************************************************************
\r
38 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
39 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
40 called. The demo applications included in the FreeRTOS.org download switch
\r
41 to supervisor mode prior to main being called. If you are not using one of
\r
42 these demo application projects then ensure Supervisor mode is used.
\r
47 * Program entry point.
\r
49 * main() is responsible for setting up the microcontroller peripherals, then
\r
50 * starting the demo application tasks. Once the tasks have been created the
\r
51 * scheduler is started and main() should never complete.
\r
53 * The demo creates the three standard 'flash' tasks to provide some visual
\r
54 * feedback that the system and scheduler are still operating correctly.
\r
56 * The HTTP server task operates at the highest priority so will always preempt
\r
57 * the flash or idle task on TCP/IP events.
\r
60 /* Standard includes. */
\r
63 /* Scheduler include files. */
\r
64 #include "FreeRTOS.h"
\r
68 /* Application includes. */
\r
70 #include "HTTP_Serv.h"
\r
72 #include "partest.h"
\r
73 #include "dynamic.h"
\r
74 #include "semtest.h"
\r
77 #include "integer.h"
\r
79 /*-----------------------------------------------------------*/
\r
81 /* Constants to setup the PLL. */
\r
82 #define mainPLL_MUL_4 ( ( unsigned portCHAR ) 0x0003 )
\r
83 #define mainPLL_DIV_1 ( ( unsigned portCHAR ) 0x0000 )
\r
84 #define mainPLL_ENABLE ( ( unsigned portCHAR ) 0x0001 )
\r
85 #define mainPLL_CONNECT ( ( unsigned portCHAR ) 0x0003 )
\r
86 #define mainPLL_FEED_BYTE1 ( ( unsigned portCHAR ) 0xaa )
\r
87 #define mainPLL_FEED_BYTE2 ( ( unsigned portCHAR ) 0x55 )
\r
88 #define mainPLL_LOCK ( ( unsigned portLONG ) 0x0400 )
\r
90 /* Constants to setup the MAM. */
\r
91 #define mainMAM_TIM_3 ( ( unsigned portCHAR ) 0x03 )
\r
92 #define mainMAM_MODE_FULL ( ( unsigned portCHAR ) 0x02 )
\r
94 /* Constants to setup the peripheral bus. */
\r
95 #define mainBUS_CLK_FULL ( ( unsigned portCHAR ) 0x01 )
\r
97 /* Constants to setup I/O and processor. */
\r
98 #define mainBUS_CLK_FULL ( ( unsigned portCHAR ) 0x01 )
\r
99 #define mainLED_TO_OUTPUT ( ( unsigned portLONG ) 0xff0000 )
\r
100 #define mainJTAG_PORT ( ( unsigned portLONG ) 0x3E0000UL )
\r
102 /* Priorities for the demo application tasks. */
\r
103 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
104 #define mainHTTP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
105 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
106 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
107 #define mainERROR_CHECK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
109 /* Flash rates of the on board LED to indicate the health of the system. */
\r
110 #define mainNO_ERROR_DELAY ( 3000 )
\r
111 #define mainERROR_DELAY ( 500 )
\r
112 #define mainON_BOARD_LED_BIT ( ( unsigned portLONG ) 0x80 )
\r
114 /*-----------------------------------------------------------*/
\r
117 * The Olimex demo board has a single built in LED. This function simply
\r
118 * toggles its state.
\r
120 void prvToggleOnBoardLED( void );
\r
123 * Configure the processor for use with the Olimex demo board.
\r
125 static void prvSetupHardware( void );
\r
128 * Simply check for errors and toggle the onboard LED.
\r
130 static void prvErrorChecks( void *pvParameters );
\r
133 * Return true if the demo tasks are executing without error - otherwise
\r
136 static void prvMainCheckOtherTasksAreStillRunning( void );
\r
137 /*-----------------------------------------------------------*/
\r
139 /* Flag set by prvMainCheckOtherTasksAreStillExecuting(). */
\r
140 portLONG lErrorInTask = pdFALSE;
\r
143 * Application entry point:
\r
144 * Starts all the other tasks, then starts the scheduler.
\r
148 /* Setup the hardware for use with the Olimex demo board. */
\r
149 prvSetupHardware();
\r
151 /* Start the standard flash tasks so the WEB server is not the only thing
\r
153 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
154 vStartSemaphoreTasks( tskIDLE_PRIORITY );
\r
155 vStartDynamicPriorityTasks();
\r
156 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
157 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
158 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
160 /* Start the WEB server task and the error check task. */
\r
161 xTaskCreate( vHTTPServerTask, ( signed portCHAR * ) "HTTP", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );
\r
162 xTaskCreate( prvErrorChecks, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainERROR_CHECK_PRIORITY, NULL );
\r
164 /* Now all the tasks have been started - start the scheduler.
\r
166 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
167 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
168 called. The demo applications included in the FreeRTOS.org download switch
\r
169 to supervisor mode prior to main being called. If you are not using one of
\r
170 these demo application projects then ensure Supervisor mode is used. */
\r
171 vTaskStartScheduler();
\r
173 /* Should never reach here! */
\r
176 /*-----------------------------------------------------------*/
\r
178 static void prvSetupHardware( void )
\r
180 #ifdef RUN_FROM_RAM
\r
181 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
185 /* Set all GPIO to output other than the P0.14 (BSL), and the JTAG pins.
\r
186 The JTAG pins are left as input as I'm not sure what will happen if the
\r
187 Wiggler is connected after powerup - not that it would be a good idea to
\r
189 GPIO_IODIR = ~( mainJTAG_PORT );
\r
191 /* Setup the PLL to multiply the XTAL input by 4. */
\r
192 SCB_PLLCFG = ( mainPLL_MUL_4 | mainPLL_DIV_1 );
\r
194 /* Activate the PLL by turning it on then feeding the correct sequence of
\r
196 SCB_PLLCON = mainPLL_ENABLE;
\r
197 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
198 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
200 /* Wait for the PLL to lock... */
\r
201 while( !( SCB_PLLSTAT & mainPLL_LOCK ) );
\r
203 /* ...before connecting it using the feed sequence again. */
\r
204 SCB_PLLCON = mainPLL_CONNECT;
\r
205 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
206 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
208 /* Setup and turn on the MAM. Three cycle access is used due to the fast
\r
209 PLL used. It is possible faster overall performance could be obtained by
\r
210 tuning the MAM and PLL settings. */
\r
211 MAM_TIM = mainMAM_TIM_3;
\r
212 MAM_CR = mainMAM_MODE_FULL;
\r
214 /* Setup the peripheral bus to be the same as the PLL output. */
\r
215 SCB_VPBDIV = mainBUS_CLK_FULL;
\r
217 /* Initialise the i2c peripheral. */
\r
220 /* Initialise the LED's used by the flash tasks. */
\r
221 vParTestInitialise();
\r
223 /*-----------------------------------------------------------*/
\r
225 static void prvMainCheckOtherTasksAreStillRunning( void )
\r
227 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
228 that they are all still running, and that none of them have detected
\r
231 /* This function is called from more than one task. */
\r
232 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
234 lErrorInTask = pdTRUE;
\r
237 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
239 lErrorInTask = pdTRUE;
\r
242 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
244 lErrorInTask = pdTRUE;
\r
247 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
249 lErrorInTask = pdTRUE;
\r
252 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
254 lErrorInTask = pdTRUE;
\r
257 /*-----------------------------------------------------------*/
\r
259 void prvToggleOnBoardLED( void )
\r
261 unsigned portLONG ulState;
\r
263 ulState = GPIO0_IOPIN;
\r
264 if( ulState & mainON_BOARD_LED_BIT )
\r
266 GPIO_IOCLR = mainON_BOARD_LED_BIT;
\r
270 GPIO_IOSET = mainON_BOARD_LED_BIT;
\r
273 /*-----------------------------------------------------------*/
\r
275 static void prvErrorChecks( void *pvParameters )
\r
277 portTickType xDelay = mainNO_ERROR_DELAY;
\r
279 /* The parameters are not used. */
\r
280 ( void ) pvParameters;
\r
284 /* How long we delay depends on whether an error has been detected
\r
285 or not. Therefore the flash rate of the on board LED indicates
\r
286 whether or not an error has occurred. */
\r
287 vTaskDelay( xDelay );
\r
289 /* Update the lErrorInTask flag. */
\r
290 prvMainCheckOtherTasksAreStillRunning();
\r
294 /* An error has been found so reduce the delay period and in so
\r
295 doing speed up the flash rate of the on board LED. */
\r
296 xDelay = mainERROR_DELAY;
\r
299 prvToggleOnBoardLED();
\r