| 382 | #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) |
| 383 | |
| 384 | QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, |
| 385 | const UBaseType_t uxItemSize, |
| 386 | const uint8_t ucQueueType ) |
| 387 | { |
| 388 | Queue_t * pxNewQueue; |
| 389 | size_t xQueueSizeInBytes; |
| 390 | uint8_t * pucQueueStorage; |
| 391 | |
| 392 | configASSERT( uxQueueLength > ( UBaseType_t ) 0 ); |
| 393 | |
| 394 | /* Allocate enough space to hold the maximum number of items that |
| 395 | * can be in the queue at any time. It is valid for uxItemSize to be |
| 396 | * zero in the case the queue is used as a semaphore. */ |
| 397 | xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ |
| 398 | |
| 399 | /* Check for multiplication overflow. */ |
| 400 | configASSERT( ( uxItemSize == 0 ) || ( uxQueueLength == ( xQueueSizeInBytes / uxItemSize ) ) ); |
| 401 | |
| 402 | /* Check for addition overflow. */ |
| 403 | configASSERT( ( sizeof( Queue_t ) + xQueueSizeInBytes ) > xQueueSizeInBytes ); |
| 404 | |
| 405 | /* Allocate the queue and storage area. Justification for MISRA |
| 406 | * deviation as follows: pvPortMalloc() always ensures returned memory |
| 407 | * blocks are aligned per the requirements of the MCU stack. In this case |
| 408 | * pvPortMalloc() must return a pointer that is guaranteed to meet the |
| 409 | * alignment requirements of the Queue_t structure - which in this case |
| 410 | * is an int8_t *. Therefore, whenever the stack alignment requirements |
| 411 | * are greater than or equal to the pointer to char requirements the cast |
| 412 | * is safe. In other cases alignment requirements are not strict (one or |
| 413 | * two bytes). */ |
| 414 | pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) + xQueueSizeInBytes ); /*lint !e9087 !e9079 see comment above. */ |
| 415 | |
| 416 | if( pxNewQueue != NULL ) |
| 417 | { |
| 418 | /* Jump past the queue structure to find the location of the queue |
| 419 | * storage area. */ |
| 420 | pucQueueStorage = ( uint8_t * ) pxNewQueue; |
| 421 | pucQueueStorage += sizeof( Queue_t ); /*lint !e9016 Pointer arithmetic allowed on char types, especially when it assists conveying intent. */ |
| 422 | |
| 423 | #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) |
| 424 | { |
| 425 | /* Queues can be created either statically or dynamically, so |
| 426 | * note this task was created dynamically in case it is later |
| 427 | * deleted. */ |
| 428 | pxNewQueue->ucStaticallyAllocated = pdFALSE; |
| 429 | } |
| 430 | #endif /* configSUPPORT_STATIC_ALLOCATION */ |
| 431 | |
| 432 | prvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue ); |
| 433 | } |
| 434 | else |
| 435 | { |
| 436 | traceQUEUE_CREATE_FAILED( ucQueueType ); |
| 437 | mtCOVERAGE_TEST_MARKER(); |
| 438 | } |
| 439 | |
| 440 | return pxNewQueue; |
| 441 | } |
no test coverage detected