2 FreeRTOS V8.2.3 - Copyright (C) 2015 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 * Creates all the application tasks, then starts the scheduler.
\r
82 * A task is created called "uIP". This executes the uIP stack and small
\r
83 * WEB server sample. All the other tasks are from the set of standard
\r
84 * demo tasks. The WEB documentation provides more details of the standard
\r
85 * demo application tasks.
\r
87 * Main.c also creates a task called "Check". This only executes every three
\r
88 * seconds but has the highest priority so is guaranteed to get processor time.
\r
89 * Its main function is to check that all the other tasks are still operational.
\r
90 * Each standard demo task maintains a unique count that is incremented each
\r
91 * time the task successfully completes its function. Should any error occur
\r
92 * within such a task the count is permanently halted. The check task inspects
\r
93 * the count of each task to ensure it has changed since the last time the
\r
94 * check task executed. If all the count variables have changed all the tasks
\r
95 * are still executing error free, and the check task toggles the yellow LED.
\r
96 * Should any task contain an error at any time the LED toggle rate will change
\r
97 * from 3 seconds to 500ms.
\r
102 /* Standard includes. */
\r
103 #include <stdlib.h>
\r
104 #include <string.h>
\r
106 /* Scheduler includes. */
\r
107 #include "FreeRTOS.h"
\r
110 /* Demo application includes. */
\r
112 #include "dynamic.h"
\r
113 #include "semtest.h"
\r
115 /*-----------------------------------------------------------*/
\r
117 /* Constants to setup the PLL. */
\r
118 #define mainPLL_MUL_4 ( ( unsigned char ) 0x0003 )
\r
119 #define mainPLL_DIV_1 ( ( unsigned char ) 0x0000 )
\r
120 #define mainPLL_ENABLE ( ( unsigned char ) 0x0001 )
\r
121 #define mainPLL_CONNECT ( ( unsigned char ) 0x0003 )
\r
122 #define mainPLL_FEED_BYTE1 ( ( unsigned char ) 0xaa )
\r
123 #define mainPLL_FEED_BYTE2 ( ( unsigned char ) 0x55 )
\r
124 #define mainPLL_LOCK ( ( unsigned long ) 0x0400 )
\r
126 /* Constants to setup the MAM. */
\r
127 #define mainMAM_TIM_3 ( ( unsigned char ) 0x03 )
\r
128 #define mainMAM_MODE_FULL ( ( unsigned char ) 0x02 )
\r
130 /* Constants to setup the peripheral bus. */
\r
131 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
133 /* Priorities/stacks for the demo application tasks. */
\r
134 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
135 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
136 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
137 #define mainUIP_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
138 #define mainUIP_TASK_STACK_SIZE ( 150 )
\r
140 /* The rate at which the on board LED will toggle when there is/is not an
\r
142 #define mainNO_ERROR_FLASH_PERIOD ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
\r
143 #define mainERROR_FLASH_PERIOD ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
\r
144 #define mainON_BOARD_LED_BIT ( ( unsigned long ) 0x80 )
\r
145 #define mainYELLOW_LED ( 1 << 11 )
\r
147 /*-----------------------------------------------------------*/
\r
150 * This is the uIP task which is defined within the uip.c file. This has not
\r
151 * been placed into a header file in order to minimise the changes to the uip
\r
154 extern void ( vuIP_TASK ) ( void *pvParameters );
\r
157 * The Yellow LED is under the control of the Check task. All the other LED's
\r
158 * are under the control of the uIP task.
\r
160 void prvToggleOnBoardLED( void );
\r
163 * Checks that all the demo application tasks are still executing without error
\r
164 * - as described at the top of the file.
\r
166 static long prvCheckOtherTasksAreStillRunning( void );
\r
169 * The task that executes at the highest priority and calls
\r
170 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
173 static void vErrorChecks( void *pvParameters );
\r
176 * Configure the processor for use with the Olimex demo board. This includes
\r
177 * setup for the I/O, system clock, and access timings.
\r
179 static void prvSetupHardware( void );
\r
181 /*-----------------------------------------------------------*/
\r
184 * Starts all the other tasks, then starts the scheduler.
\r
188 /* Configure the processor. */
\r
189 prvSetupHardware();
\r
191 /* Start the task that handles the TCP/IP functionality. */
\r
192 xTaskCreate( vuIP_TASK, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );
\r
194 /* Start the demo/test application tasks. These are created in addition
\r
195 to the TCP/IP task for demonstration and test purposes. */
\r
196 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
197 vStartDynamicPriorityTasks();
\r
198 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
200 /* Start the check task - which is defined in this file. */
\r
201 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
203 /* Now all the tasks have been started - start the scheduler.
\r
205 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
206 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
207 called. The demo applications included in the FreeRTOS.org download switch
\r
208 to supervisor mode prior to main being called. If you are not using one of
\r
209 these demo application projects then ensure Supervisor mode is used here. */
\r
210 vTaskStartScheduler();
\r
212 /* Should never reach here! */
\r
215 /*-----------------------------------------------------------*/
\r
217 static void vErrorChecks( void *pvParameters )
\r
219 TickType_t xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
221 /* Cycle for ever, delaying then checking all the other tasks are still
\r
222 operating without error. If an error is detected then the delay period
\r
223 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
224 the on board LED flash rate will increase. */
\r
227 /* Delay until it is time to execute again. */
\r
228 vTaskDelay( xDelayPeriod );
\r
230 /* Check all the standard demo application tasks are executing without
\r
232 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
234 /* An error has been detected in one of the tasks - flash faster. */
\r
235 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
238 prvToggleOnBoardLED();
\r
241 /*-----------------------------------------------------------*/
\r
243 static void prvSetupHardware( void )
\r
245 #ifdef RUN_FROM_RAM
\r
246 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
250 /* Setup the PLL to multiply the XTAL input by 4. */
\r
251 SCB_PLLCFG = ( mainPLL_MUL_4 | mainPLL_DIV_1 );
\r
253 /* Activate the PLL by turning it on then feeding the correct sequence of
\r
255 SCB_PLLCON = mainPLL_ENABLE;
\r
256 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
257 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
259 /* Wait for the PLL to lock... */
\r
260 while( !( SCB_PLLSTAT & mainPLL_LOCK ) );
\r
262 /* ...before connecting it using the feed sequence again. */
\r
263 SCB_PLLCON = mainPLL_CONNECT;
\r
264 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
265 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
267 /* Setup and turn on the MAM. Three cycle access is used due to the fast
\r
268 PLL used. It is possible faster overall performance could be obtained by
\r
269 tuning the MAM and PLL settings. */
\r
270 MAM_TIM = mainMAM_TIM_3;
\r
271 MAM_CR = mainMAM_MODE_FULL;
\r
273 /* Setup the peripheral bus to be the same as the PLL output. */
\r
274 SCB_VPBDIV = mainBUS_CLK_FULL;
\r
276 /*-----------------------------------------------------------*/
\r
278 void prvToggleOnBoardLED( void )
\r
280 unsigned long ulState;
\r
282 ulState = GPIO0_IOPIN;
\r
283 if( ulState & mainYELLOW_LED )
\r
285 GPIO_IOCLR = mainYELLOW_LED;
\r
289 GPIO_IOSET = mainYELLOW_LED;
\r
292 /*-----------------------------------------------------------*/
\r
294 static long prvCheckOtherTasksAreStillRunning( void )
\r
296 long lReturn = ( long ) pdPASS;
\r
298 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
299 that they are all still running, and that none of them have detected
\r
302 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
304 lReturn = ( long ) pdFAIL;
\r
307 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
309 lReturn = ( long ) pdFAIL;
\r
312 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
314 lReturn = ( long ) pdFAIL;
\r