2 FreeRTOS V7.1.0 - 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 *******************************************************************************
\r
56 * -NOTE- The Win32 port is a simulation (or is that emulation?) only! Do not
\r
57 * expect to get real time behaviour from the Win32 port or this demo
\r
58 * application. It is provided as a convenient development and demonstration
\r
59 * test bed only. This was tested using Windows XP on a dual core laptop.
\r
61 * - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT -
\r
62 *******************************************************************************
\r
64 * main() creates all the demo application tasks, then starts the scheduler.
\r
65 * The web documentation provides more details of the standard demo application
\r
66 * tasks, which provide no particular functionality but do provide a good
\r
67 * example of how to use the FreeRTOS API.
\r
69 * In addition to the standard demo tasks, the following tasks and tests are
\r
70 * defined and/or created within this file:
\r
72 * "Check" task - This only executes every five seconds but has a high priority
\r
73 * to ensure it gets processor time. Its main function is to check that all the
\r
74 * standard demo tasks are still operational. While no errors have been
\r
75 * discovered the check task will print out "OK" and the current simulated tick
\r
76 * time. If an error is discovered in the execution of a task then the check
\r
77 * task will print out an appropriate error message.
\r
82 /* Standard includes. */
\r
85 /* Kernel includes. */
\r
86 #include <FreeRTOS.h>
\r
92 /* Standard demo includes. */
\r
94 #include "integer.h"
\r
95 #include "semtest.h"
\r
97 #include "GenQTest.h"
\r
99 #include "recmutex.h"
\r
101 #include "TimerDemo.h"
\r
102 #include "countsem.h"
\r
104 #include "dynamic.h"
\r
106 /* Priorities at which the tasks are created. */
\r
107 #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
\r
108 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
109 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
110 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
111 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
112 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
113 #define mainuIP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
114 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
115 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
116 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
118 #define mainTIMER_TEST_PERIOD ( 50 )
\r
120 /* Task function prototypes. */
\r
121 static void prvCheckTask( void *pvParameters );
\r
123 /* The variable into which error messages are latched. */
\r
124 static char *pcStatusMessage = "OK";
\r
126 /* This semaphore is created purely to test using the vSemaphoreDelete() and
\r
127 semaphore tracing API functions. It has no other purpose. */
\r
128 static xSemaphoreHandle xMutexToDelete = NULL;
\r
130 /*-----------------------------------------------------------*/
\r
134 /* Start the check task as described at the top of this file. */
\r
135 xTaskCreate( prvCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
137 /* Create the standard demo tasks. */
\r
138 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
139 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
140 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
141 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
142 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
143 vStartQueuePeekTasks();
\r
144 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
145 vStartRecursiveMutexTasks();
\r
146 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
147 vStartCountingSemaphoreTasks();
\r
148 vStartDynamicPriorityTasks();
\r
150 /* The suicide tasks must be created last as they need to know how many
\r
151 tasks were running prior to their creation. This then allows them to
\r
152 ascertain whether or not the correct/expected number of tasks are running at
\r
154 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
156 /* Create the semaphore that will be deleted in the idle task hook. This
\r
157 is done purely to test the use of vSemaphoreDelete(). */
\r
158 xMutexToDelete = xSemaphoreCreateMutex();
\r
160 /* Start the scheduler itself. */
\r
161 vTaskStartScheduler();
\r
163 /* Should never get here unless there was not enough heap space to create
\r
164 the idle and other system tasks. */
\r
167 /*-----------------------------------------------------------*/
\r
169 static void prvCheckTask( void *pvParameters )
\r
171 portTickType xNextWakeTime;
\r
172 const portTickType xCycleFrequency = 1000 / portTICK_RATE_MS;
\r
174 /* Just to remove compiler warning. */
\r
175 ( void ) pvParameters;
\r
177 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
178 xNextWakeTime = xTaskGetTickCount();
\r
182 /* Place this task in the blocked state until it is time to run again. */
\r
183 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );
\r
185 /* Check the standard demo tasks are running without error. */
\r
186 if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )
\r
188 pcStatusMessage = "Error: TimerDemo";
\r
190 else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
192 pcStatusMessage = "Error: IntMath";
\r
194 else if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
196 pcStatusMessage = "Error: GenQueue";
\r
198 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
200 pcStatusMessage = "Error: QueuePeek";
\r
202 else if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
204 pcStatusMessage = "Error: BlockQueue";
\r
206 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
208 pcStatusMessage = "Error: SemTest";
\r
210 else if( xArePollingQueuesStillRunning() != pdTRUE )
\r
212 pcStatusMessage = "Error: PollQueue";
\r
214 else if( xAreMathsTaskStillRunning() != pdPASS )
\r
216 pcStatusMessage = "Error: Flop";
\r
218 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
220 pcStatusMessage = "Error: RecMutex";
\r
222 else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
224 pcStatusMessage = "Error: CountSem";
\r
226 else if( xIsCreateTaskStillRunning() != pdTRUE )
\r
228 pcStatusMessage = "Error: Death";
\r
230 else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )
\r
232 pcStatusMessage = "Error: Dynamic\r\n";
\r
235 /* This is the only task that uses stdout so its ok to call printf()
\r
237 printf( "%s - %d\r\n", pcStatusMessage, xTaskGetTickCount() );
\r
240 /*-----------------------------------------------------------*/
\r
242 void vApplicationIdleHook( void )
\r
244 const unsigned long ulMSToSleep = 5;
\r
245 xTaskHandle xIdleTaskHandle, xTimerTaskHandle;
\r
246 signed char *pcTaskName;
\r
247 const unsigned char ucConstQueueNumber = 0xaaU, ucConstTaskNumber = 0x55U;
\r
249 /* These three functions are only meant for use by trace code, and not for
\r
250 direct use from application code, hence their prototypes are not in queue.h. */
\r
251 extern void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber );
\r
252 extern unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue );
\r
253 extern unsigned char ucQueueGetQueueType( xQueueHandle pxQueue );
\r
254 extern void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle );
\r
255 extern unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask );
\r
257 /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are
\r
258 tasks waiting to be terminated by the idle task. */
\r
259 Sleep( ulMSToSleep );
\r
261 /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and
\r
262 xTaskGetIdleTaskHandle() functions. Also try using the function that sets
\r
263 the task number. */
\r
264 xIdleTaskHandle = xTaskGetIdleTaskHandle();
\r
265 xTimerTaskHandle = xTimerGetTimerDaemonTaskHandle();
\r
266 vTaskSetTaskNumber( xIdleTaskHandle, ( unsigned long ) ucConstTaskNumber );
\r
267 configASSERT( uxTaskGetTaskNumber( xIdleTaskHandle ) == ucConstTaskNumber );
\r
269 /* This is the idle hook, so the current task handle should equal the
\r
270 returned idle task handle. */
\r
271 if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle )
\r
273 pcStatusMessage = "Error: Returned idle task handle was incorrect";
\r
276 /* Check the timer task handle was returned correctly. */
\r
277 pcTaskName = pcTaskGetTaskName( xTimerTaskHandle );
\r
278 if( strcmp( pcTaskName, "Tmr Svc" ) != 0 )
\r
280 pcStatusMessage = "Error: Returned timer task handle was incorrect";
\r
283 /* If xMutexToDelete has not already been deleted, then delete it now.
\r
284 This is done purely to demonstrate the use of, and test, the
\r
285 vSemaphoreDelete() macro. Care must be taken not to delete a semaphore
\r
286 that has tasks blocked on it. */
\r
287 if( xMutexToDelete != NULL )
\r
289 /* Before deleting the semaphore, test the function used to set its
\r
290 number. This would normally only be done from trace software, rather
\r
291 than application code. */
\r
292 vQueueSetQueueNumber( xMutexToDelete, ucConstQueueNumber );
\r
294 /* Before deleting the semaphore, test the functions used to get its
\r
295 type and number. Again, these would normally only be done from trace
\r
296 software, rather than application code. */
\r
297 configASSERT( ucQueueGetQueueNumber( xMutexToDelete ) == ucConstQueueNumber );
\r
298 configASSERT( ucQueueGetQueueType( xMutexToDelete ) == queueQUEUE_TYPE_MUTEX );
\r
299 vSemaphoreDelete( xMutexToDelete );
\r
300 xMutexToDelete = NULL;
\r
303 /*-----------------------------------------------------------*/
\r
305 void vApplicationMallocFailedHook( void )
\r
307 /* Can be implemented if required, but probably not required in this
\r
308 environment and running this demo. */
\r
310 /*-----------------------------------------------------------*/
\r
312 void vApplicationStackOverflowHook( void )
\r
314 /* Can be implemented if required, but not required in this
\r
315 environment and running this demo. */
\r
317 /*-----------------------------------------------------------*/
\r
319 void vApplicationTickHook( void )
\r
321 /* Call the periodic timer test, which tests the timer API functions that
\r
322 can be called from an ISR. */
\r
323 vTimerPeriodicISRTests();
\r
325 /*-----------------------------------------------------------*/
\r
327 void vAssertCalled( void )
\r
329 taskDISABLE_INTERRUPTS();
\r