Skip to content

Commit b5f7086

Browse files
author
hagai.moshe
committed
Add API xStreamBufferResetFromISR
Allow reseting the stream buffer from ISR context Signed-off-by: hagai.moshe <hagaimoshe@outlook.com>
1 parent 6de0d7a commit b5f7086

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

include/stream_buffer.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,34 @@ BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED
781781
*/
782782
BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
783783

784+
/**
785+
* stream_buffer.h
786+
*
787+
* @code{c}
788+
* BaseType_t xStreamBufferResetFromISR( StreamBufferHandle_t xStreamBuffer );
789+
* @endcode
790+
*
791+
* An interrupt safe version of the API function that reset the stream buffer.
792+
*
793+
* Resets a stream buffer to its initial, empty, state. Any data that was in
794+
* the stream buffer is discarded. A stream buffer can only be reset if there
795+
* are no tasks blocked waiting to either send to or receive from the stream
796+
* buffer.
797+
*
798+
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
799+
* xStreamBufferResetFromISR() to be available.
800+
*
801+
* @param xStreamBuffer The handle of the stream buffer being reset.
802+
*
803+
* @return If the stream buffer is reset then pdPASS is returned. If there was
804+
* a task blocked waiting to send to or read from the stream buffer then the
805+
* stream buffer is not reset and pdFAIL is returned.
806+
*
807+
* \defgroup xStreamBufferResetFromISR xStreamBufferResetFromISR
808+
* \ingroup StreamBufferManagement
809+
*/
810+
BaseType_t xStreamBufferResetFromISR( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
811+
784812
/**
785813
* stream_buffer.h
786814
*

stream_buffer.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,68 @@ BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer )
639639
}
640640
/*-----------------------------------------------------------*/
641641

642+
BaseType_t xStreamBufferResetFromISR( StreamBufferHandle_t xStreamBuffer )
643+
{
644+
StreamBuffer_t * const pxStreamBuffer = xStreamBuffer;
645+
BaseType_t xReturn = pdFAIL;
646+
StreamBufferCallbackFunction_t pxSendCallback = NULL, pxReceiveCallback = NULL;
647+
UBaseType_t uxSavedInterruptStatus;
648+
649+
#if ( configUSE_TRACE_FACILITY == 1 )
650+
UBaseType_t uxStreamBufferNumber;
651+
#endif
652+
653+
traceENTER_xStreamBufferResetFromISR( xStreamBuffer );
654+
655+
configASSERT( pxStreamBuffer );
656+
657+
#if ( configUSE_TRACE_FACILITY == 1 )
658+
{
659+
/* Store the stream buffer number so it can be restored after the
660+
* reset. */
661+
uxStreamBufferNumber = pxStreamBuffer->uxStreamBufferNumber;
662+
}
663+
#endif
664+
665+
/* Can only reset a message buffer if there are no tasks blocked on it. */
666+
uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
667+
{
668+
if( ( pxStreamBuffer->xTaskWaitingToReceive == NULL ) && ( pxStreamBuffer->xTaskWaitingToSend == NULL ) )
669+
{
670+
#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
671+
{
672+
pxSendCallback = pxStreamBuffer->pxSendCompletedCallback;
673+
pxReceiveCallback = pxStreamBuffer->pxReceiveCompletedCallback;
674+
}
675+
#endif
676+
677+
prvInitialiseNewStreamBuffer( pxStreamBuffer,
678+
pxStreamBuffer->pucBuffer,
679+
pxStreamBuffer->xLength,
680+
pxStreamBuffer->xTriggerLevelBytes,
681+
pxStreamBuffer->ucFlags,
682+
pxSendCallback,
683+
pxReceiveCallback );
684+
685+
#if ( configUSE_TRACE_FACILITY == 1 )
686+
{
687+
pxStreamBuffer->uxStreamBufferNumber = uxStreamBufferNumber;
688+
}
689+
#endif
690+
691+
traceSTREAM_BUFFER_RESET( xStreamBuffer );
692+
693+
xReturn = pdPASS;
694+
}
695+
}
696+
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
697+
698+
traceRETURN_xStreamBufferResetFromISR( xReturn );
699+
700+
return xReturn;
701+
}
702+
/*-----------------------------------------------------------*/
703+
642704
BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer,
643705
size_t xTriggerLevel )
644706
{

0 commit comments

Comments
 (0)