]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/WIN32-MSVC/main_full.c
db89451a4670b28c49bc58ae226fb5b08522a51a
[freertos] / FreeRTOS / Demo / WIN32-MSVC / main_full.c
1 /*\r
2     FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \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
12 \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
19 \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
24 \r
25     ***************************************************************************\r
26      *                                                                       *\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
31      *                                                                       *\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
36      *                                                                       *\r
37     ***************************************************************************\r
38 \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
42 \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
46 \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
51 \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
55 \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
58 \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
62 \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
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /*\r
71  *******************************************************************************\r
72  * NOTE 1: The Win32 port is a simulation (or is that emulation?) only!  Do not\r
73  * expect to get real time behaviour from the Win32 port or this demo\r
74  * application.  It is provided as a convenient development and demonstration\r
75  * test bed only.  This was tested using Windows XP on a dual core laptop.\r
76  *\r
77  * Windows will not be running the FreeRTOS simulator threads continuously, so\r
78  * the timing information in the FreeRTOS+Trace logs have no meaningful units.\r
79  * See the documentation page for the Windows simulator for an explanation of\r
80  * the slow timing:\r
81  * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html\r
82  * - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT -\r
83  *\r
84  * NOTE 2:  This project provides two demo applications.  A simple blinky style\r
85  * project, and a more comprehensive test and demo application.  The\r
86  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
87  * between the two.  See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
88  * in main.c.  This file implements the comprehensive test and demo version.\r
89  *\r
90  * NOTE 3:  This file only contains the source code that is specific to the\r
91  * basic demo.  Generic functions, such FreeRTOS hook functions, are defined in\r
92  * main.c.\r
93  *******************************************************************************\r
94  *\r
95  * main() creates all the demo application tasks, then starts the scheduler.\r
96  * The web documentation provides more details of the standard demo application\r
97  * tasks, which provide no particular functionality but do provide a good\r
98  * example of how to use the FreeRTOS API.\r
99  *\r
100  * In addition to the standard demo tasks, the following tasks and tests are\r
101  * defined and/or created within this file:\r
102  *\r
103  * "Check" task - This only executes every five seconds but has a high priority\r
104  * to ensure it gets processor time.  Its main function is to check that all the\r
105  * standard demo tasks are still operational.  While no errors have been\r
106  * discovered the check task will print out "OK" and the current simulated tick\r
107  * time.  If an error is discovered in the execution of a task then the check\r
108  * task will print out an appropriate error message.\r
109  *\r
110  */\r
111 \r
112 \r
113 /* Standard includes. */\r
114 #include <stdio.h>\r
115 #include <stdlib.h>\r
116 \r
117 /* Kernel includes. */\r
118 #include <FreeRTOS.h>\r
119 #include <task.h>\r
120 #include <queue.h>\r
121 #include <timers.h>\r
122 #include <semphr.h>\r
123 \r
124 /* Standard demo includes. */\r
125 #include "BlockQ.h"\r
126 #include "integer.h"\r
127 #include "semtest.h"\r
128 #include "PollQ.h"\r
129 #include "GenQTest.h"\r
130 #include "QPeek.h"\r
131 #include "recmutex.h"\r
132 #include "flop.h"\r
133 #include "TimerDemo.h"\r
134 #include "countsem.h"\r
135 #include "death.h"\r
136 #include "dynamic.h"\r
137 #include "QueueSet.h"\r
138 #include "QueueOverwrite.h"\r
139 #include "EventGroupsDemo.h"\r
140 #include "IntSemTest.h"\r
141 #include "TaskNotify.h"\r
142 #include "QueueSetPolling.h"\r
143 \r
144 /* Priorities at which the tasks are created. */\r
145 #define mainCHECK_TASK_PRIORITY                 ( configMAX_PRIORITIES - 2 )\r
146 #define mainQUEUE_POLL_PRIORITY                 ( tskIDLE_PRIORITY + 1 )\r
147 #define mainSEM_TEST_PRIORITY                   ( tskIDLE_PRIORITY + 1 )\r
148 #define mainBLOCK_Q_PRIORITY                    ( tskIDLE_PRIORITY + 2 )\r
149 #define mainCREATOR_TASK_PRIORITY               ( tskIDLE_PRIORITY + 3 )\r
150 #define mainFLASH_TASK_PRIORITY                 ( tskIDLE_PRIORITY + 1 )\r
151 #define mainINTEGER_TASK_PRIORITY               ( tskIDLE_PRIORITY )\r
152 #define mainGEN_QUEUE_TASK_PRIORITY             ( tskIDLE_PRIORITY )\r
153 #define mainFLOP_TASK_PRIORITY                  ( tskIDLE_PRIORITY )\r
154 #define mainQUEUE_OVERWRITE_PRIORITY    ( tskIDLE_PRIORITY )\r
155 \r
156 #define mainTIMER_TEST_PERIOD                   ( 50 )\r
157 \r
158 /* Task function prototypes. */\r
159 static void prvCheckTask( void *pvParameters );\r
160 \r
161 /* A task that is created from the idle task to test the functionality of\r
162 eTaskStateGet(). */\r
163 static void prvTestTask( void *pvParameters );\r
164 \r
165 /*\r
166  * Called from the idle task hook function to demonstrate a few utility\r
167  * functions that are not demonstrated by any of the standard demo tasks.\r
168  */\r
169 static void prvDemonstrateTaskStateAndHandleGetFunctions( void );\r
170 \r
171 /*\r
172  * Called from the idle task hook function to demonstrate the use of\r
173  * xTimerPendFunctionCall() as xTimerPendFunctionCall() is not demonstrated by\r
174  * any of the standard demo tasks.\r
175  */\r
176 static void prvDemonstratePendingFunctionCall( void );\r
177 \r
178 /*\r
179  * The function that is pended by prvDemonstratePendingFunctionCall().\r
180  */\r
181 static void prvPendedFunction( void *pvParameter1, uint32_t ulParameter2 );\r
182 \r
183 /*\r
184  * A task to demonstrate the use of the xQueueSpacesAvailable() function.\r
185  */\r
186 static void prvDemoQueueSpaceFunctions( void *pvParameters );\r
187 \r
188 /*-----------------------------------------------------------*/\r
189 \r
190 /* The variable into which error messages are latched. */\r
191 static char *pcStatusMessage = "OK";\r
192 \r
193 /* This semaphore is created purely to test using the vSemaphoreDelete() and\r
194 semaphore tracing API functions.  It has no other purpose. */\r
195 static SemaphoreHandle_t xMutexToDelete = NULL;\r
196 \r
197 /*-----------------------------------------------------------*/\r
198 \r
199 int main_full( void )\r
200 {\r
201         /* Start the check task as described at the top of this file. */\r
202         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
203 \r
204         /* Create the standard demo tasks. */\r
205         vStartTaskNotifyTask();\r
206         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
207         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
208         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
209         vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
210         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
211         vStartQueuePeekTasks();\r
212         vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
213         vStartRecursiveMutexTasks();\r
214         vStartCountingSemaphoreTasks();\r
215         vStartDynamicPriorityTasks();\r
216         vStartQueueSetTasks();\r
217         vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY );\r
218         vStartEventGroupTasks();\r
219         vStartInterruptSemaphoreTasks();\r
220         vStartQueueSetPollingTask();\r
221         xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
222 \r
223         #if( configUSE_PREEMPTION != 0  )\r
224         {\r
225                 /* Don't expect these tasks to pass when preemption is not used. */\r
226                 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
227         }\r
228         #endif\r
229 \r
230         /* The suicide tasks must be created last as they need to know how many\r
231         tasks were running prior to their creation.  This then allows them to\r
232         ascertain whether or not the correct/expected number of tasks are running at\r
233         any given time. */\r
234         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
235 \r
236         /* Create the semaphore that will be deleted in the idle task hook.  This\r
237         is done purely to test the use of vSemaphoreDelete(). */\r
238         xMutexToDelete = xSemaphoreCreateMutex();\r
239 \r
240         /* Start the scheduler itself. */\r
241         vTaskStartScheduler();\r
242 \r
243     /* Should never get here unless there was not enough heap space to create\r
244         the idle and other system tasks. */\r
245     return 0;\r
246 }\r
247 /*-----------------------------------------------------------*/\r
248 \r
249 static void prvCheckTask( void *pvParameters )\r
250 {\r
251 TickType_t xNextWakeTime;\r
252 const TickType_t xCycleFrequency = 2500 / portTICK_PERIOD_MS;\r
253 \r
254         /* Just to remove compiler warning. */\r
255         ( void ) pvParameters;\r
256 \r
257         /* Initialise xNextWakeTime - this only needs to be done once. */\r
258         xNextWakeTime = xTaskGetTickCount();\r
259 \r
260         for( ;; )\r
261         {\r
262                 /* Place this task in the blocked state until it is time to run again. */\r
263                 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );\r
264 \r
265                 /* Check the standard demo tasks are running without error. */\r
266                 #if( configUSE_PREEMPTION != 0 )\r
267                 {\r
268                         /* These tasks are only created when preemption is used. */\r
269                         if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )\r
270                         {\r
271                                 pcStatusMessage = "Error: TimerDemo";\r
272                         }\r
273                 }\r
274                 #endif\r
275 \r
276                 if( xAreTaskNotificationTasksStillRunning() != pdTRUE )\r
277                 {\r
278                         pcStatusMessage = "Error:  Notification";\r
279                 }\r
280 \r
281                 if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )\r
282                 {\r
283                         pcStatusMessage = "Error: IntSem";\r
284                 }\r
285                 else if( xAreEventGroupTasksStillRunning() != pdTRUE )\r
286                 {\r
287                         pcStatusMessage = "Error: EventGroup";\r
288                 }\r
289             else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
290             {\r
291                         pcStatusMessage = "Error: IntMath";\r
292             }\r
293                 else if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
294                 {\r
295                         pcStatusMessage = "Error: GenQueue";\r
296                 }\r
297                 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
298                 {\r
299                         pcStatusMessage = "Error: QueuePeek";\r
300                 }\r
301                 else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
302                 {\r
303                         pcStatusMessage = "Error: BlockQueue";\r
304                 }\r
305             else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
306             {\r
307                         pcStatusMessage = "Error: SemTest";\r
308             }\r
309             else if( xArePollingQueuesStillRunning() != pdTRUE )\r
310             {\r
311                         pcStatusMessage = "Error: PollQueue";\r
312             }\r
313                 else if( xAreMathsTaskStillRunning() != pdPASS )\r
314                 {\r
315                         pcStatusMessage = "Error: Flop";\r
316                 }\r
317             else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
318             {\r
319                         pcStatusMessage = "Error: RecMutex";\r
320                 }\r
321                 else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
322                 {\r
323                         pcStatusMessage = "Error: CountSem";\r
324                 }\r
325                 else if( xIsCreateTaskStillRunning() != pdTRUE )\r
326                 {\r
327                         pcStatusMessage = "Error: Death";\r
328                 }\r
329                 else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )\r
330                 {\r
331                         pcStatusMessage = "Error: Dynamic";\r
332                 }\r
333                 else if( xAreQueueSetTasksStillRunning() != pdPASS )\r
334                 {\r
335                         pcStatusMessage = "Error: Queue set";\r
336                 }\r
337                 else if( xIsQueueOverwriteTaskStillRunning() != pdPASS )\r
338                 {\r
339                         pcStatusMessage = "Error: Queue overwrite";\r
340                 }\r
341                 else if( xAreQueueSetPollTasksStillRunning() != pdPASS )\r
342                 {\r
343                         pcStatusMessage = "Error: Queue set polling";\r
344                 }\r
345 \r
346                 /* This is the only task that uses stdout so its ok to call printf()\r
347                 directly. */\r
348                 printf( "%s - %d\r\n", pcStatusMessage, xTaskGetTickCount() );\r
349         }\r
350 }\r
351 /*-----------------------------------------------------------*/\r
352 \r
353 static void prvTestTask( void *pvParameters )\r
354 {\r
355 const unsigned long ulMSToSleep = 5;\r
356 \r
357         /* Just to remove compiler warnings. */\r
358         ( void ) pvParameters;\r
359 \r
360         /* This task is just used to test the eTaskStateGet() function.  It\r
361         does not have anything to do. */\r
362         for( ;; )\r
363         {\r
364                 /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are\r
365                 tasks waiting to be terminated by the idle task. */\r
366                 Sleep( ulMSToSleep );\r
367         }\r
368 }\r
369 /*-----------------------------------------------------------*/\r
370 \r
371 /* Called from vApplicationIdleHook(), which is defined in main.c. */\r
372 void vFullDemoIdleFunction( void )\r
373 {\r
374 const unsigned long ulMSToSleep = 15;\r
375 void *pvAllocated;\r
376 \r
377         /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are\r
378         tasks waiting to be terminated by the idle task. */\r
379         Sleep( ulMSToSleep );\r
380 \r
381         /* Demonstrate a few utility functions that are not demonstrated by any of\r
382         the standard demo tasks. */\r
383         prvDemonstrateTaskStateAndHandleGetFunctions();\r
384 \r
385         /* Demonstrate the use of xTimerPendFunctionCall(), which is not\r
386         demonstrated by any of the standard demo tasks. */\r
387         prvDemonstratePendingFunctionCall();\r
388 \r
389         /* If xMutexToDelete has not already been deleted, then delete it now.\r
390         This is done purely to demonstrate the use of, and test, the\r
391         vSemaphoreDelete() macro.  Care must be taken not to delete a semaphore\r
392         that has tasks blocked on it. */\r
393         if( xMutexToDelete != NULL )\r
394         {\r
395                 vSemaphoreDelete( xMutexToDelete );\r
396                 xMutexToDelete = NULL;\r
397         }\r
398 \r
399         /* Exercise heap_5 a bit.  The malloc failed hook will trap failed\r
400         allocations so there is no need to test here. */\r
401         pvAllocated = pvPortMalloc( ( rand() % 100 ) + 1 );\r
402         vPortFree( pvAllocated );\r
403 }\r
404 /*-----------------------------------------------------------*/\r
405 \r
406 /* Called by vApplicationTickHook(), which is defined in main.c. */\r
407 void vFullDemoTickHookFunction( void )\r
408 {\r
409 TaskHandle_t xTimerTask;\r
410 \r
411         /* Call the periodic timer test, which tests the timer API functions that\r
412         can be called from an ISR. */\r
413         #if( configUSE_PREEMPTION != 0 )\r
414         {\r
415                 /* Only created when preemption is used. */\r
416                 vTimerPeriodicISRTests();\r
417         }\r
418         #endif\r
419 \r
420         /* Call the periodic queue overwrite from ISR demo. */\r
421         vQueueOverwritePeriodicISRDemo();\r
422 \r
423         /* Write to a queue that is in use as part of the queue set demo to\r
424         demonstrate using queue sets from an ISR. */\r
425         vQueueSetAccessQueueSetFromISR();\r
426         vQueueSetPollingInterruptAccess();\r
427 \r
428         /* Exercise event groups from interrupts. */\r
429         vPeriodicEventGroupsProcessing();\r
430 \r
431         /* Exercise giving mutexes from an interrupt. */\r
432         vInterruptSemaphorePeriodicTest();\r
433 \r
434         /* Exercise using task notifications from an interrupt. */\r
435         xNotifyTaskFromISR();\r
436 \r
437         /* For code coverage purposes. */\r
438         xTimerTask = xTimerGetTimerDaemonTaskHandle();\r
439         configASSERT( uxTaskPriorityGetFromISR( xTimerTask ) == configTIMER_TASK_PRIORITY );\r
440 }\r
441 /*-----------------------------------------------------------*/\r
442 \r
443 static void prvPendedFunction( void *pvParameter1, uint32_t ulParameter2 )\r
444 {\r
445 static uint32_t ulLastParameter1 = 1000UL, ulLastParameter2 = 0UL;\r
446 uint32_t ulParameter1;\r
447 \r
448         ulParameter1 = ( uint32_t ) pvParameter1;\r
449 \r
450         /* Ensure the parameters are as expected. */\r
451         configASSERT( ulParameter1 == ( ulLastParameter1 + 1 ) );\r
452         configASSERT( ulParameter2 == ( ulLastParameter2 + 1 ) );\r
453 \r
454         /* Remember the parameters for the next time the function is called. */\r
455         ulLastParameter1 = ulParameter1;\r
456         ulLastParameter2 = ulParameter2;\r
457 }\r
458 /*-----------------------------------------------------------*/\r
459 \r
460 static void prvDemonstratePendingFunctionCall( void )\r
461 {\r
462 static uint32_t ulParameter1 = 1000UL, ulParameter2 = 0UL;\r
463 const TickType_t xDontBlock = 0; /* This is called from the idle task so must *not* attempt to block. */\r
464 \r
465         /* prvPendedFunction() just expects the parameters to be incremented by one\r
466         each time it is called. */\r
467         ulParameter1++;\r
468         ulParameter2++;\r
469 \r
470         /* Pend the function call, sending the parameters. */\r
471         xTimerPendFunctionCall( prvPendedFunction, ( void * ) ulParameter1, ulParameter2, xDontBlock );\r
472 }\r
473 /*-----------------------------------------------------------*/\r
474 \r
475 static void prvDemonstrateTaskStateAndHandleGetFunctions( void )\r
476 {\r
477 TaskHandle_t xIdleTaskHandle, xTimerTaskHandle;\r
478 char *pcTaskName;\r
479 static portBASE_TYPE xPerformedOneShotTests = pdFALSE;\r
480 TaskHandle_t xTestTask;\r
481 \r
482         /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and\r
483         xTaskGetIdleTaskHandle() functions.  Also try using the function that sets\r
484         the task number. */\r
485         xIdleTaskHandle = xTaskGetIdleTaskHandle();\r
486         xTimerTaskHandle = xTimerGetTimerDaemonTaskHandle();\r
487 \r
488         /* This is the idle hook, so the current task handle should equal the\r
489         returned idle task handle. */\r
490         if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle )\r
491         {\r
492                 pcStatusMessage = "Error:  Returned idle task handle was incorrect";\r
493         }\r
494 \r
495         /* Check the timer task handle was returned correctly. */\r
496         pcTaskName = pcTaskGetTaskName( xTimerTaskHandle );\r
497         if( strcmp( pcTaskName, "Tmr Svc" ) != 0 )\r
498         {\r
499                 pcStatusMessage = "Error:  Returned timer task handle was incorrect";\r
500         }\r
501 \r
502         /* This task is running, make sure it's state is returned as running. */\r
503         if( eTaskStateGet( xIdleTaskHandle ) != eRunning )\r
504         {\r
505                 pcStatusMessage = "Error:  Returned idle task state was incorrect";\r
506         }\r
507 \r
508         /* If this task is running, then the timer task must be blocked. */\r
509         if( eTaskStateGet( xTimerTaskHandle ) != eBlocked )\r
510         {\r
511                 pcStatusMessage = "Error:  Returned timer task state was incorrect";\r
512         }\r
513 \r
514         /* Other tests that should only be performed once follow.  The test task\r
515         is not created on each iteration because to do so would cause the death\r
516         task to report an error (too many tasks running). */\r
517         if( xPerformedOneShotTests == pdFALSE )\r
518         {\r
519                 /* Don't run this part of the test again. */\r
520                 xPerformedOneShotTests = pdTRUE;\r
521 \r
522                 /* Create a test task to use to test other eTaskStateGet() return values. */\r
523                 if( xTaskCreate( prvTestTask, "Test", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTestTask ) == pdPASS )\r
524                 {\r
525                         /* If this task is running, the test task must be in the ready state. */\r
526                         if( eTaskStateGet( xTestTask ) != eReady )\r
527                         {\r
528                                 pcStatusMessage = "Error: Returned test task state was incorrect 1";\r
529                         }\r
530 \r
531                         /* Now suspend the test task and check its state is reported correctly. */\r
532                         vTaskSuspend( xTestTask );\r
533                         if( eTaskStateGet( xTestTask ) != eSuspended )\r
534                         {\r
535                                 pcStatusMessage = "Error: Returned test task state was incorrect 2";\r
536                         }\r
537 \r
538                         /* Now delete the task and check its state is reported correctly. */\r
539                         vTaskDelete( xTestTask );\r
540                         if( eTaskStateGet( xTestTask ) != eDeleted )\r
541                         {\r
542                                 pcStatusMessage = "Error: Returned test task state was incorrect 3";\r
543                         }\r
544                 }\r
545         }\r
546 }\r
547 /*-----------------------------------------------------------*/\r
548 \r
549 static void prvDemoQueueSpaceFunctions( void *pvParameters )\r
550 {\r
551 QueueHandle_t xQueue = NULL;\r
552 const unsigned portBASE_TYPE uxQueueLength = 10;\r
553 unsigned portBASE_TYPE uxReturn, x;\r
554 \r
555         /* Remove compiler warnings. */\r
556         ( void ) pvParameters;\r
557 \r
558         /* Create the queue that will be used.  Nothing is actually going to be\r
559         sent or received so the queue item size is set to 0. */\r
560         xQueue = xQueueCreate( uxQueueLength, 0 );\r
561         configASSERT( xQueue );\r
562 \r
563         for( ;; )\r
564         {\r
565                 for( x = 0; x < uxQueueLength; x++ )\r
566                 {\r
567                         /* Ask how many messages are available... */\r
568                         uxReturn = uxQueueMessagesWaiting( xQueue );\r
569 \r
570                         /* Check the number of messages being reported as being available\r
571                         is as expected, and force an assert if not. */\r
572                         if( uxReturn != x )\r
573                         {\r
574                                 /* xQueue cannot be NULL so this is deliberately causing an\r
575                                 assert to be triggered as there is an error. */\r
576                                 configASSERT( xQueue == NULL );\r
577                         }\r
578 \r
579                         /* Ask how many spaces remain in the queue... */\r
580                         uxReturn = uxQueueSpacesAvailable( xQueue );\r
581 \r
582                         /* Check the number of spaces being reported as being available\r
583                         is as expected, and force an assert if not. */\r
584                         if( uxReturn != ( uxQueueLength - x ) )\r
585                         {\r
586                                 /* xQueue cannot be NULL so this is deliberately causing an\r
587                                 assert to be triggered as there is an error. */\r
588                                 configASSERT( xQueue == NULL );\r
589                         }\r
590 \r
591                         /* Fill one more space in the queue. */\r
592                         xQueueSendToBack( xQueue, NULL, 0 );\r
593                 }\r
594 \r
595                 /* Perform the same check while the queue is full. */\r
596                 uxReturn = uxQueueMessagesWaiting( xQueue );\r
597                 if( uxReturn != uxQueueLength )\r
598                 {\r
599                         configASSERT( xQueue == NULL );\r
600                 }\r
601 \r
602                 uxReturn = uxQueueSpacesAvailable( xQueue );\r
603 \r
604                 if( uxReturn != 0 )\r
605                 {\r
606                         configASSERT( xQueue == NULL );\r
607                 }\r
608 \r
609                 /* The queue is full, start again. */\r
610                 xQueueReset( xQueue );\r
611 \r
612                 #if( configUSE_PREEMPTION == 0 )\r
613                         taskYIELD();\r
614                 #endif\r
615         }\r
616 }\r
617 \r
618 \r