2 FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
67 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
68 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
69 called. The demo applications included in the FreeRTOS.org download switch
\r
70 to supervisor mode prior to main being called. If you are not using one of
\r
71 these demo application projects then ensure Supervisor mode is used.
\r
76 * Program entry point.
\r
78 * main() is responsible for setting up the microcontroller peripherals, then
\r
79 * starting the demo application tasks. Once the tasks have been created the
\r
80 * scheduler is started and main() should never complete.
\r
82 * The demo creates the three standard 'flash' tasks to provide some visual
\r
83 * feedback that the system and scheduler are still operating correctly.
\r
85 * The HTTP server task operates at the highest priority so will always preempt
\r
86 * the flash or idle task on TCP/IP events.
\r
89 /* Standard includes. */
\r
92 /* Scheduler include files. */
\r
93 #include "FreeRTOS.h"
\r
97 /* Application includes. */
\r
99 #include "HTTP_Serv.h"
\r
101 #include "partest.h"
\r
102 #include "dynamic.h"
\r
103 #include "semtest.h"
\r
105 #include "BlockQ.h"
\r
106 #include "integer.h"
\r
108 /*-----------------------------------------------------------*/
\r
110 /* Constants to setup the PLL. */
\r
111 #define mainPLL_MUL_4 ( ( unsigned char ) 0x0003 )
\r
112 #define mainPLL_DIV_1 ( ( unsigned char ) 0x0000 )
\r
113 #define mainPLL_ENABLE ( ( unsigned char ) 0x0001 )
\r
114 #define mainPLL_CONNECT ( ( unsigned char ) 0x0003 )
\r
115 #define mainPLL_FEED_BYTE1 ( ( unsigned char ) 0xaa )
\r
116 #define mainPLL_FEED_BYTE2 ( ( unsigned char ) 0x55 )
\r
117 #define mainPLL_LOCK ( ( unsigned long ) 0x0400 )
\r
119 /* Constants to setup the MAM. */
\r
120 #define mainMAM_TIM_3 ( ( unsigned char ) 0x03 )
\r
121 #define mainMAM_MODE_FULL ( ( unsigned char ) 0x02 )
\r
123 /* Constants to setup the peripheral bus. */
\r
124 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
126 /* Constants to setup I/O and processor. */
\r
127 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
128 #define mainLED_TO_OUTPUT ( ( unsigned long ) 0xff0000 )
\r
129 #define mainJTAG_PORT ( ( unsigned long ) 0x3E0000UL )
\r
131 /* Priorities for the demo application tasks. */
\r
132 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
133 #define mainHTTP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
134 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
135 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
136 #define mainERROR_CHECK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
138 /* Flash rates of the on board LED to indicate the health of the system. */
\r
139 #define mainNO_ERROR_DELAY ( 3000 )
\r
140 #define mainERROR_DELAY ( 500 )
\r
141 #define mainON_BOARD_LED_BIT ( ( unsigned long ) 0x80 )
\r
143 /*-----------------------------------------------------------*/
\r
146 * The Olimex demo board has a single built in LED. This function simply
\r
147 * toggles its state.
\r
149 void prvToggleOnBoardLED( void );
\r
152 * Configure the processor for use with the Olimex demo board.
\r
154 static void prvSetupHardware( void );
\r
157 * Simply check for errors and toggle the onboard LED.
\r
159 static void prvErrorChecks( void *pvParameters );
\r
162 * Return true if the demo tasks are executing without error - otherwise
\r
165 static void prvMainCheckOtherTasksAreStillRunning( void );
\r
166 /*-----------------------------------------------------------*/
\r
168 /* Flag set by prvMainCheckOtherTasksAreStillExecuting(). */
\r
169 long lErrorInTask = pdFALSE;
\r
172 * Application entry point:
\r
173 * Starts all the other tasks, then starts the scheduler.
\r
177 /* Setup the hardware for use with the Olimex demo board. */
\r
178 prvSetupHardware();
\r
180 /* Start the standard flash tasks so the WEB server is not the only thing
\r
182 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
183 vStartSemaphoreTasks( tskIDLE_PRIORITY );
\r
184 vStartDynamicPriorityTasks();
\r
185 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
186 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
187 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
189 /* Start the WEB server task and the error check task. */
\r
190 xTaskCreate( vHTTPServerTask, ( signed char * ) "HTTP", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );
\r
191 xTaskCreate( prvErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainERROR_CHECK_PRIORITY, NULL );
\r
193 /* Now all the tasks have been started - start the scheduler.
\r
195 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
196 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
197 called. The demo applications included in the FreeRTOS.org download switch
\r
198 to supervisor mode prior to main being called. If you are not using one of
\r
199 these demo application projects then ensure Supervisor mode is used. */
\r
200 vTaskStartScheduler();
\r
202 /* Should never reach here! */
\r
205 /*-----------------------------------------------------------*/
\r
207 static void prvSetupHardware( void )
\r
209 #ifdef RUN_FROM_RAM
\r
210 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
214 /* Set all GPIO to output other than the P0.14 (BSL), and the JTAG pins.
\r
215 The JTAG pins are left as input as I'm not sure what will happen if the
\r
216 Wiggler is connected after powerup - not that it would be a good idea to
\r
218 GPIO_IODIR = ~( mainJTAG_PORT );
\r
220 /* Setup the PLL to multiply the XTAL input by 4. */
\r
221 SCB_PLLCFG = ( mainPLL_MUL_4 | mainPLL_DIV_1 );
\r
223 /* Activate the PLL by turning it on then feeding the correct sequence of
\r
225 SCB_PLLCON = mainPLL_ENABLE;
\r
226 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
227 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
229 /* Wait for the PLL to lock... */
\r
230 while( !( SCB_PLLSTAT & mainPLL_LOCK ) );
\r
232 /* ...before connecting it using the feed sequence again. */
\r
233 SCB_PLLCON = mainPLL_CONNECT;
\r
234 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
235 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
237 /* Setup and turn on the MAM. Three cycle access is used due to the fast
\r
238 PLL used. It is possible faster overall performance could be obtained by
\r
239 tuning the MAM and PLL settings. */
\r
240 MAM_TIM = mainMAM_TIM_3;
\r
241 MAM_CR = mainMAM_MODE_FULL;
\r
243 /* Setup the peripheral bus to be the same as the PLL output. */
\r
244 SCB_VPBDIV = mainBUS_CLK_FULL;
\r
246 /* Initialise the i2c peripheral. */
\r
249 /* Initialise the LED's used by the flash tasks. */
\r
250 vParTestInitialise();
\r
252 /*-----------------------------------------------------------*/
\r
254 static void prvMainCheckOtherTasksAreStillRunning( void )
\r
256 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
257 that they are all still running, and that none of them have detected
\r
260 /* This function is called from more than one task. */
\r
261 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
263 lErrorInTask = pdTRUE;
\r
266 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
268 lErrorInTask = pdTRUE;
\r
271 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
273 lErrorInTask = pdTRUE;
\r
276 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
278 lErrorInTask = pdTRUE;
\r
281 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
283 lErrorInTask = pdTRUE;
\r
286 /*-----------------------------------------------------------*/
\r
288 void prvToggleOnBoardLED( void )
\r
290 unsigned long ulState;
\r
292 ulState = GPIO0_IOPIN;
\r
293 if( ulState & mainON_BOARD_LED_BIT )
\r
295 GPIO_IOCLR = mainON_BOARD_LED_BIT;
\r
299 GPIO_IOSET = mainON_BOARD_LED_BIT;
\r
302 /*-----------------------------------------------------------*/
\r
304 static void prvErrorChecks( void *pvParameters )
\r
306 portTickType xDelay = mainNO_ERROR_DELAY;
\r
308 /* The parameters are not used. */
\r
309 ( void ) pvParameters;
\r
313 /* How long we delay depends on whether an error has been detected
\r
314 or not. Therefore the flash rate of the on board LED indicates
\r
315 whether or not an error has occurred. */
\r
316 vTaskDelay( xDelay );
\r
318 /* Update the lErrorInTask flag. */
\r
319 prvMainCheckOtherTasksAreStillRunning();
\r
323 /* An error has been found so reduce the delay period and in so
\r
324 doing speed up the flash rate of the on board LED. */
\r
325 xDelay = mainERROR_DELAY;
\r
328 prvToggleOnBoardLED();
\r