]> begriffs open source - cmsis-freertos/blob - Demo/Common/Minimal/StaticAllocation.c
Update cmsis_os2.c
[cmsis-freertos] / Demo / Common / Minimal / StaticAllocation.c
1 /*
2     FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
3     All rights reserved
4
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6
7     This file is part of the FreeRTOS distribution.
8
9     FreeRTOS is free software; you can redistribute it and/or modify it under
10     the terms of the GNU General Public License (version 2) as published by the
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
12
13     ***************************************************************************
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<
16     >>!   obliged to provide the source code for proprietary components     !<<
17     >>!   outside of the FreeRTOS kernel.                                   !<<
18     ***************************************************************************
19
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following
23     link: http://www.freertos.org/a00114.html
24
25     ***************************************************************************
26      *                                                                       *
27      *    FreeRTOS provides completely free yet professionally developed,    *
28      *    robust, strictly quality controlled, supported, and cross          *
29      *    platform software that is more than just the market leader, it     *
30      *    is the industry's de facto standard.                               *
31      *                                                                       *
32      *    Help yourself get started quickly while simultaneously helping     *
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *
34      *    tutorial book, reference manual, or both:                          *
35      *    http://www.FreeRTOS.org/Documentation                              *
36      *                                                                       *
37     ***************************************************************************
38
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
40     the FAQ page "My application does not run, what could be wrong?".  Have you
41     defined configASSERT()?
42
43     http://www.FreeRTOS.org/support - In return for receiving this top quality
44     embedded software for free we request you assist our global community by
45     participating in the support forum.
46
47     http://www.FreeRTOS.org/training - Investing in training allows your team to
48     be as productive as possible as early as possible.  Now you can receive
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50     Ltd, and the world's leading authority on the world's leading RTOS.
51
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.
55
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
61     licenses offer ticketed support, indemnification and commercial middleware.
62
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64     engineered and independently SIL3 certified version for use in safety and
65     mission critical applications that require provable dependability.
66
67     1 tab == 4 spaces!
68 */
69
70
71 /*
72  * Demonstrates how to create FreeRTOS objects using pre-allocated memory,
73  * rather than the normal dynamically allocated memory, and tests objects being
74  * created and deleted with both statically allocated memory and dynamically
75  * allocated memory.
76  *
77  * See http://www.FreeRTOS.org/Static_Vs_Dynamic_Memory_Allocation.html
78  */
79
80 /* Scheduler include files. */
81 #include "FreeRTOS.h"
82 #include "task.h"
83 #include "queue.h"
84 #include "semphr.h"
85 #include "event_groups.h"
86 #include "timers.h"
87
88 /* Demo program include files. */
89 #include "StaticAllocation.h"
90
91 /* Exclude the entire file if configSUPPORT_STATIC_ALLOCATION is 0. */
92 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
93
94 /* The priority at which the task that performs the tests is created. */
95 #define staticTASK_PRIORITY                                     ( tskIDLE_PRIORITY + 2 )
96
97 /* The length of the queue, in items, not bytes, used in the queue static
98 allocation tests. */
99 #define staticQUEUE_LENGTH_IN_ITEMS                     ( 5 )
100
101 /* A block time of 0 simply means "don't block". */
102 #define staticDONT_BLOCK                                        ( ( TickType_t ) 0 )
103
104 /* Binary semaphores have a maximum count of 1. */
105 #define staticBINARY_SEMAPHORE_MAX_COUNT        ( 1 )
106
107 /* The size of the stack used by the task that runs the tests. */
108 #define staticCREATOR_TASK_STACK_SIZE           ( configMINIMAL_STACK_SIZE * 2 )
109
110 /* The number of times the software timer will execute before stopping itself. */
111 #define staticMAX_TIMER_CALLBACK_EXECUTIONS     ( 5 )
112
113
114 /*-----------------------------------------------------------*/
115
116 /*
117  * The task that repeatedly creates and deletes statically allocated tasks, and
118  * other RTOS objects.
119  */
120 static void prvStaticallyAllocatedCreator( void *pvParameters );
121
122 /*
123  * The callback function used by the software timer that is repeatedly created
124  * and deleted using both static and dynamically allocated memory.
125  */
126 static void prvTimerCallback( TimerHandle_t xExpiredTimer );
127
128 /*
129  * A task that is created and deleted multiple times, using both statically and
130  * dynamically allocated stack and TCB.
131  */
132 static void prvStaticallyAllocatedTask( void *pvParameters );
133
134 /*
135  * A function that demonstrates and tests the API functions that create and
136  * delete tasks using both statically and dynamically allocated TCBs and stacks.
137  */
138 static void prvCreateAndDeleteStaticallyAllocatedTasks( void );
139
140 /*
141  * A function that demonstrates and tests the API functions that create and
142  * delete event groups using both statically and dynamically allocated RAM.
143  */
144 static void prvCreateAndDeleteStaticallyAllocatedEventGroups( void );
145
146 /*
147  * A function that demonstrates and tests the API functions that create and
148  * delete queues using both statically and dynamically allocated RAM.
149  */
150 static void prvCreateAndDeleteStaticallyAllocatedQueues( void );
151
152 /*
153  * A function that demonstrates and tests the API functions that create and
154  * delete binary semaphores using both statically and dynamically allocated RAM.
155  */
156 static void prvCreateAndDeleteStaticallyAllocatedBinarySemaphores( void );
157
158 /*
159  * A function that demonstrates and tests the API functions that create and
160  * delete software timers using both statically and dynamically allocated RAM.
161  */
162 static void prvCreateAndDeleteStaticallyAllocatedTimers( void );
163
164 /*
165  * A function that demonstrates and tests the API functions that create and
166  * delete mutexes using both statically and dynamically allocated RAM.
167  */
168 static void prvCreateAndDeleteStaticallyAllocatedMutexes( void );
169
170 /*
171  * A function that demonstrates and tests the API functions that create and
172  * delete counting semaphores using both statically and dynamically allocated
173  * RAM.
174  */
175 static void prvCreateAndDeleteStaticallyAllocatedCountingSemaphores( void );
176
177 /*
178  * A function that demonstrates and tests the API functions that create and
179  * delete recursive mutexes using both statically and dynamically allocated RAM.
180  */
181 static void prvCreateAndDeleteStaticallyAllocatedRecursiveMutexes( void );
182
183 /*
184  * Utility function to create pseudo random numbers.
185  */
186 static UBaseType_t prvRand( void );
187
188 /*
189  * The task that creates and deletes other tasks has to delay occasionally to
190  * ensure lower priority tasks are not starved of processing time.  A pseudo
191  * random delay time is used just to add a little bit of randomisation into the
192  * execution pattern.  prvGetNextDelayTime() generates the pseudo random delay.
193  */
194 static TickType_t prvGetNextDelayTime( void );
195
196 /*
197  * Checks the basic operation of a queue after it has been created.
198  */
199 static void prvSanityCheckCreatedQueue( QueueHandle_t xQueue );
200
201 /*
202  * Checks the basic operation of a recursive mutex after it has been created.
203  */
204 static void prvSanityCheckCreatedRecursiveMutex( SemaphoreHandle_t xSemaphore );
205
206 /*
207  * Checks the basic operation of a binary semaphore after it has been created.
208  */
209 static void prvSanityCheckCreatedSemaphore( SemaphoreHandle_t xSemaphore, UBaseType_t uxMaxCount );
210
211 /*
212  * Checks the basic operation of an event group after it has been created.
213  */
214 static void prvSanityCheckCreatedEventGroup( EventGroupHandle_t xEventGroup );
215
216 /*-----------------------------------------------------------*/
217
218 /* StaticTask_t is a publicly accessible structure that has the same size and
219 alignment requirements as the real TCB structure.  It is provided as a mechanism
220 for applications to know the size of the TCB (which is dependent on the
221 architecture and configuration file settings) without breaking the strict data
222 hiding policy by exposing the real TCB.  This StaticTask_t variable is passed
223 into the xTaskCreateStatic() function that creates the
224 prvStaticallyAllocatedCreator() task, and will hold the TCB of the created
225 tasks. */
226 static StaticTask_t xCreatorTaskTCBBuffer;
227
228 /* This is the stack that will be used by the prvStaticallyAllocatedCreator()
229 task, which is itself created using statically allocated buffers (so without any
230 dynamic memory allocation). */
231 static StackType_t uxCreatorTaskStackBuffer[ staticCREATOR_TASK_STACK_SIZE ];
232
233 /* Used by the pseudo random number generating function. */
234 static uint32_t ulNextRand = 0;
235
236 /* Used so a check task can ensure this test is still executing, and not
237 stalled. */
238 static volatile UBaseType_t uxCycleCounter = 0;
239
240 /* A variable that gets set to pdTRUE if an error is detected. */
241 static volatile BaseType_t xErrorOccurred = pdFALSE;
242
243 /*-----------------------------------------------------------*/
244
245 void vStartStaticallyAllocatedTasks( void  )
246 {
247         /* Create a single task, which then repeatedly creates and deletes the other
248         RTOS objects using both statically and dynamically allocated RAM. */
249         xTaskCreateStatic( prvStaticallyAllocatedCreator,               /* The function that implements the task being created. */
250                                            "StatCreate",                                                /* Text name for the task - not used by the RTOS, its just to assist debugging. */
251                                            staticCREATOR_TASK_STACK_SIZE,               /* Size of the buffer passed in as the stack - in words, not bytes! */
252                                            NULL,                                                                /* Parameter passed into the task - not used in this case. */
253                                            staticTASK_PRIORITY,                                 /* Priority of the task. */
254                                            &( uxCreatorTaskStackBuffer[ 0 ] ),  /* The buffer to use as the task's stack. */
255                                            &xCreatorTaskTCBBuffer );                    /* The variable that will hold the task's TCB. */
256 }
257 /*-----------------------------------------------------------*/
258
259 static void prvStaticallyAllocatedCreator( void *pvParameters )
260 {
261         /* Avoid compiler warnings. */
262         ( void ) pvParameters;
263
264         for( ;; )
265         {
266                 /* Loop, running functions that create and delete the various RTOS
267                 objects that can be optionally created using either static or dynamic
268                 memory allocation. */
269                 prvCreateAndDeleteStaticallyAllocatedTasks();
270                 prvCreateAndDeleteStaticallyAllocatedQueues();
271
272                 /* Delay to ensure lower priority tasks get CPU time, and increment the
273                 cycle counter so a 'check' task can determine that this task is still
274                 executing. */
275                 vTaskDelay( prvGetNextDelayTime() );
276                 uxCycleCounter++;
277
278                 prvCreateAndDeleteStaticallyAllocatedBinarySemaphores();
279                 prvCreateAndDeleteStaticallyAllocatedCountingSemaphores();
280
281                 vTaskDelay( prvGetNextDelayTime() );
282                 uxCycleCounter++;
283
284                 prvCreateAndDeleteStaticallyAllocatedMutexes();
285                 prvCreateAndDeleteStaticallyAllocatedRecursiveMutexes();
286
287                 vTaskDelay( prvGetNextDelayTime() );
288                 uxCycleCounter++;
289
290                 prvCreateAndDeleteStaticallyAllocatedEventGroups();
291                 prvCreateAndDeleteStaticallyAllocatedTimers();
292         }
293 }
294 /*-----------------------------------------------------------*/
295
296 static void prvCreateAndDeleteStaticallyAllocatedCountingSemaphores( void )
297 {
298 SemaphoreHandle_t xSemaphore;
299 const UBaseType_t uxMaxCount = ( UBaseType_t ) 10;
300
301 /* StaticSemaphore_t is a publicly accessible structure that has the same size
302 and alignment requirements as the real semaphore structure.  It is provided as a
303 mechanism for applications to know the size of the semaphore (which is dependent
304 on the architecture and configuration file settings) without breaking the strict
305 data hiding policy by exposing the real semaphore internals.  This
306 StaticSemaphore_t variable is passed into the xSemaphoreCreateCountingStatic()
307 function calls within this function.  NOTE: In most usage scenarios now it is
308 faster and more memory efficient to use a direct to task notification instead of
309 a counting semaphore.  http://www.freertos.org/RTOS-task-notifications.html */
310 StaticSemaphore_t xSemaphoreBuffer;
311
312         /* Create the semaphore.  xSemaphoreCreateCountingStatic() has one more
313         parameter than the usual xSemaphoreCreateCounting() function.  The parameter
314         is a pointer to the pre-allocated StaticSemaphore_t structure, which will
315         hold information on the semaphore in an anonymous way.  If the pointer is
316         passed as NULL then the structure will be allocated dynamically, just as
317         when xSemaphoreCreateCounting() is called. */
318         xSemaphore = xSemaphoreCreateCountingStatic( uxMaxCount, 0, &xSemaphoreBuffer );
319
320         /* The semaphore handle should equal the static semaphore structure passed
321         into the xSemaphoreCreateBinaryStatic() function. */
322         configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );
323
324         /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */
325         prvSanityCheckCreatedSemaphore( xSemaphore, uxMaxCount );
326
327         /* Delete the semaphore again so the buffers can be reused. */
328         vSemaphoreDelete( xSemaphore );
329
330         #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
331         {
332                 /* Now do the same but using dynamically allocated buffers to ensure the
333                 delete functions are working correctly in both the static and dynamic
334                 allocation cases. */
335                 xSemaphore = xSemaphoreCreateCounting( uxMaxCount, 0 );
336                 configASSERT( xSemaphore != NULL );
337                 prvSanityCheckCreatedSemaphore( xSemaphore, uxMaxCount );
338                 vSemaphoreDelete( xSemaphore );
339         }
340         #endif
341 }
342 /*-----------------------------------------------------------*/
343
344 static void prvCreateAndDeleteStaticallyAllocatedRecursiveMutexes( void )
345 {
346 SemaphoreHandle_t xSemaphore;
347
348 /* StaticSemaphore_t is a publicly accessible structure that has the same size
349 and alignment requirements as the real semaphore structure.  It is provided as a
350 mechanism for applications to know the size of the semaphore (which is dependent
351 on the architecture and configuration file settings) without breaking the strict
352 data hiding policy by exposing the real semaphore internals.  This
353 StaticSemaphore_t variable is passed into the
354 xSemaphoreCreateRecursiveMutexStatic() function calls within this function. */
355 StaticSemaphore_t xSemaphoreBuffer;
356
357         /* Create the semaphore.  xSemaphoreCreateRecursiveMutexStatic() has one
358         more parameter than the usual xSemaphoreCreateRecursiveMutex() function.
359         The parameter is a pointer to the pre-allocated StaticSemaphore_t structure,
360         which will hold information on the semaphore in an anonymous way.  If the
361         pointer is passed as NULL then the structure will be allocated dynamically,
362         just as when xSemaphoreCreateRecursiveMutex() is called. */
363         xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xSemaphoreBuffer );
364
365         /* The semaphore handle should equal the static semaphore structure passed
366         into the xSemaphoreCreateBinaryStatic() function. */
367         configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );
368
369         /* Ensure the semaphore passes a few sanity checks as a valid
370         recursive semaphore. */
371         prvSanityCheckCreatedRecursiveMutex( xSemaphore );
372
373         /* Delete the semaphore again so the buffers can be reused. */
374         vSemaphoreDelete( xSemaphore );
375
376         /* Now do the same using dynamically allocated buffers to ensure the delete
377         functions are working correctly in both the static and dynamic memory
378         allocation cases. */
379         #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
380         {
381                 xSemaphore = xSemaphoreCreateRecursiveMutex();
382                 configASSERT( xSemaphore != NULL );
383                 prvSanityCheckCreatedRecursiveMutex( xSemaphore );
384                 vSemaphoreDelete( xSemaphore );
385         }
386         #endif
387 }
388 /*-----------------------------------------------------------*/
389
390 static void prvCreateAndDeleteStaticallyAllocatedQueues( void )
391 {
392 QueueHandle_t xQueue;
393
394 /* StaticQueue_t is a publicly accessible structure that has the same size and
395 alignment requirements as the real queue structure.  It is provided as a
396 mechanism for applications to know the size of the queue (which is dependent on
397 the architecture and configuration file settings) without breaking the strict
398 data hiding policy by exposing the real queue internals.  This StaticQueue_t
399 variable is passed into the xQueueCreateStatic() function calls within this
400 function. */
401 static StaticQueue_t xStaticQueue;
402
403 /* The queue storage area must be large enough to hold the maximum number of
404 items it is possible for the queue to hold at any one time, which equals the
405 queue length (in items, not bytes) multiplied by the size of each item.  In this
406 case the queue will hold staticQUEUE_LENGTH_IN_ITEMS 64-bit items.  See
407 http://www.freertos.org/Embedded-RTOS-Queues.html */
408 static uint8_t ucQueueStorageArea[ staticQUEUE_LENGTH_IN_ITEMS * sizeof( uint64_t ) ];
409
410         /* Create the queue.  xQueueCreateStatic() has two more parameters than the
411         usual xQueueCreate() function.  The first new parameter is a pointer to the
412         pre-allocated queue storage area.  The second new parameter is a pointer to
413         the StaticQueue_t structure that will hold the queue state information in
414         an anonymous way.  If the two pointers are passed as NULL then the data
415         will be allocated dynamically as if xQueueCreate() had been called. */
416         xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */
417                                                                  sizeof( uint64_t ), /* The size of each item. */
418                                                                  ucQueueStorageArea, /* The buffer used to hold items within the queue. */
419                                                                  &xStaticQueue );        /* The static queue structure that will hold the state of the queue. */
420
421         /* The queue handle should equal the static queue structure passed into the
422         xQueueCreateStatic() function. */
423         configASSERT( xQueue == ( QueueHandle_t ) &xStaticQueue );
424
425         /* Ensure the queue passes a few sanity checks as a valid queue. */
426         prvSanityCheckCreatedQueue( xQueue );
427
428         /* Delete the queue again so the buffers can be reused. */
429         vQueueDelete( xQueue );
430
431         /* Now do the same using a dynamically allocated queue to ensure the delete
432         function is working correctly in both the static and dynamic memory
433         allocation cases. */
434         #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
435         {
436                 xQueue = xQueueCreate( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */
437                                                            sizeof( uint64_t ) );                /* The size of each item. */
438
439                 /* The queue handle should equal the static queue structure passed into the
440                 xQueueCreateStatic() function. */
441                 configASSERT( xQueue != NULL );
442
443                 /* Ensure the queue passes a few sanity checks as a valid queue. */
444                 prvSanityCheckCreatedQueue( xQueue );
445
446                 /* Delete the queue again so the buffers can be reused. */
447                 vQueueDelete( xQueue );
448         }
449         #endif
450 }
451 /*-----------------------------------------------------------*/
452
453 static void prvCreateAndDeleteStaticallyAllocatedMutexes( void )
454 {
455 SemaphoreHandle_t xSemaphore;
456 BaseType_t xReturned;
457
458 /* StaticSemaphore_t is a publicly accessible structure that has the same size
459 and alignment requirements as the real semaphore structure.  It is provided as a
460 mechanism for applications to know the size of the semaphore (which is dependent
461 on the architecture and configuration file settings) without breaking the strict
462 data hiding policy by exposing the real semaphore internals.  This
463 StaticSemaphore_t variable is passed into the xSemaphoreCreateMutexStatic()
464 function calls within this function. */
465 StaticSemaphore_t xSemaphoreBuffer;
466
467         /* Create the semaphore.  xSemaphoreCreateMutexStatic() has one more
468         parameter than the usual xSemaphoreCreateMutex() function.  The parameter
469         is a pointer to the pre-allocated StaticSemaphore_t structure, which will
470         hold information on the semaphore in an anonymous way.  If the pointer is
471         passed as NULL then the structure will be allocated dynamically, just as
472         when xSemaphoreCreateMutex() is called. */
473         xSemaphore = xSemaphoreCreateMutexStatic( &xSemaphoreBuffer );
474
475         /* The semaphore handle should equal the static semaphore structure passed
476         into the xSemaphoreCreateMutexStatic() function. */
477         configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );
478
479         /* Take the mutex so the mutex is in the state expected by the
480         prvSanityCheckCreatedSemaphore() function. */
481         xReturned = xSemaphoreTake( xSemaphore, staticDONT_BLOCK );
482
483         if( xReturned != pdPASS )
484         {
485                 xErrorOccurred = pdTRUE;
486         }
487
488         /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */
489         prvSanityCheckCreatedSemaphore( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );
490
491         /* Delete the semaphore again so the buffers can be reused. */
492         vSemaphoreDelete( xSemaphore );
493
494         /* Now do the same using a dynamically allocated mutex to ensure the delete
495         function is working correctly in both the static and dynamic allocation
496         cases. */
497         #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
498         {
499                 xSemaphore = xSemaphoreCreateMutex();
500
501                 /* The semaphore handle should equal the static semaphore structure
502                 passed into the xSemaphoreCreateMutexStatic() function. */
503                 configASSERT( xSemaphore != NULL );
504
505                 /* Take the mutex so the mutex is in the state expected by the
506                 prvSanityCheckCreatedSemaphore() function. */
507                 xReturned = xSemaphoreTake( xSemaphore, staticDONT_BLOCK );
508
509                 if( xReturned != pdPASS )
510                 {
511                         xErrorOccurred = pdTRUE;
512                 }
513
514                 /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */
515                 prvSanityCheckCreatedSemaphore( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );
516
517                 /* Delete the semaphore again so the buffers can be reused. */
518                 vSemaphoreDelete( xSemaphore );
519         }
520         #endif
521 }
522 /*-----------------------------------------------------------*/
523
524 static void prvCreateAndDeleteStaticallyAllocatedBinarySemaphores( void )
525 {
526 SemaphoreHandle_t xSemaphore;
527
528 /* StaticSemaphore_t is a publicly accessible structure that has the same size
529 and alignment requirements as the real semaphore structure.  It is provided as a
530 mechanism for applications to know the size of the semaphore (which is dependent
531 on the architecture and configuration file settings) without breaking the strict
532 data hiding policy by exposing the real semaphore internals.  This
533 StaticSemaphore_t variable is passed into the xSemaphoreCreateBinaryStatic()
534 function calls within this function.  NOTE: In most usage scenarios now it is
535 faster and more memory efficient to use a direct to task notification instead of
536 a binary semaphore.  http://www.freertos.org/RTOS-task-notifications.html */
537 StaticSemaphore_t xSemaphoreBuffer;
538
539         /* Create the semaphore.  xSemaphoreCreateBinaryStatic() has one more
540         parameter than the usual xSemaphoreCreateBinary() function.  The parameter
541         is a pointer to the pre-allocated StaticSemaphore_t structure, which will
542         hold information on the semaphore in an anonymous way.  If the pointer is
543         passed as NULL then the structure will be allocated dynamically, just as
544         when xSemaphoreCreateBinary() is called. */
545         xSemaphore = xSemaphoreCreateBinaryStatic( &xSemaphoreBuffer );
546
547         /* The semaphore handle should equal the static semaphore structure passed
548         into the xSemaphoreCreateBinaryStatic() function. */
549         configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );
550
551         /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */
552         prvSanityCheckCreatedSemaphore( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );
553
554         /* Delete the semaphore again so the buffers can be reused. */
555         vSemaphoreDelete( xSemaphore );
556
557         /* Now do the same using a dynamically allocated semaphore to check the
558         delete function is working correctly in both the static and dynamic
559         allocation cases. */
560         #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
561         {
562                 xSemaphore = xSemaphoreCreateBinary();
563                 configASSERT( xSemaphore != NULL );
564                 prvSanityCheckCreatedSemaphore( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );
565                 vSemaphoreDelete( xSemaphore );
566         }
567         #endif
568
569         /* There isn't a static version of the old and deprecated
570         vSemaphoreCreateBinary() macro (because its deprecated!), but check it is
571         still functioning correctly. */
572         #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
573         {
574                 vSemaphoreCreateBinary( xSemaphore );
575
576                 /* The macro starts with the binary semaphore available, but the test
577                 function expects it to be unavailable. */
578                 if( xSemaphoreTake( xSemaphore, staticDONT_BLOCK ) == pdFAIL )
579                 {
580                         xErrorOccurred = pdTRUE;
581                 }
582
583                 prvSanityCheckCreatedSemaphore( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );
584                 vSemaphoreDelete( xSemaphore );
585         }
586         #endif
587 }
588 /*-----------------------------------------------------------*/
589
590 static void prvTimerCallback( TimerHandle_t xExpiredTimer )
591 {
592 UBaseType_t *puxVariableToIncrement;
593 BaseType_t xReturned;
594
595         /* The timer callback just demonstrates it is executing by incrementing a
596         variable - the address of which is passed into the timer as its ID.  Obtain
597         the address of the variable to increment. */
598         puxVariableToIncrement = ( UBaseType_t * ) pvTimerGetTimerID( xExpiredTimer );
599
600         /* Increment the variable to show the timer callback has executed. */
601         ( *puxVariableToIncrement )++;
602
603         /* If this callback has executed the required number of times, stop the
604         timer. */
605         if( *puxVariableToIncrement == staticMAX_TIMER_CALLBACK_EXECUTIONS )
606         {
607                 /* This is called from a timer callback so must not block.  See
608                 http://www.FreeRTOS.org/FreeRTOS-timers-xTimerStop.html */
609                 xReturned = xTimerStop( xExpiredTimer, staticDONT_BLOCK );
610
611                 if( xReturned != pdPASS )
612                 {
613                         xErrorOccurred = pdTRUE;
614                 }
615         }
616 }
617 /*-----------------------------------------------------------*/
618
619 static void prvCreateAndDeleteStaticallyAllocatedTimers( void )
620 {
621 TimerHandle_t xTimer;
622 UBaseType_t uxVariableToIncrement;
623 const TickType_t xTimerPeriod = pdMS_TO_TICKS( 20 );
624 BaseType_t xReturned;
625
626 /* StaticTimer_t is a publicly accessible structure that has the same size
627 and alignment requirements as the real timer structure.  It is provided as a
628 mechanism for applications to know the size of the timer structure (which is
629 dependent on the architecture and configuration file settings) without breaking
630 the strict data hiding policy by exposing the real timer internals.  This
631 StaticTimer_t variable is passed into the xTimerCreateStatic() function calls
632 within this function. */
633 StaticTimer_t xTimerBuffer;
634
635         /* Create the software time.  xTimerCreateStatic() has an extra parameter
636         than the normal xTimerCreate() API function.  The parameter is a pointer to
637         the StaticTimer_t structure that will hold the software timer structure.  If
638         the parameter is passed as NULL then the structure will be allocated
639         dynamically, just as if xTimerCreate() had been called. */
640         xTimer = xTimerCreateStatic( "T1",                                      /* Text name for the task.  Helps debugging only.  Not used by FreeRTOS. */
641                                                                  xTimerPeriod,                  /* The period of the timer in ticks. */
642                                                                  pdTRUE,                                /* This is an auto-reload timer. */
643                                                                  ( void * ) &uxVariableToIncrement,     /* The variable incremented by the test is passed into the timer callback using the timer ID. */
644                                                                  prvTimerCallback,              /* The function to execute when the timer expires. */
645                                                                  &xTimerBuffer );               /* The buffer that will hold the software timer structure. */
646
647         /* The timer handle should equal the static timer structure passed into the
648         xTimerCreateStatic() function. */
649         configASSERT( xTimer == ( TimerHandle_t ) &xTimerBuffer );
650
651         /* Set the variable to 0, wait for a few timer periods to expire, then check
652         the timer callback has incremented the variable to the expected value. */
653         uxVariableToIncrement = 0;
654
655         /* This is a low priority so a block time should not be needed. */
656         xReturned = xTimerStart( xTimer, staticDONT_BLOCK );
657
658         if( xReturned != pdPASS )
659         {
660                 xErrorOccurred = pdTRUE;
661         }
662
663         vTaskDelay( xTimerPeriod * staticMAX_TIMER_CALLBACK_EXECUTIONS );
664
665         /* By now the timer should have expired staticMAX_TIMER_CALLBACK_EXECUTIONS
666         times, and then stopped itself. */
667         if( uxVariableToIncrement != staticMAX_TIMER_CALLBACK_EXECUTIONS )
668         {
669                 xErrorOccurred = pdTRUE;
670         }
671
672         /* Finished with the timer, delete it. */
673         xReturned = xTimerDelete( xTimer, staticDONT_BLOCK );
674
675         /* Again, as this is a low priority task it is expected that the timer
676         command will have been sent even without a block time being used. */
677         if( xReturned != pdPASS )
678         {
679                 xErrorOccurred = pdTRUE;
680         }
681
682         /* Just to show the check task that this task is still executing. */
683         uxCycleCounter++;
684
685         /* Now do the same using a dynamically allocated software timer to ensure
686         the delete function is working correctly in both the static and dynamic
687         allocation cases. */
688         #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
689         {
690                 xTimer = xTimerCreate( "T1",                                                            /* Text name for the task.  Helps debugging only.  Not used by FreeRTOS. */
691                                                             xTimerPeriod,                                               /* The period of the timer in ticks. */
692                                                                 pdTRUE,                                                         /* This is an auto-reload timer. */
693                                                                 ( void * ) &uxVariableToIncrement,      /* The variable incremented by the test is passed into the timer callback using the timer ID. */
694                                                                 prvTimerCallback );                                     /* The function to execute when the timer expires. */
695
696                 configASSERT( xTimer != NULL );
697
698                 uxVariableToIncrement = 0;
699                 xReturned = xTimerStart( xTimer, staticDONT_BLOCK );
700
701                 if( xReturned != pdPASS )
702                 {
703                         xErrorOccurred = pdTRUE;
704                 }
705
706                 vTaskDelay( xTimerPeriod * staticMAX_TIMER_CALLBACK_EXECUTIONS );
707
708                 if( uxVariableToIncrement != staticMAX_TIMER_CALLBACK_EXECUTIONS )
709                 {
710                         xErrorOccurred = pdTRUE;
711                 }
712
713                 xReturned = xTimerDelete( xTimer, staticDONT_BLOCK );
714
715                 if( xReturned != pdPASS )
716                 {
717                         xErrorOccurred = pdTRUE;
718                 }
719         }
720         #endif
721 }
722 /*-----------------------------------------------------------*/
723
724 static void prvCreateAndDeleteStaticallyAllocatedEventGroups( void )
725 {
726 EventGroupHandle_t xEventGroup;
727
728 /* StaticEventGroup_t is a publicly accessible structure that has the same size
729 and alignment requirements as the real event group structure.  It is provided as
730 a mechanism for applications to know the size of the event group (which is
731 dependent on the architecture and configuration file settings) without breaking
732 the strict data hiding policy by exposing the real event group internals.  This
733 StaticEventGroup_t variable is passed into the xSemaphoreCreateEventGroupStatic()
734 function calls within this function. */
735 StaticEventGroup_t xEventGroupBuffer;
736
737         /* Create the event group.  xEventGroupCreateStatic() has an extra parameter
738         than the normal xEventGroupCreate() API function.  The parameter is a
739         pointer to the StaticEventGroup_t structure that will hold the event group
740         structure.  If the parameter is passed as NULL then the structure will be
741         allocated dynamically, just as if xEventGroupCreate() had been called. */
742         xEventGroup = xEventGroupCreateStatic( &xEventGroupBuffer );
743
744         /* The event group handle should equal the static event group structure
745         passed into the xEventGroupCreateStatic() function. */
746         configASSERT( xEventGroup == ( EventGroupHandle_t ) &xEventGroupBuffer );
747
748         /* Ensure the event group passes a few sanity checks as a valid event
749         group. */
750         prvSanityCheckCreatedEventGroup( xEventGroup );
751
752         /* Delete the event group again so the buffers can be reused. */
753         vEventGroupDelete( xEventGroup );
754
755         /* Now do the same using a dynamically allocated event group to ensure the
756         delete function is working correctly in both the static and dynamic
757         allocation cases. */
758         #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
759         {
760                 xEventGroup = xEventGroupCreate();
761                 configASSERT( xEventGroup != NULL );
762                 prvSanityCheckCreatedEventGroup( xEventGroup );
763                 vEventGroupDelete( xEventGroup );
764         }
765         #endif
766 }
767 /*-----------------------------------------------------------*/
768
769 static void prvCreateAndDeleteStaticallyAllocatedTasks( void )
770 {
771 TaskHandle_t xCreatedTask;
772
773 /* The variable that will hold the TCB of tasks created by this function.  See
774 the comments above the declaration of the xCreatorTaskTCBBuffer variable for
775 more information. */
776 StaticTask_t xTCBBuffer;
777
778 /* This buffer that will be used as the stack of tasks created by this function.
779 See the comments above the declaration of the uxCreatorTaskStackBuffer[] array
780 above for more information. */
781 static StackType_t uxStackBuffer[ configMINIMAL_STACK_SIZE ];
782
783         /* Create the task.  xTaskCreateStatic() has two more parameters than
784         the usual xTaskCreate() function.  The first new parameter is a pointer to
785         the pre-allocated stack.  The second new parameter is a pointer to the
786         StaticTask_t structure that will hold the task's TCB.  If both pointers are
787         passed as NULL then the respective object will be allocated dynamically as
788         if xTaskCreate() had been called. */
789         xCreatedTask = xTaskCreateStatic(
790                                                 prvStaticallyAllocatedTask,     /* Function that implements the task. */
791                                                 "Static",                                               /* Human readable name for the task. */
792                                                 configMINIMAL_STACK_SIZE,               /* Task's stack size, in words (not bytes!). */
793                                                 NULL,                                                   /* Parameter to pass into the task. */
794                                                 uxTaskPriorityGet( NULL ) + 1,  /* The priority of the task. */
795                                                 &( uxStackBuffer[ 0 ] ),                /* The buffer to use as the task's stack. */
796                                                 &xTCBBuffer );                                  /* The variable that will hold that task's TCB. */
797
798         /* Check the task was created correctly, then delete the task. */
799         if( xCreatedTask == NULL )
800         {
801                 xErrorOccurred = pdTRUE;
802         }
803         else if( eTaskGetState( xCreatedTask ) != eSuspended )
804         {
805                 /* The created task had a higher priority so should have executed and
806                 suspended itself by now. */
807                 xErrorOccurred = pdTRUE;
808         }
809         else
810         {
811                 vTaskDelete( xCreatedTask );
812         }
813
814         /* Now do the same using a dynamically allocated task to ensure the delete
815         function is working correctly in both the static and dynamic allocation
816         cases. */
817         #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
818         {
819         BaseType_t xReturned;
820
821                 xReturned = xTaskCreate(
822                                                                         prvStaticallyAllocatedTask,             /* Function that implements the task - the same function is used but is actually dynamically allocated this time. */
823                                                                         "Static",                                               /* Human readable name for the task. */
824                                                                         configMINIMAL_STACK_SIZE,               /* Task's stack size, in words (not bytes!). */
825                                                                         NULL,                                                   /* Parameter to pass into the task. */
826                                                                         uxTaskPriorityGet( NULL ) + 1,  /* The priority of the task. */
827                                                                         &xCreatedTask );                                /* Handle of the task being created. */
828
829                 if( eTaskGetState( xCreatedTask ) != eSuspended )
830                 {
831                         xErrorOccurred = pdTRUE;
832                 }
833
834                 configASSERT( xReturned == pdPASS );
835                 if( xReturned != pdPASS )
836                 {
837                         xErrorOccurred = pdTRUE;
838                 }
839                 vTaskDelete( xCreatedTask );
840         }
841         #endif
842 }
843 /*-----------------------------------------------------------*/
844
845 static void prvStaticallyAllocatedTask( void *pvParameters )
846 {
847         ( void ) pvParameters;
848
849         /* The created task just suspends itself to wait to get deleted.  The task
850         that creates this task checks this task is in the expected Suspended state
851         before deleting it. */
852         vTaskSuspend( NULL );
853 }
854 /*-----------------------------------------------------------*/
855
856 static UBaseType_t prvRand( void )
857 {
858 const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;
859
860         /* Utility function to generate a pseudo random number. */
861         ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;
862         return( ( ulNextRand >> 16UL ) & 0x7fffUL );
863 }
864 /*-----------------------------------------------------------*/
865
866 static TickType_t prvGetNextDelayTime( void )
867 {
868 TickType_t xNextDelay;
869 const TickType_t xMaxDelay = pdMS_TO_TICKS( ( TickType_t ) 150 );
870 const TickType_t xMinDelay = pdMS_TO_TICKS( ( TickType_t ) 75 );
871 const TickType_t xTinyDelay = pdMS_TO_TICKS( ( TickType_t ) 2 );
872
873         /* Generate the next delay time.  This is kept within a narrow band so as
874         not to disturb the timing of other tests - but does add in some pseudo
875         randomisation into the tests. */
876         do
877         {
878                 xNextDelay = prvRand() % xMaxDelay;
879
880                 /* Just in case this loop is executed lots of times. */
881                 vTaskDelay( xTinyDelay );
882
883         } while ( xNextDelay < xMinDelay );
884
885         return xNextDelay;
886 }
887 /*-----------------------------------------------------------*/
888
889 static void prvSanityCheckCreatedEventGroup( EventGroupHandle_t xEventGroup )
890 {
891 EventBits_t xEventBits;
892 const EventBits_t xFirstTestBits = ( EventBits_t ) 0xaa, xSecondTestBits = ( EventBits_t ) 0x55;
893
894         /* The event group should not have any bits set yet. */
895         xEventBits = xEventGroupGetBits( xEventGroup );
896
897         if( xEventBits != ( EventBits_t ) 0 )
898         {
899                 xErrorOccurred = pdTRUE;
900         }
901
902         /* Some some bits, then read them back to check they are as expected. */
903         xEventGroupSetBits( xEventGroup, xFirstTestBits );
904
905         xEventBits = xEventGroupGetBits( xEventGroup );
906
907         if( xEventBits != xFirstTestBits )
908         {
909                 xErrorOccurred = pdTRUE;
910         }
911
912         xEventGroupSetBits( xEventGroup, xSecondTestBits );
913
914         xEventBits = xEventGroupGetBits( xEventGroup );
915
916         if( xEventBits != ( xFirstTestBits | xSecondTestBits ) )
917         {
918                 xErrorOccurred = pdTRUE;
919         }
920
921         /* Finally try clearing some bits too and check that operation proceeds as
922         expected. */
923         xEventGroupClearBits( xEventGroup, xFirstTestBits );
924
925         xEventBits = xEventGroupGetBits( xEventGroup );
926
927         if( xEventBits != xSecondTestBits )
928         {
929                 xErrorOccurred = pdTRUE;
930         }
931 }
932 /*-----------------------------------------------------------*/
933
934 static void prvSanityCheckCreatedSemaphore( SemaphoreHandle_t xSemaphore, UBaseType_t uxMaxCount )
935 {
936 BaseType_t xReturned;
937 UBaseType_t x;
938 const TickType_t xShortBlockTime = pdMS_TO_TICKS( 10 );
939 TickType_t xTickCount;
940
941         /* The binary semaphore should start 'empty', so a call to xSemaphoreTake()
942         should fail. */
943         xTickCount = xTaskGetTickCount();
944         xReturned = xSemaphoreTake( xSemaphore, xShortBlockTime );
945
946         if( ( ( TickType_t ) ( xTaskGetTickCount() - xTickCount ) ) < xShortBlockTime )
947         {
948                 /* Did not block on the semaphore as long as expected. */
949                 xErrorOccurred = pdTRUE;
950         }
951
952         if( xReturned != pdFAIL )
953         {
954                 xErrorOccurred = pdTRUE;
955         }
956
957         /* Should be possible to 'give' the semaphore up to a maximum of uxMaxCount
958         times. */
959         for( x = 0; x < uxMaxCount; x++ )
960         {
961                 xReturned = xSemaphoreGive( xSemaphore );
962
963                 if( xReturned == pdFAIL )
964                 {
965                         xErrorOccurred = pdTRUE;
966                 }
967         }
968
969         /* Giving the semaphore again should fail, as it is 'full'. */
970         xReturned = xSemaphoreGive( xSemaphore );
971
972         if( xReturned != pdFAIL )
973         {
974                 xErrorOccurred = pdTRUE;
975         }
976
977         configASSERT( uxSemaphoreGetCount( xSemaphore ) == uxMaxCount );
978
979         /* Should now be possible to 'take' the semaphore up to a maximum of
980         uxMaxCount times without blocking. */
981         for( x = 0; x < uxMaxCount; x++ )
982         {
983                 xReturned = xSemaphoreTake( xSemaphore, staticDONT_BLOCK );
984
985                 if( xReturned == pdFAIL )
986                 {
987                         xErrorOccurred = pdTRUE;
988                 }
989         }
990
991         /* Back to the starting condition, where the semaphore should not be
992         available. */
993         xTickCount = xTaskGetTickCount();
994         xReturned = xSemaphoreTake( xSemaphore, xShortBlockTime );
995
996         if( ( ( TickType_t ) ( xTaskGetTickCount() - xTickCount ) ) < xShortBlockTime )
997         {
998                 /* Did not block on the semaphore as long as expected. */
999                 xErrorOccurred = pdTRUE;
1000         }
1001
1002         if( xReturned != pdFAIL )
1003         {
1004                 xErrorOccurred = pdTRUE;
1005         }
1006
1007         configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );
1008 }
1009 /*-----------------------------------------------------------*/
1010
1011 static void prvSanityCheckCreatedQueue( QueueHandle_t xQueue )
1012 {
1013 uint64_t ull, ullRead;
1014 BaseType_t xReturned, xLoop;
1015
1016         /* This test is done twice to ensure the queue storage area wraps. */
1017         for( xLoop = 0; xLoop < 2; xLoop++ )
1018         {
1019                 /* A very basic test that the queue can be written to and read from as
1020                 expected.  First the queue should be empty. */
1021                 xReturned = xQueueReceive( xQueue, &ull, staticDONT_BLOCK );
1022                 if( xReturned != errQUEUE_EMPTY )
1023                 {
1024                         xErrorOccurred = pdTRUE;
1025                 }
1026
1027                 /* Now it should be possible to write to the queue staticQUEUE_LENGTH_IN_ITEMS
1028                 times. */
1029                 for( ull = 0; ull < staticQUEUE_LENGTH_IN_ITEMS; ull++ )
1030                 {
1031                         xReturned = xQueueSend( xQueue, &ull, staticDONT_BLOCK );
1032                         if( xReturned != pdPASS )
1033                         {
1034                                 xErrorOccurred = pdTRUE;
1035                         }
1036                 }
1037
1038                 /* Should not now be possible to write to the queue again. */
1039                 xReturned = xQueueSend( xQueue, &ull, staticDONT_BLOCK );
1040                 if( xReturned != errQUEUE_FULL )
1041                 {
1042                         xErrorOccurred = pdTRUE;
1043                 }
1044
1045                 /* Now read back from the queue to ensure the data read back matches that
1046                 written. */
1047                 for( ull = 0; ull < staticQUEUE_LENGTH_IN_ITEMS; ull++ )
1048                 {
1049                         xReturned = xQueueReceive( xQueue, &ullRead, staticDONT_BLOCK );
1050
1051                         if( xReturned != pdPASS )
1052                         {
1053                                 xErrorOccurred = pdTRUE;
1054                         }
1055
1056                         if( ullRead != ull )
1057                         {
1058                                 xErrorOccurred = pdTRUE;
1059                         }
1060                 }
1061
1062                 /* The queue should be empty again. */
1063                 xReturned = xQueueReceive( xQueue, &ull, staticDONT_BLOCK );
1064                 if( xReturned != errQUEUE_EMPTY )
1065                 {
1066                         xErrorOccurred = pdTRUE;
1067                 }
1068         }
1069 }
1070 /*-----------------------------------------------------------*/
1071
1072 static void prvSanityCheckCreatedRecursiveMutex( SemaphoreHandle_t xSemaphore )
1073 {
1074 const BaseType_t xLoops = 5;
1075 BaseType_t x, xReturned;
1076
1077         /* A very basic test that the recursive semaphore behaved like a recursive
1078         semaphore. First the semaphore should not be able to be given, as it has not
1079         yet been taken. */
1080         xReturned = xSemaphoreGiveRecursive( xSemaphore );
1081
1082         if( xReturned != pdFAIL )
1083         {
1084                 xErrorOccurred = pdTRUE;
1085         }
1086
1087         /* Now it should be possible to take the mutex a number of times. */
1088         for( x = 0; x < xLoops; x++ )
1089         {
1090                 xReturned = xSemaphoreTakeRecursive( xSemaphore, staticDONT_BLOCK );
1091
1092                 if( xReturned != pdPASS )
1093                 {
1094                         xErrorOccurred = pdTRUE;
1095                 }
1096         }
1097
1098         /* Should be possible to give the semaphore the same number of times as it
1099         was given in the loop above. */
1100         for( x = 0; x < xLoops; x++ )
1101         {
1102                 xReturned = xSemaphoreGiveRecursive( xSemaphore );
1103
1104                 if( xReturned != pdPASS )
1105                 {
1106                         xErrorOccurred = pdTRUE;
1107                 }
1108         }
1109
1110         /* No more gives should be possible though. */
1111         xReturned = xSemaphoreGiveRecursive( xSemaphore );
1112
1113         if( xReturned != pdFAIL )
1114         {
1115                 xErrorOccurred = pdTRUE;
1116         }
1117 }
1118 /*-----------------------------------------------------------*/
1119
1120 BaseType_t xAreStaticAllocationTasksStillRunning( void )
1121 {
1122 static UBaseType_t uxLastCycleCounter = 0;
1123 BaseType_t xReturn;
1124
1125         if( uxCycleCounter == uxLastCycleCounter )
1126         {
1127                 xErrorOccurred = pdTRUE;
1128         }
1129         else
1130         {
1131                 uxLastCycleCounter = uxCycleCounter;
1132         }
1133
1134         if( xErrorOccurred != pdFALSE )
1135         {
1136                 xReturn = pdFAIL;
1137         }
1138         else
1139         {
1140                 xReturn = pdPASS;
1141         }
1142
1143         return xReturn;
1144 }
1145 /*-----------------------------------------------------------*/
1146
1147 /* Exclude the entire file if configSUPPORT_STATIC_ALLOCATION is 0. */
1148 #endif /* configSUPPORT_STATIC_ALLOCATION == 1 */