mirror of
https://github.com/espressif/esp-modbus.git
synced 2025-07-29 18:07:17 +02:00
Bugfix/fix stuck in init on incorrect data input
This commit is contained in:
@ -137,7 +137,7 @@ eMBMasterASCIIStart( void )
|
||||
ENTER_CRITICAL_SECTION( );
|
||||
eRcvState = STATE_M_RX_IDLE;
|
||||
vMBMasterPortSerialEnable( TRUE, FALSE );
|
||||
vMBMasterPortTimersT35Enable( );
|
||||
xMBMasterPortEventPost(EV_MASTER_READY);
|
||||
EXIT_CRITICAL_SECTION( );
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ eMBMasterTCPInit( USHORT ucTCPPort )
|
||||
|
||||
// initialize the OS resource for modbus master.
|
||||
vMBMasterOsResInit();
|
||||
if( xMBMasterPortTimersInit( MB_MASTER_TIMEOUT_MS_RESPOND * MB_TIMER_TICS_PER_MS ) != TRUE )
|
||||
if (xMBMasterPortTimersInit(MB_MASTER_TIMEOUT_MS_RESPOND * MB_TIMER_TICS_PER_MS) != TRUE)
|
||||
{
|
||||
eStatus = MB_EPORTERR;
|
||||
}
|
||||
@ -338,6 +338,8 @@ eMBMasterPoll( void )
|
||||
// together (even from one subset mask) than process them consistently
|
||||
if ( MB_PORT_CHECK_EVENT( eEvent, EV_MASTER_READY ) ) {
|
||||
ESP_LOGD(MB_PORT_TAG, "%s:EV_MASTER_READY", __func__);
|
||||
vMBMasterSetErrorType( EV_ERROR_INIT );
|
||||
vMBMasterRunResRelease( );
|
||||
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__);
|
||||
@ -359,8 +361,8 @@ eMBMasterPoll( void )
|
||||
MB_PORT_CLEAR_EVENT( eEvent, EV_MASTER_FRAME_SENT );
|
||||
} else if ( MB_PORT_CHECK_EVENT( eEvent, EV_MASTER_FRAME_RECEIVED ) ) {
|
||||
if (xTransactionIsActive) {
|
||||
ESP_LOGD( MB_PORT_TAG, "%s:EV_MASTER_FRAME_RECEIVED", __func__ );
|
||||
eStatus = peMBMasterFrameReceiveCur( &ucRcvAddress, &ucMBRcvFrame, &usLength);
|
||||
MB_PORT_CHECK(ucMBRcvFrame, MB_EILLSTATE, "Receive buffer initialization fail.");
|
||||
MB_PORT_CHECK(ucMBSendFrame, MB_EILLSTATE, "Send buffer initialization fail.");
|
||||
// Check if the frame is for us. If not ,send an error process event.
|
||||
if ( ( eStatus == MB_ENOERR ) && ( ( ucRcvAddress == ucMBMasterGetDestAddress() )
|
||||
|
@ -141,7 +141,7 @@ eMBMasterRTUStart( void )
|
||||
* to STATE_M_RX_IDLE. This makes sure that we delay startup of the
|
||||
* modbus protocol stack until the bus is free.
|
||||
*/
|
||||
eRcvState = STATE_M_RX_IDLE; //STATE_M_RX_INIT (We start processing immediately)
|
||||
eRcvState = STATE_M_RX_INIT;
|
||||
vMBMasterPortSerialEnable( TRUE, FALSE );
|
||||
vMBMasterPortTimersT35Enable( );
|
||||
|
||||
@ -264,6 +264,7 @@ xMBMasterRTUReceiveFSM( void )
|
||||
*/
|
||||
case STATE_M_RX_INIT:
|
||||
vMBMasterPortTimersT35Enable( );
|
||||
ESP_LOGD("DBG", "Start initialization phase.");
|
||||
break;
|
||||
|
||||
/* In the error state we wait until all characters in the
|
||||
@ -381,6 +382,7 @@ xMBMasterRTUTimerExpired(void)
|
||||
/* Timer t35 expired. Startup phase is finished. */
|
||||
case STATE_M_RX_INIT:
|
||||
xNeedPoll = xMBMasterPortEventPost(EV_MASTER_READY);
|
||||
ESP_EARLY_LOGD("DBG", "RTU timer, init FSM state.");
|
||||
break;
|
||||
|
||||
/* A frame was received and t35 expired. Notify the listener that
|
||||
|
@ -160,7 +160,6 @@ xMBMasterPortEventGet( eMBMasterEventType* eEvent )
|
||||
void vMBMasterOsResInit( void )
|
||||
{
|
||||
xResourceMasterHdl = xEventGroupCreate();
|
||||
xEventGroupSetBits(xResourceMasterHdl, MB_EVENT_RESOURCE);
|
||||
MB_PORT_CHECK((xResourceMasterHdl != NULL), ; , "Resource create error.");
|
||||
}
|
||||
|
||||
|
@ -101,14 +101,12 @@ static BOOL xMBMasterPortTimersEnable(uint64_t xToutUs)
|
||||
|
||||
void vMBMasterPortTimersT35Enable(void)
|
||||
{
|
||||
#if CONFIG_FMB_TIMER_PORT_ENABLED
|
||||
uint64_t xToutUs = (pxTimerContext->usT35Ticks * MB_TIMER_TICK_TIME_US);
|
||||
|
||||
// Set current timer mode, don't change it.
|
||||
vMBMasterSetCurTimerMode(MB_TMODE_T35);
|
||||
// Set timer alarm
|
||||
(void)xMBMasterPortTimersEnable(xToutUs);
|
||||
#endif
|
||||
}
|
||||
|
||||
void vMBMasterPortTimersConvertDelayEnable(void)
|
||||
|
@ -682,6 +682,8 @@ static void vMBTCPPortMasterTask(void *pvParameters)
|
||||
ESP_LOGE(TAG, "Fail to register slave IP.");
|
||||
} else {
|
||||
if (xSlaveAddrInfo.pcIPAddr == NULL && xMbPortConfig.usMbSlaveInfoCount && xSlaveAddrInfo.usIndex == 0xFF) {
|
||||
// Init start timeout that allows to initialize the main FSM
|
||||
xMBMasterPortEventPost(EV_MASTER_READY);
|
||||
break;
|
||||
}
|
||||
if (xMbPortConfig.usMbSlaveInfoCount > MB_TCP_PORT_MAX_CONN) {
|
||||
@ -1020,10 +1022,12 @@ BOOL MB_PORT_ISR_ATTR
|
||||
xMBMasterTCPTimerExpired(void)
|
||||
{
|
||||
BOOL xNeedPoll = FALSE;
|
||||
eMBMasterTimerMode eTimerMode = xMBMasterGetCurTimerMode();
|
||||
|
||||
vMBMasterPortTimersDisable();
|
||||
|
||||
// If timer mode is respond timeout, the master event then turns EV_MASTER_EXECUTE status.
|
||||
if (xMBMasterGetCurTimerMode() == MB_TMODE_RESPOND_TIMEOUT) {
|
||||
if (eTimerMode == MB_TMODE_RESPOND_TIMEOUT) {
|
||||
vMBMasterSetErrorType(EV_ERROR_RESPOND_TIMEOUT);
|
||||
xNeedPoll = xMBMasterPortEventPost(EV_MASTER_ERROR_PROCESS);
|
||||
}
|
||||
|
Reference in New Issue
Block a user