2 * FreeRTOS Kernel V10.0.0
\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. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
30 *******************************************************************************
\r
31 * NOTE 1: The Win32 port is a simulation (or is that emulation?) only! Do not
\r
32 * expect to get real time behaviour from the Win32 port or this demo
\r
33 * application. It is provided as a convenient development and demonstration
\r
36 * Windows will not be running the FreeRTOS simulator threads continuously, so
\r
37 * the timing information in the FreeRTOS+Trace logs have no meaningful units.
\r
38 * See the documentation page for the Windows simulator for an explanation of
\r
40 * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html
\r
41 * - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT -
\r
43 * NOTE 2: This project provides two demo applications. A simple blinky style
\r
44 * project, and a more comprehensive test and demo application. The
\r
45 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
46 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
47 * in main.c. This file implements the comprehensive test and demo version.
\r
49 * NOTE 3: This file only contains the source code that is specific to the
\r
50 * basic demo. Generic functions, such FreeRTOS hook functions, are defined in
\r
52 *******************************************************************************
\r
54 * main() creates all the demo application tasks, then starts the scheduler.
\r
55 * The web documentation provides more details of the standard demo application
\r
56 * tasks, which provide no particular functionality but do provide a good
\r
57 * example of how to use the FreeRTOS API.
\r
59 * In addition to the standard demo tasks, the following tasks and tests are
\r
60 * defined and/or created within this file:
\r
62 * "Check" task - This only executes every five seconds but has a high priority
\r
63 * to ensure it gets processor time. Its main function is to check that all the
\r
64 * standard demo tasks are still operational. While no errors have been
\r
65 * discovered the check task will print out "OK" and the current simulated tick
\r
66 * time. If an error is discovered in the execution of a task then the check
\r
67 * task will print out an appropriate error message.
\r
72 /* Standard includes. */
\r
76 /* Kernel includes. */
\r
77 #include <FreeRTOS.h>
\r
83 /* Standard demo includes. */
\r
85 #include "integer.h"
\r
86 #include "semtest.h"
\r
88 #include "GenQTest.h"
\r
90 #include "recmutex.h"
\r
92 #include "TimerDemo.h"
\r
93 #include "countsem.h"
\r
95 #include "dynamic.h"
\r
96 #include "QueueSet.h"
\r
97 #include "QueueOverwrite.h"
\r
98 #include "EventGroupsDemo.h"
\r
99 #include "IntSemTest.h"
\r
100 #include "TaskNotify.h"
\r
101 #include "QueueSetPolling.h"
\r
102 #include "blocktim.h"
\r
103 #include "AbortDelay.h"
\r
104 #include "MessageBufferDemo.h"
\r
105 #include "StreamBufferDemo.h"
\r
107 /* Priorities at which the tasks are created. */
\r
108 #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
\r
109 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
110 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
111 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
112 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
113 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
114 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
115 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
116 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
117 #define mainQUEUE_OVERWRITE_PRIORITY ( tskIDLE_PRIORITY )
\r
119 #define mainTIMER_TEST_PERIOD ( 50 )
\r
121 /* Task function prototypes. */
\r
122 static void prvCheckTask( void *pvParameters );
\r
124 /* A task that is created from the idle task to test the functionality of
\r
125 eTaskStateGet(). */
\r
126 static void prvTestTask( void *pvParameters );
\r
129 * Called from the idle task hook function to demonstrate a few utility
\r
130 * functions that are not demonstrated by any of the standard demo tasks.
\r
132 static void prvDemonstrateTaskStateAndHandleGetFunctions( void );
\r
135 * Called from the idle task hook function to demonstrate the use of
\r
136 * xTimerPendFunctionCall() as xTimerPendFunctionCall() is not demonstrated by
\r
137 * any of the standard demo tasks.
\r
139 static void prvDemonstratePendingFunctionCall( void );
\r
142 * The function that is pended by prvDemonstratePendingFunctionCall().
\r
144 static void prvPendedFunction( void *pvParameter1, uint32_t ulParameter2 );
\r
147 * prvDemonstrateTimerQueryFunctions() is called from the idle task hook
\r
148 * function to demonstrate the use of functions that query information about a
\r
149 * software timer. prvTestTimerCallback() is the callback function for the
\r
150 * timer being queried.
\r
152 static void prvDemonstrateTimerQueryFunctions( void );
\r
153 static void prvTestTimerCallback( TimerHandle_t xTimer );
\r
156 * A task to demonstrate the use of the xQueueSpacesAvailable() function.
\r
158 static void prvDemoQueueSpaceFunctions( void *pvParameters );
\r
161 * Tasks that ensure indefinite delays are truly indefinite.
\r
163 static void prvPermanentlyBlockingSemaphoreTask( void *pvParameters );
\r
164 static void prvPermanentlyBlockingNotificationTask( void *pvParameters );
\r
166 /*-----------------------------------------------------------*/
\r
168 /* The variable into which error messages are latched. */
\r
169 static char *pcStatusMessage = "No errors";
\r
171 /* This semaphore is created purely to test using the vSemaphoreDelete() and
\r
172 semaphore tracing API functions. It has no other purpose. */
\r
173 static SemaphoreHandle_t xMutexToDelete = NULL;
\r
175 /*-----------------------------------------------------------*/
\r
177 int main_full( void )
\r
179 /* Start the check task as described at the top of this file. */
\r
180 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
182 /* Create the standard demo tasks. */
\r
183 vStartTaskNotifyTask();
\r
184 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
185 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
186 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
187 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
188 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
189 vStartQueuePeekTasks();
\r
190 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
191 vStartRecursiveMutexTasks();
\r
192 vStartCountingSemaphoreTasks();
\r
193 vStartDynamicPriorityTasks();
\r
194 vStartQueueSetTasks();
\r
195 vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY );
\r
196 xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
197 vStartEventGroupTasks();
\r
198 vStartInterruptSemaphoreTasks();
\r
199 vStartQueueSetPollingTask();
\r
200 vCreateBlockTimeTasks();
\r
201 vCreateAbortDelayTasks();
\r
202 xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
203 xTaskCreate( prvPermanentlyBlockingSemaphoreTask, "BlockSem", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
204 xTaskCreate( prvPermanentlyBlockingNotificationTask, "BlockNoti", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
206 vStartMessageBufferTasks();
\r
207 vStartStreamBufferTasks();
\r
209 #if( configUSE_PREEMPTION != 0 )
\r
211 /* Don't expect these tasks to pass when preemption is not used. */
\r
212 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
216 /* The suicide tasks must be created last as they need to know how many
\r
217 tasks were running prior to their creation. This then allows them to
\r
218 ascertain whether or not the correct/expected number of tasks are running at
\r
220 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
222 /* Create the semaphore that will be deleted in the idle task hook. This
\r
223 is done purely to test the use of vSemaphoreDelete(). */
\r
224 xMutexToDelete = xSemaphoreCreateMutex();
\r
226 /* Start the scheduler itself. */
\r
227 vTaskStartScheduler();
\r
229 /* Should never get here unless there was not enough heap space to create
\r
230 the idle and other system tasks. */
\r
233 /*-----------------------------------------------------------*/
\r
235 static void prvCheckTask( void *pvParameters )
\r
237 TickType_t xNextWakeTime;
\r
238 const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL );
\r
240 /* Just to remove compiler warning. */
\r
241 ( void ) pvParameters;
\r
243 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
244 xNextWakeTime = xTaskGetTickCount();
\r
248 /* Place this task in the blocked state until it is time to run again. */
\r
249 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );
\r
251 /* Check the standard demo tasks are running without error. */
\r
252 #if( configUSE_PREEMPTION != 0 )
\r
254 /* These tasks are only created when preemption is used. */
\r
255 if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )
\r
257 pcStatusMessage = "Error: TimerDemo";
\r
262 if( xAreStreamBufferTasksStillRunning() != pdTRUE )
\r
264 pcStatusMessage = "Error: StreamBuffer";
\r
266 else if( xAreMessageBufferTasksStillRunning() != pdTRUE )
\r
268 pcStatusMessage = "Error: MessageBuffer";
\r
270 else if( xAreTaskNotificationTasksStillRunning() != pdTRUE )
\r
272 pcStatusMessage = "Error: Notification";
\r
274 else if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )
\r
276 pcStatusMessage = "Error: IntSem";
\r
278 else if( xAreEventGroupTasksStillRunning() != pdTRUE )
\r
280 pcStatusMessage = "Error: EventGroup";
\r
282 else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
284 pcStatusMessage = "Error: IntMath";
\r
286 else if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
288 pcStatusMessage = "Error: GenQueue";
\r
290 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
292 pcStatusMessage = "Error: QueuePeek";
\r
294 else if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
296 pcStatusMessage = "Error: BlockQueue";
\r
298 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
300 pcStatusMessage = "Error: SemTest";
\r
302 else if( xArePollingQueuesStillRunning() != pdTRUE )
\r
304 pcStatusMessage = "Error: PollQueue";
\r
306 else if( xAreMathsTaskStillRunning() != pdPASS )
\r
308 pcStatusMessage = "Error: Flop";
\r
310 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
312 pcStatusMessage = "Error: RecMutex";
\r
314 else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
316 pcStatusMessage = "Error: CountSem";
\r
318 else if( xIsCreateTaskStillRunning() != pdTRUE )
\r
320 pcStatusMessage = "Error: Death";
\r
322 else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )
\r
324 pcStatusMessage = "Error: Dynamic";
\r
326 else if( xAreQueueSetTasksStillRunning() != pdPASS )
\r
328 pcStatusMessage = "Error: Queue set";
\r
330 else if( xIsQueueOverwriteTaskStillRunning() != pdPASS )
\r
332 pcStatusMessage = "Error: Queue overwrite";
\r
334 else if( xAreQueueSetPollTasksStillRunning() != pdPASS )
\r
336 pcStatusMessage = "Error: Queue set polling";
\r
338 else if( xAreBlockTimeTestTasksStillRunning() != pdPASS )
\r
340 pcStatusMessage = "Error: Block time";
\r
342 else if( xAreAbortDelayTestTasksStillRunning() != pdPASS )
\r
344 pcStatusMessage = "Error: Abort delay";
\r
347 /* This is the only task that uses stdout so its ok to call printf()
\r
349 printf( ( char * ) "%s - %u\r\n", pcStatusMessage, ( unsigned int ) xTaskGetTickCount() );
\r
353 /*-----------------------------------------------------------*/
\r
355 static void prvTestTask( void *pvParameters )
\r
357 const unsigned long ulMSToSleep = 5;
\r
359 /* Just to remove compiler warnings. */
\r
360 ( void ) pvParameters;
\r
362 /* This task is just used to test the eTaskStateGet() function. It
\r
363 does not have anything to do. */
\r
366 /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are
\r
367 tasks waiting to be terminated by the idle task. */
\r
368 Sleep( ulMSToSleep );
\r
371 /*-----------------------------------------------------------*/
\r
373 /* Called from vApplicationIdleHook(), which is defined in main.c. */
\r
374 void vFullDemoIdleFunction( void )
\r
376 const unsigned long ulMSToSleep = 15;
\r
379 /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are
\r
380 tasks waiting to be terminated by the idle task. */
\r
381 Sleep( ulMSToSleep );
\r
383 /* Demonstrate a few utility functions that are not demonstrated by any of
\r
384 the standard demo tasks. */
\r
385 prvDemonstrateTaskStateAndHandleGetFunctions();
\r
387 /* Demonstrate the use of xTimerPendFunctionCall(), which is not
\r
388 demonstrated by any of the standard demo tasks. */
\r
389 prvDemonstratePendingFunctionCall();
\r
391 /* Demonstrate the use of functions that query information about a software
\r
393 prvDemonstrateTimerQueryFunctions();
\r
396 /* If xMutexToDelete has not already been deleted, then delete it now.
\r
397 This is done purely to demonstrate the use of, and test, the
\r
398 vSemaphoreDelete() macro. Care must be taken not to delete a semaphore
\r
399 that has tasks blocked on it. */
\r
400 if( xMutexToDelete != NULL )
\r
402 /* For test purposes, add the mutex to the registry, then remove it
\r
403 again, before it is deleted - checking its name is as expected before
\r
404 and after the assertion into the registry and its removal from the
\r
406 configASSERT( pcQueueGetName( xMutexToDelete ) == NULL );
\r
407 vQueueAddToRegistry( xMutexToDelete, "Test_Mutex" );
\r
408 configASSERT( strcmp( pcQueueGetName( xMutexToDelete ), "Test_Mutex" ) == 0 );
\r
409 vQueueUnregisterQueue( xMutexToDelete );
\r
410 configASSERT( pcQueueGetName( xMutexToDelete ) == NULL );
\r
412 vSemaphoreDelete( xMutexToDelete );
\r
413 xMutexToDelete = NULL;
\r
416 /* Exercise heap_5 a bit. The malloc failed hook will trap failed
\r
417 allocations so there is no need to test here. */
\r
418 pvAllocated = pvPortMalloc( ( rand() % 500 ) + 1 );
\r
419 vPortFree( pvAllocated );
\r
421 /*-----------------------------------------------------------*/
\r
423 /* Called by vApplicationTickHook(), which is defined in main.c. */
\r
424 void vFullDemoTickHookFunction( void )
\r
426 TaskHandle_t xTimerTask;
\r
428 /* Call the periodic timer test, which tests the timer API functions that
\r
429 can be called from an ISR. */
\r
430 #if( configUSE_PREEMPTION != 0 )
\r
432 /* Only created when preemption is used. */
\r
433 vTimerPeriodicISRTests();
\r
437 /* Call the periodic queue overwrite from ISR demo. */
\r
438 vQueueOverwritePeriodicISRDemo();
\r
440 /* Write to a queue that is in use as part of the queue set demo to
\r
441 demonstrate using queue sets from an ISR. */
\r
442 vQueueSetAccessQueueSetFromISR();
\r
443 vQueueSetPollingInterruptAccess();
\r
445 /* Exercise event groups from interrupts. */
\r
446 vPeriodicEventGroupsProcessing();
\r
448 /* Exercise giving mutexes from an interrupt. */
\r
449 vInterruptSemaphorePeriodicTest();
\r
451 /* Exercise using task notifications from an interrupt. */
\r
452 xNotifyTaskFromISR();
\r
454 /* Writes to stream buffer byte by byte to test the stream buffer trigger
\r
455 level functionality. */
\r
456 vPeriodicStreamBufferProcessing();
\r
458 /* For code coverage purposes. */
\r
459 xTimerTask = xTimerGetTimerDaemonTaskHandle();
\r
460 configASSERT( uxTaskPriorityGetFromISR( xTimerTask ) == configTIMER_TASK_PRIORITY );
\r
461 ( void ) xTimerTask; /* In case configASSERT() is not defined. */
\r
463 /*-----------------------------------------------------------*/
\r
465 static void prvPendedFunction( void *pvParameter1, uint32_t ulParameter2 )
\r
467 static uint32_t ulLastParameter1 = 1000UL, ulLastParameter2 = 0UL;
\r
468 uint32_t ulParameter1;
\r
470 ulParameter1 = ( uint32_t ) pvParameter1;
\r
472 /* Ensure the parameters are as expected. */
\r
473 configASSERT( ulParameter1 == ( ulLastParameter1 + 1 ) );
\r
474 configASSERT( ulParameter2 == ( ulLastParameter2 + 1 ) );
\r
476 /* Remember the parameters for the next time the function is called. */
\r
477 ulLastParameter1 = ulParameter1;
\r
478 ulLastParameter2 = ulParameter2;
\r
480 /* Remove compiler warnings in case configASSERT() is not defined. */
\r
481 ( void ) ulLastParameter1;
\r
482 ( void ) ulLastParameter2;
\r
484 /*-----------------------------------------------------------*/
\r
486 static void prvTestTimerCallback( TimerHandle_t xTimer )
\r
488 /* This is the callback function for the timer accessed by
\r
489 prvDemonstrateTimerQueryFunctions(). The callback does not do anything. */
\r
492 /*-----------------------------------------------------------*/
\r
494 static void prvDemonstrateTimerQueryFunctions( void )
\r
496 static TimerHandle_t xTimer = NULL;
\r
497 const char *pcTimerName = "TestTimer";
\r
498 volatile TickType_t xExpiryTime;
\r
499 const TickType_t xDontBlock = 0;
\r
501 if( xTimer == NULL )
\r
503 xTimer = xTimerCreate( pcTimerName, portMAX_DELAY, pdTRUE, NULL, prvTestTimerCallback );
\r
505 if( xTimer != NULL )
\r
507 /* Called from the idle task so a block time must not be
\r
509 xTimerStart( xTimer, xDontBlock );
\r
513 if( xTimer != NULL )
\r
515 /* Demonstrate querying a timer's name. */
\r
516 configASSERT( strcmp( pcTimerGetName( xTimer ), pcTimerName ) == 0 );
\r
518 /* Demonstrate querying a timer's period. */
\r
519 configASSERT( xTimerGetPeriod( xTimer ) == portMAX_DELAY );
\r
521 /* Demonstrate querying a timer's next expiry time, although nothing is
\r
522 done with the returned value. Note if the expiry time is less than the
\r
523 maximum tick count then the expiry time has overflowed from the current
\r
524 time. In this case the expiry time was set to portMAX_DELAY, so it is
\r
525 expected to be less than the current time until the current time has
\r
526 itself overflowed. */
\r
527 xExpiryTime = xTimerGetExpiryTime( xTimer );
\r
528 ( void ) xExpiryTime;
\r
531 /*-----------------------------------------------------------*/
\r
533 static void prvDemonstratePendingFunctionCall( void )
\r
535 static uint32_t ulParameter1 = 1000UL, ulParameter2 = 0UL;
\r
536 const TickType_t xDontBlock = 0; /* This is called from the idle task so must *not* attempt to block. */
\r
538 /* prvPendedFunction() just expects the parameters to be incremented by one
\r
539 each time it is called. */
\r
543 /* Pend the function call, sending the parameters. */
\r
544 xTimerPendFunctionCall( prvPendedFunction, ( void * ) ulParameter1, ulParameter2, xDontBlock );
\r
546 /*-----------------------------------------------------------*/
\r
548 static void prvDemonstrateTaskStateAndHandleGetFunctions( void )
\r
550 TaskHandle_t xIdleTaskHandle, xTimerTaskHandle;
\r
552 static portBASE_TYPE xPerformedOneShotTests = pdFALSE;
\r
553 TaskHandle_t xTestTask;
\r
554 TaskStatus_t xTaskInfo;
\r
556 /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and
\r
557 xTaskGetIdleTaskHandle() functions. Also try using the function that sets
\r
558 the task number. */
\r
559 xIdleTaskHandle = xTaskGetIdleTaskHandle();
\r
560 xTimerTaskHandle = xTimerGetTimerDaemonTaskHandle();
\r
562 /* This is the idle hook, so the current task handle should equal the
\r
563 returned idle task handle. */
\r
564 if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle )
\r
566 pcStatusMessage = "Error: Returned idle task handle was incorrect";
\r
569 /* Check the same handle is obtained using the idle task's name. First try
\r
570 with the wrong name, then the right name. */
\r
571 if( xTaskGetHandle( "Idle" ) == xIdleTaskHandle )
\r
573 pcStatusMessage = "Error: Returned handle for name Idle was incorrect";
\r
576 if( xTaskGetHandle( "IDLE" ) != xIdleTaskHandle )
\r
578 pcStatusMessage = "Error: Returned handle for name Idle was incorrect";
\r
581 /* Check the timer task handle was returned correctly. */
\r
582 pcTaskName = pcTaskGetName( xTimerTaskHandle );
\r
583 if( strcmp( pcTaskName, "Tmr Svc" ) != 0 )
\r
585 pcStatusMessage = "Error: Returned timer task handle was incorrect";
\r
588 if( xTaskGetHandle( "Tmr Svc" ) != xTimerTaskHandle )
\r
590 pcStatusMessage = "Error: Returned handle for name Tmr Svc was incorrect";
\r
593 /* This task is running, make sure it's state is returned as running. */
\r
594 if( eTaskStateGet( xIdleTaskHandle ) != eRunning )
\r
596 pcStatusMessage = "Error: Returned idle task state was incorrect";
\r
599 /* If this task is running, then the timer task must be blocked. */
\r
600 if( eTaskStateGet( xTimerTaskHandle ) != eBlocked )
\r
602 pcStatusMessage = "Error: Returned timer task state was incorrect";
\r
605 /* Also with the vTaskGetInfo() function. */
\r
606 vTaskGetInfo( xTimerTaskHandle, /* The task being queried. */
\r
607 &xTaskInfo, /* The structure into which information on the task will be written. */
\r
608 pdTRUE, /* Include the task's high watermark in the structure. */
\r
609 eInvalid ); /* Include the task state in the structure. */
\r
611 /* Check the information returned by vTaskGetInfo() is as expected. */
\r
612 if( ( xTaskInfo.eCurrentState != eBlocked ) ||
\r
613 ( strcmp( xTaskInfo.pcTaskName, "Tmr Svc" ) != 0 ) ||
\r
614 ( xTaskInfo.uxCurrentPriority != configTIMER_TASK_PRIORITY ) ||
\r
615 ( xTaskInfo.xHandle != xTimerTaskHandle ) )
\r
617 pcStatusMessage = "Error: vTaskGetInfo() returned incorrect information about the timer task";
\r
620 /* Other tests that should only be performed once follow. The test task
\r
621 is not created on each iteration because to do so would cause the death
\r
622 task to report an error (too many tasks running). */
\r
623 if( xPerformedOneShotTests == pdFALSE )
\r
625 /* Don't run this part of the test again. */
\r
626 xPerformedOneShotTests = pdTRUE;
\r
628 /* Create a test task to use to test other eTaskStateGet() return values. */
\r
629 if( xTaskCreate( prvTestTask, "Test", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTestTask ) == pdPASS )
\r
631 /* If this task is running, the test task must be in the ready state. */
\r
632 if( eTaskStateGet( xTestTask ) != eReady )
\r
634 pcStatusMessage = "Error: Returned test task state was incorrect 1";
\r
637 /* Now suspend the test task and check its state is reported correctly. */
\r
638 vTaskSuspend( xTestTask );
\r
639 if( eTaskStateGet( xTestTask ) != eSuspended )
\r
641 pcStatusMessage = "Error: Returned test task state was incorrect 2";
\r
644 /* Now delete the task and check its state is reported correctly. */
\r
645 vTaskDelete( xTestTask );
\r
646 if( eTaskStateGet( xTestTask ) != eDeleted )
\r
648 pcStatusMessage = "Error: Returned test task state was incorrect 3";
\r
653 /*-----------------------------------------------------------*/
\r
655 static void prvDemoQueueSpaceFunctions( void *pvParameters )
\r
657 QueueHandle_t xQueue = NULL;
\r
658 const unsigned portBASE_TYPE uxQueueLength = 10;
\r
659 unsigned portBASE_TYPE uxReturn, x;
\r
661 /* Remove compiler warnings. */
\r
662 ( void ) pvParameters;
\r
664 /* Create the queue that will be used. Nothing is actually going to be
\r
665 sent or received so the queue item size is set to 0. */
\r
666 xQueue = xQueueCreate( uxQueueLength, 0 );
\r
667 configASSERT( xQueue );
\r
671 for( x = 0; x < uxQueueLength; x++ )
\r
673 /* Ask how many messages are available... */
\r
674 uxReturn = uxQueueMessagesWaiting( xQueue );
\r
676 /* Check the number of messages being reported as being available
\r
677 is as expected, and force an assert if not. */
\r
678 if( uxReturn != x )
\r
680 /* xQueue cannot be NULL so this is deliberately causing an
\r
681 assert to be triggered as there is an error. */
\r
682 configASSERT( xQueue == NULL );
\r
685 /* Ask how many spaces remain in the queue... */
\r
686 uxReturn = uxQueueSpacesAvailable( xQueue );
\r
688 /* Check the number of spaces being reported as being available
\r
689 is as expected, and force an assert if not. */
\r
690 if( uxReturn != ( uxQueueLength - x ) )
\r
692 /* xQueue cannot be NULL so this is deliberately causing an
\r
693 assert to be triggered as there is an error. */
\r
694 configASSERT( xQueue == NULL );
\r
697 /* Fill one more space in the queue. */
\r
698 xQueueSendToBack( xQueue, NULL, 0 );
\r
701 /* Perform the same check while the queue is full. */
\r
702 uxReturn = uxQueueMessagesWaiting( xQueue );
\r
703 if( uxReturn != uxQueueLength )
\r
705 configASSERT( xQueue == NULL );
\r
708 uxReturn = uxQueueSpacesAvailable( xQueue );
\r
710 if( uxReturn != 0 )
\r
712 configASSERT( xQueue == NULL );
\r
715 /* The queue is full, start again. */
\r
716 xQueueReset( xQueue );
\r
718 #if( configUSE_PREEMPTION == 0 )
\r
723 /*-----------------------------------------------------------*/
\r
725 static void prvPermanentlyBlockingSemaphoreTask( void *pvParameters )
\r
727 SemaphoreHandle_t xSemaphore;
\r
729 /* Prevent compiler warning about unused parameter in the case that
\r
730 configASSERT() is not defined. */
\r
731 ( void ) pvParameters;
\r
733 /* This task should block on a semaphore, and never return. */
\r
734 xSemaphore = xSemaphoreCreateBinary();
\r
735 configASSERT( xSemaphore );
\r
737 xSemaphoreTake( xSemaphore, portMAX_DELAY );
\r
739 /* The above xSemaphoreTake() call should never return, force an assert if
\r
741 configASSERT( pvParameters != NULL );
\r
742 vTaskDelete( NULL );
\r
744 /*-----------------------------------------------------------*/
\r
746 static void prvPermanentlyBlockingNotificationTask( void *pvParameters )
\r
748 /* Prevent compiler warning about unused parameter in the case that
\r
749 configASSERT() is not defined. */
\r
750 ( void ) pvParameters;
\r
752 /* This task should block on a task notification, and never return. */
\r
753 ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
\r
755 /* The above ulTaskNotifyTake() call should never return, force an assert
\r
757 configASSERT( pvParameters != NULL );
\r
758 vTaskDelete( NULL );
\r