2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 This file is part of the FreeRTOS distribution.
9 FreeRTOS is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License (version 2) as published by the
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
13 ***************************************************************************
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
15 >>! distribute a combined work that includes FreeRTOS without being !<<
16 >>! obliged to provide the source code for proprietary components !<<
17 >>! outside of the FreeRTOS kernel. !<<
18 ***************************************************************************
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
23 link: http://www.freertos.org/a00114.html
25 ***************************************************************************
27 * FreeRTOS provides completely free yet professionally developed, *
28 * robust, strictly quality controlled, supported, and cross *
29 * platform software that is more than just the market leader, it *
30 * is the industry's de facto standard. *
32 * Help yourself get started quickly while simultaneously helping *
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
34 * tutorial book, reference manual, or both: *
35 * http://www.FreeRTOS.org/Documentation *
37 ***************************************************************************
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40 the FAQ page "My application does not run, what could be wrong?". Have you
41 defined configASSERT()?
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
44 embedded software for free we request you assist our global community by
45 participating in the support forum.
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
48 be as productive as possible as early as possible. Now you can receive
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50 Ltd, and the world's leading authority on the world's leading RTOS.
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61 licenses offer ticketed support, indemnification and commercial middleware.
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64 engineered and independently SIL3 certified version for use in safety and
65 mission critical applications that require provable dependability.
71 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
72 The processor MUST be in supervisor mode when vTaskStartScheduler is
73 called. The demo applications included in the FreeRTOS.org download switch
74 to supervisor mode prior to main being called. If you are not using one of
75 these demo application projects then ensure Supervisor mode is used.
80 * Program entry point.
82 * main() is responsible for setting up the microcontroller peripherals, then
83 * starting the demo application tasks. Once the tasks have been created the
84 * scheduler is started and main() should never complete.
86 * The demo creates the three standard 'flash' tasks to provide some visual
87 * feedback that the system and scheduler are still operating correctly.
89 * The HTTP server task operates at the highest priority so will always preempt
90 * the flash or idle task on TCP/IP events.
93 /* Standard includes. */
96 /* Scheduler include files. */
101 /* Application includes. */
103 #include "HTTP_Serv.h"
112 /*-----------------------------------------------------------*/
114 /* Constants to setup the PLL. */
115 #define mainPLL_MUL_4 ( ( unsigned char ) 0x0003 )
116 #define mainPLL_DIV_1 ( ( unsigned char ) 0x0000 )
117 #define mainPLL_ENABLE ( ( unsigned char ) 0x0001 )
118 #define mainPLL_CONNECT ( ( unsigned char ) 0x0003 )
119 #define mainPLL_FEED_BYTE1 ( ( unsigned char ) 0xaa )
120 #define mainPLL_FEED_BYTE2 ( ( unsigned char ) 0x55 )
121 #define mainPLL_LOCK ( ( unsigned long ) 0x0400 )
123 /* Constants to setup the MAM. */
124 #define mainMAM_TIM_3 ( ( unsigned char ) 0x03 )
125 #define mainMAM_MODE_FULL ( ( unsigned char ) 0x02 )
127 /* Constants to setup the peripheral bus. */
128 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
130 /* Constants to setup I/O and processor. */
131 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
132 #define mainLED_TO_OUTPUT ( ( unsigned long ) 0xff0000 )
133 #define mainJTAG_PORT ( ( unsigned long ) 0x3E0000UL )
135 /* Priorities for the demo application tasks. */
136 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
137 #define mainHTTP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
138 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
139 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
140 #define mainERROR_CHECK_PRIORITY ( tskIDLE_PRIORITY + 1 )
142 /* Flash rates of the on board LED to indicate the health of the system. */
143 #define mainNO_ERROR_DELAY ( 3000 )
144 #define mainERROR_DELAY ( 500 )
145 #define mainON_BOARD_LED_BIT ( ( unsigned long ) 0x80 )
147 /*-----------------------------------------------------------*/
150 * The Olimex demo board has a single built in LED. This function simply
153 void prvToggleOnBoardLED( void );
156 * Configure the processor for use with the Olimex demo board.
158 static void prvSetupHardware( void );
161 * Simply check for errors and toggle the onboard LED.
163 static void prvErrorChecks( void *pvParameters );
166 * Return true if the demo tasks are executing without error - otherwise
169 static void prvMainCheckOtherTasksAreStillRunning( void );
170 /*-----------------------------------------------------------*/
172 /* Flag set by prvMainCheckOtherTasksAreStillExecuting(). */
173 long lErrorInTask = pdFALSE;
176 * Application entry point:
177 * Starts all the other tasks, then starts the scheduler.
181 /* Setup the hardware for use with the Olimex demo board. */
184 /* Start the standard flash tasks so the WEB server is not the only thing
186 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
187 vStartSemaphoreTasks( tskIDLE_PRIORITY );
188 vStartDynamicPriorityTasks();
189 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
190 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
191 vStartIntegerMathTasks( tskIDLE_PRIORITY );
193 /* Start the WEB server task and the error check task. */
194 xTaskCreate( vHTTPServerTask, "HTTP", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );
195 xTaskCreate( prvErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainERROR_CHECK_PRIORITY, NULL );
197 /* Now all the tasks have been started - start the scheduler.
199 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
200 The processor MUST be in supervisor mode when vTaskStartScheduler is
201 called. The demo applications included in the FreeRTOS.org download switch
202 to supervisor mode prior to main being called. If you are not using one of
203 these demo application projects then ensure Supervisor mode is used. */
204 vTaskStartScheduler();
206 /* Should never reach here! */
209 /*-----------------------------------------------------------*/
211 static void prvSetupHardware( void )
214 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
218 /* Set all GPIO to output other than the P0.14 (BSL), and the JTAG pins.
219 The JTAG pins are left as input as I'm not sure what will happen if the
220 Wiggler is connected after powerup - not that it would be a good idea to
222 GPIO_IODIR = ~( mainJTAG_PORT );
224 /* Setup the PLL to multiply the XTAL input by 4. */
225 SCB_PLLCFG = ( mainPLL_MUL_4 | mainPLL_DIV_1 );
227 /* Activate the PLL by turning it on then feeding the correct sequence of
229 SCB_PLLCON = mainPLL_ENABLE;
230 SCB_PLLFEED = mainPLL_FEED_BYTE1;
231 SCB_PLLFEED = mainPLL_FEED_BYTE2;
233 /* Wait for the PLL to lock... */
234 while( !( SCB_PLLSTAT & mainPLL_LOCK ) );
236 /* ...before connecting it using the feed sequence again. */
237 SCB_PLLCON = mainPLL_CONNECT;
238 SCB_PLLFEED = mainPLL_FEED_BYTE1;
239 SCB_PLLFEED = mainPLL_FEED_BYTE2;
241 /* Setup and turn on the MAM. Three cycle access is used due to the fast
242 PLL used. It is possible faster overall performance could be obtained by
243 tuning the MAM and PLL settings. */
244 MAM_TIM = mainMAM_TIM_3;
245 MAM_CR = mainMAM_MODE_FULL;
247 /* Setup the peripheral bus to be the same as the PLL output. */
248 SCB_VPBDIV = mainBUS_CLK_FULL;
250 /* Initialise the i2c peripheral. */
253 /* Initialise the LED's used by the flash tasks. */
254 vParTestInitialise();
256 /*-----------------------------------------------------------*/
258 static void prvMainCheckOtherTasksAreStillRunning( void )
260 /* Check all the demo tasks (other than the flash tasks) to ensure
261 that they are all still running, and that none of them have detected
264 /* This function is called from more than one task. */
265 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
267 lErrorInTask = pdTRUE;
270 if( xArePollingQueuesStillRunning() != pdTRUE )
272 lErrorInTask = pdTRUE;
275 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
277 lErrorInTask = pdTRUE;
280 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
282 lErrorInTask = pdTRUE;
285 if( xAreBlockingQueuesStillRunning() != pdTRUE )
287 lErrorInTask = pdTRUE;
290 /*-----------------------------------------------------------*/
292 void prvToggleOnBoardLED( void )
294 unsigned long ulState;
296 ulState = GPIO0_IOPIN;
297 if( ulState & mainON_BOARD_LED_BIT )
299 GPIO_IOCLR = mainON_BOARD_LED_BIT;
303 GPIO_IOSET = mainON_BOARD_LED_BIT;
306 /*-----------------------------------------------------------*/
308 static void prvErrorChecks( void *pvParameters )
310 TickType_t xDelay = mainNO_ERROR_DELAY;
312 /* The parameters are not used. */
313 ( void ) pvParameters;
317 /* How long we delay depends on whether an error has been detected
318 or not. Therefore the flash rate of the on board LED indicates
319 whether or not an error has occurred. */
320 vTaskDelay( xDelay );
322 /* Update the lErrorInTask flag. */
323 prvMainCheckOtherTasksAreStillRunning();
327 /* An error has been found so reduce the delay period and in so
328 doing speed up the flash rate of the on board LED. */
329 xDelay = mainERROR_DELAY;
332 prvToggleOnBoardLED();