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