2 FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
66 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
67 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
68 called. The demo applications included in the FreeRTOS.org download switch
\r
69 to supervisor mode prior to main being called. If you are not using one of
\r
70 these demo application projects then ensure Supervisor mode is used.
\r
75 * Program entry point.
\r
77 * main() is responsible for setting up the microcontroller peripherals, then
\r
78 * starting the demo application tasks. Once the tasks have been created the
\r
79 * scheduler is started and main() should never complete.
\r
81 * The demo creates the three standard 'flash' tasks to provide some visual
\r
82 * feedback that the system and scheduler are still operating correctly.
\r
84 * The HTTP server task operates at the highest priority so will always preempt
\r
85 * the flash or idle task on TCP/IP events.
\r
88 /* Standard includes. */
\r
91 /* Scheduler include files. */
\r
92 #include "FreeRTOS.h"
\r
96 /* Application includes. */
\r
98 #include "HTTP_Serv.h"
\r
100 #include "partest.h"
\r
101 #include "dynamic.h"
\r
102 #include "semtest.h"
\r
104 #include "BlockQ.h"
\r
105 #include "integer.h"
\r
107 /*-----------------------------------------------------------*/
\r
109 /* Constants to setup the PLL. */
\r
110 #define mainPLL_MUL_4 ( ( unsigned char ) 0x0003 )
\r
111 #define mainPLL_DIV_1 ( ( unsigned char ) 0x0000 )
\r
112 #define mainPLL_ENABLE ( ( unsigned char ) 0x0001 )
\r
113 #define mainPLL_CONNECT ( ( unsigned char ) 0x0003 )
\r
114 #define mainPLL_FEED_BYTE1 ( ( unsigned char ) 0xaa )
\r
115 #define mainPLL_FEED_BYTE2 ( ( unsigned char ) 0x55 )
\r
116 #define mainPLL_LOCK ( ( unsigned long ) 0x0400 )
\r
118 /* Constants to setup the MAM. */
\r
119 #define mainMAM_TIM_3 ( ( unsigned char ) 0x03 )
\r
120 #define mainMAM_MODE_FULL ( ( unsigned char ) 0x02 )
\r
122 /* Constants to setup the peripheral bus. */
\r
123 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
125 /* Constants to setup I/O and processor. */
\r
126 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
127 #define mainLED_TO_OUTPUT ( ( unsigned long ) 0xff0000 )
\r
128 #define mainJTAG_PORT ( ( unsigned long ) 0x3E0000UL )
\r
130 /* Priorities for the demo application tasks. */
\r
131 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
132 #define mainHTTP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
133 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
134 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
135 #define mainERROR_CHECK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
137 /* Flash rates of the on board LED to indicate the health of the system. */
\r
138 #define mainNO_ERROR_DELAY ( 3000 )
\r
139 #define mainERROR_DELAY ( 500 )
\r
140 #define mainON_BOARD_LED_BIT ( ( unsigned long ) 0x80 )
\r
142 /*-----------------------------------------------------------*/
\r
145 * The Olimex demo board has a single built in LED. This function simply
\r
146 * toggles its state.
\r
148 void prvToggleOnBoardLED( void );
\r
151 * Configure the processor for use with the Olimex demo board.
\r
153 static void prvSetupHardware( void );
\r
156 * Simply check for errors and toggle the onboard LED.
\r
158 static void prvErrorChecks( void *pvParameters );
\r
161 * Return true if the demo tasks are executing without error - otherwise
\r
164 static void prvMainCheckOtherTasksAreStillRunning( void );
\r
165 /*-----------------------------------------------------------*/
\r
167 /* Flag set by prvMainCheckOtherTasksAreStillExecuting(). */
\r
168 long lErrorInTask = pdFALSE;
\r
171 * Application entry point:
\r
172 * Starts all the other tasks, then starts the scheduler.
\r
176 /* Setup the hardware for use with the Olimex demo board. */
\r
177 prvSetupHardware();
\r
179 /* Start the standard flash tasks so the WEB server is not the only thing
\r
181 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
182 vStartSemaphoreTasks( tskIDLE_PRIORITY );
\r
183 vStartDynamicPriorityTasks();
\r
184 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
185 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
186 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
188 /* Start the WEB server task and the error check task. */
\r
189 xTaskCreate( vHTTPServerTask, ( signed char * ) "HTTP", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );
\r
190 xTaskCreate( prvErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainERROR_CHECK_PRIORITY, NULL );
\r
192 /* Now all the tasks have been started - start the scheduler.
\r
194 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
195 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
196 called. The demo applications included in the FreeRTOS.org download switch
\r
197 to supervisor mode prior to main being called. If you are not using one of
\r
198 these demo application projects then ensure Supervisor mode is used. */
\r
199 vTaskStartScheduler();
\r
201 /* Should never reach here! */
\r
204 /*-----------------------------------------------------------*/
\r
206 static void prvSetupHardware( void )
\r
208 #ifdef RUN_FROM_RAM
\r
209 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
213 /* Set all GPIO to output other than the P0.14 (BSL), and the JTAG pins.
\r
214 The JTAG pins are left as input as I'm not sure what will happen if the
\r
215 Wiggler is connected after powerup - not that it would be a good idea to
\r
217 GPIO_IODIR = ~( mainJTAG_PORT );
\r
219 /* Setup the PLL to multiply the XTAL input by 4. */
\r
220 SCB_PLLCFG = ( mainPLL_MUL_4 | mainPLL_DIV_1 );
\r
222 /* Activate the PLL by turning it on then feeding the correct sequence of
\r
224 SCB_PLLCON = mainPLL_ENABLE;
\r
225 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
226 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
228 /* Wait for the PLL to lock... */
\r
229 while( !( SCB_PLLSTAT & mainPLL_LOCK ) );
\r
231 /* ...before connecting it using the feed sequence again. */
\r
232 SCB_PLLCON = mainPLL_CONNECT;
\r
233 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
234 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
236 /* Setup and turn on the MAM. Three cycle access is used due to the fast
\r
237 PLL used. It is possible faster overall performance could be obtained by
\r
238 tuning the MAM and PLL settings. */
\r
239 MAM_TIM = mainMAM_TIM_3;
\r
240 MAM_CR = mainMAM_MODE_FULL;
\r
242 /* Setup the peripheral bus to be the same as the PLL output. */
\r
243 SCB_VPBDIV = mainBUS_CLK_FULL;
\r
245 /* Initialise the i2c peripheral. */
\r
248 /* Initialise the LED's used by the flash tasks. */
\r
249 vParTestInitialise();
\r
251 /*-----------------------------------------------------------*/
\r
253 static void prvMainCheckOtherTasksAreStillRunning( void )
\r
255 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
256 that they are all still running, and that none of them have detected
\r
259 /* This function is called from more than one task. */
\r
260 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
262 lErrorInTask = pdTRUE;
\r
265 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
267 lErrorInTask = pdTRUE;
\r
270 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
272 lErrorInTask = pdTRUE;
\r
275 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
277 lErrorInTask = pdTRUE;
\r
280 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
282 lErrorInTask = pdTRUE;
\r
285 /*-----------------------------------------------------------*/
\r
287 void prvToggleOnBoardLED( void )
\r
289 unsigned long ulState;
\r
291 ulState = GPIO0_IOPIN;
\r
292 if( ulState & mainON_BOARD_LED_BIT )
\r
294 GPIO_IOCLR = mainON_BOARD_LED_BIT;
\r
298 GPIO_IOSET = mainON_BOARD_LED_BIT;
\r
301 /*-----------------------------------------------------------*/
\r
303 static void prvErrorChecks( void *pvParameters )
\r
305 portTickType xDelay = mainNO_ERROR_DELAY;
\r
307 /* The parameters are not used. */
\r
308 ( void ) pvParameters;
\r
312 /* How long we delay depends on whether an error has been detected
\r
313 or not. Therefore the flash rate of the on board LED indicates
\r
314 whether or not an error has occurred. */
\r
315 vTaskDelay( xDelay );
\r
317 /* Update the lErrorInTask flag. */
\r
318 prvMainCheckOtherTasksAreStillRunning();
\r
322 /* An error has been found so reduce the delay period and in so
\r
323 doing speed up the flash rate of the on board LED. */
\r
324 xDelay = mainERROR_DELAY;
\r
327 prvToggleOnBoardLED();
\r