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