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