static void prvCreateAndDeleteStaticallyAllocatedQueues( void ) { QueueHandle_t xQueue; /* StaticQueue_t is a publicly accessible structure that has the same size and alignment requirements as the real queue structure. It is provided as a mechanism for applications to know the size of the queue (which is dependent on the architecture and configuration file settings) without breaking the strict data hiding policy by exposing the real queue internals. This StaticQueue_t variable is passed into the xQueueCreateStatic() function calls within this function. */ static StaticQueue_t xStaticQueue; /* The queue storage area must be large enough to hold the maximum number of items it is possible for the queue to hold at any one time, which equals the queue length (in items, not bytes) multiplied by the size of each item. In this case the queue will hold staticQUEUE_LENGTH_IN_ITEMS 64-bit items. See http://www.freertos.org/Embedded-RTOS-Queues.html */ static uint8_t ucQueueStorageArea[ staticQUEUE_LENGTH_IN_ITEMS * sizeof( uint64_t ) ]; /* Create the queue. xQueueCreateStatic() has two more parameters than the usual xQueueCreate() function. The first new parameter is a pointer to the pre-allocated queue storage area. The second new parameter is a pointer to the StaticQueue_t structure that will hold the queue state information in an anonymous way. If the two pointers are passed as NULL then the data will be allocated dynamically as if xQueueCreate() had been called. */ xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */ sizeof( uint64_t ), /* The size of each item. */ ucQueueStorageArea, /* The buffer used to hold items within the queue. */ &xStaticQueue ); /* The static queue structure that will hold the state of the queue. */ /* The queue handle should equal the static queue structure passed into the xQueueCreateStatic() function. */ configASSERT( xQueue == ( QueueHandle_t ) &xStaticQueue ); /* Ensure the queue passes a few sanity checks as a valid queue. */ prvSanityCheckCreatedQueue( xQueue ); /* Delete the queue again so the buffers can be reused. */ vQueueDelete( xQueue ); /* Now do the same using a dynamically allocated queue to ensure the delete function is working correctly in both the static and dynamic memory allocation cases. */ #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) { xQueue = xQueueCreate( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */ sizeof( uint64_t ) ); /* The size of each item. */ /* The queue handle should equal the static queue structure passed into the xQueueCreateStatic() function. */ configASSERT( xQueue != NULL ); /* Ensure the queue passes a few sanity checks as a valid queue. */ prvSanityCheckCreatedQueue( xQueue ); /* Delete the queue again so the buffers can be reused. */ vQueueDelete( xQueue ); } #endif }
static void prvCreateAndDeleteStaticallyAllocatedQueues( void ) { QueueHandle_t xQueue; /* StaticQueue_t is a publicly accessible structure that has the same size and alignment requirements as the real queue structure. It is provided as a mechanism for applications to know the size of the queue (which is dependent on the architecture and configuration file settings) without breaking the strict data hiding policy by exposing the real queue internals. This StaticQueue_t variable is passed into the xQueueCreateStatic() function calls within this function. */ static StaticQueue_t xStaticQueue; /* The queue storage area must be large enough to hold the maximum number of items it is possible for the queue to hold at any one time, which equals the queue length (in items, not bytes) multiplied by the size of each item. In this case the queue will hold staticQUEUE_LENGTH_IN_ITEMS 64-bit items. See http://www.freertos.org/Embedded-RTOS-Queues.html */ static uint8_t ucQueueStorageArea[ staticQUEUE_LENGTH_IN_ITEMS * sizeof( uint64_t ) ]; /* Create the queue. xQueueCreateStatic() has two more parameters than the usual xQueueCreate() function. The first new paraemter is a pointer to the pre-allocated queue storage area. The second new parameter is a pointer to the StaticQueue_t structure that will hold the queue state information in an anonymous way. If either pointer is passed as NULL then the respective data will be allocated dynamically as if xQueueCreate() had been called. */ xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */ sizeof( uint64_t ), /* The size of each item. */ ucQueueStorageArea, /* The buffer used to hold items within the queue. */ &xStaticQueue ); /* The static queue structure that will hold the state of the queue. */ /* The queue handle should equal the static queue structure passed into the xQueueCreateStatic() function. */ configASSERT( xQueue == ( QueueHandle_t ) &xStaticQueue ); /* Ensure the queue passes a few sanity checks as a valid queue. */ prvSanityCheckCreatedQueue( xQueue ); /* Delete the queue again so the buffers can be reused. */ vQueueDelete( xQueue ); /* The queue created above had a statically allocated queue storage area and queue structure. Repeat the above with three more times - with different combinations of static and dynamic allocation. */ xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */ sizeof( uint64_t ), /* The size of each item. */ NULL, /* Allocate the buffer used to hold items within the queue dynamically. */ &xStaticQueue ); /* The static queue structure that will hold the state of the queue. */ configASSERT( xQueue == ( QueueHandle_t ) &xStaticQueue ); prvSanityCheckCreatedQueue( xQueue ); vQueueDelete( xQueue ); /* Ensure lower priority tasks get CPU time. */ vTaskDelay( prvGetNextDelayTime() ); /* Just to show the check task that this task is still executing. */ uxCycleCounter++; xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */ sizeof( uint64_t ), /* The size of each item. */ ucQueueStorageArea, /* The buffer used to hold items within the queue. */ NULL ); /* The queue structure is allocated dynamically. */ prvSanityCheckCreatedQueue( xQueue ); vQueueDelete( xQueue ); xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */ sizeof( uint64_t ), /* The size of each item. */ NULL, /* Allocate the buffer used to hold items within the queue dynamically. */ NULL ); /* The queue structure is allocated dynamically. */ prvSanityCheckCreatedQueue( xQueue ); vQueueDelete( xQueue ); /* Ensure lower priority tasks get CPU time. */ vTaskDelay( prvGetNextDelayTime() ); /* Just to show the check task that this task is still executing. */ uxCycleCounter++; }