Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed timing-dependent hang with M5 #282

Merged
merged 1 commit into from
Feb 8, 2022
Merged

Fixed timing-dependent hang with M5 #282

merged 1 commit into from
Feb 8, 2022

Conversation

MitchBradley
Copy link
Collaborator

Under hard-to-predict conditions, M5 will hang the system. Here is the analysis:

void protocol_auto_cycle_start() {
    if (plan_get_current_block() != NULL) {  // Check if there are any blocks in the buffer.
        rtCycleStart = true;                 // If so, execute them!
    }
}
void protocol_buffer_synchronize() {
    // If system is queued, ensure cycle resumes if the auto start flag is present.
    protocol_auto_cycle_start();
    do {
        pollChannels();
        protocol_execute_realtime();  // Check and execute run-time commands
        if (sys.abort) {
            return;  // Check for system abort
        }
    } while (plan_get_current_block() || (sys.state == State::Cycle));
}

Before the loop, protocol_auto_cycle_start() is called to make things run if there is anything in the planner.
Then the stepper runs and, if the segment is short, it might just finish with it by the time protocol_execute_realtime() is called, and if so, protocol_execute_realtime will see the rtCycleStop and set state to Idle.
The while will not exit the loop because plan_get_current_block() is still returning non-null, i.e. there are some planner blocks left. But since we are in idle state, there is no way to run them.
If you move the protocol_auto_cycle_start() inside the loop, it works.

@MitchBradley MitchBradley merged commit ccbb98f into main Feb 8, 2022
@MitchBradley MitchBradley deleted the M5Hang branch February 8, 2022 00:30
MitchBradley added a commit that referenced this pull request Feb 8, 2022
MitchBradley added a commit that referenced this pull request Feb 24, 2022
* Fixed timing-dependent hang with M5 (#282)

* fix wifi+bt startup crash

Co-authored-by: bdring <barton.dring@gmail.com>
Co-authored-by: Mitch Bradley <wmb@firmworks.com>
Co-authored-by: Sergey Averin <xek@ozon.ru>
atlaste pushed a commit to atlaste/FluidNC that referenced this pull request Jul 21, 2022
atlaste pushed a commit to atlaste/FluidNC that referenced this pull request Jul 21, 2022
* Fixed timing-dependent hang with M5 (bdring#282)

* fix wifi+bt startup crash

Co-authored-by: bdring <barton.dring@gmail.com>
Co-authored-by: Mitch Bradley <wmb@firmworks.com>
Co-authored-by: Sergey Averin <xek@ozon.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant