]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/WIN32-MSVC/main_full.c
Enable the Win32 comprehensive test/demo build and run when configUSE_QUEUE_SETS...
[freertos] / FreeRTOS / Demo / WIN32-MSVC / main_full.c
1 /*\r
2  * FreeRTOS Kernel V10.2.1\r
3  * Copyright (C) 2019 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /*\r
29  *******************************************************************************\r
30  * NOTE 1: The Win32 port is a simulation (or is that emulation?) only!  Do not\r
31  * expect to get real time behaviour from the Win32 port or this demo\r
32  * application.  It is provided as a convenient development and demonstration\r
33  * test bed only.\r
34  *\r
35  * Windows will not be running the FreeRTOS simulator threads continuously, so\r
36  * the timing information in the FreeRTOS+Trace logs have no meaningful units.\r
37  * See the documentation page for the Windows simulator for an explanation of\r
38  * the slow timing:\r
39  * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html\r
40  * - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT -\r
41  *\r
42  * NOTE 2:  This project provides two demo applications.  A simple blinky style\r
43  * project, and a more comprehensive test and demo application.  The\r
44  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
45  * between the two.  See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
46  * in main.c.  This file implements the comprehensive test and demo version.\r
47  *\r
48  * NOTE 3:  This file only contains the source code that is specific to the\r
49  * full demo.  Generic functions, such FreeRTOS hook functions, are defined in\r
50  * main.c.\r
51  *******************************************************************************\r
52  *\r
53  * main() creates all the demo application tasks, then starts the scheduler.\r
54  * The web documentation provides more details of the standard demo application\r
55  * tasks, which provide no particular functionality but do provide a good\r
56  * example of how to use the FreeRTOS API.\r
57  *\r
58  * In addition to the standard demo tasks, the following tasks and tests are\r
59  * defined and/or created within this file:\r
60  *\r
61  * "Check" task - This only executes every five seconds but has a high priority\r
62  * to ensure it gets processor time.  Its main function is to check that all the\r
63  * standard demo tasks are still operational.  While no errors have been\r
64  * discovered the check task will print out "OK" and the current simulated tick\r
65  * time.  If an error is discovered in the execution of a task then the check\r
66  * task will print out an appropriate error message.\r
67  *\r
68  */\r
69 \r
70 \r
71 /* Standard includes. */\r
72 #include <stdio.h>\r
73 #include <stdlib.h>\r
74 \r
75 /* Kernel includes. */\r
76 #include <FreeRTOS.h>\r
77 #include <task.h>\r
78 #include <queue.h>\r
79 #include <timers.h>\r
80 #include <semphr.h>\r
81 \r
82 /* Standard demo includes. */\r
83 #include "BlockQ.h"\r
84 #include "integer.h"\r
85 #include "semtest.h"\r
86 #include "PollQ.h"\r
87 #include "GenQTest.h"\r
88 #include "QPeek.h"\r
89 #include "recmutex.h"\r
90 #include "flop.h"\r
91 #include "TimerDemo.h"\r
92 #include "countsem.h"\r
93 #include "death.h"\r
94 #include "dynamic.h"\r
95 #include "QueueSet.h"\r
96 #include "QueueOverwrite.h"\r
97 #include "EventGroupsDemo.h"\r
98 #include "IntSemTest.h"\r
99 #include "TaskNotify.h"\r
100 #include "QueueSetPolling.h"\r
101 #include "StaticAllocation.h"\r
102 #include "blocktim.h"\r
103 #include "AbortDelay.h"\r
104 #include "MessageBufferDemo.h"\r
105 #include "StreamBufferDemo.h"\r
106 #include "StreamBufferInterrupt.h"\r
107 #include "MessageBufferAMP.h"\r
108 \r
109 /* Priorities at which the tasks are created. */\r
110 #define mainCHECK_TASK_PRIORITY                 ( configMAX_PRIORITIES - 2 )\r
111 #define mainQUEUE_POLL_PRIORITY                 ( tskIDLE_PRIORITY + 1 )\r
112 #define mainSEM_TEST_PRIORITY                   ( tskIDLE_PRIORITY + 1 )\r
113 #define mainBLOCK_Q_PRIORITY                    ( tskIDLE_PRIORITY + 2 )\r
114 #define mainCREATOR_TASK_PRIORITY               ( tskIDLE_PRIORITY + 3 )\r
115 #define mainFLASH_TASK_PRIORITY                 ( tskIDLE_PRIORITY + 1 )\r
116 #define mainINTEGER_TASK_PRIORITY               ( tskIDLE_PRIORITY )\r
117 #define mainGEN_QUEUE_TASK_PRIORITY             ( tskIDLE_PRIORITY )\r
118 #define mainFLOP_TASK_PRIORITY                  ( tskIDLE_PRIORITY )\r
119 #define mainQUEUE_OVERWRITE_PRIORITY    ( tskIDLE_PRIORITY )\r
120 \r
121 #define mainTIMER_TEST_PERIOD                   ( 50 )\r
122 \r
123 /* Task function prototypes. */\r
124 static void prvCheckTask( void *pvParameters );\r
125 \r
126 /* A task that is created from the idle task to test the functionality of\r
127 eTaskStateGet(). */\r
128 static void prvTestTask( void *pvParameters );\r
129 \r
130 /*\r
131  * Called from the idle task hook function to demonstrate a few utility\r
132  * functions that are not demonstrated by any of the standard demo tasks.\r
133  */\r
134 static void prvDemonstrateTaskStateAndHandleGetFunctions( void );\r
135 \r
136 /*\r
137  * Called from the idle task hook function to demonstrate the use of\r
138  * xTimerPendFunctionCall() as xTimerPendFunctionCall() is not demonstrated by\r
139  * any of the standard demo tasks.\r
140  */\r
141 static void prvDemonstratePendingFunctionCall( void );\r
142 \r
143 /*\r
144  * The function that is pended by prvDemonstratePendingFunctionCall().\r
145  */\r
146 static void prvPendedFunction( void *pvParameter1, uint32_t ulParameter2 );\r
147 \r
148 /*\r
149  * prvDemonstrateTimerQueryFunctions() is called from the idle task hook\r
150  * function to demonstrate the use of functions that query information about a\r
151  * software timer.  prvTestTimerCallback() is the callback function for the\r
152  * timer being queried.\r
153  */\r
154 static void prvDemonstrateTimerQueryFunctions( void );\r
155 static void prvTestTimerCallback( TimerHandle_t xTimer );\r
156 \r
157 /*\r
158  * A task to demonstrate the use of the xQueueSpacesAvailable() function.\r
159  */\r
160 static void prvDemoQueueSpaceFunctions( void *pvParameters );\r
161 \r
162 /*\r
163  * Tasks that ensure indefinite delays are truly indefinite.\r
164  */\r
165 static void prvPermanentlyBlockingSemaphoreTask( void *pvParameters );\r
166 static void prvPermanentlyBlockingNotificationTask( void *pvParameters );\r
167 \r
168 /*-----------------------------------------------------------*/\r
169 \r
170 /* The variable into which error messages are latched. */\r
171 static char *pcStatusMessage = "No errors";\r
172 \r
173 /* This semaphore is created purely to test using the vSemaphoreDelete() and\r
174 semaphore tracing API functions.  It has no other purpose. */\r
175 static SemaphoreHandle_t xMutexToDelete = NULL;\r
176 \r
177 /*-----------------------------------------------------------*/\r
178 \r
179 int main_full( void )\r
180 {\r
181         /* Start the check task as described at the top of this file. */\r
182         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
183 \r
184         /* Create the standard demo tasks. */\r
185         vStartTaskNotifyTask();\r
186         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
187         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
188         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
189         vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
190         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
191         vStartQueuePeekTasks();\r
192         vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
193         vStartRecursiveMutexTasks();\r
194         vStartCountingSemaphoreTasks();\r
195         vStartDynamicPriorityTasks();\r
196         vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY );\r
197         vStartEventGroupTasks();\r
198         vStartInterruptSemaphoreTasks();\r
199         vCreateBlockTimeTasks();\r
200         vCreateAbortDelayTasks();\r
201         xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
202         xTaskCreate( prvPermanentlyBlockingSemaphoreTask, "BlockSem", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
203         xTaskCreate( prvPermanentlyBlockingNotificationTask, "BlockNoti", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
204 \r
205         vStartMessageBufferTasks( configMINIMAL_STACK_SIZE );\r
206         vStartStreamBufferTasks();\r
207         vStartStreamBufferInterruptDemo();\r
208         vStartMessageBufferAMPTasks( configMINIMAL_STACK_SIZE );\r
209 \r
210         #if( configUSE_QUEUE_SETS == 1 )\r
211         {\r
212                 vStartQueueSetTasks();\r
213                 vStartQueueSetPollingTask();\r
214         }\r
215         #endif\r
216 \r
217         #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
218         {\r
219                 vStartStaticallyAllocatedTasks();\r
220         }\r
221         #endif\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 = pdMS_TO_TICKS( 5000UL );\r
253 HeapStats_t xHeapStats;\r
254 \r
255         /* Just to remove compiler warning. */\r
256         ( void ) pvParameters;\r
257 \r
258         /* Initialise xNextWakeTime - this only needs to be done once. */\r
259         xNextWakeTime = xTaskGetTickCount();\r
260 \r
261         for( ;; )\r
262         {\r
263                 /* Place this task in the blocked state until it is time to run again. */\r
264                 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );\r
265 \r
266                 /* Check the standard demo tasks are running without error. */\r
267                 #if( configUSE_PREEMPTION != 0 )\r
268                 {\r
269                         /* These tasks are only created when preemption is used. */\r
270                         if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )\r
271                         {\r
272                                 pcStatusMessage = "Error: TimerDemo";\r
273                         }\r
274                 }\r
275                 #endif\r
276 \r
277                 if( xAreStreamBufferTasksStillRunning() != pdTRUE )\r
278                 {\r
279                         pcStatusMessage = "Error:  StreamBuffer";\r
280                 }\r
281                 else if( xAreMessageBufferTasksStillRunning() != pdTRUE )\r
282                 {\r
283                         pcStatusMessage = "Error:  MessageBuffer";\r
284                 }\r
285                 else if( xAreTaskNotificationTasksStillRunning() != pdTRUE )\r
286                 {\r
287                         pcStatusMessage = "Error:  Notification";\r
288                 }\r
289                 else if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )\r
290                 {\r
291                         pcStatusMessage = "Error: IntSem";\r
292                 }\r
293                 else if( xAreEventGroupTasksStillRunning() != pdTRUE )\r
294                 {\r
295                         pcStatusMessage = "Error: EventGroup";\r
296                 }\r
297                 else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
298                 {\r
299                         pcStatusMessage = "Error: IntMath";\r
300                 }\r
301                 else if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
302                 {\r
303                         pcStatusMessage = "Error: GenQueue";\r
304                 }\r
305                 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
306                 {\r
307                         pcStatusMessage = "Error: QueuePeek";\r
308                 }\r
309                 else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
310                 {\r
311                         pcStatusMessage = "Error: BlockQueue";\r
312                 }\r
313                 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
314                 {\r
315                         pcStatusMessage = "Error: SemTest";\r
316                 }\r
317                 else if( xArePollingQueuesStillRunning() != pdTRUE )\r
318                 {\r
319                         pcStatusMessage = "Error: PollQueue";\r
320                 }\r
321                 else if( xAreMathsTaskStillRunning() != pdPASS )\r
322                 {\r
323                         pcStatusMessage = "Error: Flop";\r
324                 }\r
325                 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
326                 {\r
327                         pcStatusMessage = "Error: RecMutex";\r
328                 }\r
329                 else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
330                 {\r
331                         pcStatusMessage = "Error: CountSem";\r
332                 }\r
333                 else if( xIsCreateTaskStillRunning() != pdTRUE )\r
334                 {\r
335                         pcStatusMessage = "Error: Death";\r
336                 }\r
337                 else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )\r
338                 {\r
339                         pcStatusMessage = "Error: Dynamic";\r
340                 }\r
341                 else if( xIsQueueOverwriteTaskStillRunning() != pdPASS )\r
342                 {\r
343                         pcStatusMessage = "Error: Queue overwrite";\r
344                 }\r
345                 else if( xAreBlockTimeTestTasksStillRunning() != pdPASS )\r
346                 {\r
347                         pcStatusMessage = "Error: Block time";\r
348                 }\r
349                 else if( xAreAbortDelayTestTasksStillRunning() != pdPASS )\r
350                 {\r
351                         pcStatusMessage = "Error: Abort delay";\r
352                 }\r
353                 else if( xIsInterruptStreamBufferDemoStillRunning() != pdPASS )\r
354                 {\r
355                         pcStatusMessage = "Error: Stream buffer interrupt";\r
356                 }\r
357                 else if( xAreMessageBufferAMPTasksStillRunning() != pdPASS )\r
358                 {\r
359                         pcStatusMessage = "Error: Message buffer AMP";\r
360                 }\r
361 \r
362                 #if( configUSE_QUEUE_SETS == 1 )\r
363                         else if( xAreQueueSetTasksStillRunning() != pdPASS )\r
364                         {\r
365                                 pcStatusMessage = "Error: Queue set";\r
366                         }\r
367                         else if( xAreQueueSetPollTasksStillRunning() != pdPASS )\r
368                         {\r
369                                 pcStatusMessage = "Error: Queue set polling";\r
370                         }\r
371                 #endif\r
372 \r
373                 #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
374                         else if( xAreStaticAllocationTasksStillRunning() != pdPASS )\r
375                         {\r
376                                 pcStatusMessage = "Error: Static allocation";\r
377                         }\r
378                 #endif /* configSUPPORT_STATIC_ALLOCATION */\r
379 \r
380                 /* This is the only task that uses stdout so its ok to call printf()\r
381                 directly. */\r
382                 vPortGetHeapStats( &xHeapStats );\r
383 \r
384                 configASSERT( xHeapStats.xAvailableHeapSpaceInBytes == xPortGetFreeHeapSize() );\r
385                 configASSERT( xHeapStats.xMinimumEverFreeBytesRemaining == xPortGetMinimumEverFreeHeapSize() );\r
386 \r
387                 printf( "%s - tick count %zu - free heap %zu - min free heap %zu - largest free block %zu \r\n",\r
388                         pcStatusMessage,\r
389                         xTaskGetTickCount(),\r
390                         xHeapStats.xAvailableHeapSpaceInBytes,\r
391                         xHeapStats.xMinimumEverFreeBytesRemaining,\r
392                         xHeapStats.xSizeOfLargestFreeBlockInBytes );\r
393         }\r
394 }\r
395 /*-----------------------------------------------------------*/\r
396 \r
397 static void prvTestTask( void *pvParameters )\r
398 {\r
399 const unsigned long ulMSToSleep = 5;\r
400 \r
401         /* Just to remove compiler warnings. */\r
402         ( void ) pvParameters;\r
403 \r
404         /* This task is just used to test the eTaskStateGet() function.  It\r
405         does not have anything to do. */\r
406         for( ;; )\r
407         {\r
408                 /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are\r
409                 tasks waiting to be terminated by the idle task. */\r
410                 Sleep( ulMSToSleep );\r
411         }\r
412 }\r
413 /*-----------------------------------------------------------*/\r
414 \r
415 /* Called from vApplicationIdleHook(), which is defined in main.c. */\r
416 void vFullDemoIdleFunction( void )\r
417 {\r
418 const unsigned long ulMSToSleep = 15;\r
419 void *pvAllocated;\r
420 \r
421         /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are\r
422         tasks waiting to be terminated by the idle task. */\r
423         Sleep( ulMSToSleep );\r
424 \r
425         /* Demonstrate a few utility functions that are not demonstrated by any of\r
426         the standard demo tasks. */\r
427         prvDemonstrateTaskStateAndHandleGetFunctions();\r
428 \r
429         /* Demonstrate the use of xTimerPendFunctionCall(), which is not\r
430         demonstrated by any of the standard demo tasks. */\r
431         prvDemonstratePendingFunctionCall();\r
432 \r
433         /* Demonstrate the use of functions that query information about a software\r
434         timer. */\r
435         prvDemonstrateTimerQueryFunctions();\r
436 \r
437 \r
438         /* If xMutexToDelete has not already been deleted, then delete it now.\r
439         This is done purely to demonstrate the use of, and test, the\r
440         vSemaphoreDelete() macro.  Care must be taken not to delete a semaphore\r
441         that has tasks blocked on it. */\r
442         if( xMutexToDelete != NULL )\r
443         {\r
444                 /* For test purposes, add the mutex to the registry, then remove it\r
445                 again, before it is deleted - checking its name is as expected before\r
446                 and after the assertion into the registry and its removal from the\r
447                 registry. */\r
448                 configASSERT( pcQueueGetName( xMutexToDelete ) == NULL );\r
449                 vQueueAddToRegistry( xMutexToDelete, "Test_Mutex" );\r
450                 configASSERT( strcmp( pcQueueGetName( xMutexToDelete ), "Test_Mutex" ) == 0 );\r
451                 vQueueUnregisterQueue( xMutexToDelete );\r
452                 configASSERT( pcQueueGetName( xMutexToDelete ) == NULL );\r
453 \r
454                 vSemaphoreDelete( xMutexToDelete );\r
455                 xMutexToDelete = NULL;\r
456         }\r
457 \r
458         /* Exercise heap_5 a bit.  The malloc failed hook will trap failed\r
459         allocations so there is no need to test here. */\r
460         pvAllocated = pvPortMalloc( ( rand() % 500 ) + 1 );\r
461         vPortFree( pvAllocated );\r
462 }\r
463 /*-----------------------------------------------------------*/\r
464 \r
465 /* Called by vApplicationTickHook(), which is defined in main.c. */\r
466 void vFullDemoTickHookFunction( void )\r
467 {\r
468 TaskHandle_t xTimerTask;\r
469 \r
470         /* Call the periodic timer test, which tests the timer API functions that\r
471         can be called from an ISR. */\r
472         #if( configUSE_PREEMPTION != 0 )\r
473         {\r
474                 /* Only created when preemption is used. */\r
475                 vTimerPeriodicISRTests();\r
476         }\r
477         #endif\r
478 \r
479         /* Call the periodic queue overwrite from ISR demo. */\r
480         vQueueOverwritePeriodicISRDemo();\r
481 \r
482         #if( configUSE_QUEUE_SETS == 1 ) /* Remove the tests if queue sets are not defined. */\r
483         {\r
484                 /* Write to a queue that is in use as part of the queue set demo to\r
485                 demonstrate using queue sets from an ISR. */\r
486                 vQueueSetAccessQueueSetFromISR();\r
487                 vQueueSetPollingInterruptAccess();\r
488         }\r
489         #endif\r
490 \r
491         /* Exercise event groups from interrupts. */\r
492         vPeriodicEventGroupsProcessing();\r
493 \r
494         /* Exercise giving mutexes from an interrupt. */\r
495         vInterruptSemaphorePeriodicTest();\r
496 \r
497         /* Exercise using task notifications from an interrupt. */\r
498         xNotifyTaskFromISR();\r
499 \r
500         /* Writes to stream buffer byte by byte to test the stream buffer trigger\r
501         level functionality. */\r
502         vPeriodicStreamBufferProcessing();\r
503 \r
504         /* Writes a string to a string buffer four bytes at a time to demonstrate\r
505         a stream being sent from an interrupt to a task. */\r
506         vBasicStreamBufferSendFromISR();\r
507 \r
508         /* For code coverage purposes. */\r
509         xTimerTask = xTimerGetTimerDaemonTaskHandle();\r
510         configASSERT( uxTaskPriorityGetFromISR( xTimerTask ) == configTIMER_TASK_PRIORITY );\r
511 }\r
512 /*-----------------------------------------------------------*/\r
513 \r
514 static void prvPendedFunction( void *pvParameter1, uint32_t ulParameter2 )\r
515 {\r
516 static uint32_t ulLastParameter1 = 1000UL, ulLastParameter2 = 0UL;\r
517 uint32_t ulParameter1;\r
518 \r
519         ulParameter1 = ( uint32_t ) pvParameter1;\r
520 \r
521         /* Ensure the parameters are as expected. */\r
522         configASSERT( ulParameter1 == ( ulLastParameter1 + 1 ) );\r
523         configASSERT( ulParameter2 == ( ulLastParameter2 + 1 ) );\r
524 \r
525         /* Remember the parameters for the next time the function is called. */\r
526         ulLastParameter1 = ulParameter1;\r
527         ulLastParameter2 = ulParameter2;\r
528 }\r
529 /*-----------------------------------------------------------*/\r
530 \r
531 static void prvTestTimerCallback( TimerHandle_t xTimer )\r
532 {\r
533         /* This is the callback function for the timer accessed by\r
534         prvDemonstrateTimerQueryFunctions().  The callback does not do anything. */\r
535         ( void ) xTimer;\r
536 }\r
537 /*-----------------------------------------------------------*/\r
538 \r
539 static void prvDemonstrateTimerQueryFunctions( void )\r
540 {\r
541 static TimerHandle_t xTimer = NULL;\r
542 const char *pcTimerName = "TestTimer";\r
543 volatile TickType_t xExpiryTime;\r
544 const TickType_t xDontBlock = 0;\r
545 \r
546         if( xTimer == NULL )\r
547         {\r
548                 xTimer = xTimerCreate( pcTimerName, portMAX_DELAY, pdTRUE, NULL, prvTestTimerCallback );\r
549 \r
550                 if( xTimer != NULL )\r
551                 {\r
552                         /* Called from the idle task so a block time must not be\r
553                         specified. */\r
554                         xTimerStart( xTimer, xDontBlock );\r
555                 }\r
556         }\r
557 \r
558         if( xTimer != NULL )\r
559         {\r
560                 /* Demonstrate querying a timer's name. */\r
561                 configASSERT( strcmp( pcTimerGetName( xTimer ), pcTimerName ) == 0 );\r
562 \r
563                 /* Demonstrate querying a timer's period. */\r
564                 configASSERT( xTimerGetPeriod( xTimer ) == portMAX_DELAY );\r
565 \r
566                 /* Demonstrate querying a timer's next expiry time, although nothing is\r
567                 done with the returned value.  Note if the expiry time is less than the\r
568                 maximum tick count then the expiry time has overflowed from the current\r
569                 time.  In this case the expiry time was set to portMAX_DELAY, so it is\r
570                 expected to be less than the current time until the current time has\r
571                 itself overflowed. */\r
572                 xExpiryTime = xTimerGetExpiryTime( xTimer );\r
573                 ( void ) xExpiryTime;\r
574         }\r
575 }\r
576 /*-----------------------------------------------------------*/\r
577 \r
578 static void prvDemonstratePendingFunctionCall( void )\r
579 {\r
580 static uint32_t ulParameter1 = 1000UL, ulParameter2 = 0UL;\r
581 const TickType_t xDontBlock = 0; /* This is called from the idle task so must *not* attempt to block. */\r
582 \r
583         /* prvPendedFunction() just expects the parameters to be incremented by one\r
584         each time it is called. */\r
585         ulParameter1++;\r
586         ulParameter2++;\r
587 \r
588         /* Pend the function call, sending the parameters. */\r
589         xTimerPendFunctionCall( prvPendedFunction, ( void * ) ulParameter1, ulParameter2, xDontBlock );\r
590 }\r
591 /*-----------------------------------------------------------*/\r
592 \r
593 static void prvDemonstrateTaskStateAndHandleGetFunctions( void )\r
594 {\r
595 TaskHandle_t xIdleTaskHandle, xTimerTaskHandle;\r
596 char *pcTaskName;\r
597 static portBASE_TYPE xPerformedOneShotTests = pdFALSE;\r
598 TaskHandle_t xTestTask;\r
599 TaskStatus_t xTaskInfo;\r
600 extern StackType_t uxTimerTaskStack[];\r
601 \r
602         /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and\r
603         xTaskGetIdleTaskHandle() functions.  Also try using the function that sets\r
604         the task number. */\r
605         xIdleTaskHandle = xTaskGetIdleTaskHandle();\r
606         xTimerTaskHandle = xTimerGetTimerDaemonTaskHandle();\r
607 \r
608         /* This is the idle hook, so the current task handle should equal the\r
609         returned idle task handle. */\r
610         if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle )\r
611         {\r
612                 pcStatusMessage = "Error:  Returned idle task handle was incorrect";\r
613         }\r
614 \r
615         /* Check the same handle is obtained using the idle task's name.  First try\r
616         with the wrong name, then the right name. */\r
617         if( xTaskGetHandle( "Idle" ) == xIdleTaskHandle )\r
618         {\r
619                 pcStatusMessage = "Error:  Returned handle for name Idle was incorrect";\r
620         }\r
621 \r
622         if( xTaskGetHandle( "IDLE" ) != xIdleTaskHandle )\r
623         {\r
624                 pcStatusMessage = "Error:  Returned handle for name Idle was incorrect";\r
625         }\r
626 \r
627         /* Check the timer task handle was returned correctly. */\r
628         pcTaskName = pcTaskGetName( xTimerTaskHandle );\r
629         if( strcmp( pcTaskName, "Tmr Svc" ) != 0 )\r
630         {\r
631                 pcStatusMessage = "Error:  Returned timer task handle was incorrect";\r
632         }\r
633 \r
634         if( xTaskGetHandle( "Tmr Svc" ) != xTimerTaskHandle )\r
635         {\r
636                 pcStatusMessage = "Error:  Returned handle for name Tmr Svc was incorrect";\r
637         }\r
638 \r
639         /* This task is running, make sure it's state is returned as running. */\r
640         if( eTaskStateGet( xIdleTaskHandle ) != eRunning )\r
641         {\r
642                 pcStatusMessage = "Error:  Returned idle task state was incorrect";\r
643         }\r
644 \r
645         /* If this task is running, then the timer task must be blocked. */\r
646         if( eTaskStateGet( xTimerTaskHandle ) != eBlocked )\r
647         {\r
648                 pcStatusMessage = "Error:  Returned timer task state was incorrect";\r
649         }\r
650 \r
651         /* Also with the vTaskGetInfo() function. */\r
652         vTaskGetInfo( xTimerTaskHandle, /* The task being queried. */\r
653                                           &xTaskInfo,           /* The structure into which information on the task will be written. */\r
654                                           pdTRUE,                       /* Include the task's high watermark in the structure. */\r
655                                           eInvalid );           /* Include the task state in the structure. */\r
656 \r
657         /* Check the information returned by vTaskGetInfo() is as expected. */\r
658         if( ( xTaskInfo.eCurrentState != eBlocked )                                              ||\r
659                 ( strcmp( xTaskInfo.pcTaskName, "Tmr Svc" ) != 0 )                       ||\r
660                 ( xTaskInfo.uxCurrentPriority != configTIMER_TASK_PRIORITY ) ||\r
661                 ( xTaskInfo.pxStackBase != uxTimerTaskStack )                            ||\r
662                 ( xTaskInfo.xHandle != xTimerTaskHandle ) )\r
663         {\r
664                 pcStatusMessage = "Error:  vTaskGetInfo() returned incorrect information about the timer task";\r
665         }\r
666 \r
667         /* Other tests that should only be performed once follow.  The test task\r
668         is not created on each iteration because to do so would cause the death\r
669         task to report an error (too many tasks running). */\r
670         if( xPerformedOneShotTests == pdFALSE )\r
671         {\r
672                 /* Don't run this part of the test again. */\r
673                 xPerformedOneShotTests = pdTRUE;\r
674 \r
675                 /* Create a test task to use to test other eTaskStateGet() return values. */\r
676                 if( xTaskCreate( prvTestTask, "Test", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTestTask ) == pdPASS )\r
677                 {\r
678                         /* If this task is running, the test task must be in the ready state. */\r
679                         if( eTaskStateGet( xTestTask ) != eReady )\r
680                         {\r
681                                 pcStatusMessage = "Error: Returned test task state was incorrect 1";\r
682                         }\r
683 \r
684                         /* Now suspend the test task and check its state is reported correctly. */\r
685                         vTaskSuspend( xTestTask );\r
686                         if( eTaskStateGet( xTestTask ) != eSuspended )\r
687                         {\r
688                                 pcStatusMessage = "Error: Returned test task state was incorrect 2";\r
689                         }\r
690 \r
691                         /* Now delete the task and check its state is reported correctly. */\r
692                         vTaskDelete( xTestTask );\r
693                         if( eTaskStateGet( xTestTask ) != eDeleted )\r
694                         {\r
695                                 pcStatusMessage = "Error: Returned test task state was incorrect 3";\r
696                         }\r
697                 }\r
698         }\r
699 }\r
700 /*-----------------------------------------------------------*/\r
701 \r
702 static void prvDemoQueueSpaceFunctions( void *pvParameters )\r
703 {\r
704 QueueHandle_t xQueue = NULL;\r
705 const unsigned portBASE_TYPE uxQueueLength = 10;\r
706 unsigned portBASE_TYPE uxReturn, x;\r
707 \r
708         /* Remove compiler warnings. */\r
709         ( void ) pvParameters;\r
710 \r
711         /* Create the queue that will be used.  Nothing is actually going to be\r
712         sent or received so the queue item size is set to 0. */\r
713         xQueue = xQueueCreate( uxQueueLength, 0 );\r
714         configASSERT( xQueue );\r
715 \r
716         for( ;; )\r
717         {\r
718                 for( x = 0; x < uxQueueLength; x++ )\r
719                 {\r
720                         /* Ask how many messages are available... */\r
721                         uxReturn = uxQueueMessagesWaiting( xQueue );\r
722 \r
723                         /* Check the number of messages being reported as being available\r
724                         is as expected, and force an assert if not. */\r
725                         if( uxReturn != x )\r
726                         {\r
727                                 /* xQueue cannot be NULL so this is deliberately causing an\r
728                                 assert to be triggered as there is an error. */\r
729                                 configASSERT( xQueue == NULL );\r
730                         }\r
731 \r
732                         /* Ask how many spaces remain in the queue... */\r
733                         uxReturn = uxQueueSpacesAvailable( xQueue );\r
734 \r
735                         /* Check the number of spaces being reported as being available\r
736                         is as expected, and force an assert if not. */\r
737                         if( uxReturn != ( uxQueueLength - x ) )\r
738                         {\r
739                                 /* xQueue cannot be NULL so this is deliberately causing an\r
740                                 assert to be triggered as there is an error. */\r
741                                 configASSERT( xQueue == NULL );\r
742                         }\r
743 \r
744                         /* Fill one more space in the queue. */\r
745                         xQueueSendToBack( xQueue, NULL, 0 );\r
746                 }\r
747 \r
748                 /* Perform the same check while the queue is full. */\r
749                 uxReturn = uxQueueMessagesWaiting( xQueue );\r
750                 if( uxReturn != uxQueueLength )\r
751                 {\r
752                         configASSERT( xQueue == NULL );\r
753                 }\r
754 \r
755                 uxReturn = uxQueueSpacesAvailable( xQueue );\r
756 \r
757                 if( uxReturn != 0 )\r
758                 {\r
759                         configASSERT( xQueue == NULL );\r
760                 }\r
761 \r
762                 /* The queue is full, start again. */\r
763                 xQueueReset( xQueue );\r
764 \r
765                 #if( configUSE_PREEMPTION == 0 )\r
766                         taskYIELD();\r
767                 #endif\r
768         }\r
769 }\r
770 /*-----------------------------------------------------------*/\r
771 \r
772 static void prvPermanentlyBlockingSemaphoreTask( void *pvParameters )\r
773 {\r
774 SemaphoreHandle_t xSemaphore;\r
775 \r
776         /* Prevent compiler warning about unused parameter in the case that\r
777         configASSERT() is not defined. */\r
778         ( void ) pvParameters;\r
779 \r
780         /* This task should block on a semaphore, and never return. */\r
781         xSemaphore = xSemaphoreCreateBinary();\r
782         configASSERT( xSemaphore );\r
783 \r
784         xSemaphoreTake( xSemaphore, portMAX_DELAY );\r
785 \r
786         /* The above xSemaphoreTake() call should never return, force an assert if\r
787         it does. */\r
788         configASSERT( pvParameters != NULL );\r
789         vTaskDelete( NULL );\r
790 }\r
791 /*-----------------------------------------------------------*/\r
792 \r
793 static void prvPermanentlyBlockingNotificationTask( void *pvParameters )\r
794 {\r
795         /* Prevent compiler warning about unused parameter in the case that\r
796         configASSERT() is not defined. */\r
797         ( void ) pvParameters;\r
798 \r
799         /* This task should block on a task notification, and never return. */\r
800         ulTaskNotifyTake( pdTRUE, portMAX_DELAY );\r
801 \r
802         /* The above ulTaskNotifyTake() call should never return, force an assert\r
803         if it does. */\r
804         configASSERT( pvParameters != NULL );\r
805         vTaskDelete( NULL );\r
806 }\r
807 \r
808 \r
809 \r