@@ -161,37 +161,55 @@ void mb_port_event_res_release(mb_port_base_t *inst)
161161 }
162162}
163163
164- void mb_port_event_set_resp_flag (mb_port_base_t * inst , mb_event_enum_t event_mask )
164+ void mb_port_event_set_resp_flag (mb_port_base_t * inst , mb_err_event_t event_mask )
165165{
166166 MB_RETURN_ON_FALSE ((inst ), ;, TAG , "incorrect object handle." );
167- (void )xEventGroupSetBits (inst -> event_obj -> event_group_hdl , event_mask );
167+ (void )xEventGroupSetBits (inst -> event_obj -> event_group_hdl , ( EventBits_t ) event_mask );
168168}
169169
170170mb_err_enum_t mb_port_event_wait_req_finish (mb_port_base_t * inst )
171171{
172172 MB_RETURN_ON_FALSE ((inst ), MB_EINVAL , TAG ,
173173 "incorrect object handle." );
174- mb_err_enum_t err_status = MB_ENOERR ;
175- mb_event_enum_t rcv_event ;
176- EventBits_t bits = xEventGroupWaitBits (inst -> event_obj -> event_group_hdl ,// The event group being tested.
177- MB_EVENT_REQ_MASK , // The bits within the event group to wait for.
178- pdTRUE , // Masked bits should be cleared before returning.
179- pdFALSE , // Don't wait for both bits, either bit will do.
180- MB_EVENT_QUEUE_TIMEOUT_MAX );// Wait forever for either bit to be set.
181- rcv_event = (mb_event_enum_t )(bits );
174+ mb_err_enum_t err_status = MB_ETIMEDOUT ;
175+ mb_err_event_t rcv_event ;
176+ EventBits_t bits = EV_ERROR_INIT ;
177+ bits = xEventGroupWaitBits (inst -> event_obj -> event_group_hdl , // The event group being tested.
178+ MB_EVENT_REQ_MASK , // The bits within the event group to wait for.
179+ pdTRUE , // Masked bits should be cleared before returning.
180+ pdFALSE , // Don't wait for both bits, either bit will do.
181+ MB_EVENT_QUEUE_TIMEOUT_MAX ); // Wait forever for either bit to be set.
182+ rcv_event = (mb_err_event_t )(bits );
182183 if (rcv_event ) {
183184 ESP_LOGD (TAG , "%s, %s: returned event = 0x%x" , inst -> descr .parent_name , __func__ , (int )rcv_event );
184185 if (!(rcv_event & MB_EVENT_REQ_MASK )) {
185186 // if we wait for certain event bits but get from poll subset
186187 ESP_LOGE (TAG , "%s, %s: incorrect event set = 0x%x" , inst -> descr .parent_name , __func__ , (int )rcv_event );
187188 }
188189 if (MB_PORT_CHECK_EVENT (rcv_event , EV_ERROR_OK )) {
190+ // Just to check if abnormal state is detected (multiple errors are active). Should not happen in normal FSM handling.
191+ if (MB_PORT_CHECK_EVENT (rcv_event , (EV_ERROR_RECEIVE_DATA | EV_ERROR_RESPOND_TIMEOUT | EV_ERROR_EXECUTE_FUNCTION ))) {
192+ ESP_LOGD (TAG , "%s, %s: multiple errors detected? = 0x%x, clear." , inst -> descr .parent_name , __func__ , (int )rcv_event );
193+ MB_PORT_CLEAR_EVENT (rcv_event , (EV_ERROR_RECEIVE_DATA | EV_ERROR_RESPOND_TIMEOUT | EV_ERROR_EXECUTE_FUNCTION ));
194+ }
189195 err_status = MB_ENOERR ;
190196 } else if (MB_PORT_CHECK_EVENT (rcv_event , EV_ERROR_RESPOND_TIMEOUT )) {
197+ if (MB_PORT_CHECK_EVENT (rcv_event , (EV_ERROR_RECEIVE_DATA | EV_ERROR_OK | EV_ERROR_EXECUTE_FUNCTION ))) {
198+ ESP_LOGD (TAG , "%s, %s: multiple errors detected? = 0x%x, clear." , inst -> descr .parent_name , __func__ , (int )rcv_event );
199+ MB_PORT_CLEAR_EVENT (rcv_event , (EV_ERROR_RECEIVE_DATA | EV_ERROR_OK | EV_ERROR_EXECUTE_FUNCTION ));
200+ }
191201 err_status = MB_ETIMEDOUT ;
192202 } else if (MB_PORT_CHECK_EVENT (rcv_event , EV_ERROR_RECEIVE_DATA )) {
203+ if (MB_PORT_CHECK_EVENT (rcv_event , (EV_ERROR_RESPOND_TIMEOUT | EV_ERROR_OK | EV_ERROR_EXECUTE_FUNCTION ))) {
204+ ESP_LOGD (TAG , "%s, %s: multiple errors detected? = 0x%x, clear." , inst -> descr .parent_name , __func__ , (int )rcv_event );
205+ MB_PORT_CLEAR_EVENT (rcv_event , (EV_ERROR_RESPOND_TIMEOUT | EV_ERROR_OK | EV_ERROR_EXECUTE_FUNCTION ));
206+ }
193207 err_status = MB_ERECVDATA ;
194208 } else if (MB_PORT_CHECK_EVENT (rcv_event , EV_ERROR_EXECUTE_FUNCTION )) {
209+ if (MB_PORT_CHECK_EVENT (rcv_event , (EV_ERROR_RECEIVE_DATA | EV_ERROR_OK | EV_ERROR_RESPOND_TIMEOUT ))) {
210+ ESP_LOGD (TAG , "%s, %s: multiple errors detected? = 0x%x, clear." , inst -> descr .parent_name , __func__ , (int )rcv_event );
211+ MB_PORT_CLEAR_EVENT (rcv_event , (EV_ERROR_RECEIVE_DATA | EV_ERROR_OK | EV_ERROR_RESPOND_TIMEOUT ));
212+ }
195213 err_status = MB_EILLFUNC ;
196214 }
197215 } else {
0 commit comments