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