]> git.feebdaed.xyz Git - 0xmirror/SOEM.git/commitdiff
Fix ecx_mbxreceive for non-cyclic mailbox handler
authorHans-Erik Floryd <hans-erik.floryd@rt-labs.com>
Thu, 10 Jul 2025 14:20:10 +0000 (16:20 +0200)
committerHans-Erik Floryd <hans-erik.floryd@rt-labs.com>
Fri, 11 Jul 2025 09:28:30 +0000 (11:28 +0200)
mbx was not assigned when mailbox was successfully read in non-cyclic
mailbox handler mode.

Change-Id: I282eaf373b63e4f2ad22d5fa74c9e6f8731ed47d

src/ec_main.c

index 5df3100759790131b468a7444094a6be07990f95..df1acbded2576600fc30befd4995fab8cc1340cb 100644 (file)
@@ -1720,31 +1720,33 @@ int ecx_mbxreceive(ecx_contextt *context, uint16 slave, ec_mbxbuft **mbx, int ti
                   mbxin = NULL;
                }
             }
-            else
+            else if (wkc > 0)
+            {
+               *mbx = mbxin;
+               mbxin = NULL;
+            }
+            else /* read mailbox lost */
             {
-               if (wkc <= 0) /* read mailbox lost */
+               do /* read extended mailbox status */
                {
-                  do /* read extended mailbox status */
-                  {
-                     wkc2 = ecx_readmbxstatusex(context, slave, &SMstatex);
-                  } while ((wkc2 <= 0) && (osal_timer_is_expired(&timer) == FALSE));
-                  SMstatex ^= 0x0200; /* toggle repeat request */
-                  SMstatex = htoes(SMstatex);
-                  wkc2 = ecx_FPWR(&context->port, configadr, ECT_REG_SM1STAT, sizeof(SMstatex), &SMstatex, EC_TIMEOUTRET);
-                  SMstatex = etohs(SMstatex);
-                  do /* wait for toggle ack */
-                  {
-                     wkc2 = ecx_FPRD(&context->port, configadr, ECT_REG_SM1CONTR, sizeof(SMcontr), &SMcontr, EC_TIMEOUTRET);
-                  } while (((wkc2 <= 0) || ((SMcontr & 0x02) != (HI_BYTE(SMstatex) & 0x02))) && (osal_timer_is_expired(&timer) == FALSE));
-                  do /* wait for read mailbox available */
+                  wkc2 = ecx_readmbxstatusex(context, slave, &SMstatex);
+               } while ((wkc2 <= 0) && (osal_timer_is_expired(&timer) == FALSE));
+               SMstatex ^= 0x0200; /* toggle repeat request */
+               SMstatex = htoes(SMstatex);
+               wkc2 = ecx_FPWR(&context->port, configadr, ECT_REG_SM1STAT, sizeof(SMstatex), &SMstatex, EC_TIMEOUTRET);
+               SMstatex = etohs(SMstatex);
+               do /* wait for toggle ack */
+               {
+                  wkc2 = ecx_FPRD(&context->port, configadr, ECT_REG_SM1CONTR, sizeof(SMcontr), &SMcontr, EC_TIMEOUTRET);
+               } while (((wkc2 <= 0) || ((SMcontr & 0x02) != (HI_BYTE(SMstatex) & 0x02))) && (osal_timer_is_expired(&timer) == FALSE));
+               do /* wait for read mailbox available */
+               {
+                  wkc2 = ecx_readmbxstatusex(context, slave, &SMstatex);
+                  if (((SMstatex & 0x08) == 0) && (timeout > EC_LOCALDELAY))
                   {
-                     wkc2 = ecx_readmbxstatusex(context, slave, &SMstatex);
-                     if (((SMstatex & 0x08) == 0) && (timeout > EC_LOCALDELAY))
-                     {
-                        osal_usleep(EC_LOCALDELAY);
-                     }
-                  } while (((wkc2 <= 0) || ((SMstatex & 0x08) == 0)) && (osal_timer_is_expired(&timer) == FALSE));
-               }
+                     osal_usleep(EC_LOCALDELAY);
+                  }
+               } while (((wkc2 <= 0) || ((SMstatex & 0x08) == 0)) && (osal_timer_is_expired(&timer) == FALSE));
             }
          } while ((wkc <= 0) && (osal_timer_is_expired(&timer) == FALSE)); /* if WKC<=0 repeat */
          if (mbxin) ecx_dropmbx(context, mbxin);