mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-09-09 23:57:49 -04:00
Add API xStreamBufferResetFromISR
Allow reseting the stream buffer from ISR context Signed-off-by: hagai.moshe <hagaimoshe@outlook.com>
This commit is contained in:
parent
6de0d7a737
commit
887e78c64f
3 changed files with 98 additions and 0 deletions
|
@ -2437,6 +2437,14 @@
|
|||
#define traceRETURN_xStreamBufferReset( xReturn )
|
||||
#endif
|
||||
|
||||
#ifndef traceENTER_xStreamBufferResetFromISR
|
||||
#define traceENTER_xStreamBufferResetFromISR( xStreamBuffer )
|
||||
#endif
|
||||
|
||||
#ifndef traceRETURN_xStreamBufferResetFromISR
|
||||
#define traceRETURN_xStreamBufferResetFromISR( xReturn )
|
||||
#endif
|
||||
|
||||
#ifndef traceENTER_xStreamBufferSetTriggerLevel
|
||||
#define traceENTER_xStreamBufferSetTriggerLevel( xStreamBuffer, xTriggerLevel )
|
||||
#endif
|
||||
|
|
|
@ -781,6 +781,34 @@ BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED
|
|||
*/
|
||||
BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
|
||||
|
||||
/**
|
||||
* stream_buffer.h
|
||||
*
|
||||
* @code{c}
|
||||
* BaseType_t xStreamBufferResetFromISR( StreamBufferHandle_t xStreamBuffer );
|
||||
* @endcode
|
||||
*
|
||||
* An interrupt safe version of the API function that reset the stream buffer.
|
||||
*
|
||||
* Resets a stream buffer to its initial, empty, state. Any data that was in
|
||||
* the stream buffer is discarded. A stream buffer can only be reset if there
|
||||
* are no tasks blocked waiting to either send to or receive from the stream
|
||||
* buffer.
|
||||
*
|
||||
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
|
||||
* xStreamBufferResetFromISR() to be available.
|
||||
*
|
||||
* @param xStreamBuffer The handle of the stream buffer being reset.
|
||||
*
|
||||
* @return If the stream buffer is reset then pdPASS is returned. If there was
|
||||
* a task blocked waiting to send to or read from the stream buffer then the
|
||||
* stream buffer is not reset and pdFAIL is returned.
|
||||
*
|
||||
* \defgroup xStreamBufferResetFromISR xStreamBufferResetFromISR
|
||||
* \ingroup StreamBufferManagement
|
||||
*/
|
||||
BaseType_t xStreamBufferResetFromISR( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
|
||||
|
||||
/**
|
||||
* stream_buffer.h
|
||||
*
|
||||
|
|
|
@ -639,6 +639,68 @@ BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xStreamBufferResetFromISR( StreamBufferHandle_t xStreamBuffer )
|
||||
{
|
||||
StreamBuffer_t * const pxStreamBuffer = xStreamBuffer;
|
||||
BaseType_t xReturn = pdFAIL;
|
||||
StreamBufferCallbackFunction_t pxSendCallback = NULL, pxReceiveCallback = NULL;
|
||||
UBaseType_t uxSavedInterruptStatus;
|
||||
|
||||
#if ( configUSE_TRACE_FACILITY == 1 )
|
||||
UBaseType_t uxStreamBufferNumber;
|
||||
#endif
|
||||
|
||||
traceENTER_xStreamBufferResetFromISR( xStreamBuffer );
|
||||
|
||||
configASSERT( pxStreamBuffer );
|
||||
|
||||
#if ( configUSE_TRACE_FACILITY == 1 )
|
||||
{
|
||||
/* Store the stream buffer number so it can be restored after the
|
||||
* reset. */
|
||||
uxStreamBufferNumber = pxStreamBuffer->uxStreamBufferNumber;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Can only reset a message buffer if there are no tasks blocked on it. */
|
||||
uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
|
||||
{
|
||||
if( ( pxStreamBuffer->xTaskWaitingToReceive == NULL ) && ( pxStreamBuffer->xTaskWaitingToSend == NULL ) )
|
||||
{
|
||||
#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
|
||||
{
|
||||
pxSendCallback = pxStreamBuffer->pxSendCompletedCallback;
|
||||
pxReceiveCallback = pxStreamBuffer->pxReceiveCompletedCallback;
|
||||
}
|
||||
#endif
|
||||
|
||||
prvInitialiseNewStreamBuffer( pxStreamBuffer,
|
||||
pxStreamBuffer->pucBuffer,
|
||||
pxStreamBuffer->xLength,
|
||||
pxStreamBuffer->xTriggerLevelBytes,
|
||||
pxStreamBuffer->ucFlags,
|
||||
pxSendCallback,
|
||||
pxReceiveCallback );
|
||||
|
||||
#if ( configUSE_TRACE_FACILITY == 1 )
|
||||
{
|
||||
pxStreamBuffer->uxStreamBufferNumber = uxStreamBufferNumber;
|
||||
}
|
||||
#endif
|
||||
|
||||
traceSTREAM_BUFFER_RESET( xStreamBuffer );
|
||||
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
|
||||
|
||||
traceRETURN_xStreamBufferResetFromISR( xReturn );
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer,
|
||||
size_t xTriggerLevel )
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue