2 * FreeRTOS Kernel V10.0.1
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\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
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\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
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
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
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
48 * NOTE 3: This file only contains the source code that is specific to the
\r
49 * basic demo. Generic functions, such FreeRTOS hook functions, are defined in
\r
51 *******************************************************************************
\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
58 * In addition to the standard demo tasks, the following tasks and tests are
\r
59 * defined and/or created within this file:
\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
71 /* Standard includes. */
\r
75 /* Kernel includes. */
\r
76 #include <FreeRTOS.h>
\r
82 /* Standard demo includes. */
\r
84 #include "integer.h"
\r
85 #include "semtest.h"
\r
87 #include "GenQTest.h"
\r
89 #include "recmutex.h"
\r
91 #include "TimerDemo.h"
\r
92 #include "countsem.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 "blocktim.h"
\r
102 #include "AbortDelay.h"
\r
103 #include "MessageBufferDemo.h"
\r
104 #include "StreamBufferDemo.h"
\r
106 /* Priorities at which the tasks are created. */
\r
107 #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
\r
108 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
109 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
110 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
111 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
112 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
113 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
114 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
115 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
116 #define mainQUEUE_OVERWRITE_PRIORITY ( tskIDLE_PRIORITY )
\r
118 #define mainTIMER_TEST_PERIOD ( 50 )
\r
120 /* Task function prototypes. */
\r
121 static void prvCheckTask( void *pvParameters );
\r
123 /* A task that is created from the idle task to test the functionality of
\r
124 eTaskStateGet(). */
\r
125 static void prvTestTask( void *pvParameters );
\r
128 * Called from the idle task hook function to demonstrate a few utility
\r
129 * functions that are not demonstrated by any of the standard demo tasks.
\r
131 static void prvDemonstrateTaskStateAndHandleGetFunctions( void );
\r
134 * Called from the idle task hook function to demonstrate the use of
\r
135 * xTimerPendFunctionCall() as xTimerPendFunctionCall() is not demonstrated by
\r
136 * any of the standard demo tasks.
\r
138 static void prvDemonstratePendingFunctionCall( void );
\r
141 * The function that is pended by prvDemonstratePendingFunctionCall().
\r
143 static void prvPendedFunction( void *pvParameter1, uint32_t ulParameter2 );
\r
146 * prvDemonstrateTimerQueryFunctions() is called from the idle task hook
\r
147 * function to demonstrate the use of functions that query information about a
\r
148 * software timer. prvTestTimerCallback() is the callback function for the
\r
149 * timer being queried.
\r
151 static void prvDemonstrateTimerQueryFunctions( void );
\r
152 static void prvTestTimerCallback( TimerHandle_t xTimer );
\r
155 * A task to demonstrate the use of the xQueueSpacesAvailable() function.
\r
157 static void prvDemoQueueSpaceFunctions( void *pvParameters );
\r
160 * Tasks that ensure indefinite delays are truly indefinite.
\r
162 static void prvPermanentlyBlockingSemaphoreTask( void *pvParameters );
\r
163 static void prvPermanentlyBlockingNotificationTask( void *pvParameters );
\r
165 /*-----------------------------------------------------------*/
\r
167 /* The variable into which error messages are latched. */
\r
168 static char *pcStatusMessage = "No errors";
\r
170 /* This semaphore is created purely to test using the vSemaphoreDelete() and
\r
171 semaphore tracing API functions. It has no other purpose. */
\r
172 static SemaphoreHandle_t xMutexToDelete = NULL;
\r
174 /*-----------------------------------------------------------*/
\r
176 int main_full( void )
\r
178 /* Start the check task as described at the top of this file. */
\r
179 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
181 /* Create the standard demo tasks. */
\r
182 vStartTaskNotifyTask();
\r
183 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
184 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
185 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
186 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
187 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
188 vStartQueuePeekTasks();
\r
189 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
190 vStartRecursiveMutexTasks();
\r
191 vStartCountingSemaphoreTasks();
\r
192 vStartDynamicPriorityTasks();
\r
193 vStartQueueSetTasks();
\r
194 vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY );
\r
195 xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
196 vStartEventGroupTasks();
\r
197 vStartInterruptSemaphoreTasks();
\r
198 vStartQueueSetPollingTask();
\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
205 vStartMessageBufferTasks();
\r
206 vStartStreamBufferTasks();
\r
208 #if( configUSE_PREEMPTION != 0 )
\r
210 /* Don't expect these tasks to pass when preemption is not used. */
\r
211 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
215 /* The suicide tasks must be created last as they need to know how many
\r
216 tasks were running prior to their creation. This then allows them to
\r
217 ascertain whether or not the correct/expected number of tasks are running at
\r
219 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
221 /* Create the semaphore that will be deleted in the idle task hook. This
\r
222 is done purely to test the use of vSemaphoreDelete(). */
\r
223 xMutexToDelete = xSemaphoreCreateMutex();
\r
225 /* Start the scheduler itself. */
\r
226 vTaskStartScheduler();
\r
228 /* Should never get here unless there was not enough heap space to create
\r
229 the idle and other system tasks. */
\r
232 /*-----------------------------------------------------------*/
\r
234 static void prvCheckTask( void *pvParameters )
\r
236 TickType_t xNextWakeTime;
\r
237 const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL );
\r
239 /* Just to remove compiler warning. */
\r
240 ( void ) pvParameters;
\r
242 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
243 xNextWakeTime = xTaskGetTickCount();
\r
247 /* Place this task in the blocked state until it is time to run again. */
\r
248 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );
\r
250 /* Check the standard demo tasks are running without error. */
\r
251 #if( configUSE_PREEMPTION != 0 )
\r
253 /* These tasks are only created when preemption is used. */
\r
254 if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )
\r
256 pcStatusMessage = "Error: TimerDemo";
\r
261 if( xAreStreamBufferTasksStillRunning() != pdTRUE )
\r
263 pcStatusMessage = "Error: StreamBuffer";
\r
265 else if( xAreMessageBufferTasksStillRunning() != pdTRUE )
\r
267 pcStatusMessage = "Error: MessageBuffer";
\r
269 else if( xAreTaskNotificationTasksStillRunning() != pdTRUE )
\r
271 pcStatusMessage = "Error: Notification";
\r
273 else if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )
\r
275 pcStatusMessage = "Error: IntSem";
\r
277 else if( xAreEventGroupTasksStillRunning() != pdTRUE )
\r
279 pcStatusMessage = "Error: EventGroup";
\r
281 else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
283 pcStatusMessage = "Error: IntMath";
\r
285 else if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
287 pcStatusMessage = "Error: GenQueue";
\r
289 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
291 pcStatusMessage = "Error: QueuePeek";
\r
293 else if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
295 pcStatusMessage = "Error: BlockQueue";
\r
297 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
299 pcStatusMessage = "Error: SemTest";
\r
301 else if( xArePollingQueuesStillRunning() != pdTRUE )
\r
303 pcStatusMessage = "Error: PollQueue";
\r
305 else if( xAreMathsTaskStillRunning() != pdPASS )
\r
307 pcStatusMessage = "Error: Flop";
\r
309 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
311 pcStatusMessage = "Error: RecMutex";
\r
313 else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
315 pcStatusMessage = "Error: CountSem";
\r
317 else if( xIsCreateTaskStillRunning() != pdTRUE )
\r
319 pcStatusMessage = "Error: Death";
\r
321 else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )
\r
323 pcStatusMessage = "Error: Dynamic";
\r
325 else if( xAreQueueSetTasksStillRunning() != pdPASS )
\r
327 pcStatusMessage = "Error: Queue set";
\r
329 else if( xIsQueueOverwriteTaskStillRunning() != pdPASS )
\r
331 pcStatusMessage = "Error: Queue overwrite";
\r
333 else if( xAreQueueSetPollTasksStillRunning() != pdPASS )
\r
335 pcStatusMessage = "Error: Queue set polling";
\r
337 else if( xAreBlockTimeTestTasksStillRunning() != pdPASS )
\r
339 pcStatusMessage = "Error: Block time";
\r
341 else if( xAreAbortDelayTestTasksStillRunning() != pdPASS )
\r
343 pcStatusMessage = "Error: Abort delay";
\r
346 /* This is the only task that uses stdout so its ok to call printf()
\r
348 printf( ( char * ) "%s - %u\r\n", pcStatusMessage, ( unsigned int ) xTaskGetTickCount() );
\r
352 /*-----------------------------------------------------------*/
\r
354 static void prvTestTask( void *pvParameters )
\r
356 const unsigned long ulMSToSleep = 5;
\r
358 /* Just to remove compiler warnings. */
\r
359 ( void ) pvParameters;
\r
361 /* This task is just used to test the eTaskStateGet() function. It
\r
362 does not have anything to do. */
\r
365 /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are
\r
366 tasks waiting to be terminated by the idle task. */
\r
367 Sleep( ulMSToSleep );
\r
370 /*-----------------------------------------------------------*/
\r
372 /* Called from vApplicationIdleHook(), which is defined in main.c. */
\r
373 void vFullDemoIdleFunction( void )
\r
375 const unsigned long ulMSToSleep = 15;
\r
378 /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are
\r
379 tasks waiting to be terminated by the idle task. */
\r
380 Sleep( ulMSToSleep );
\r
382 /* Demonstrate a few utility functions that are not demonstrated by any of
\r
383 the standard demo tasks. */
\r
384 prvDemonstrateTaskStateAndHandleGetFunctions();
\r
386 /* Demonstrate the use of xTimerPendFunctionCall(), which is not
\r
387 demonstrated by any of the standard demo tasks. */
\r
388 prvDemonstratePendingFunctionCall();
\r
390 /* Demonstrate the use of functions that query information about a software
\r
392 prvDemonstrateTimerQueryFunctions();
\r
395 /* If xMutexToDelete has not already been deleted, then delete it now.
\r
396 This is done purely to demonstrate the use of, and test, the
\r
397 vSemaphoreDelete() macro. Care must be taken not to delete a semaphore
\r
398 that has tasks blocked on it. */
\r
399 if( xMutexToDelete != NULL )
\r
401 /* For test purposes, add the mutex to the registry, then remove it
\r
402 again, before it is deleted - checking its name is as expected before
\r
403 and after the assertion into the registry and its removal from the
\r
405 configASSERT( pcQueueGetName( xMutexToDelete ) == NULL );
\r
406 vQueueAddToRegistry( xMutexToDelete, "Test_Mutex" );
\r
407 configASSERT( strcmp( pcQueueGetName( xMutexToDelete ), "Test_Mutex" ) == 0 );
\r
408 vQueueUnregisterQueue( xMutexToDelete );
\r
409 configASSERT( pcQueueGetName( xMutexToDelete ) == NULL );
\r
411 vSemaphoreDelete( xMutexToDelete );
\r
412 xMutexToDelete = NULL;
\r
415 /* Exercise heap_5 a bit. The malloc failed hook will trap failed
\r
416 allocations so there is no need to test here. */
\r
417 pvAllocated = pvPortMalloc( ( rand() % 500 ) + 1 );
\r
418 vPortFree( pvAllocated );
\r
420 /*-----------------------------------------------------------*/
\r
422 /* Called by vApplicationTickHook(), which is defined in main.c. */
\r
423 void vFullDemoTickHookFunction( void )
\r
425 TaskHandle_t xTimerTask;
\r
427 /* Call the periodic timer test, which tests the timer API functions that
\r
428 can be called from an ISR. */
\r
429 #if( configUSE_PREEMPTION != 0 )
\r
431 /* Only created when preemption is used. */
\r
432 vTimerPeriodicISRTests();
\r
436 /* Call the periodic queue overwrite from ISR demo. */
\r
437 vQueueOverwritePeriodicISRDemo();
\r
439 /* Write to a queue that is in use as part of the queue set demo to
\r
440 demonstrate using queue sets from an ISR. */
\r
441 vQueueSetAccessQueueSetFromISR();
\r
442 vQueueSetPollingInterruptAccess();
\r
444 /* Exercise event groups from interrupts. */
\r
445 vPeriodicEventGroupsProcessing();
\r
447 /* Exercise giving mutexes from an interrupt. */
\r
448 vInterruptSemaphorePeriodicTest();
\r
450 /* Exercise using task notifications from an interrupt. */
\r
451 xNotifyTaskFromISR();
\r
453 /* Writes to stream buffer byte by byte to test the stream buffer trigger
\r
454 level functionality. */
\r
455 vPeriodicStreamBufferProcessing();
\r
457 /* For code coverage purposes. */
\r
458 xTimerTask = xTimerGetTimerDaemonTaskHandle();
\r
459 configASSERT( uxTaskPriorityGetFromISR( xTimerTask ) == configTIMER_TASK_PRIORITY );
\r
460 ( void ) xTimerTask; /* In case configASSERT() is not defined. */
\r
462 /*-----------------------------------------------------------*/
\r
464 static void prvPendedFunction( void *pvParameter1, uint32_t ulParameter2 )
\r
466 static uint32_t ulLastParameter1 = 1000UL, ulLastParameter2 = 0UL;
\r
467 uint32_t ulParameter1;
\r
469 ulParameter1 = ( uint32_t ) pvParameter1;
\r
471 /* Ensure the parameters are as expected. */
\r
472 configASSERT( ulParameter1 == ( ulLastParameter1 + 1 ) );
\r
473 configASSERT( ulParameter2 == ( ulLastParameter2 + 1 ) );
\r
475 /* Remember the parameters for the next time the function is called. */
\r
476 ulLastParameter1 = ulParameter1;
\r
477 ulLastParameter2 = ulParameter2;
\r
479 /* Remove compiler warnings in case configASSERT() is not defined. */
\r
480 ( void ) ulLastParameter1;
\r
481 ( void ) ulLastParameter2;
\r
483 /*-----------------------------------------------------------*/
\r
485 static void prvTestTimerCallback( TimerHandle_t xTimer )
\r
487 /* This is the callback function for the timer accessed by
\r
488 prvDemonstrateTimerQueryFunctions(). The callback does not do anything. */
\r
491 /*-----------------------------------------------------------*/
\r
493 static void prvDemonstrateTimerQueryFunctions( void )
\r
495 static TimerHandle_t xTimer = NULL;
\r
496 const char *pcTimerName = "TestTimer";
\r
497 volatile TickType_t xExpiryTime;
\r
498 const TickType_t xDontBlock = 0;
\r
500 if( xTimer == NULL )
\r
502 xTimer = xTimerCreate( pcTimerName, portMAX_DELAY, pdTRUE, NULL, prvTestTimerCallback );
\r
504 if( xTimer != NULL )
\r
506 /* Called from the idle task so a block time must not be
\r
508 xTimerStart( xTimer, xDontBlock );
\r
512 if( xTimer != NULL )
\r
514 /* Demonstrate querying a timer's name. */
\r
515 configASSERT( strcmp( pcTimerGetName( xTimer ), pcTimerName ) == 0 );
\r
517 /* Demonstrate querying a timer's period. */
\r
518 configASSERT( xTimerGetPeriod( xTimer ) == portMAX_DELAY );
\r
520 /* Demonstrate querying a timer's next expiry time, although nothing is
\r
521 done with the returned value. Note if the expiry time is less than the
\r
522 maximum tick count then the expiry time has overflowed from the current
\r
523 time. In this case the expiry time was set to portMAX_DELAY, so it is
\r
524 expected to be less than the current time until the current time has
\r
525 itself overflowed. */
\r
526 xExpiryTime = xTimerGetExpiryTime( xTimer );
\r
527 ( void ) xExpiryTime;
\r
530 /*-----------------------------------------------------------*/
\r
532 static void prvDemonstratePendingFunctionCall( void )
\r
534 static uint32_t ulParameter1 = 1000UL, ulParameter2 = 0UL;
\r
535 const TickType_t xDontBlock = 0; /* This is called from the idle task so must *not* attempt to block. */
\r
537 /* prvPendedFunction() just expects the parameters to be incremented by one
\r
538 each time it is called. */
\r
542 /* Pend the function call, sending the parameters. */
\r
543 xTimerPendFunctionCall( prvPendedFunction, ( void * ) ulParameter1, ulParameter2, xDontBlock );
\r
545 /*-----------------------------------------------------------*/
\r
547 static void prvDemonstrateTaskStateAndHandleGetFunctions( void )
\r
549 TaskHandle_t xIdleTaskHandle, xTimerTaskHandle;
\r
551 static portBASE_TYPE xPerformedOneShotTests = pdFALSE;
\r
552 TaskHandle_t xTestTask;
\r
553 TaskStatus_t xTaskInfo;
\r
555 /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and
\r
556 xTaskGetIdleTaskHandle() functions. Also try using the function that sets
\r
557 the task number. */
\r
558 xIdleTaskHandle = xTaskGetIdleTaskHandle();
\r
559 xTimerTaskHandle = xTimerGetTimerDaemonTaskHandle();
\r
561 /* This is the idle hook, so the current task handle should equal the
\r
562 returned idle task handle. */
\r
563 if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle )
\r
565 pcStatusMessage = "Error: Returned idle task handle was incorrect";
\r
568 /* Check the same handle is obtained using the idle task's name. First try
\r
569 with the wrong name, then the right name. */
\r
570 if( xTaskGetHandle( "Idle" ) == xIdleTaskHandle )
\r
572 pcStatusMessage = "Error: Returned handle for name Idle was incorrect";
\r
575 if( xTaskGetHandle( "IDLE" ) != xIdleTaskHandle )
\r
577 pcStatusMessage = "Error: Returned handle for name Idle was incorrect";
\r
580 /* Check the timer task handle was returned correctly. */
\r
581 pcTaskName = pcTaskGetName( xTimerTaskHandle );
\r
582 if( strcmp( pcTaskName, "Tmr Svc" ) != 0 )
\r
584 pcStatusMessage = "Error: Returned timer task handle was incorrect";
\r
587 if( xTaskGetHandle( "Tmr Svc" ) != xTimerTaskHandle )
\r
589 pcStatusMessage = "Error: Returned handle for name Tmr Svc was incorrect";
\r
592 /* This task is running, make sure it's state is returned as running. */
\r
593 if( eTaskStateGet( xIdleTaskHandle ) != eRunning )
\r
595 pcStatusMessage = "Error: Returned idle task state was incorrect";
\r
598 /* If this task is running, then the timer task must be blocked. */
\r
599 if( eTaskStateGet( xTimerTaskHandle ) != eBlocked )
\r
601 pcStatusMessage = "Error: Returned timer task state was incorrect";
\r
604 /* Also with the vTaskGetInfo() function. */
\r
605 vTaskGetInfo( xTimerTaskHandle, /* The task being queried. */
\r
606 &xTaskInfo, /* The structure into which information on the task will be written. */
\r
607 pdTRUE, /* Include the task's high watermark in the structure. */
\r
608 eInvalid ); /* Include the task state in the structure. */
\r
610 /* Check the information returned by vTaskGetInfo() is as expected. */
\r
611 if( ( xTaskInfo.eCurrentState != eBlocked ) ||
\r
612 ( strcmp( xTaskInfo.pcTaskName, "Tmr Svc" ) != 0 ) ||
\r
613 ( xTaskInfo.uxCurrentPriority != configTIMER_TASK_PRIORITY ) ||
\r
614 ( xTaskInfo.xHandle != xTimerTaskHandle ) )
\r
616 pcStatusMessage = "Error: vTaskGetInfo() returned incorrect information about the timer task";
\r
619 /* Other tests that should only be performed once follow. The test task
\r
620 is not created on each iteration because to do so would cause the death
\r
621 task to report an error (too many tasks running). */
\r
622 if( xPerformedOneShotTests == pdFALSE )
\r
624 /* Don't run this part of the test again. */
\r
625 xPerformedOneShotTests = pdTRUE;
\r
627 /* Create a test task to use to test other eTaskStateGet() return values. */
\r
628 if( xTaskCreate( prvTestTask, "Test", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTestTask ) == pdPASS )
\r
630 /* If this task is running, the test task must be in the ready state. */
\r
631 if( eTaskStateGet( xTestTask ) != eReady )
\r
633 pcStatusMessage = "Error: Returned test task state was incorrect 1";
\r
636 /* Now suspend the test task and check its state is reported correctly. */
\r
637 vTaskSuspend( xTestTask );
\r
638 if( eTaskStateGet( xTestTask ) != eSuspended )
\r
640 pcStatusMessage = "Error: Returned test task state was incorrect 2";
\r
643 /* Now delete the task and check its state is reported correctly. */
\r
644 vTaskDelete( xTestTask );
\r
645 if( eTaskStateGet( xTestTask ) != eDeleted )
\r
647 pcStatusMessage = "Error: Returned test task state was incorrect 3";
\r
652 /*-----------------------------------------------------------*/
\r
654 static void prvDemoQueueSpaceFunctions( void *pvParameters )
\r
656 QueueHandle_t xQueue = NULL;
\r
657 const unsigned portBASE_TYPE uxQueueLength = 10;
\r
658 unsigned portBASE_TYPE uxReturn, x;
\r
660 /* Remove compiler warnings. */
\r
661 ( void ) pvParameters;
\r
663 /* Create the queue that will be used. Nothing is actually going to be
\r
664 sent or received so the queue item size is set to 0. */
\r
665 xQueue = xQueueCreate( uxQueueLength, 0 );
\r
666 configASSERT( xQueue );
\r
670 for( x = 0; x < uxQueueLength; x++ )
\r
672 /* Ask how many messages are available... */
\r
673 uxReturn = uxQueueMessagesWaiting( xQueue );
\r
675 /* Check the number of messages being reported as being available
\r
676 is as expected, and force an assert if not. */
\r
677 if( uxReturn != x )
\r
679 /* xQueue cannot be NULL so this is deliberately causing an
\r
680 assert to be triggered as there is an error. */
\r
681 configASSERT( xQueue == NULL );
\r
684 /* Ask how many spaces remain in the queue... */
\r
685 uxReturn = uxQueueSpacesAvailable( xQueue );
\r
687 /* Check the number of spaces being reported as being available
\r
688 is as expected, and force an assert if not. */
\r
689 if( uxReturn != ( uxQueueLength - x ) )
\r
691 /* xQueue cannot be NULL so this is deliberately causing an
\r
692 assert to be triggered as there is an error. */
\r
693 configASSERT( xQueue == NULL );
\r
696 /* Fill one more space in the queue. */
\r
697 xQueueSendToBack( xQueue, NULL, 0 );
\r
700 /* Perform the same check while the queue is full. */
\r
701 uxReturn = uxQueueMessagesWaiting( xQueue );
\r
702 if( uxReturn != uxQueueLength )
\r
704 configASSERT( xQueue == NULL );
\r
707 uxReturn = uxQueueSpacesAvailable( xQueue );
\r
709 if( uxReturn != 0 )
\r
711 configASSERT( xQueue == NULL );
\r
714 /* The queue is full, start again. */
\r
715 xQueueReset( xQueue );
\r
717 #if( configUSE_PREEMPTION == 0 )
\r
722 /*-----------------------------------------------------------*/
\r
724 static void prvPermanentlyBlockingSemaphoreTask( void *pvParameters )
\r
726 SemaphoreHandle_t xSemaphore;
\r
728 /* Prevent compiler warning about unused parameter in the case that
\r
729 configASSERT() is not defined. */
\r
730 ( void ) pvParameters;
\r
732 /* This task should block on a semaphore, and never return. */
\r
733 xSemaphore = xSemaphoreCreateBinary();
\r
734 configASSERT( xSemaphore );
\r
736 xSemaphoreTake( xSemaphore, portMAX_DELAY );
\r
738 /* The above xSemaphoreTake() call should never return, force an assert if
\r
740 configASSERT( pvParameters != NULL );
\r
741 vTaskDelete( NULL );
\r
743 /*-----------------------------------------------------------*/
\r
745 static void prvPermanentlyBlockingNotificationTask( void *pvParameters )
\r
747 /* Prevent compiler warning about unused parameter in the case that
\r
748 configASSERT() is not defined. */
\r
749 ( void ) pvParameters;
\r
751 /* This task should block on a task notification, and never return. */
\r
752 ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
\r
754 /* The above ulTaskNotifyTake() call should never return, force an assert
\r
756 configASSERT( pvParameters != NULL );
\r
757 vTaskDelete( NULL );
\r