mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/freemodbus_fix_mbm_event_processing_v41' into 'release/v4.1'
freemodbuss: fix event processing after merge (backport v4.1) See merge request espressif/esp-idf!12824
This commit is contained in:
commit
1e309a3885
@ -78,9 +78,11 @@ typedef enum {
|
|||||||
} eMBMasterEventType;
|
} eMBMasterEventType;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
EV_ERROR_INIT, /*!< No error, initial state. */
|
||||||
EV_ERROR_RESPOND_TIMEOUT, /*!< Slave respond timeout. */
|
EV_ERROR_RESPOND_TIMEOUT, /*!< Slave respond timeout. */
|
||||||
EV_ERROR_RECEIVE_DATA, /*!< Receive frame data erroe. */
|
EV_ERROR_RECEIVE_DATA, /*!< Receive frame data error. */
|
||||||
EV_ERROR_EXECUTE_FUNCTION, /*!< Execute function error. */
|
EV_ERROR_EXECUTE_FUNCTION, /*!< Execute function error. */
|
||||||
|
EV_ERROR_OK /*!< No error, processing completed. */
|
||||||
} eMBMasterErrorEventType;
|
} eMBMasterErrorEventType;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -285,26 +285,43 @@ eMBMasterPoll( void )
|
|||||||
* Otherwise we will handle the event. */
|
* Otherwise we will handle the event. */
|
||||||
if ( xMBMasterPortEventGet( &eEvent ) == TRUE )
|
if ( xMBMasterPortEventGet( &eEvent ) == TRUE )
|
||||||
{
|
{
|
||||||
|
while( eEvent ) {
|
||||||
// In some cases it is possible that more than one event set
|
// In some cases it is possible that more than one event set
|
||||||
// together (even from one subset mask) than process them consistently
|
// together (even from one subset mask) than process them consistently
|
||||||
if ( MB_PORT_CHECK_EVENT( eEvent, EV_MASTER_READY ) ) {
|
if ( MB_PORT_CHECK_EVENT( eEvent, EV_MASTER_READY ) ) {
|
||||||
ESP_LOGD(MB_PORT_TAG, "%s:EV_MASTER_READY", __func__);
|
ESP_LOGD(MB_PORT_TAG, "%s:EV_MASTER_READY", __func__);
|
||||||
MB_PORT_CLEAR_EVENT( eEvent, EV_MASTER_READY );
|
MB_PORT_CLEAR_EVENT( eEvent, EV_MASTER_READY );
|
||||||
|
} else if ( MB_PORT_CHECK_EVENT( eEvent, EV_MASTER_FRAME_TRANSMIT ) ) {
|
||||||
|
ESP_LOGD(MB_PORT_TAG, "%s:EV_MASTER_FRAME_TRANSMIT", __func__);
|
||||||
|
/* Master is busy now. */
|
||||||
|
vMBMasterGetPDUSndBuf( &ucMBFrame );
|
||||||
|
ESP_LOG_BUFFER_HEX_LEVEL("POLL transmit buffer", (void*)ucMBFrame, usMBMasterGetPDUSndLength(), ESP_LOG_DEBUG);
|
||||||
|
eStatus = peMBMasterFrameSendCur( ucMBMasterGetDestAddress(), ucMBFrame, usMBMasterGetPDUSndLength() );
|
||||||
|
if (eStatus != MB_ENOERR)
|
||||||
|
{
|
||||||
|
ESP_LOGE( MB_PORT_TAG, "%s:Frame send error. %d", __func__, eStatus );
|
||||||
|
}
|
||||||
|
MB_PORT_CLEAR_EVENT( eEvent, EV_MASTER_FRAME_TRANSMIT );
|
||||||
|
} else if ( MB_PORT_CHECK_EVENT( eEvent, EV_MASTER_FRAME_SENT ) ) {
|
||||||
|
ESP_LOGD( MB_PORT_TAG, "%s:EV_MASTER_FRAME_SENT", __func__ );
|
||||||
|
ESP_LOG_BUFFER_HEX_LEVEL("POLL sent buffer", (void*)ucMBFrame, usMBMasterGetPDUSndLength(), ESP_LOG_DEBUG);
|
||||||
|
MB_PORT_CLEAR_EVENT( eEvent, EV_MASTER_FRAME_SENT );
|
||||||
} else if ( MB_PORT_CHECK_EVENT( eEvent, EV_MASTER_FRAME_RECEIVED ) ) {
|
} else if ( MB_PORT_CHECK_EVENT( eEvent, EV_MASTER_FRAME_RECEIVED ) ) {
|
||||||
eStatus = peMBMasterFrameReceiveCur( &ucRcvAddress, &ucMBFrame, &usLength);
|
eStatus = peMBMasterFrameReceiveCur( &ucRcvAddress, &ucMBFrame, &usLength);
|
||||||
ESP_LOG_BUFFER_HEX_LEVEL("POLL RCV buffer:", (void*)ucMBFrame, (uint16_t)usLength, ESP_LOG_DEBUG);
|
|
||||||
// Check if the frame is for us. If not ,send an error process event.
|
// Check if the frame is for us. If not ,send an error process event.
|
||||||
if ( ( eStatus == MB_ENOERR ) && ( ucRcvAddress == ucMBMasterGetDestAddress() ) )
|
if ( ( eStatus == MB_ENOERR ) && ( ucRcvAddress == ucMBMasterGetDestAddress() ) )
|
||||||
{
|
{
|
||||||
ESP_LOGD(MB_PORT_TAG, "%s: Packet data received successfully (%u).", __func__, eStatus);
|
|
||||||
( void ) xMBMasterPortEventPost( EV_MASTER_EXECUTE );
|
( void ) xMBMasterPortEventPost( EV_MASTER_EXECUTE );
|
||||||
|
ESP_LOGD(MB_PORT_TAG, "%s: Packet data received successfully (%u).", __func__, eStatus);
|
||||||
|
ESP_LOG_BUFFER_HEX_LEVEL("POLL receive buffer", (void*)ucMBFrame, (uint16_t)usLength, ESP_LOG_DEBUG);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vMBMasterSetErrorType(EV_ERROR_RECEIVE_DATA);
|
vMBMasterSetErrorType(EV_ERROR_RECEIVE_DATA);
|
||||||
|
( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
|
||||||
ESP_LOGD( MB_PORT_TAG, "%s: Packet data receive failed (addr=%u)(%u).",
|
ESP_LOGD( MB_PORT_TAG, "%s: Packet data receive failed (addr=%u)(%u).",
|
||||||
__func__, ucRcvAddress, eStatus);
|
__func__, ucRcvAddress, eStatus);
|
||||||
( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
|
|
||||||
}
|
}
|
||||||
MB_PORT_CLEAR_EVENT( eEvent, EV_MASTER_FRAME_RECEIVED );
|
MB_PORT_CLEAR_EVENT( eEvent, EV_MASTER_FRAME_RECEIVED );
|
||||||
} else if ( MB_PORT_CHECK_EVENT( eEvent, EV_MASTER_EXECUTE ) ) {
|
} else if ( MB_PORT_CHECK_EVENT( eEvent, EV_MASTER_EXECUTE ) ) {
|
||||||
@ -351,31 +368,21 @@ eMBMasterPoll( void )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* If master has exception ,Master will send error process.Otherwise the Master is idle.*/
|
/* If master has exception, will send error process event. Otherwise the master is idle.*/
|
||||||
if (eException != MB_EX_NONE)
|
if ( eException != MB_EX_NONE )
|
||||||
{
|
{
|
||||||
vMBMasterSetErrorType(EV_ERROR_EXECUTE_FUNCTION);
|
vMBMasterSetErrorType( EV_ERROR_EXECUTE_FUNCTION );
|
||||||
( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
|
( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vMBMasterCBRequestSuccess( );
|
if ( eMBMasterGetErrorType( ) == EV_ERROR_INIT ) {
|
||||||
vMBMasterRunResRelease( );
|
vMBMasterSetErrorType(EV_ERROR_OK);
|
||||||
|
ESP_LOGD( MB_PORT_TAG, "%s: set event EV_ERROR_OK", __func__ );
|
||||||
|
( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MB_PORT_CLEAR_EVENT( eEvent, EV_MASTER_EXECUTE );
|
MB_PORT_CLEAR_EVENT( eEvent, EV_MASTER_EXECUTE );
|
||||||
} else if ( MB_PORT_CHECK_EVENT( eEvent, EV_MASTER_FRAME_TRANSMIT ) ) {
|
|
||||||
ESP_LOGD(MB_PORT_TAG, "%s:EV_MASTER_FRAME_TRANSMIT", __func__);
|
|
||||||
/* Master is busy now. */
|
|
||||||
vMBMasterGetPDUSndBuf( &ucMBFrame );
|
|
||||||
eStatus = peMBMasterFrameSendCur( ucMBMasterGetDestAddress(), ucMBFrame, usMBMasterGetPDUSndLength() );
|
|
||||||
if (eStatus != MB_ENOERR)
|
|
||||||
{
|
|
||||||
ESP_LOGE( MB_PORT_TAG, "%s:Frame send error. %d", __func__, eStatus );
|
|
||||||
}
|
|
||||||
MB_PORT_CLEAR_EVENT( eEvent, EV_MASTER_FRAME_TRANSMIT );
|
|
||||||
} else if ( MB_PORT_CHECK_EVENT( eEvent, EV_MASTER_FRAME_SENT ) ) {
|
|
||||||
ESP_LOGD( MB_PORT_TAG, "%s:EV_MASTER_FRAME_SENT", __func__ );
|
|
||||||
MB_PORT_CLEAR_EVENT( eEvent, EV_MASTER_FRAME_SENT );
|
|
||||||
} else if ( MB_PORT_CHECK_EVENT( eEvent, EV_MASTER_ERROR_PROCESS ) ) {
|
} else if ( MB_PORT_CHECK_EVENT( eEvent, EV_MASTER_ERROR_PROCESS ) ) {
|
||||||
ESP_LOGD( MB_PORT_TAG, "%s:EV_MASTER_ERROR_PROCESS", __func__ );
|
ESP_LOGD( MB_PORT_TAG, "%s:EV_MASTER_ERROR_PROCESS", __func__ );
|
||||||
/* Execute specified error process callback function. */
|
/* Execute specified error process callback function. */
|
||||||
@ -395,22 +402,21 @@ eMBMasterPoll( void )
|
|||||||
vMBMasterErrorCBExecuteFunction( ucMBMasterGetDestAddress( ),
|
vMBMasterErrorCBExecuteFunction( ucMBMasterGetDestAddress( ),
|
||||||
ucMBFrame, usMBMasterGetPDUSndLength( ) );
|
ucMBFrame, usMBMasterGetPDUSndLength( ) );
|
||||||
break;
|
break;
|
||||||
|
case EV_ERROR_OK:
|
||||||
|
vMBMasterCBRequestSuccess( );
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
ESP_LOGE( MB_PORT_TAG, "%s: incorrect error type = %d.", __func__, errorType);
|
ESP_LOGE( MB_PORT_TAG, "%s: incorrect error type = %d.", __func__, errorType);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
vMBMasterRunResRelease( );
|
vMBMasterSetErrorType( EV_ERROR_INIT );
|
||||||
MB_PORT_CLEAR_EVENT( eEvent, EV_MASTER_ERROR_PROCESS );
|
MB_PORT_CLEAR_EVENT( eEvent, EV_MASTER_ERROR_PROCESS );
|
||||||
|
vMBMasterRunResRelease( );
|
||||||
}
|
}
|
||||||
if ( eEvent ) {
|
|
||||||
// Event processing is done, but some poll events still set then
|
|
||||||
// postpone its processing for next poll cycle (rare case).
|
|
||||||
ESP_LOGW( MB_PORT_TAG, "%s: Unprocessed event %d.", __func__, eEvent );
|
|
||||||
( void ) xMBMasterPortEventPost( eEvent );
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Something went wrong and task unblocked but there are no any correct events set
|
// Something went wrong and task unblocked but there are no any correct events set
|
||||||
ESP_LOGE( MB_PORT_TAG, "%s: Unexpected event triggered %d.", __func__, eEvent );
|
ESP_LOGE( MB_PORT_TAG, "%s: Unexpected event triggered 0x%02x.", __func__, eEvent );
|
||||||
eStatus = MB_EILLSTATE;
|
eStatus = MB_EILLSTATE;
|
||||||
}
|
}
|
||||||
return eStatus;
|
return eStatus;
|
||||||
|
Loading…
Reference in New Issue
Block a user