2 FreeRTOS V7.0.1 - Copyright (C) 2011 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 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
55 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
56 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
57 called. The demo applications included in the FreeRTOS.org download switch
\r
58 to supervisor mode prior to main being called. If you are not using one of
\r
59 these demo application projects then ensure Supervisor mode is used.
\r
64 * Creates all the application tasks, then starts the scheduler.
\r
66 * A task is created called "uIP". This executes the uIP stack and small
\r
67 * WEB server sample. All the other tasks are from the set of standard
\r
68 * demo tasks. The WEB documentation provides more details of the standard
\r
69 * demo application tasks.
\r
71 * Main.c also creates a task called "Check". This only executes every three
\r
72 * seconds but has the highest priority so is guaranteed to get processor time.
\r
73 * Its main function is to check that all the other tasks are still operational.
\r
74 * Each standard demo task maintains a unique count that is incremented each
\r
75 * time the task successfully completes its function. Should any error occur
\r
76 * within such a task the count is permanently halted. The check task inspects
\r
77 * the count of each task to ensure it has changed since the last time the
\r
78 * check task executed. If all the count variables have changed all the tasks
\r
79 * are still executing error free, and the check task toggles the yellow LED.
\r
80 * Should any task contain an error at any time the LED toggle rate will change
\r
81 * from 3 seconds to 500ms.
\r
86 /* Standard includes. */
\r
90 /* Scheduler includes. */
\r
91 #include "FreeRTOS.h"
\r
94 /* Demo application includes. */
\r
96 #include "dynamic.h"
\r
97 #include "semtest.h"
\r
99 /*-----------------------------------------------------------*/
\r
101 /* Constants to setup the PLL. */
\r
102 #define mainPLL_MUL_4 ( ( unsigned char ) 0x0003 )
\r
103 #define mainPLL_DIV_1 ( ( unsigned char ) 0x0000 )
\r
104 #define mainPLL_ENABLE ( ( unsigned char ) 0x0001 )
\r
105 #define mainPLL_CONNECT ( ( unsigned char ) 0x0003 )
\r
106 #define mainPLL_FEED_BYTE1 ( ( unsigned char ) 0xaa )
\r
107 #define mainPLL_FEED_BYTE2 ( ( unsigned char ) 0x55 )
\r
108 #define mainPLL_LOCK ( ( unsigned long ) 0x0400 )
\r
110 /* Constants to setup the MAM. */
\r
111 #define mainMAM_TIM_3 ( ( unsigned char ) 0x03 )
\r
112 #define mainMAM_MODE_FULL ( ( unsigned char ) 0x02 )
\r
114 /* Constants to setup the peripheral bus. */
\r
115 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
117 /* Priorities/stacks for the demo application tasks. */
\r
118 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
119 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
120 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
121 #define mainUIP_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
122 #define mainUIP_TASK_STACK_SIZE ( 150 )
\r
124 /* The rate at which the on board LED will toggle when there is/is not an
\r
126 #define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
127 #define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
128 #define mainON_BOARD_LED_BIT ( ( unsigned long ) 0x80 )
\r
129 #define mainYELLOW_LED ( 1 << 11 )
\r
131 /*-----------------------------------------------------------*/
\r
134 * This is the uIP task which is defined within the uip.c file. This has not
\r
135 * been placed into a header file in order to minimise the changes to the uip
\r
138 extern void ( vuIP_TASK ) ( void *pvParameters );
\r
141 * The Yellow LED is under the control of the Check task. All the other LED's
\r
142 * are under the control of the uIP task.
\r
144 void prvToggleOnBoardLED( void );
\r
147 * Checks that all the demo application tasks are still executing without error
\r
148 * - as described at the top of the file.
\r
150 static long prvCheckOtherTasksAreStillRunning( void );
\r
153 * The task that executes at the highest priority and calls
\r
154 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
157 static void vErrorChecks( void *pvParameters );
\r
160 * Configure the processor for use with the Olimex demo board. This includes
\r
161 * setup for the I/O, system clock, and access timings.
\r
163 static void prvSetupHardware( void );
\r
165 /*-----------------------------------------------------------*/
\r
168 * Starts all the other tasks, then starts the scheduler.
\r
172 /* Configure the processor. */
\r
173 prvSetupHardware();
\r
175 /* Start the task that handles the TCP/IP functionality. */
\r
176 xTaskCreate( vuIP_TASK, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );
\r
178 /* Start the demo/test application tasks. These are created in addition
\r
179 to the TCP/IP task for demonstration and test purposes. */
\r
180 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
181 vStartDynamicPriorityTasks();
\r
182 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
184 /* Start the check task - which is defined in this file. */
\r
185 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
187 /* Now all the tasks have been started - start the scheduler.
\r
189 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
190 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
191 called. The demo applications included in the FreeRTOS.org download switch
\r
192 to supervisor mode prior to main being called. If you are not using one of
\r
193 these demo application projects then ensure Supervisor mode is used here. */
\r
194 vTaskStartScheduler();
\r
196 /* Should never reach here! */
\r
199 /*-----------------------------------------------------------*/
\r
201 static void vErrorChecks( void *pvParameters )
\r
203 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
205 /* Cycle for ever, delaying then checking all the other tasks are still
\r
206 operating without error. If an error is detected then the delay period
\r
207 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
208 the on board LED flash rate will increase. */
\r
211 /* Delay until it is time to execute again. */
\r
212 vTaskDelay( xDelayPeriod );
\r
214 /* Check all the standard demo application tasks are executing without
\r
216 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
218 /* An error has been detected in one of the tasks - flash faster. */
\r
219 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
222 prvToggleOnBoardLED();
\r
225 /*-----------------------------------------------------------*/
\r
227 static void prvSetupHardware( void )
\r
229 #ifdef RUN_FROM_RAM
\r
230 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
234 /* Setup the PLL to multiply the XTAL input by 4. */
\r
235 SCB_PLLCFG = ( mainPLL_MUL_4 | mainPLL_DIV_1 );
\r
237 /* Activate the PLL by turning it on then feeding the correct sequence of
\r
239 SCB_PLLCON = mainPLL_ENABLE;
\r
240 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
241 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
243 /* Wait for the PLL to lock... */
\r
244 while( !( SCB_PLLSTAT & mainPLL_LOCK ) );
\r
246 /* ...before connecting it using the feed sequence again. */
\r
247 SCB_PLLCON = mainPLL_CONNECT;
\r
248 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
249 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
251 /* Setup and turn on the MAM. Three cycle access is used due to the fast
\r
252 PLL used. It is possible faster overall performance could be obtained by
\r
253 tuning the MAM and PLL settings. */
\r
254 MAM_TIM = mainMAM_TIM_3;
\r
255 MAM_CR = mainMAM_MODE_FULL;
\r
257 /* Setup the peripheral bus to be the same as the PLL output. */
\r
258 SCB_VPBDIV = mainBUS_CLK_FULL;
\r
260 /*-----------------------------------------------------------*/
\r
262 void prvToggleOnBoardLED( void )
\r
264 unsigned long ulState;
\r
266 ulState = GPIO0_IOPIN;
\r
267 if( ulState & mainYELLOW_LED )
\r
269 GPIO_IOCLR = mainYELLOW_LED;
\r
273 GPIO_IOSET = mainYELLOW_LED;
\r
276 /*-----------------------------------------------------------*/
\r
278 static long prvCheckOtherTasksAreStillRunning( void )
\r
280 long lReturn = ( long ) pdPASS;
\r
282 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
283 that they are all still running, and that none of them have detected
\r
286 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
288 lReturn = ( long ) pdFAIL;
\r
291 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
293 lReturn = ( long ) pdFAIL;
\r
296 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
298 lReturn = ( long ) pdFAIL;
\r