2 FreeRTOS.org V5.4.0 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify it
\r
7 under the terms of the GNU General Public License (version 2) as published
\r
8 by the Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS.org without being obliged to provide
\r
11 the source code for any proprietary components. Alternative commercial
\r
12 license and support terms are also available upon request. See the
\r
13 licensing section of http://www.FreeRTOS.org for full details.
\r
15 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
20 You should have received a copy of the GNU General Public License along
\r
21 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
22 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
25 ***************************************************************************
\r
27 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
29 * This is a concise, step by step, 'hands on' guide that describes both *
\r
30 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
31 * explains numerous examples that are written using the FreeRTOS API. *
\r
32 * Full source code for all the examples is provided in an accompanying *
\r
35 ***************************************************************************
\r
39 Please ensure to read the configuration and relevant port sections of the
\r
40 online documentation.
\r
42 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
45 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
48 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
49 licensing and training services.
\r
54 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
55 * documentation provides more details of the standard demo application tasks
\r
56 * (which just exist to test the kernel port and provide an example of how to use
\r
57 * each FreeRTOS API function).
\r
59 * In addition to the standard demo tasks, the following tasks and tests are
\r
60 * defined and/or created within this file:
\r
62 * "Check" hook - This only executes fully every five seconds from the tick
\r
63 * hook. Its main function is to check that all the standard demo tasks are
\r
64 * still operational. The status can be viewed using on the Task Stats page
\r
65 * served by the WEB server.
\r
67 * "uIP" task - This is the task that handles the uIP stack. All TCP/IP
\r
68 * processing is performed in this task.
\r
71 /* Standard includes. */
\r
74 /* Scheduler includes. */
\r
75 #include "FreeRTOS.h"
\r
78 /* Demo app includes. */
\r
80 #include "integer.h"
\r
81 #include "blocktim.h"
\r
83 #include "partest.h"
\r
84 #include "semtest.h"
\r
86 #include "GenQTest.h"
\r
88 #include "recmutex.h"
\r
90 /* Red Suite includes. */
\r
91 #include "lcd_driver.h"
\r
94 /*-----------------------------------------------------------*/
\r
96 /* The time between cycles of the 'check' functionality (defined within the
\r
98 #define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )
\r
100 /* Task priorities. */
\r
101 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
102 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
103 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
104 #define mainUIP_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
105 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
106 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
107 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
109 /* The WEB server has a larger stack as it utilises stack hungry string
\r
110 handling library calls. */
\r
111 #define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 4 )
\r
113 /* The message displayed by the WEB server when all tasks are executing
\r
114 without an error being reported. */
\r
115 #define mainPASS_STATUS_MESSAGE "All tasks are executing without error."
\r
117 /*-----------------------------------------------------------*/
\r
120 * Configure the hardware for the demo.
\r
122 static void prvSetupHardware( void );
\r
125 * The task that handles the uIP stack. All TCP/IP processing is performed in
\r
128 extern void vuIP_Task( void *pvParameters );
\r
131 * Simply returns the current status message for display on served WEB pages.
\r
133 char *pcGetTaskStatusMessage( void );
\r
135 /*-----------------------------------------------------------*/
\r
137 /* Holds the status message displayed by the WEB server. */
\r
138 static char *pcStatusMessage = mainPASS_STATUS_MESSAGE;
\r
140 /*-----------------------------------------------------------*/
\r
144 char cIPAddress[ 16 ]; /* Enough space for "xxx.xxx.xxx.xxx\0". */
\r
146 /* Configure the hardware for use by this demo. */
\r
147 prvSetupHardware();
\r
149 /* Start the standard demo tasks. These are just here to exercise the
\r
150 kernel port and provide examples of how the FreeRTOS API can be used. */
\r
151 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
152 vCreateBlockTimeTasks();
\r
153 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
154 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
155 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
156 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
157 vStartQueuePeekTasks();
\r
158 vStartRecursiveMutexTasks();
\r
159 vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
\r
161 /* Display the IP address, then create the uIP task. The WEB server runs
\r
163 LCDdriver_initialisation();
\r
164 LCD_PrintString( 5, 10, "FreeRTOS.org", 14, COLOR_GREEN);
\r
165 sprintf( cIPAddress, "%d.%d.%d.%d", configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
\r
166 LCD_PrintString( 5, 30, cIPAddress, 14, COLOR_RED);
\r
167 xTaskCreate( vuIP_Task, ( signed char * ) "uIP", mainBASIC_WEB_STACK_SIZE, ( void * ) NULL, mainUIP_TASK_PRIORITY, NULL );
\r
169 /* Start the scheduler. */
\r
170 vTaskStartScheduler();
\r
172 /* Will only get here if there was insufficient memory to create the idle
\r
173 task. The idle task is created within vTaskStartScheduler(). */
\r
176 /*-----------------------------------------------------------*/
\r
178 void vApplicationTickHook( void )
\r
180 static unsigned portLONG ulTicksSinceLastDisplay = 0;
\r
182 /* Called from every tick interrupt as described in the comments at the top
\r
185 Have enough ticks passed to make it time to perform our health status
\r
187 ulTicksSinceLastDisplay++;
\r
188 if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
\r
190 /* Reset the counter so these checks run again in mainCHECK_DELAY
\r
192 ulTicksSinceLastDisplay = 0;
\r
194 /* Has an error been found in any task? */
\r
195 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
197 pcStatusMessage = "An error has been detected in the Generic Queue test/demo.";
\r
199 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
201 pcStatusMessage = "An error has been detected in the Peek Queue test/demo.";
\r
203 else if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
205 pcStatusMessage = "An error has been detected in the Block Queue test/demo.";
\r
207 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
209 pcStatusMessage = "An error has been detected in the Block Time test/demo.";
\r
211 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
213 pcStatusMessage = "An error has been detected in the Semaphore test/demo.";
\r
215 else if( xArePollingQueuesStillRunning() != pdTRUE )
\r
217 pcStatusMessage = "An error has been detected in the Poll Queue test/demo.";
\r
219 else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
221 pcStatusMessage = "An error has been detected in the Int Math test/demo.";
\r
223 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
225 pcStatusMessage = "An error has been detected in the Mutex test/demo.";
\r
229 /*-----------------------------------------------------------*/
\r
231 char *pcGetTaskStatusMessage( void )
\r
233 /* Not bothered about a critical section here. */
\r
234 return pcStatusMessage;
\r
236 /*-----------------------------------------------------------*/
\r
238 void prvSetupHardware( void )
\r
240 /* Disable peripherals power. */
\r
243 /* Enable GPIO power. */
\r
244 SC->PCONP = PCONP_PCGPIO;
\r
246 /* Disable TPIU. */
\r
247 PINCON->PINSEL10 = 0;
\r
249 /* Disconnect the main PLL. */
\r
250 SC->PLL0CON &= ~PLLCON_PLLC;
\r
251 SC->PLL0FEED = PLLFEED_FEED1;
\r
252 SC->PLL0FEED = PLLFEED_FEED2;
\r
253 while ((SC->PLL0STAT & PLLSTAT_PLLC) != 0);
\r
255 /* Turn off the main PLL. */
\r
256 SC->PLL0CON &= ~PLLCON_PLLE;
\r
257 SC->PLL0FEED = PLLFEED_FEED1;
\r
258 SC->PLL0FEED = PLLFEED_FEED2;
\r
259 while ((SC->PLL0STAT & PLLSTAT_PLLE) != 0);
\r
261 /* No CPU clock divider. */
\r
266 while ((SC->SCS & 0x40) == 0);
\r
268 /* Use main oscillator. */
\r
270 SC->PLL0CFG = (PLLCFG_MUL16 | PLLCFG_DIV1);
\r
272 SC->PLL0FEED = PLLFEED_FEED1;
\r
273 SC->PLL0FEED = PLLFEED_FEED2;
\r
275 /* Activate the PLL by turning it on then feeding the correct
\r
276 sequence of bytes. */
\r
277 SC->PLL0CON = PLLCON_PLLE;
\r
278 SC->PLL0FEED = PLLFEED_FEED1;
\r
279 SC->PLL0FEED = PLLFEED_FEED2;
\r
281 /* 6x CPU clock divider (64 MHz) */
\r
284 /* Wait for the PLL to lock. */
\r
285 while ((SC->PLL0STAT & PLLSTAT_PLOCK) == 0);
\r
287 /* Connect the PLL. */
\r
288 SC->PLL0CON = PLLCON_PLLC | PLLCON_PLLE;
\r
289 SC->PLL0FEED = PLLFEED_FEED1;
\r
290 SC->PLL0FEED = PLLFEED_FEED2;
\r
292 /* Setup the peripheral bus to be the same as the PLL output (64 MHz). */
\r
293 SC->PCLKSEL0 = 0x05555555;
\r
295 /* Configure the LEDs. */
\r
296 vParTestInitialise();
\r
298 /*-----------------------------------------------------------*/
\r
300 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )
\r
302 /* This function will get called if a task overflows its stack. */
\r
305 ( void ) pcTaskName;
\r
309 /*-----------------------------------------------------------*/
\r
311 void vConfigureTimerForRunTimeStats( void )
\r
313 const unsigned long TCR_COUNT_RESET = 2, CTCR_CTM_TIMER = 0x00, TCR_COUNT_ENABLE = 0x01;
\r
315 /* This function configures a timer that is used as the time base when
\r
316 collecting run time statistical information - basically the percentage
\r
317 of CPU time that each task is utilising. It is called automatically when
\r
318 the scheduler is started (assuming configGENERATE_RUN_TIME_STATS is set
\r
321 /* Power up and feed the timer. */
\r
322 SC->PCONP |= 0x02UL;
\r
323 SC->PCLKSEL0 = (SC->PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2);
\r
325 /* Reset Timer 0 */
\r
326 TIM0->TCR = TCR_COUNT_RESET;
\r
328 /* Just count up. */
\r
329 TIM0->CTCR = CTCR_CTM_TIMER;
\r
331 /* Prescale to a frequency that is good enough to get a decent resolution,
\r
332 but not too fast so as to overflow all the time. */
\r
333 TIM0->PR = ( configCPU_CLOCK_HZ / 10000UL ) - 1UL;
\r
335 /* Start the counter. */
\r
336 TIM0->TCR = TCR_COUNT_ENABLE;
\r
338 /*-----------------------------------------------------------*/
\r