static queue set

filo123 wrote on Saturday, June 30, 2018:

I want to use a statically allocated queue set (yes - I know that there are other equivalent mechanisms). There is no xQueueCreateSetStatic so I have come up with this piece of code:

#if( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )

	QueueSetHandle_t xQueueCreateSetStatic( const UBaseType_t uxEventQueueLength, uint8_t *pucQueueSetStorage, StaticQueue_t *pxStaticQueueSet )
	QueueSetHandle_t pxQueue;

		pxQueue = xQueueGenericCreateStatic( uxEventQueueLength, ( UBaseType_t ) sizeof( Queue_t * ), pucQueueSetStorage, pxStaticQueueSet, queueQUEUE_TYPE_SET );

		return pxQueue;

#endif /* configUSE_QUEUE_SETS */


  1. Is there a better/clearer way to implement this functionality?
  2. When using this function I have to pass a pointer to a buffer that will hold the queue set elements, internally each element has size sizeof(Queue_t*), which is simply size of a pointer. Is it safe to use static uint8_t queue_set_storage[sizeof(void*)*N]; as the buffer? (GCC, Cortex-M)

rtel wrote on Saturday, June 30, 2018:

That looks fine. Your application could of course just call
xQueueGeneriCreateStatic() directly, but its not a documented API
function so could change in the future - hence the way you are doing is
probably best.