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