2 FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
68 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
69 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
70 called. The demo applications included in the FreeRTOS.org download switch
\r
71 to supervisor mode prior to main being called. If you are not using one of
\r
72 these demo application projects then ensure Supervisor mode is used.
\r
77 * Program entry point.
\r
79 * main() is responsible for setting up the microcontroller peripherals, then
\r
80 * starting the demo application tasks. Once the tasks have been created the
\r
81 * scheduler is started and main() should never complete.
\r
83 * The demo creates the three standard 'flash' tasks to provide some visual
\r
84 * feedback that the system and scheduler are still operating correctly.
\r
86 * The HTTP server task operates at the highest priority so will always preempt
\r
87 * the flash or idle task on TCP/IP events.
\r
90 /* Standard includes. */
\r
93 /* Scheduler include files. */
\r
94 #include "FreeRTOS.h"
\r
98 /* Application includes. */
\r
100 #include "HTTP_Serv.h"
\r
102 #include "partest.h"
\r
103 #include "dynamic.h"
\r
104 #include "semtest.h"
\r
106 #include "BlockQ.h"
\r
107 #include "integer.h"
\r
109 /*-----------------------------------------------------------*/
\r
111 /* Constants to setup the PLL. */
\r
112 #define mainPLL_MUL_4 ( ( unsigned char ) 0x0003 )
\r
113 #define mainPLL_DIV_1 ( ( unsigned char ) 0x0000 )
\r
114 #define mainPLL_ENABLE ( ( unsigned char ) 0x0001 )
\r
115 #define mainPLL_CONNECT ( ( unsigned char ) 0x0003 )
\r
116 #define mainPLL_FEED_BYTE1 ( ( unsigned char ) 0xaa )
\r
117 #define mainPLL_FEED_BYTE2 ( ( unsigned char ) 0x55 )
\r
118 #define mainPLL_LOCK ( ( unsigned long ) 0x0400 )
\r
120 /* Constants to setup the MAM. */
\r
121 #define mainMAM_TIM_3 ( ( unsigned char ) 0x03 )
\r
122 #define mainMAM_MODE_FULL ( ( unsigned char ) 0x02 )
\r
124 /* Constants to setup the peripheral bus. */
\r
125 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
127 /* Constants to setup I/O and processor. */
\r
128 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
129 #define mainLED_TO_OUTPUT ( ( unsigned long ) 0xff0000 )
\r
130 #define mainJTAG_PORT ( ( unsigned long ) 0x3E0000UL )
\r
132 /* Priorities for the demo application tasks. */
\r
133 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
134 #define mainHTTP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
135 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
136 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
137 #define mainERROR_CHECK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
139 /* Flash rates of the on board LED to indicate the health of the system. */
\r
140 #define mainNO_ERROR_DELAY ( 3000 )
\r
141 #define mainERROR_DELAY ( 500 )
\r
142 #define mainON_BOARD_LED_BIT ( ( unsigned long ) 0x80 )
\r
144 /*-----------------------------------------------------------*/
\r
147 * The Olimex demo board has a single built in LED. This function simply
\r
148 * toggles its state.
\r
150 void prvToggleOnBoardLED( void );
\r
153 * Configure the processor for use with the Olimex demo board.
\r
155 static void prvSetupHardware( void );
\r
158 * Simply check for errors and toggle the onboard LED.
\r
160 static void prvErrorChecks( void *pvParameters );
\r
163 * Return true if the demo tasks are executing without error - otherwise
\r
166 static void prvMainCheckOtherTasksAreStillRunning( void );
\r
167 /*-----------------------------------------------------------*/
\r
169 /* Flag set by prvMainCheckOtherTasksAreStillExecuting(). */
\r
170 long lErrorInTask = pdFALSE;
\r
173 * Application entry point:
\r
174 * Starts all the other tasks, then starts the scheduler.
\r
178 /* Setup the hardware for use with the Olimex demo board. */
\r
179 prvSetupHardware();
\r
181 /* Start the standard flash tasks so the WEB server is not the only thing
\r
183 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
184 vStartSemaphoreTasks( tskIDLE_PRIORITY );
\r
185 vStartDynamicPriorityTasks();
\r
186 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
187 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
188 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
190 /* Start the WEB server task and the error check task. */
\r
191 xTaskCreate( vHTTPServerTask, ( signed char * ) "HTTP", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );
\r
192 xTaskCreate( prvErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainERROR_CHECK_PRIORITY, NULL );
\r
194 /* Now all the tasks have been started - start the scheduler.
\r
196 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
197 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
198 called. The demo applications included in the FreeRTOS.org download switch
\r
199 to supervisor mode prior to main being called. If you are not using one of
\r
200 these demo application projects then ensure Supervisor mode is used. */
\r
201 vTaskStartScheduler();
\r
203 /* Should never reach here! */
\r
206 /*-----------------------------------------------------------*/
\r
208 static void prvSetupHardware( void )
\r
210 #ifdef RUN_FROM_RAM
\r
211 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
215 /* Set all GPIO to output other than the P0.14 (BSL), and the JTAG pins.
\r
216 The JTAG pins are left as input as I'm not sure what will happen if the
\r
217 Wiggler is connected after powerup - not that it would be a good idea to
\r
219 GPIO_IODIR = ~( mainJTAG_PORT );
\r
221 /* Setup the PLL to multiply the XTAL input by 4. */
\r
222 SCB_PLLCFG = ( mainPLL_MUL_4 | mainPLL_DIV_1 );
\r
224 /* Activate the PLL by turning it on then feeding the correct sequence of
\r
226 SCB_PLLCON = mainPLL_ENABLE;
\r
227 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
228 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
230 /* Wait for the PLL to lock... */
\r
231 while( !( SCB_PLLSTAT & mainPLL_LOCK ) );
\r
233 /* ...before connecting it using the feed sequence again. */
\r
234 SCB_PLLCON = mainPLL_CONNECT;
\r
235 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
236 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
238 /* Setup and turn on the MAM. Three cycle access is used due to the fast
\r
239 PLL used. It is possible faster overall performance could be obtained by
\r
240 tuning the MAM and PLL settings. */
\r
241 MAM_TIM = mainMAM_TIM_3;
\r
242 MAM_CR = mainMAM_MODE_FULL;
\r
244 /* Setup the peripheral bus to be the same as the PLL output. */
\r
245 SCB_VPBDIV = mainBUS_CLK_FULL;
\r
247 /* Initialise the i2c peripheral. */
\r
250 /* Initialise the LED's used by the flash tasks. */
\r
251 vParTestInitialise();
\r
253 /*-----------------------------------------------------------*/
\r
255 static void prvMainCheckOtherTasksAreStillRunning( void )
\r
257 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
258 that they are all still running, and that none of them have detected
\r
261 /* This function is called from more than one task. */
\r
262 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
264 lErrorInTask = pdTRUE;
\r
267 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
269 lErrorInTask = pdTRUE;
\r
272 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
274 lErrorInTask = pdTRUE;
\r
277 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
279 lErrorInTask = pdTRUE;
\r
282 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
284 lErrorInTask = pdTRUE;
\r
287 /*-----------------------------------------------------------*/
\r
289 void prvToggleOnBoardLED( void )
\r
291 unsigned long ulState;
\r
293 ulState = GPIO0_IOPIN;
\r
294 if( ulState & mainON_BOARD_LED_BIT )
\r
296 GPIO_IOCLR = mainON_BOARD_LED_BIT;
\r
300 GPIO_IOSET = mainON_BOARD_LED_BIT;
\r
303 /*-----------------------------------------------------------*/
\r
305 static void prvErrorChecks( void *pvParameters )
\r
307 portTickType xDelay = mainNO_ERROR_DELAY;
\r
309 /* The parameters are not used. */
\r
310 ( void ) pvParameters;
\r
314 /* How long we delay depends on whether an error has been detected
\r
315 or not. Therefore the flash rate of the on board LED indicates
\r
316 whether or not an error has occurred. */
\r
317 vTaskDelay( xDelay );
\r
319 /* Update the lErrorInTask flag. */
\r
320 prvMainCheckOtherTasksAreStillRunning();
\r
324 /* An error has been found so reduce the delay period and in so
\r
325 doing speed up the flash rate of the on board LED. */
\r
326 xDelay = mainERROR_DELAY;
\r
329 prvToggleOnBoardLED();
\r