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 "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
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
121 #define mainTIMER_TEST_PERIOD ( 50 )
\r
123 /* Task function prototypes. */
\r
124 static void prvCheckTask( void *pvParameters );
\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
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
134 static void prvDemonstrateTaskStateAndHandleGetFunctions( void );
\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
141 static void prvDemonstratePendingFunctionCall( void );
\r
144 * The function that is pended by prvDemonstratePendingFunctionCall().
\r
146 static void prvPendedFunction( void *pvParameter1, uint32_t ulParameter2 );
\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
154 static void prvDemonstrateTimerQueryFunctions( void );
\r
155 static void prvTestTimerCallback( TimerHandle_t xTimer );
\r
158 * A task to demonstrate the use of the xQueueSpacesAvailable() function.
\r
160 static void prvDemoQueueSpaceFunctions( void *pvParameters );
\r
163 * Tasks that ensure indefinite delays are truly indefinite.
\r
165 static void prvPermanentlyBlockingSemaphoreTask( void *pvParameters );
\r
166 static void prvPermanentlyBlockingNotificationTask( void *pvParameters );
\r
168 /*-----------------------------------------------------------*/
\r
170 /* The variable into which error messages are latched. */
\r
171 static char *pcStatusMessage = "No errors";
\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
177 /*-----------------------------------------------------------*/
\r
179 int main_full( void )
\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
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 vStartQueueSetTasks();
\r
197 vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY );
\r
198 xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
199 vStartEventGroupTasks();
\r
200 vStartInterruptSemaphoreTasks();
\r
201 vStartQueueSetPollingTask();
\r
202 vCreateBlockTimeTasks();
\r
203 vCreateAbortDelayTasks();
\r
204 xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
205 xTaskCreate( prvPermanentlyBlockingSemaphoreTask, "BlockSem", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
206 xTaskCreate( prvPermanentlyBlockingNotificationTask, "BlockNoti", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
208 vStartMessageBufferTasks();
\r
209 vStartStreamBufferTasks();
\r
210 vStartStreamBufferInterruptDemo();
\r
211 vStartMessageBufferAMPTasks();
\r
213 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
\r
215 vStartStaticallyAllocatedTasks();
\r
219 #if( configUSE_PREEMPTION != 0 )
\r
221 /* Don't expect these tasks to pass when preemption is not used. */
\r
222 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
226 /* The suicide tasks must be created last as they need to know how many
\r
227 tasks were running prior to their creation. This then allows them to
\r
228 ascertain whether or not the correct/expected number of tasks are running at
\r
230 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
232 /* Create the semaphore that will be deleted in the idle task hook. This
\r
233 is done purely to test the use of vSemaphoreDelete(). */
\r
234 xMutexToDelete = xSemaphoreCreateMutex();
\r
236 /* Start the scheduler itself. */
\r
237 vTaskStartScheduler();
\r
239 /* Should never get here unless there was not enough heap space to create
\r
240 the idle and other system tasks. */
\r
243 /*-----------------------------------------------------------*/
\r
245 static void prvCheckTask( void *pvParameters )
\r
247 TickType_t xNextWakeTime;
\r
248 const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL );
\r
250 /* Just to remove compiler warning. */
\r
251 ( void ) pvParameters;
\r
253 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
254 xNextWakeTime = xTaskGetTickCount();
\r
258 /* Place this task in the blocked state until it is time to run again. */
\r
259 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );
\r
261 /* Check the standard demo tasks are running without error. */
\r
262 #if( configUSE_PREEMPTION != 0 )
\r
264 /* These tasks are only created when preemption is used. */
\r
265 if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )
\r
267 pcStatusMessage = "Error: TimerDemo";
\r
272 if( xAreStreamBufferTasksStillRunning() != pdTRUE )
\r
274 pcStatusMessage = "Error: StreamBuffer";
\r
276 else if( xAreMessageBufferTasksStillRunning() != pdTRUE )
\r
278 pcStatusMessage = "Error: MessageBuffer";
\r
280 else if( xAreTaskNotificationTasksStillRunning() != pdTRUE )
\r
282 pcStatusMessage = "Error: Notification";
\r
284 else if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )
\r
286 pcStatusMessage = "Error: IntSem";
\r
288 else if( xAreEventGroupTasksStillRunning() != pdTRUE )
\r
290 pcStatusMessage = "Error: EventGroup";
\r
292 else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
294 pcStatusMessage = "Error: IntMath";
\r
296 else if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
298 pcStatusMessage = "Error: GenQueue";
\r
300 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
302 pcStatusMessage = "Error: QueuePeek";
\r
304 else if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
306 pcStatusMessage = "Error: BlockQueue";
\r
308 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
310 pcStatusMessage = "Error: SemTest";
\r
312 else if( xArePollingQueuesStillRunning() != pdTRUE )
\r
314 pcStatusMessage = "Error: PollQueue";
\r
316 else if( xAreMathsTaskStillRunning() != pdPASS )
\r
318 pcStatusMessage = "Error: Flop";
\r
320 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
322 pcStatusMessage = "Error: RecMutex";
\r
324 else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
326 pcStatusMessage = "Error: CountSem";
\r
328 else if( xIsCreateTaskStillRunning() != pdTRUE )
\r
330 pcStatusMessage = "Error: Death";
\r
332 else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )
\r
334 pcStatusMessage = "Error: Dynamic";
\r
336 else if( xAreQueueSetTasksStillRunning() != pdPASS )
\r
338 pcStatusMessage = "Error: Queue set";
\r
340 else if( xIsQueueOverwriteTaskStillRunning() != pdPASS )
\r
342 pcStatusMessage = "Error: Queue overwrite";
\r
344 else if( xAreQueueSetPollTasksStillRunning() != pdPASS )
\r
346 pcStatusMessage = "Error: Queue set polling";
\r
348 else if( xAreBlockTimeTestTasksStillRunning() != pdPASS )
\r
350 pcStatusMessage = "Error: Block time";
\r
352 else if( xAreAbortDelayTestTasksStillRunning() != pdPASS )
\r
354 pcStatusMessage = "Error: Abort delay";
\r
356 else if( xIsInterruptStreamBufferDemoStillRunning() != pdPASS )
\r
358 pcStatusMessage = "Error: Stream buffer interrupt";
\r
360 else if( xAreMessageBufferAMPTasksStillRunning() != pdPASS )
\r
362 pcStatusMessage = "Error: Message buffer AMP";
\r
365 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
\r
366 else if( xAreStaticAllocationTasksStillRunning() != pdPASS )
\r
368 pcStatusMessage = "Error: Static allocation";
\r
370 #endif /* configSUPPORT_STATIC_ALLOCATION */
\r
372 /* This is the only task that uses stdout so its ok to call printf()
\r
374 printf( "%s - tick count %u - free heap %u - min free heap %u\r\n", pcStatusMessage,
\r
375 xTaskGetTickCount(),
\r
376 xPortGetFreeHeapSize(),
\r
377 xPortGetMinimumEverFreeHeapSize() );
\r
381 /*-----------------------------------------------------------*/
\r
383 static void prvTestTask( void *pvParameters )
\r
385 const unsigned long ulMSToSleep = 5;
\r
387 /* Just to remove compiler warnings. */
\r
388 ( void ) pvParameters;
\r
390 /* This task is just used to test the eTaskStateGet() function. It
\r
391 does not have anything to do. */
\r
394 /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are
\r
395 tasks waiting to be terminated by the idle task. */
\r
396 Sleep( ulMSToSleep );
\r
399 /*-----------------------------------------------------------*/
\r
401 /* Called from vApplicationIdleHook(), which is defined in main.c. */
\r
402 void vFullDemoIdleFunction( void )
\r
404 const unsigned long ulMSToSleep = 15;
\r
407 /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are
\r
408 tasks waiting to be terminated by the idle task. */
\r
409 Sleep( ulMSToSleep );
\r
411 /* Demonstrate a few utility functions that are not demonstrated by any of
\r
412 the standard demo tasks. */
\r
413 prvDemonstrateTaskStateAndHandleGetFunctions();
\r
415 /* Demonstrate the use of xTimerPendFunctionCall(), which is not
\r
416 demonstrated by any of the standard demo tasks. */
\r
417 prvDemonstratePendingFunctionCall();
\r
419 /* Demonstrate the use of functions that query information about a software
\r
421 prvDemonstrateTimerQueryFunctions();
\r
424 /* If xMutexToDelete has not already been deleted, then delete it now.
\r
425 This is done purely to demonstrate the use of, and test, the
\r
426 vSemaphoreDelete() macro. Care must be taken not to delete a semaphore
\r
427 that has tasks blocked on it. */
\r
428 if( xMutexToDelete != NULL )
\r
430 /* For test purposes, add the mutex to the registry, then remove it
\r
431 again, before it is deleted - checking its name is as expected before
\r
432 and after the assertion into the registry and its removal from the
\r
434 configASSERT( pcQueueGetName( xMutexToDelete ) == NULL );
\r
435 vQueueAddToRegistry( xMutexToDelete, "Test_Mutex" );
\r
436 configASSERT( strcmp( pcQueueGetName( xMutexToDelete ), "Test_Mutex" ) == 0 );
\r
437 vQueueUnregisterQueue( xMutexToDelete );
\r
438 configASSERT( pcQueueGetName( xMutexToDelete ) == NULL );
\r
440 vSemaphoreDelete( xMutexToDelete );
\r
441 xMutexToDelete = NULL;
\r
444 /* Exercise heap_5 a bit. The malloc failed hook will trap failed
\r
445 allocations so there is no need to test here. */
\r
446 pvAllocated = pvPortMalloc( ( rand() % 500 ) + 1 );
\r
447 vPortFree( pvAllocated );
\r
449 /*-----------------------------------------------------------*/
\r
451 /* Called by vApplicationTickHook(), which is defined in main.c. */
\r
452 void vFullDemoTickHookFunction( void )
\r
454 TaskHandle_t xTimerTask;
\r
456 /* Call the periodic timer test, which tests the timer API functions that
\r
457 can be called from an ISR. */
\r
458 #if( configUSE_PREEMPTION != 0 )
\r
460 /* Only created when preemption is used. */
\r
461 vTimerPeriodicISRTests();
\r
465 /* Call the periodic queue overwrite from ISR demo. */
\r
466 vQueueOverwritePeriodicISRDemo();
\r
468 /* Write to a queue that is in use as part of the queue set demo to
\r
469 demonstrate using queue sets from an ISR. */
\r
470 vQueueSetAccessQueueSetFromISR();
\r
471 vQueueSetPollingInterruptAccess();
\r
473 /* Exercise event groups from interrupts. */
\r
474 vPeriodicEventGroupsProcessing();
\r
476 /* Exercise giving mutexes from an interrupt. */
\r
477 vInterruptSemaphorePeriodicTest();
\r
479 /* Exercise using task notifications from an interrupt. */
\r
480 xNotifyTaskFromISR();
\r
482 /* Writes to stream buffer byte by byte to test the stream buffer trigger
\r
483 level functionality. */
\r
484 vPeriodicStreamBufferProcessing();
\r
486 /* Writes a string to a string buffer four bytes at a time to demonstrate
\r
487 a stream being sent from an interrupt to a task. */
\r
488 vBasicStreamBufferSendFromISR();
\r
490 /* For code coverage purposes. */
\r
491 xTimerTask = xTimerGetTimerDaemonTaskHandle();
\r
492 configASSERT( uxTaskPriorityGetFromISR( xTimerTask ) == configTIMER_TASK_PRIORITY );
\r
493 ( void ) xTimerTask; /* In case configASSERT() is not defined. */
\r
495 /*-----------------------------------------------------------*/
\r
497 static void prvPendedFunction( void *pvParameter1, uint32_t ulParameter2 )
\r
499 static uint32_t ulLastParameter1 = 1000UL, ulLastParameter2 = 0UL;
\r
500 uint32_t ulParameter1;
\r
502 ulParameter1 = ( uint32_t ) pvParameter1;
\r
504 /* Ensure the parameters are as expected. */
\r
505 configASSERT( ulParameter1 == ( ulLastParameter1 + 1 ) );
\r
506 configASSERT( ulParameter2 == ( ulLastParameter2 + 1 ) );
\r
508 /* Remember the parameters for the next time the function is called. */
\r
509 ulLastParameter1 = ulParameter1;
\r
510 ulLastParameter2 = ulParameter2;
\r
512 /* Remove compiler warnings in case configASSERT() is not defined. */
\r
513 ( void ) ulLastParameter1;
\r
514 ( void ) ulLastParameter2;
\r
516 /*-----------------------------------------------------------*/
\r
518 static void prvTestTimerCallback( TimerHandle_t xTimer )
\r
520 /* This is the callback function for the timer accessed by
\r
521 prvDemonstrateTimerQueryFunctions(). The callback does not do anything. */
\r
524 /*-----------------------------------------------------------*/
\r
526 static void prvDemonstrateTimerQueryFunctions( void )
\r
528 static TimerHandle_t xTimer = NULL;
\r
529 const char *pcTimerName = "TestTimer";
\r
530 volatile TickType_t xExpiryTime;
\r
531 const TickType_t xDontBlock = 0;
\r
533 if( xTimer == NULL )
\r
535 xTimer = xTimerCreate( pcTimerName, portMAX_DELAY, pdTRUE, NULL, prvTestTimerCallback );
\r
537 if( xTimer != NULL )
\r
539 /* Called from the idle task so a block time must not be
\r
541 xTimerStart( xTimer, xDontBlock );
\r
545 if( xTimer != NULL )
\r
547 /* Demonstrate querying a timer's name. */
\r
548 configASSERT( strcmp( pcTimerGetName( xTimer ), pcTimerName ) == 0 );
\r
550 /* Demonstrate querying a timer's period. */
\r
551 configASSERT( xTimerGetPeriod( xTimer ) == portMAX_DELAY );
\r
553 /* Demonstrate querying a timer's next expiry time, although nothing is
\r
554 done with the returned value. Note if the expiry time is less than the
\r
555 maximum tick count then the expiry time has overflowed from the current
\r
556 time. In this case the expiry time was set to portMAX_DELAY, so it is
\r
557 expected to be less than the current time until the current time has
\r
558 itself overflowed. */
\r
559 xExpiryTime = xTimerGetExpiryTime( xTimer );
\r
560 ( void ) xExpiryTime;
\r
563 /*-----------------------------------------------------------*/
\r
565 static void prvDemonstratePendingFunctionCall( void )
\r
567 static uint32_t ulParameter1 = 1000UL, ulParameter2 = 0UL;
\r
568 const TickType_t xDontBlock = 0; /* This is called from the idle task so must *not* attempt to block. */
\r
570 /* prvPendedFunction() just expects the parameters to be incremented by one
\r
571 each time it is called. */
\r
575 /* Pend the function call, sending the parameters. */
\r
576 xTimerPendFunctionCall( prvPendedFunction, ( void * ) ulParameter1, ulParameter2, xDontBlock );
\r
578 /*-----------------------------------------------------------*/
\r
580 static void prvDemonstrateTaskStateAndHandleGetFunctions( void )
\r
582 TaskHandle_t xIdleTaskHandle, xTimerTaskHandle;
\r
584 static portBASE_TYPE xPerformedOneShotTests = pdFALSE;
\r
585 TaskHandle_t xTestTask;
\r
586 TaskStatus_t xTaskInfo;
\r
587 extern StackType_t uxTimerTaskStack[];
\r
589 /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and
\r
590 xTaskGetIdleTaskHandle() functions. Also try using the function that sets
\r
591 the task number. */
\r
592 xIdleTaskHandle = xTaskGetIdleTaskHandle();
\r
593 xTimerTaskHandle = xTimerGetTimerDaemonTaskHandle();
\r
595 /* This is the idle hook, so the current task handle should equal the
\r
596 returned idle task handle. */
\r
597 if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle )
\r
599 pcStatusMessage = "Error: Returned idle task handle was incorrect";
\r
602 /* Check the same handle is obtained using the idle task's name. First try
\r
603 with the wrong name, then the right name. */
\r
604 if( xTaskGetHandle( "Idle" ) == xIdleTaskHandle )
\r
606 pcStatusMessage = "Error: Returned handle for name Idle was incorrect";
\r
609 if( xTaskGetHandle( "IDLE" ) != xIdleTaskHandle )
\r
611 pcStatusMessage = "Error: Returned handle for name Idle was incorrect";
\r
614 /* Check the timer task handle was returned correctly. */
\r
615 pcTaskName = pcTaskGetName( xTimerTaskHandle );
\r
616 if( strcmp( pcTaskName, "Tmr Svc" ) != 0 )
\r
618 pcStatusMessage = "Error: Returned timer task handle was incorrect";
\r
621 if( xTaskGetHandle( "Tmr Svc" ) != xTimerTaskHandle )
\r
623 pcStatusMessage = "Error: Returned handle for name Tmr Svc was incorrect";
\r
626 /* This task is running, make sure it's state is returned as running. */
\r
627 if( eTaskStateGet( xIdleTaskHandle ) != eRunning )
\r
629 pcStatusMessage = "Error: Returned idle task state was incorrect";
\r
632 /* If this task is running, then the timer task must be blocked. */
\r
633 if( eTaskStateGet( xTimerTaskHandle ) != eBlocked )
\r
635 pcStatusMessage = "Error: Returned timer task state was incorrect";
\r
638 /* Also with the vTaskGetInfo() function. */
\r
639 vTaskGetInfo( xTimerTaskHandle, /* The task being queried. */
\r
640 &xTaskInfo, /* The structure into which information on the task will be written. */
\r
641 pdTRUE, /* Include the task's high watermark in the structure. */
\r
642 eInvalid ); /* Include the task state in the structure. */
\r
644 /* Check the information returned by vTaskGetInfo() is as expected. */
\r
645 if( ( xTaskInfo.eCurrentState != eBlocked ) ||
\r
646 ( strcmp( xTaskInfo.pcTaskName, "Tmr Svc" ) != 0 ) ||
\r
647 ( xTaskInfo.uxCurrentPriority != configTIMER_TASK_PRIORITY ) ||
\r
648 ( xTaskInfo.pxStackBase != uxTimerTaskStack ) ||
\r
649 ( xTaskInfo.xHandle != xTimerTaskHandle ) )
\r
651 pcStatusMessage = "Error: vTaskGetInfo() returned incorrect information about the timer task";
\r
654 /* Other tests that should only be performed once follow. The test task
\r
655 is not created on each iteration because to do so would cause the death
\r
656 task to report an error (too many tasks running). */
\r
657 if( xPerformedOneShotTests == pdFALSE )
\r
659 /* Don't run this part of the test again. */
\r
660 xPerformedOneShotTests = pdTRUE;
\r
662 /* Create a test task to use to test other eTaskStateGet() return values. */
\r
663 if( xTaskCreate( prvTestTask, "Test", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTestTask ) == pdPASS )
\r
665 /* If this task is running, the test task must be in the ready state. */
\r
666 if( eTaskStateGet( xTestTask ) != eReady )
\r
668 pcStatusMessage = "Error: Returned test task state was incorrect 1";
\r
671 /* Now suspend the test task and check its state is reported correctly. */
\r
672 vTaskSuspend( xTestTask );
\r
673 if( eTaskStateGet( xTestTask ) != eSuspended )
\r
675 pcStatusMessage = "Error: Returned test task state was incorrect 2";
\r
678 /* Now delete the task and check its state is reported correctly. */
\r
679 vTaskDelete( xTestTask );
\r
680 if( eTaskStateGet( xTestTask ) != eDeleted )
\r
682 pcStatusMessage = "Error: Returned test task state was incorrect 3";
\r
687 /*-----------------------------------------------------------*/
\r
689 static void prvDemoQueueSpaceFunctions( void *pvParameters )
\r
691 QueueHandle_t xQueue = NULL;
\r
692 const unsigned portBASE_TYPE uxQueueLength = 10;
\r
693 unsigned portBASE_TYPE uxReturn, x;
\r
695 /* Remove compiler warnings. */
\r
696 ( void ) pvParameters;
\r
698 /* Create the queue that will be used. Nothing is actually going to be
\r
699 sent or received so the queue item size is set to 0. */
\r
700 xQueue = xQueueCreate( uxQueueLength, 0 );
\r
701 configASSERT( xQueue );
\r
705 for( x = 0; x < uxQueueLength; x++ )
\r
707 /* Ask how many messages are available... */
\r
708 uxReturn = uxQueueMessagesWaiting( xQueue );
\r
710 /* Check the number of messages being reported as being available
\r
711 is as expected, and force an assert if not. */
\r
712 if( uxReturn != x )
\r
714 /* xQueue cannot be NULL so this is deliberately causing an
\r
715 assert to be triggered as there is an error. */
\r
716 configASSERT( xQueue == NULL );
\r
719 /* Ask how many spaces remain in the queue... */
\r
720 uxReturn = uxQueueSpacesAvailable( xQueue );
\r
722 /* Check the number of spaces being reported as being available
\r
723 is as expected, and force an assert if not. */
\r
724 if( uxReturn != ( uxQueueLength - x ) )
\r
726 /* xQueue cannot be NULL so this is deliberately causing an
\r
727 assert to be triggered as there is an error. */
\r
728 configASSERT( xQueue == NULL );
\r
731 /* Fill one more space in the queue. */
\r
732 xQueueSendToBack( xQueue, NULL, 0 );
\r
735 /* Perform the same check while the queue is full. */
\r
736 uxReturn = uxQueueMessagesWaiting( xQueue );
\r
737 if( uxReturn != uxQueueLength )
\r
739 configASSERT( xQueue == NULL );
\r
742 uxReturn = uxQueueSpacesAvailable( xQueue );
\r
744 if( uxReturn != 0 )
\r
746 configASSERT( xQueue == NULL );
\r
749 /* The queue is full, start again. */
\r
750 xQueueReset( xQueue );
\r
752 #if( configUSE_PREEMPTION == 0 )
\r
757 /*-----------------------------------------------------------*/
\r
759 static void prvPermanentlyBlockingSemaphoreTask( void *pvParameters )
\r
761 SemaphoreHandle_t xSemaphore;
\r
763 /* Prevent compiler warning about unused parameter in the case that
\r
764 configASSERT() is not defined. */
\r
765 ( void ) pvParameters;
\r
767 /* This task should block on a semaphore, and never return. */
\r
768 xSemaphore = xSemaphoreCreateBinary();
\r
769 configASSERT( xSemaphore );
\r
771 xSemaphoreTake( xSemaphore, portMAX_DELAY );
\r
773 /* The above xSemaphoreTake() call should never return, force an assert if
\r
775 configASSERT( pvParameters != NULL );
\r
776 vTaskDelete( NULL );
\r
778 /*-----------------------------------------------------------*/
\r
780 static void prvPermanentlyBlockingNotificationTask( void *pvParameters )
\r
782 /* Prevent compiler warning about unused parameter in the case that
\r
783 configASSERT() is not defined. */
\r
784 ( void ) pvParameters;
\r
786 /* This task should block on a task notification, and never return. */
\r
787 ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
\r
789 /* The above ulTaskNotifyTake() call should never return, force an assert
\r
791 configASSERT( pvParameters != NULL );
\r
792 vTaskDelete( NULL );
\r