2 FreeRTOS V9.0.0rc1 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\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
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
71 *******************************************************************************
\r
72 * NOTE: Windows will not be running the FreeRTOS demo threads continuously, so
\r
73 * do not expect to get real time behaviour from the FreeRTOS Windows port, or
\r
74 * this demo application. Also, the timing information in the FreeRTOS+Trace
\r
75 * logs have no meaningful units. See the documentation page for the Windows
\r
76 * port for further information:
\r
77 * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html
\r
79 * NOTE 2: This project provides two demo applications. A simple blinky style
\r
80 * project, and a more comprehensive test and demo application. The
\r
81 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
82 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
83 * in main.c. This file implements the comprehensive test and demo version.
\r
85 * NOTE 3: This file only contains the source code that is specific to the
\r
86 * basic demo. Generic functions, such FreeRTOS hook functions, are defined in
\r
88 *******************************************************************************
\r
90 * main() creates all the demo application tasks, then starts the scheduler.
\r
91 * The web documentation provides more details of the standard demo application
\r
92 * tasks, which provide no particular functionality but do provide a good
\r
93 * example of how to use the FreeRTOS API.
\r
95 * In addition to the standard demo tasks, the following tasks and tests are
\r
96 * defined and/or created within this file:
\r
98 * "Check" task - This only executes every five seconds but has a high priority
\r
99 * to ensure it gets processor time. Its main function is to check that all the
\r
100 * standard demo tasks are still operational. While no errors have been
\r
101 * discovered the check task will print out "No Errors" along with some system
\r
102 * status information. If an error is discovered in the execution of a task
\r
103 * then the check task will print out an appropriate error message.
\r
108 /* Standard includes. */
\r
110 #include <stdlib.h>
\r
112 /* Kernel includes. */
\r
113 #include <FreeRTOS.h>
\r
116 #include <timers.h>
\r
117 #include <semphr.h>
\r
119 /* Standard demo includes. */
\r
120 #include "BlockQ.h"
\r
121 #include "integer.h"
\r
122 #include "semtest.h"
\r
124 #include "GenQTest.h"
\r
126 #include "recmutex.h"
\r
128 #include "TimerDemo.h"
\r
129 #include "countsem.h"
\r
131 #include "dynamic.h"
\r
132 #include "QueueSet.h"
\r
133 #include "QueueOverwrite.h"
\r
134 #include "EventGroupsDemo.h"
\r
135 #include "IntSemTest.h"
\r
136 #include "TaskNotify.h"
\r
137 #include "QueueSetPolling.h"
\r
138 #include "StaticAllocation.h"
\r
139 #include "blocktim.h"
\r
140 #include "AbortDelay.h"
\r
142 /* Priorities at which the tasks are created. */
\r
143 #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
\r
144 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
145 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
146 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
147 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
148 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
149 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
150 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
151 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
152 #define mainQUEUE_OVERWRITE_PRIORITY ( tskIDLE_PRIORITY )
\r
154 #define mainTIMER_TEST_PERIOD ( 50 )
\r
156 /* Task function prototypes. */
\r
157 static void prvCheckTask( void *pvParameters );
\r
159 /* A task that is created from the idle task to test the functionality of
\r
160 eTaskStateGet(). */
\r
161 static void prvTestTask( void *pvParameters );
\r
164 * Called from the idle task hook function to demonstrate a few utility
\r
165 * functions that are not demonstrated by any of the standard demo tasks.
\r
167 static void prvDemonstrateTaskStateAndHandleGetFunctions( void );
\r
170 * Called from the idle task hook function to demonstrate the use of
\r
171 * xTimerPendFunctionCall() as xTimerPendFunctionCall() is not demonstrated by
\r
172 * any of the standard demo tasks.
\r
174 static void prvDemonstratePendingFunctionCall( void );
\r
177 * The function that is pended by prvDemonstratePendingFunctionCall().
\r
179 static void prvPendedFunction( void *pvParameter1, uint32_t ulParameter2 );
\r
182 * A task to demonstrate the use of the xQueueSpacesAvailable() function.
\r
184 static void prvDemoQueueSpaceFunctions( void *pvParameters );
\r
187 * Tasks that ensure indefinite delays are truly indefinite.
\r
189 static void prvPermanentlyBlockingSemaphoreTask( void *pvParameters );
\r
190 static void prvPermanentlyBlockingNotificationTask( void *pvParameters );
\r
192 /*-----------------------------------------------------------*/
\r
194 /* The variable into which error messages are latched. */
\r
195 static char *pcStatusMessage = "No errors";
\r
197 /* This semaphore is created purely to test using the vSemaphoreDelete() and
\r
198 semaphore tracing API functions. It has no other purpose. */
\r
199 static SemaphoreHandle_t xMutexToDelete = NULL;
\r
201 /*-----------------------------------------------------------*/
\r
203 int main_full( void )
\r
205 /* Start the check task as described at the top of this file. */
\r
206 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
208 /* Create the standard demo tasks. */
\r
209 vStartTaskNotifyTask();
\r
210 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
211 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
212 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
213 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
214 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
215 vStartQueuePeekTasks();
\r
216 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
217 vStartRecursiveMutexTasks();
\r
218 vStartCountingSemaphoreTasks();
\r
219 vStartDynamicPriorityTasks();
\r
220 vStartQueueSetTasks();
\r
221 vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY );
\r
222 vStartEventGroupTasks();
\r
223 vStartInterruptSemaphoreTasks();
\r
224 vStartQueueSetPollingTask();
\r
225 vCreateBlockTimeTasks();
\r
226 vCreateAbortDelayTasks();
\r
227 xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
228 xTaskCreate( prvPermanentlyBlockingSemaphoreTask, "BlockSem", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
229 xTaskCreate( prvPermanentlyBlockingNotificationTask, "BlockNoti", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
231 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
\r
233 vStartStaticallyAllocatedTasks();
\r
237 #if( configUSE_PREEMPTION != 0 )
\r
239 /* Don't expect these tasks to pass when preemption is not used. */
\r
240 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
244 /* The suicide tasks must be created last as they need to know how many
\r
245 tasks were running prior to their creation. This then allows them to
\r
246 ascertain whether or not the correct/expected number of tasks are running at
\r
248 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
250 /* Create the semaphore that will be deleted in the idle task hook. This
\r
251 is done purely to test the use of vSemaphoreDelete(). */
\r
252 xMutexToDelete = xSemaphoreCreateMutex();
\r
254 /* Start the scheduler itself. */
\r
255 vTaskStartScheduler();
\r
257 /* Should never get here unless there was not enough heap space to create
\r
258 the idle and other system tasks. */
\r
261 /*-----------------------------------------------------------*/
\r
263 static void prvCheckTask( void *pvParameters )
\r
265 TickType_t xNextWakeTime;
\r
266 const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL );
\r
268 /* Just to remove compiler warning. */
\r
269 ( void ) pvParameters;
\r
271 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
272 xNextWakeTime = xTaskGetTickCount();
\r
276 /* Place this task in the blocked state until it is time to run again. */
\r
277 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );
\r
279 /* Check the standard demo tasks are running without error. */
\r
280 #if( configUSE_PREEMPTION != 0 )
\r
282 /* These tasks are only created when preemption is used. */
\r
283 if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )
\r
285 pcStatusMessage = "Error: TimerDemo";
\r
290 if( xAreTaskNotificationTasksStillRunning() != pdTRUE )
\r
292 pcStatusMessage = "Error: Notification";
\r
295 if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )
\r
297 pcStatusMessage = "Error: IntSem";
\r
299 else if( xAreEventGroupTasksStillRunning() != pdTRUE )
\r
301 pcStatusMessage = "Error: EventGroup";
\r
303 else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
305 pcStatusMessage = "Error: IntMath";
\r
307 else if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
309 pcStatusMessage = "Error: GenQueue";
\r
311 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
313 pcStatusMessage = "Error: QueuePeek";
\r
315 else if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
317 pcStatusMessage = "Error: BlockQueue";
\r
319 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
321 pcStatusMessage = "Error: SemTest";
\r
323 else if( xArePollingQueuesStillRunning() != pdTRUE )
\r
325 pcStatusMessage = "Error: PollQueue";
\r
327 else if( xAreMathsTaskStillRunning() != pdPASS )
\r
329 pcStatusMessage = "Error: Flop";
\r
331 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
333 pcStatusMessage = "Error: RecMutex";
\r
335 else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
337 pcStatusMessage = "Error: CountSem";
\r
339 else if( xIsCreateTaskStillRunning() != pdTRUE )
\r
341 pcStatusMessage = "Error: Death";
\r
343 else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )
\r
345 pcStatusMessage = "Error: Dynamic";
\r
347 else if( xAreQueueSetTasksStillRunning() != pdPASS )
\r
349 pcStatusMessage = "Error: Queue set";
\r
351 else if( xIsQueueOverwriteTaskStillRunning() != pdPASS )
\r
353 pcStatusMessage = "Error: Queue overwrite";
\r
355 else if( xAreQueueSetPollTasksStillRunning() != pdPASS )
\r
357 pcStatusMessage = "Error: Queue set polling";
\r
359 else if( xAreBlockTimeTestTasksStillRunning() != pdPASS )
\r
361 pcStatusMessage = "Error: Block time";
\r
363 else if( xAreAbortDelayTestTasksStillRunning() != pdPASS )
\r
365 pcStatusMessage = "Error: Abort delay";
\r
368 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
\r
369 else if( xAreStaticAllocationTasksStillRunning() != pdPASS )
\r
371 pcStatusMessage = "Error: Static allocation";
\r
373 #endif /* configSUPPORT_STATIC_ALLOCATION */
\r
375 /* This is the only task that uses stdout so its ok to call printf()
\r
377 printf( "%s - tick count %d - free heap %d - min free heap %d\r\n", pcStatusMessage,
\r
378 xTaskGetTickCount(),
\r
379 xPortGetFreeHeapSize(),
\r
380 xPortGetMinimumEverFreeHeapSize() );
\r
383 /*-----------------------------------------------------------*/
\r
385 static void prvTestTask( void *pvParameters )
\r
387 const unsigned long ulMSToSleep = 5;
\r
389 /* Just to remove compiler warnings. */
\r
390 ( void ) pvParameters;
\r
392 /* This task is just used to test the eTaskStateGet() function. It
\r
393 does not have anything to do. */
\r
396 /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are
\r
397 tasks waiting to be terminated by the idle task. */
\r
398 Sleep( ulMSToSleep );
\r
401 /*-----------------------------------------------------------*/
\r
403 /* Called from vApplicationIdleHook(), which is defined in main.c. */
\r
404 void vFullDemoIdleFunction( void )
\r
406 const unsigned long ulMSToSleep = 15;
\r
409 /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are
\r
410 tasks waiting to be terminated by the idle task. */
\r
411 Sleep( ulMSToSleep );
\r
413 /* Demonstrate a few utility functions that are not demonstrated by any of
\r
414 the standard demo tasks. */
\r
415 prvDemonstrateTaskStateAndHandleGetFunctions();
\r
417 /* Demonstrate the use of xTimerPendFunctionCall(), which is not
\r
418 demonstrated by any of the standard demo tasks. */
\r
419 prvDemonstratePendingFunctionCall();
\r
421 /* If xMutexToDelete has not already been deleted, then delete it now.
\r
422 This is done purely to demonstrate the use of, and test, the
\r
423 vSemaphoreDelete() macro. Care must be taken not to delete a semaphore
\r
424 that has tasks blocked on it. */
\r
425 if( xMutexToDelete != NULL )
\r
427 /* For test purposes, add the mutex to the registry, then remove it
\r
428 again, before it is deleted - checking its name is as expected before
\r
429 and after the assertion into the registry and its removal from the
\r
431 configASSERT( pcQueueGetQueueName( xMutexToDelete ) == NULL );
\r
432 vQueueAddToRegistry( xMutexToDelete, "Test_Mutex" );
\r
433 configASSERT( strcmp( pcQueueGetQueueName( xMutexToDelete ), "Test_Mutex" ) == 0 );
\r
434 vQueueUnregisterQueue( xMutexToDelete );
\r
435 configASSERT( pcQueueGetQueueName( xMutexToDelete ) == NULL );
\r
437 vSemaphoreDelete( xMutexToDelete );
\r
438 xMutexToDelete = NULL;
\r
441 /* Exercise heap_5 a bit. The malloc failed hook will trap failed
\r
442 allocations so there is no need to test here. */
\r
443 pvAllocated = pvPortMalloc( ( rand() % 500 ) + 1 );
\r
444 vPortFree( pvAllocated );
\r
446 /*-----------------------------------------------------------*/
\r
448 /* Called by vApplicationTickHook(), which is defined in main.c. */
\r
449 void vFullDemoTickHookFunction( void )
\r
451 TaskHandle_t xTimerTask;
\r
453 /* Call the periodic timer test, which tests the timer API functions that
\r
454 can be called from an ISR. */
\r
455 #if( configUSE_PREEMPTION != 0 )
\r
457 /* Only created when preemption is used. */
\r
458 vTimerPeriodicISRTests();
\r
462 /* Call the periodic queue overwrite from ISR demo. */
\r
463 vQueueOverwritePeriodicISRDemo();
\r
465 /* Write to a queue that is in use as part of the queue set demo to
\r
466 demonstrate using queue sets from an ISR. */
\r
467 vQueueSetAccessQueueSetFromISR();
\r
468 vQueueSetPollingInterruptAccess();
\r
470 /* Exercise event groups from interrupts. */
\r
471 vPeriodicEventGroupsProcessing();
\r
473 /* Exercise giving mutexes from an interrupt. */
\r
474 vInterruptSemaphorePeriodicTest();
\r
476 /* Exercise using task notifications from an interrupt. */
\r
477 xNotifyTaskFromISR();
\r
479 /* For code coverage purposes. */
\r
480 xTimerTask = xTimerGetTimerDaemonTaskHandle();
\r
481 configASSERT( uxTaskPriorityGetFromISR( xTimerTask ) == configTIMER_TASK_PRIORITY );
\r
483 /*-----------------------------------------------------------*/
\r
485 static void prvPendedFunction( void *pvParameter1, uint32_t ulParameter2 )
\r
487 static uint32_t ulLastParameter1 = 1000UL, ulLastParameter2 = 0UL;
\r
488 uint32_t ulParameter1;
\r
490 ulParameter1 = ( uint32_t ) pvParameter1;
\r
492 /* Ensure the parameters are as expected. */
\r
493 configASSERT( ulParameter1 == ( ulLastParameter1 + 1 ) );
\r
494 configASSERT( ulParameter2 == ( ulLastParameter2 + 1 ) );
\r
496 /* Remember the parameters for the next time the function is called. */
\r
497 ulLastParameter1 = ulParameter1;
\r
498 ulLastParameter2 = ulParameter2;
\r
500 /*-----------------------------------------------------------*/
\r
502 static void prvDemonstratePendingFunctionCall( void )
\r
504 static uint32_t ulParameter1 = 1000UL, ulParameter2 = 0UL;
\r
505 const TickType_t xDontBlock = 0; /* This is called from the idle task so must *not* attempt to block. */
\r
507 /* prvPendedFunction() just expects the parameters to be incremented by one
\r
508 each time it is called. */
\r
512 /* Pend the function call, sending the parameters. */
\r
513 xTimerPendFunctionCall( prvPendedFunction, ( void * ) ulParameter1, ulParameter2, xDontBlock );
\r
515 /*-----------------------------------------------------------*/
\r
517 static void prvDemonstrateTaskStateAndHandleGetFunctions( void )
\r
519 TaskHandle_t xIdleTaskHandle, xTimerTaskHandle;
\r
521 static portBASE_TYPE xPerformedOneShotTests = pdFALSE;
\r
522 TaskHandle_t xTestTask;
\r
523 TaskStatus_t xTaskInfo;
\r
524 extern StackType_t uxTimerTaskStack[];
\r
526 /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and
\r
527 xTaskGetIdleTaskHandle() functions. Also try using the function that sets
\r
528 the task number. */
\r
529 xIdleTaskHandle = xTaskGetIdleTaskHandle();
\r
530 xTimerTaskHandle = xTimerGetTimerDaemonTaskHandle();
\r
532 /* This is the idle hook, so the current task handle should equal the
\r
533 returned idle task handle. */
\r
534 if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle )
\r
536 pcStatusMessage = "Error: Returned idle task handle was incorrect";
\r
539 /* Check the same handle is obtained using the idle task's name. First try
\r
540 with the wrong name, then the right name. */
\r
541 if( xTaskGetTaskHandle( "Idle" ) == xIdleTaskHandle )
\r
543 pcStatusMessage = "Error: Returned handle for name Idle was incorrect";
\r
546 if( xTaskGetTaskHandle( "IDLE" ) != xIdleTaskHandle )
\r
548 pcStatusMessage = "Error: Returned handle for name Idle was incorrect";
\r
551 /* Check the timer task handle was returned correctly. */
\r
552 pcTaskName = pcTaskGetTaskName( xTimerTaskHandle );
\r
553 if( strcmp( pcTaskName, "Tmr Svc" ) != 0 )
\r
555 pcStatusMessage = "Error: Returned timer task handle was incorrect";
\r
558 if( xTaskGetTaskHandle( "Tmr Svc" ) != xTimerTaskHandle )
\r
560 pcStatusMessage = "Error: Returned handle for name Tmr Svc was incorrect";
\r
563 /* This task is running, make sure it's state is returned as running. */
\r
564 if( eTaskStateGet( xIdleTaskHandle ) != eRunning )
\r
566 pcStatusMessage = "Error: Returned idle task state was incorrect";
\r
569 /* If this task is running, then the timer task must be blocked. */
\r
570 if( eTaskStateGet( xTimerTaskHandle ) != eBlocked )
\r
572 pcStatusMessage = "Error: Returned timer task state was incorrect";
\r
575 /* Also with the vTaskGetTaskInfo() function. */
\r
576 vTaskGetTaskInfo( xTimerTaskHandle, /* The task being queried. */
\r
577 &xTaskInfo, /* The structure into which information on the task will be written. */
\r
578 pdTRUE, /* Include the task's high watermark in the structure. */
\r
579 eInvalid ); /* Include the task state in the structure. */
\r
581 /* Check the information returned by vTaskGetTaskInfo() is as expected. */
\r
582 if( ( xTaskInfo.eCurrentState != eBlocked ) ||
\r
583 ( strcmp( xTaskInfo.pcTaskName, "Tmr Svc" ) != 0 ) ||
\r
584 ( xTaskInfo.uxCurrentPriority != configTIMER_TASK_PRIORITY ) ||
\r
585 ( xTaskInfo.pxStackBase != uxTimerTaskStack ) ||
\r
586 ( xTaskInfo.xHandle != xTimerTaskHandle ) )
\r
588 pcStatusMessage = "Error: vTaskGetTaskInfo() returned incorrect information about the timer task";
\r
591 /* Other tests that should only be performed once follow. The test task
\r
592 is not created on each iteration because to do so would cause the death
\r
593 task to report an error (too many tasks running). */
\r
594 if( xPerformedOneShotTests == pdFALSE )
\r
596 /* Don't run this part of the test again. */
\r
597 xPerformedOneShotTests = pdTRUE;
\r
599 /* Create a test task to use to test other eTaskStateGet() return values. */
\r
600 if( xTaskCreate( prvTestTask, "Test", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTestTask ) == pdPASS )
\r
602 /* If this task is running, the test task must be in the ready state. */
\r
603 if( eTaskStateGet( xTestTask ) != eReady )
\r
605 pcStatusMessage = "Error: Returned test task state was incorrect 1";
\r
608 /* Now suspend the test task and check its state is reported correctly. */
\r
609 vTaskSuspend( xTestTask );
\r
610 if( eTaskStateGet( xTestTask ) != eSuspended )
\r
612 pcStatusMessage = "Error: Returned test task state was incorrect 2";
\r
615 /* Now delete the task and check its state is reported correctly. */
\r
616 vTaskDelete( xTestTask );
\r
617 if( eTaskStateGet( xTestTask ) != eDeleted )
\r
619 pcStatusMessage = "Error: Returned test task state was incorrect 3";
\r
624 /*-----------------------------------------------------------*/
\r
626 static void prvDemoQueueSpaceFunctions( void *pvParameters )
\r
628 QueueHandle_t xQueue = NULL;
\r
629 const unsigned portBASE_TYPE uxQueueLength = 10;
\r
630 unsigned portBASE_TYPE uxReturn, x;
\r
632 /* Remove compiler warnings. */
\r
633 ( void ) pvParameters;
\r
635 /* Create the queue that will be used. Nothing is actually going to be
\r
636 sent or received so the queue item size is set to 0. */
\r
637 xQueue = xQueueCreate( uxQueueLength, 0 );
\r
638 configASSERT( xQueue );
\r
642 for( x = 0; x < uxQueueLength; x++ )
\r
644 /* Ask how many messages are available... */
\r
645 uxReturn = uxQueueMessagesWaiting( xQueue );
\r
647 /* Check the number of messages being reported as being available
\r
648 is as expected, and force an assert if not. */
\r
649 if( uxReturn != x )
\r
651 /* xQueue cannot be NULL so this is deliberately causing an
\r
652 assert to be triggered as there is an error. */
\r
653 configASSERT( xQueue == NULL );
\r
656 /* Ask how many spaces remain in the queue... */
\r
657 uxReturn = uxQueueSpacesAvailable( xQueue );
\r
659 /* Check the number of spaces being reported as being available
\r
660 is as expected, and force an assert if not. */
\r
661 if( uxReturn != ( uxQueueLength - x ) )
\r
663 /* xQueue cannot be NULL so this is deliberately causing an
\r
664 assert to be triggered as there is an error. */
\r
665 configASSERT( xQueue == NULL );
\r
668 /* Fill one more space in the queue. */
\r
669 xQueueSendToBack( xQueue, NULL, 0 );
\r
672 /* Perform the same check while the queue is full. */
\r
673 uxReturn = uxQueueMessagesWaiting( xQueue );
\r
674 if( uxReturn != uxQueueLength )
\r
676 configASSERT( xQueue == NULL );
\r
679 uxReturn = uxQueueSpacesAvailable( xQueue );
\r
681 if( uxReturn != 0 )
\r
683 configASSERT( xQueue == NULL );
\r
686 /* The queue is full, start again. */
\r
687 xQueueReset( xQueue );
\r
689 #if( configUSE_PREEMPTION == 0 )
\r
694 /*-----------------------------------------------------------*/
\r
696 static void prvPermanentlyBlockingSemaphoreTask( void *pvParameters )
\r
698 SemaphoreHandle_t xSemaphore;
\r
700 /* Prevent compiler warning about unused parameter in the case that
\r
701 configASSERT() is not defined. */
\r
702 ( void ) pvParameters;
\r
704 /* This task should block on a semaphore, and never return. */
\r
705 xSemaphore = xSemaphoreCreateBinary();
\r
706 configASSERT( xSemaphore );
\r
708 xSemaphoreTake( xSemaphore, portMAX_DELAY );
\r
710 /* The above xSemaphoreTake() call should never return, force an assert if
\r
712 configASSERT( pvParameters != NULL );
\r
713 vTaskDelete( NULL );
\r
715 /*-----------------------------------------------------------*/
\r
717 static void prvPermanentlyBlockingNotificationTask( void *pvParameters )
\r
719 /* Prevent compiler warning about unused parameter in the case that
\r
720 configASSERT() is not defined. */
\r
721 ( void ) pvParameters;
\r
723 /* This task should block on a task notification, and never return. */
\r
724 ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
\r
726 /* The above ulTaskNotifyTake() call should never return, force an assert
\r
728 configASSERT( pvParameters != NULL );
\r
729 vTaskDelete( NULL );
\r