mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-08-06 17:30:22 +08:00
Add IRQ safe API for message buffer reset (#1033)
* Add API xStreamBufferResetFromISR Allow reseting the stream buffer from ISR context Signed-off-by: hagai.moshe <hagaimoshe@outlook.com> Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> Co-authored-by: hagai.moshe <hagai.moshe@tandemg.com> Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com> Co-authored-by: kar-rahul-aws <karahulx@amazon.com> Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
This commit is contained in:
@ -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_FROM_ISR( xStreamBuffer );
|
||||
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
|
||||
|
||||
traceRETURN_xStreamBufferResetFromISR( xReturn );
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer,
|
||||
size_t xTriggerLevel )
|
||||
{
|
||||
|
Reference in New Issue
Block a user