@@ -437,6 +437,7 @@ static void prvCopyItemAllowSplit(Ringbuffer_t *pxRingbuffer, const uint8_t *puc
437
437
xItemSize -= xRemLen ;
438
438
xAlignedItemSize -= xRemLen ;
439
439
pxFirstHeader -> uxItemFlags |= rbITEM_SPLIT_FLAG ; //There must be more data
440
+ pxFirstHeader -> uxItemFlags |= rbITEM_WRITTEN_FLAG ;
440
441
} else {
441
442
//Remaining length was only large enough to fit header
442
443
pxFirstHeader -> uxItemFlags |= rbITEM_DUMMY_DATA_FLAG ; //Item will completely be stored in 2nd part
@@ -450,6 +451,7 @@ static void prvCopyItemAllowSplit(Ringbuffer_t *pxRingbuffer, const uint8_t *puc
450
451
pxSecondHeader -> uxItemFlags = 0 ;
451
452
pxRingbuffer -> pucAcquire += rbHEADER_SIZE ; //Advance acquire pointer past header
452
453
memcpy (pxRingbuffer -> pucAcquire , pucItem , xItemSize );
454
+ pxSecondHeader -> uxItemFlags |= rbITEM_WRITTEN_FLAG ;
453
455
pxRingbuffer -> xItemsWaiting ++ ;
454
456
pxRingbuffer -> pucAcquire += xAlignedItemSize ; //Advance pucAcquire past item to next aligned address
455
457
@@ -506,13 +508,6 @@ static BaseType_t prvCheckItemAvail(Ringbuffer_t *pxRingbuffer)
506
508
return pdFALSE ; //Byte buffers do not allow multiple retrievals before return
507
509
}
508
510
if ((pxRingbuffer -> xItemsWaiting > 0 ) && ((pxRingbuffer -> pucRead != pxRingbuffer -> pucWrite ) || (pxRingbuffer -> uxRingbufferFlags & rbBUFFER_FULL_FLAG ))) {
509
- // If the ring buffer is a no-split buffer, the read pointer must point to an item that has been written to.
510
- if ((pxRingbuffer -> uxRingbufferFlags & (rbBYTE_BUFFER_FLAG | rbALLOW_SPLIT_FLAG )) == 0 ) {
511
- ItemHeader_t * pxHeader = (ItemHeader_t * )pxRingbuffer -> pucRead ;
512
- if ((pxHeader -> uxItemFlags & rbITEM_WRITTEN_FLAG ) == 0 ) {
513
- return pdFALSE ;
514
- }
515
- }
516
511
return pdTRUE ; //Items/data available for retrieval
517
512
} else {
518
513
return pdFALSE ; //No items/data available for retrieval
@@ -540,22 +535,30 @@ static void *prvGetItemDefault(Ringbuffer_t *pxRingbuffer,
540
535
pxHeader = (ItemHeader_t * )pxRingbuffer -> pucRead ;
541
536
configASSERT (pxHeader -> xItemLen <= pxRingbuffer -> xMaxItemSize );
542
537
}
543
- pcReturn = pxRingbuffer -> pucRead + rbHEADER_SIZE ; //Get pointer to part of item containing data (point past the header)
544
- if (pxHeader -> xItemLen == 0 ) {
545
- //Inclusive of pucTail for special case where item of zero length just fits at the end of the buffer
546
- configASSERT (pcReturn >= pxRingbuffer -> pucHead && pcReturn <= pxRingbuffer -> pucTail );
547
- } else {
548
- //Exclusive of pucTail if length is larger than zero, pcReturn should never point to pucTail
549
- configASSERT (pcReturn >= pxRingbuffer -> pucHead && pcReturn < pxRingbuffer -> pucTail );
550
- }
551
- * pxItemSize = pxHeader -> xItemLen ; //Get length of item
552
- pxRingbuffer -> xItemsWaiting -- ; //Update item count
553
- * pxIsSplit = (pxHeader -> uxItemFlags & rbITEM_SPLIT_FLAG ) ? pdTRUE : pdFALSE ;
554
538
555
- pxRingbuffer -> pucRead += rbHEADER_SIZE + rbALIGN_SIZE (pxHeader -> xItemLen ); //Update pucRead
556
- //Check if pucRead requires wrap around
557
- if ((pxRingbuffer -> pucTail - pxRingbuffer -> pucRead ) < rbHEADER_SIZE ) {
558
- pxRingbuffer -> pucRead = pxRingbuffer -> pucHead ;
539
+ //In case of wrap around data might not be ready
540
+ if ((pxHeader -> uxItemFlags & rbITEM_WRITTEN_FLAG ) == 0 ) {
541
+ * pxIsSplit = pdFALSE ;
542
+ * pxItemSize = 0 ;
543
+ pcReturn = NULL ;
544
+ } else {
545
+ pcReturn = pxRingbuffer -> pucRead + rbHEADER_SIZE ; //Get pointer to part of item containing data (point past the header)
546
+ if (pxHeader -> xItemLen == 0 ) {
547
+ //Inclusive of pucTail for special case where item of zero length just fits at the end of the buffer
548
+ configASSERT (pcReturn >= pxRingbuffer -> pucHead && pcReturn <= pxRingbuffer -> pucTail );
549
+ } else {
550
+ //Exclusive of pucTail if length is larger than zero, pcReturn should never point to pucTail
551
+ configASSERT (pcReturn >= pxRingbuffer -> pucHead && pcReturn < pxRingbuffer -> pucTail );
552
+ }
553
+ * pxItemSize = pxHeader -> xItemLen ; //Get length of item
554
+ pxRingbuffer -> xItemsWaiting -- ; //Update item count
555
+ * pxIsSplit = (pxHeader -> uxItemFlags & rbITEM_SPLIT_FLAG ) ? pdTRUE : pdFALSE ;
556
+
557
+ pxRingbuffer -> pucRead += rbHEADER_SIZE + rbALIGN_SIZE (pxHeader -> xItemLen ); //Update pucRead
558
+ //Check if pucRead requires wrap around
559
+ if ((pxRingbuffer -> pucTail - pxRingbuffer -> pucRead ) < rbHEADER_SIZE ) {
560
+ pxRingbuffer -> pucRead = pxRingbuffer -> pucHead ;
561
+ }
559
562
}
560
563
return (void * )pcReturn ;
561
564
}
@@ -827,13 +830,14 @@ static BaseType_t prvReceiveGeneric(Ringbuffer_t *pxRingbuffer,
827
830
BaseType_t xReturn = pdFALSE ;
828
831
BaseType_t xExitLoop = pdFALSE ;
829
832
BaseType_t xEntryTimeSet = pdFALSE ;
833
+ BaseType_t xSkipCheckAvail = pdFALSE ;
830
834
TimeOut_t xTimeOut ;
831
835
832
836
ESP_STATIC_ANALYZER_CHECK (!pvItem1 || !pvItem2 || !xItemSize1 || !xItemSize2 , pdFALSE );
833
837
834
838
while (xExitLoop == pdFALSE ) {
835
839
portENTER_CRITICAL (& pxRingbuffer -> mux );
836
- if (prvCheckItemAvail (pxRingbuffer ) == pdTRUE ) {
840
+ if ((! xSkipCheckAvail ) && prvCheckItemAvail (pxRingbuffer ) == pdTRUE ) {
837
841
//Item/data is available for retrieval
838
842
BaseType_t xIsSplit = pdFALSE ;
839
843
if (pxRingbuffer -> uxRingbufferFlags & rbBYTE_BUFFER_FLAG ) {
@@ -853,9 +857,15 @@ static BaseType_t prvReceiveGeneric(Ringbuffer_t *pxRingbuffer,
853
857
* pvItem2 = NULL ;
854
858
}
855
859
}
856
- xReturn = pdTRUE ;
857
- xExitLoop = pdTRUE ;
858
- goto loop_end ;
860
+
861
+ if (* pvItem1 == NULL ) {
862
+ xSkipCheckAvail = pdTRUE ;
863
+ goto loop_end ;
864
+ } else {
865
+ xReturn = pdTRUE ;
866
+ xExitLoop = pdTRUE ;
867
+ goto loop_end ;
868
+ }
859
869
} else if (xTicksToWait == (TickType_t ) 0 ) {
860
870
//No block time. Return immediately.
861
871
xExitLoop = pdTRUE ;
@@ -868,6 +878,7 @@ static BaseType_t prvReceiveGeneric(Ringbuffer_t *pxRingbuffer,
868
878
869
879
if (xTaskCheckForTimeOut (& xTimeOut , & xTicksToWait ) == pdFALSE ) {
870
880
//Not timed out yet. Block the current task
881
+ xSkipCheckAvail = pdFALSE ;
871
882
vTaskPlaceOnEventList (& pxRingbuffer -> xTasksWaitingToReceive , xTicksToWait );
872
883
portYIELD_WITHIN_API ();
873
884
} else {
0 commit comments