halui: clear the MDI flag in the same pass that restores the mode - #4605
Merged
Merged
Conversation
When a halui MDI command finishes, modify_hal_pins() restores the Task mode that was active before it, then clears halui_sent_mdi. Both steps tested emcStatus->status == DONE separately, but the restore goes through emcCommandSend(), which refreshes emcStatus while it waits for the echo. If Task echoes the restore while still reporting EXEC, the restore fires and the clear is skipped. The stale flag makes the next sendMdiCommand() keep the old halui_old_mode instead of recording the current mode, so halui later restores the wrong mode. In tests/halui/mdi this shows up as "timeout waiting for task mode to get to 3 (it's 2)" (reported by Bertho in LinuxCNC#4604) or "get to 2 (it's 1)", depending on which restore the Task stall hits. Take the DONE decision once, before the restore, and use it for both steps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4604.
When a halui MDI command finishes,
modify_hal_pins()restores the Task mode that was active before it and then clearshalui_sent_mdi. The two steps testedemcStatus->status == DONEseparately. The restore goes throughemcCommandSend(), which refreshesemcStatuswhile waiting for the echo, so if Task echoes the restore while still reporting EXEC, the restore fires but the clear is skipped.With the flag left set, the next
sendMdiCommand()does not record the current mode and keeps the previoushalui_old_mode. In the #4604 log that is what happened: MDI command 1 ran from AUTO, the test then switched to MDI and ran command 2, and when command 2 finished halui restored AUTO (theSET_MODEwith serial +13). The test then timed out waiting for MDI.A stuck flag does not have to leave extra commands in the log:
sendAuto()is a no-op when the mode is already AUTO, and a DONE seen at that point clears the flag silently. The failure needs Task to report EXEC from the restore until the next MDI command is triggered, which is what the 161 ms Task stall in the CI log provides. That also explains why the test passes under plain CPU load.The fix takes the DONE decision once, before the restore, and uses it for both steps.
Testing: I reproduced this deterministically with a local, not-for-merge patch that makes Task report EXEC for a set time after each
EMC_TASK_SET_MODE:g0 y2, +13 SET_MODE 2); with the fix 5/5 pass.tests/haluipasses without the injection.