Merge branch 'bugfix/ringbuf_static_object_size_v5.0' into 'release/v5.0'

Ringbuf: Fix ordering of StaticRingbuffer_t (v5.0)

See merge request espressif/esp-idf!24594
This commit is contained in:
Marius Vikhammer
2023-07-17 10:12:02 +08:00
2 changed files with 4 additions and 38 deletions

View File

@ -57,18 +57,16 @@ typedef enum {
* buffer's control data structure. * buffer's control data structure.
* *
*/ */
#if ( configSUPPORT_STATIC_ALLOCATION == 1)
typedef struct xSTATIC_RINGBUFFER { typedef struct xSTATIC_RINGBUFFER {
/** @cond */ //Doxygen command to hide this structure from API Reference /** @cond */ //Doxygen command to hide this structure from API Reference
size_t xDummy1[2]; size_t xDummy1[2];
UBaseType_t uxDummy2; UBaseType_t uxDummy2;
BaseType_t xDummy3; void *pvDummy3[11];
void *pvDummy4[11]; BaseType_t xDummy4;
StaticSemaphore_t xDummy5[2]; StaticSemaphore_t xDummy5[2];
portMUX_TYPE muxDummy; portMUX_TYPE muxDummy;
/** @endcond */ /** @endcond */
} StaticRingbuffer_t; } StaticRingbuffer_t;
#endif
/** /**
* @brief Create a ring buffer * @brief Create a ring buffer
@ -111,12 +109,10 @@ RingbufHandle_t xRingbufferCreateNoSplit(size_t xItemSize, size_t xItemNum);
* *
* @return A handle to the created ring buffer * @return A handle to the created ring buffer
*/ */
#if ( configSUPPORT_STATIC_ALLOCATION == 1)
RingbufHandle_t xRingbufferCreateStatic(size_t xBufferSize, RingbufHandle_t xRingbufferCreateStatic(size_t xBufferSize,
RingbufferType_t xBufferType, RingbufferType_t xBufferType,
uint8_t *pucRingbufferStorage, uint8_t *pucRingbufferStorage,
StaticRingbuffer_t *pxStaticRingbuffer); StaticRingbuffer_t *pxStaticRingbuffer);
#endif
/** /**
* @brief Insert an item into the ring buffer * @brief Insert an item into the ring buffer

View File

@ -29,13 +29,8 @@
#define rbITEM_WRITTEN_FLAG ( ( UBaseType_t ) 8 ) //Item has been written to by the application, thus can be read #define rbITEM_WRITTEN_FLAG ( ( UBaseType_t ) 8 ) //Item has been written to by the application, thus can be read
//Static allocation related //Static allocation related
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
#define rbGET_TX_SEM_HANDLE( pxRingbuffer ) ( (SemaphoreHandle_t) &(pxRingbuffer->xTransSemStatic) ) #define rbGET_TX_SEM_HANDLE( pxRingbuffer ) ( (SemaphoreHandle_t) &(pxRingbuffer->xTransSemStatic) )
#define rbGET_RX_SEM_HANDLE( pxRingbuffer ) ( (SemaphoreHandle_t) &(pxRingbuffer->xRecvSemStatic) ) #define rbGET_RX_SEM_HANDLE( pxRingbuffer ) ( (SemaphoreHandle_t) &(pxRingbuffer->xRecvSemStatic) )
#else
#define rbGET_TX_SEM_HANDLE( pxRingbuffer ) ( pxRingbuffer->xTransSemHandle )
#define rbGET_RX_SEM_HANDLE( pxRingbuffer ) ( pxRingbuffer->xRecvSemHandle )
#endif
typedef struct { typedef struct {
//This size of this structure must be 32-bit aligned //This size of this structure must be 32-bit aligned
@ -87,21 +82,13 @@ typedef struct RingbufferDefinition {
* making the ring buffer's control structure slightly smaller when * making the ring buffer's control structure slightly smaller when
* static allocation is disabled. * static allocation is disabled.
*/ */
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
StaticSemaphore_t xTransSemStatic; StaticSemaphore_t xTransSemStatic;
StaticSemaphore_t xRecvSemStatic; StaticSemaphore_t xRecvSemStatic;
#else
SemaphoreHandle_t xTransSemHandle;
SemaphoreHandle_t xRecvSemHandle;
#endif
portMUX_TYPE mux; //Spinlock required for SMP portMUX_TYPE mux; //Spinlock required for SMP
} Ringbuffer_t; } Ringbuffer_t;
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
#if __GNUC_PREREQ(4, 6)
_Static_assert(sizeof(StaticRingbuffer_t) == sizeof(Ringbuffer_t), "StaticRingbuffer_t != Ringbuffer_t"); _Static_assert(sizeof(StaticRingbuffer_t) == sizeof(Ringbuffer_t), "StaticRingbuffer_t != Ringbuffer_t");
#endif
#endif
/* /*
Remark: A counting semaphore for items_buffered_sem would be more logical, but counting semaphores in Remark: A counting semaphore for items_buffered_sem would be more logical, but counting semaphores in
FreeRTOS need a maximum count, and allocate more memory the larger the maximum count is. Here, we FreeRTOS need a maximum count, and allocate more memory the larger the maximum count is. Here, we
@ -885,23 +872,9 @@ RingbufHandle_t xRingbufferCreate(size_t xBufferSize, RingbufferType_t xBufferTy
} }
//Initialize Semaphores //Initialize Semaphores
#if ( configSUPPORT_STATIC_ALLOCATION == 1)
//We don't use the handles for static semaphores, and xSemaphoreCreateBinaryStatic will never fail thus no need to check static case //We don't use the handles for static semaphores, and xSemaphoreCreateBinaryStatic will never fail thus no need to check static case
xSemaphoreCreateBinaryStatic(&(pxNewRingbuffer->xTransSemStatic)); xSemaphoreCreateBinaryStatic(&(pxNewRingbuffer->xTransSemStatic));
xSemaphoreCreateBinaryStatic(&(pxNewRingbuffer->xRecvSemStatic)); xSemaphoreCreateBinaryStatic(&(pxNewRingbuffer->xRecvSemStatic));
#else
pxNewRingbuffer->xTransSemHandle = xSemaphoreCreateBinary();
pxNewRingbuffer->xRecvSemHandle = xSemaphoreCreateBinary();
if (pxNewRingbuffer->xTransSemHandle == NULL || pxNewRingbuffer->xRecvSemHandle == NULL) {
if (pxNewRingbuffer->xTransSemHandle != NULL) {
vSemaphoreDelete(pxNewRingbuffer->xTransSemHandle);
}
if (pxNewRingbuffer->xRecvSemHandle != NULL) {
vSemaphoreDelete(pxNewRingbuffer->xRecvSemHandle);
}
goto err;
}
#endif
prvInitializeNewRingbuffer(xBufferSize, xBufferType, pxNewRingbuffer, pucRingbufferStorage); prvInitializeNewRingbuffer(xBufferSize, xBufferType, pxNewRingbuffer, pucRingbufferStorage);
return (RingbufHandle_t)pxNewRingbuffer; return (RingbufHandle_t)pxNewRingbuffer;
@ -918,7 +891,6 @@ RingbufHandle_t xRingbufferCreateNoSplit(size_t xItemSize, size_t xItemNum)
return xRingbufferCreate((rbALIGN_SIZE(xItemSize) + rbHEADER_SIZE) * xItemNum, RINGBUF_TYPE_NOSPLIT); return xRingbufferCreate((rbALIGN_SIZE(xItemSize) + rbHEADER_SIZE) * xItemNum, RINGBUF_TYPE_NOSPLIT);
} }
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
RingbufHandle_t xRingbufferCreateStatic(size_t xBufferSize, RingbufHandle_t xRingbufferCreateStatic(size_t xBufferSize,
RingbufferType_t xBufferType, RingbufferType_t xBufferType,
uint8_t *pucRingbufferStorage, uint8_t *pucRingbufferStorage,
@ -940,7 +912,6 @@ RingbufHandle_t xRingbufferCreateStatic(size_t xBufferSize,
pxNewRingbuffer->uxRingbufferFlags |= rbBUFFER_STATIC_FLAG; pxNewRingbuffer->uxRingbufferFlags |= rbBUFFER_STATIC_FLAG;
return (RingbufHandle_t)pxNewRingbuffer; return (RingbufHandle_t)pxNewRingbuffer;
} }
#endif
BaseType_t xRingbufferSendAcquire(RingbufHandle_t xRingbuffer, void **ppvItem, size_t xItemSize, TickType_t xTicksToWait) BaseType_t xRingbufferSendAcquire(RingbufHandle_t xRingbuffer, void **ppvItem, size_t xItemSize, TickType_t xTicksToWait)
{ {
@ -1317,12 +1288,11 @@ void vRingbufferDelete(RingbufHandle_t xRingbuffer)
vSemaphoreDelete(rbGET_TX_SEM_HANDLE(pxRingbuffer)); vSemaphoreDelete(rbGET_TX_SEM_HANDLE(pxRingbuffer));
vSemaphoreDelete(rbGET_RX_SEM_HANDLE(pxRingbuffer)); vSemaphoreDelete(rbGET_RX_SEM_HANDLE(pxRingbuffer));
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
if (pxRingbuffer->uxRingbufferFlags & rbBUFFER_STATIC_FLAG) { if (pxRingbuffer->uxRingbufferFlags & rbBUFFER_STATIC_FLAG) {
//Ring buffer was statically allocated, no need to free //Ring buffer was statically allocated, no need to free
return; return;
} }
#endif
free(pxRingbuffer->pucHead); free(pxRingbuffer->pucHead);
free(pxRingbuffer); free(pxRingbuffer);
} }